Skip to content
Snippets Groups Projects
Commit 589a51eb authored by Chris Beer's avatar Chris Beer
Browse files

Trim wrapping divs where possible

parent 2250f69a
No related branches found
No related tags found
1 merge request!19Draft: Merge video support into mui5
import { Component, lazy, Suspense } from 'react'; import { Component, lazy, Suspense } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { styled } from '@mui/material/styles'; import { styled } from '@mui/material/styles';
import classNames from 'classnames';
import WindowSideBar from '../containers/WindowSideBar'; import WindowSideBar from '../containers/WindowSideBar';
import CompanionArea from '../containers/CompanionArea'; import CompanionArea from '../containers/CompanionArea';
import CollectionDialog from '../containers/CollectionDialog'; import CollectionDialog from '../containers/CollectionDialog';
...@@ -16,7 +17,7 @@ GalleryView.displayName = 'GalleryView'; ...@@ -16,7 +17,7 @@ GalleryView.displayName = 'GalleryView';
SelectCollection.displayName = 'SelectCollection'; SelectCollection.displayName = 'SelectCollection';
WindowViewer.displayName = 'WindowViewer'; WindowViewer.displayName = 'WindowViewer';
const StyledPrimaryWindowContainer = styled('div')(() => ({ const Root = styled('div', { name: 'PrimaryWindow', slot: 'root' })(() => ({
display: 'flex', display: 'flex',
flex: 1, flex: 1,
position: 'relative', position: 'relative',
...@@ -80,17 +81,18 @@ export class PrimaryWindow extends Component { ...@@ -80,17 +81,18 @@ export class PrimaryWindow extends Component {
*/ */
render() { render() {
const { const {
isCollectionDialogVisible, windowId, children, isCollectionDialogVisible, windowId, children, className,
} = this.props; } = this.props;
return ( return (
<StyledPrimaryWindowContainer data-testid="test-window" className={ns('primary-window')}> <Root data-testid="test-window" className={classNames(ns('primary-window'), className)}>
<WindowSideBar windowId={windowId} /> <WindowSideBar windowId={windowId} />
<CompanionArea windowId={windowId} position="left" /> <CompanionArea windowId={windowId} position="left" />
{ isCollectionDialogVisible && <CollectionDialog windowId={windowId} /> } { isCollectionDialogVisible && <CollectionDialog windowId={windowId} /> }
<Suspense fallback={<div />}> <Suspense fallback={<div />}>
{children || this.renderViewer()} {children || this.renderViewer()}
</Suspense> </Suspense>
</StyledPrimaryWindowContainer> </Root>
); );
} }
} }
...@@ -98,6 +100,7 @@ export class PrimaryWindow extends Component { ...@@ -98,6 +100,7 @@ export class PrimaryWindow extends Component {
PrimaryWindow.propTypes = { PrimaryWindow.propTypes = {
audioResources: PropTypes.arrayOf(PropTypes.object), // eslint-disable-line react/forbid-prop-types audioResources: PropTypes.arrayOf(PropTypes.object), // eslint-disable-line react/forbid-prop-types
children: PropTypes.node, children: PropTypes.node,
className: PropTypes.string,
isCollection: PropTypes.bool, isCollection: PropTypes.bool,
isCollectionDialogVisible: PropTypes.bool, isCollectionDialogVisible: PropTypes.bool,
isFetching: PropTypes.bool, isFetching: PropTypes.bool,
...@@ -109,6 +112,7 @@ PrimaryWindow.propTypes = { ...@@ -109,6 +112,7 @@ PrimaryWindow.propTypes = {
PrimaryWindow.defaultProps = { PrimaryWindow.defaultProps = {
audioResources: [], audioResources: [],
children: undefined, children: undefined,
className: undefined,
isCollection: false, isCollection: false,
isCollectionDialogVisible: false, isCollectionDialogVisible: false,
isFetching: false, isFetching: false,
......
import { Component } from 'react'; import { Component, useContext } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { styled } from '@mui/material/styles'; import { styled } from '@mui/material/styles';
import Paper from '@mui/material/Paper'; import Paper from '@mui/material/Paper';
...@@ -12,13 +12,25 @@ import ErrorContent from '../containers/ErrorContent'; ...@@ -12,13 +12,25 @@ import ErrorContent from '../containers/ErrorContent';
import IIIFAuthentication from '../containers/IIIFAuthentication'; import IIIFAuthentication from '../containers/IIIFAuthentication';
import { PluginHook } from './PluginHook'; import { PluginHook } from './PluginHook';
const rowMixin = {
display: 'flex',
flex: '1',
flexDirection: 'row',
minHeight: 0,
};
const columnMixin = {
display: 'flex',
flex: '1',
flexDirection: 'column',
minHeight: 0,
};
const Root = styled(Paper)(({ ownerState, theme }) => ({ const Root = styled(Paper)(({ ownerState, theme }) => ({
...columnMixin,
backgroundColor: theme.palette.shades?.dark, backgroundColor: theme.palette.shades?.dark,
borderRadius: 0, borderRadius: 0,
display: 'flex',
flexDirection: 'column',
height: '100%', height: '100%',
minHeight: 0,
overflow: 'hidden', overflow: 'hidden',
width: '100%', width: '100%',
...(ownerState?.maximized && { ...(ownerState?.maximized && {
...@@ -29,41 +41,39 @@ const Root = styled(Paper)(({ ownerState, theme }) => ({ ...@@ -29,41 +41,39 @@ const Root = styled(Paper)(({ ownerState, theme }) => ({
}), }),
})); }));
const StyledMiddle = styled('div')(() => ({ const ContentRow = styled('div')(() => ({
display: 'flex', ...rowMixin,
flex: '1',
flexDirection: 'row',
minHeight: 0,
})); }));
const StyledMiddleLeft = styled('div')(() => ({ const ContentColumn = styled('div')(() => ({
display: 'flex', ...columnMixin,
flex: '1',
flexDirection: 'column',
minHeight: 0,
})); }));
const StyledPrimaryWindow = styled('div')(() => ({ const StyledPrimaryWindow = styled(PrimaryWindow)(() => ({
display: 'flex', ...rowMixin,
flex: '1',
height: '300px', height: '300px',
minHeight: 0,
position: 'relative', position: 'relative',
})); }));
const StyledCompanionAreaBottom = styled('div')(() => ({ const StyledCompanionAreaBottom = styled(CompanionArea)(() => ({
display: 'flex', ...rowMixin,
flex: '0', flex: '0',
flexBasis: 'auto', flexBasis: 'auto',
minHeight: 0,
})); }));
const StyledCompanionAreaRight = styled('div')(() => ({ const StyledCompanionAreaRight = styled('div')(() => ({
display: 'flex', ...rowMixin,
flex: '0 1 auto', flex: '0 1 auto',
minHeight: 0,
})); }));
/** Window title bar wrapper for drag controls in the mosaic view */
const DraggableNavBar = ({ children, ...props }) => {
const { mosaicWindowActions } = useContext(MosaicWindowContext);
return mosaicWindowActions.connectDragSource(
<nav {...props}>{children}</nav>,
);
};
/** /**
* Represents a Window in the mirador workspace * Represents a Window in the mirador workspace
* @param {object} window * @param {object} window
...@@ -81,40 +91,13 @@ export class Window extends Component { ...@@ -81,40 +91,13 @@ export class Window extends Component {
return { error, hasError: true }; return { error, hasError: true };
} }
/**
* wrappedTopBar - will conditionally wrap a WindowTopBar for needed
* additional functionality based on workspace type
*/
wrappedTopBar() {
const {
windowId, workspaceType, windowDraggable,
} = this.props;
const topBar = (
<div>
<WindowTopBar
windowId={windowId}
windowDraggable={windowDraggable}
/>
<IIIFAuthentication windowId={windowId} />
</div>
);
if (workspaceType === 'mosaic' && windowDraggable) {
const { mosaicWindowActions } = this.context;
return mosaicWindowActions.connectDragSource(
topBar,
);
}
return topBar;
}
/** /**
* Renders things * Renders things
*/ */
render() { render() {
const { const {
focusWindow, label, isFetching, sideBarOpen, focusWindow, label, isFetching, sideBarOpen,
view, windowId, t, view, windowDraggable, windowId, workspaceType, t,
manifestError, manifestError,
} = this.props; } = this.props;
...@@ -138,27 +121,28 @@ export class Window extends Component { ...@@ -138,27 +121,28 @@ export class Window extends Component {
className={ns('window')} className={ns('window')}
aria-label={t('window', { label })} aria-label={t('window', { label })}
> >
{this.wrappedTopBar()} <WindowTopBar
component={workspaceType === 'mosaic' && windowDraggable ? DraggableNavBar : undefined}
windowId={windowId}
windowDraggable={windowDraggable}
/>
<IIIFAuthentication windowId={windowId} />
{ manifestError && <ErrorContent error={{ stack: manifestError }} windowId={windowId} /> } { manifestError && <ErrorContent error={{ stack: manifestError }} windowId={windowId} /> }
<StyledMiddle> <ContentRow>
<StyledMiddleLeft> <ContentColumn>
<StyledPrimaryWindow> <StyledPrimaryWindow
<PrimaryWindow
view={view} view={view}
windowId={windowId} windowId={windowId}
isFetching={isFetching} isFetching={isFetching}
sideBarOpen={sideBarOpen} sideBarOpen={sideBarOpen}
/> />
</StyledPrimaryWindow> <StyledCompanionAreaBottom windowId={windowId} position="bottom" />
<StyledCompanionAreaBottom> </ContentColumn>
<CompanionArea windowId={windowId} position="bottom" />
</StyledCompanionAreaBottom>
</StyledMiddleLeft>
<StyledCompanionAreaRight> <StyledCompanionAreaRight>
<CompanionArea windowId={windowId} position="right" /> <CompanionArea windowId={windowId} position="right" />
<CompanionArea windowId={windowId} position="far-right" /> <CompanionArea windowId={windowId} position="far-right" />
</StyledCompanionAreaRight> </StyledCompanionAreaRight>
</StyledMiddle> </ContentRow>
<CompanionArea windowId={windowId} position="far-bottom" /> <CompanionArea windowId={windowId} position="far-bottom" />
<PluginHook {...this.props} /> <PluginHook {...this.props} />
</Root> </Root>
......
...@@ -45,10 +45,11 @@ export class WindowTopBar extends Component { ...@@ -45,10 +45,11 @@ export class WindowTopBar extends Component {
removeWindow, windowId, toggleWindowSideBar, t, removeWindow, windowId, toggleWindowSideBar, t,
maximizeWindow, maximized, minimizeWindow, allowClose, allowMaximize, maximizeWindow, maximized, minimizeWindow, allowClose, allowMaximize,
focusWindow, allowFullscreen, allowTopMenuButton, allowWindowSideBar, focusWindow, allowFullscreen, allowTopMenuButton, allowWindowSideBar,
component,
} = this.props; } = this.props;
return ( return (
<Root component="nav" aria-label={t('windowNavigation')} position="relative" color="default" enableColorOnDark> <Root component={component} aria-label={t('windowNavigation')} position="relative" color="default" enableColorOnDark>
<StyledToolbar <StyledToolbar
disableGutters disableGutters
onMouseDown={focusWindow} onMouseDown={focusWindow}
...@@ -106,6 +107,7 @@ WindowTopBar.propTypes = { ...@@ -106,6 +107,7 @@ WindowTopBar.propTypes = {
allowMaximize: PropTypes.bool, allowMaximize: PropTypes.bool,
allowTopMenuButton: PropTypes.bool, allowTopMenuButton: PropTypes.bool,
allowWindowSideBar: PropTypes.bool, allowWindowSideBar: PropTypes.bool,
component: PropTypes.elementType,
focused: PropTypes.bool, // eslint-disable-line react/no-unused-prop-types focused: PropTypes.bool, // eslint-disable-line react/no-unused-prop-types
focusWindow: PropTypes.func, focusWindow: PropTypes.func,
maximized: PropTypes.bool, maximized: PropTypes.bool,
...@@ -124,6 +126,7 @@ WindowTopBar.defaultProps = { ...@@ -124,6 +126,7 @@ WindowTopBar.defaultProps = {
allowMaximize: true, allowMaximize: true,
allowTopMenuButton: true, allowTopMenuButton: true,
allowWindowSideBar: true, allowWindowSideBar: true,
component: 'nav',
focused: false, focused: false,
focusWindow: () => {}, focusWindow: () => {},
maximized: false, maximized: false,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment