Skip to content

Commit

Permalink
Migrate components to MUI v5 with sx/styled API
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilhelm Herbrich committed Sep 18, 2023
1 parent fb9634c commit c5603a4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 57 deletions.
18 changes: 14 additions & 4 deletions src/components/WorkspaceAddButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class WorkspaceAddButton extends Component {
*/
render() {
const {
classes, t, setWorkspaceAddVisibility, isWorkspaceAddVisible, useExtendedFab,
t, setWorkspaceAddVisibility, isWorkspaceAddVisible, useExtendedFab,
} = this.props;
return (
<Tooltip title={isWorkspaceAddVisible ? t('closeAddResourceMenu') : t('addResource')}>
Expand All @@ -28,8 +28,19 @@ export class WorkspaceAddButton extends Component {
? t('closeAddResourceMenu')
: ((useExtendedFab && t('startHere')) || t('addResource'))
}
className={classes.fab}
classes={{ primary: classes.fabPrimary, secondary: classes.fabSecondary }}
sx={{
'.MuiFab-primary': {
'&:focus': {
backgroundColor: 'primary.dark',
},
},
'.MuiFab-secondary': {
'&:focus': {
backgroundColor: 'secondary.dark',
},
},
margin: 1,
}}
variant={useExtendedFab ? 'extended' : 'circular'}
onClick={() => { setWorkspaceAddVisibility(!isWorkspaceAddVisible); }}
>
Expand All @@ -46,7 +57,6 @@ export class WorkspaceAddButton extends Component {
}

WorkspaceAddButton.propTypes = {
classes: PropTypes.objectOf(PropTypes.string).isRequired,
isWorkspaceAddVisible: PropTypes.bool,
setWorkspaceAddVisibility: PropTypes.func.isRequired,
t: PropTypes.func,
Expand Down
24 changes: 18 additions & 6 deletions src/components/WorkspaceArea.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { styled, lighten, darken } from '@mui/material/styles';
import ErrorDialog from '../containers/ErrorDialog';
import WorkspaceControlPanel from '../containers/WorkspaceControlPanel';
import Workspace from '../containers/Workspace';
import WorkspaceAdd from '../containers/WorkspaceAdd';
import BackgroundPluginArea from '../containers/BackgroundPluginArea';
import ns from '../config/css-ns';

const StyledMain = styled('main')(({ theme }) => {
const getBackgroundColor = theme.palette.mode === 'light' ? darken : lighten;

return {
background: getBackgroundColor(theme.palette.shades.light, 0.1),
bottom: 0,
left: 0,
overflow: 'hidden',
position: 'absolute',
right: 0,
top: 0,
};
});

/**
* This is the top level Mirador component.
* @prop {Object} manifests
Expand All @@ -20,7 +34,6 @@ export class WorkspaceArea extends Component {
render() {
const {
areaRef,
classes,
controlPanelVariant,
isWorkspaceAddVisible,
isWorkspaceControlPanelVisible,
Expand All @@ -34,8 +47,8 @@ export class WorkspaceArea extends Component {
isWorkspaceControlPanelVisible
&& <WorkspaceControlPanel variant={controlPanelVariant} />
}
<main
className={classNames(classes.viewer, ns('viewer'))}
<StyledMain
className={ns('viewer')}
lang={lang}
aria-label={t('workspace')}
{...(areaRef ? { ref: areaRef } : {})}
Expand All @@ -47,15 +60,14 @@ export class WorkspaceArea extends Component {
}
<ErrorDialog />
<BackgroundPluginArea />
</main>
</StyledMain>
</>
);
}
}

WorkspaceArea.propTypes = {
areaRef: PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
classes: PropTypes.objectOf(PropTypes.string).isRequired,
controlPanelVariant: PropTypes.string,
isWorkspaceAddVisible: PropTypes.bool,
isWorkspaceControlPanelVisible: PropTypes.bool.isRequired,
Expand Down
23 changes: 0 additions & 23 deletions src/containers/WorkspaceAddButton.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { connect } from 'react-redux';
import { compose } from 'redux';
import { withTranslation } from 'react-i18next';
import withStyles from '@mui/styles/withStyles';
import { useTheme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import { withPlugins } from '../extend/withPlugins';
Expand Down Expand Up @@ -57,30 +56,8 @@ const mapStateToProps = (state, { width }) => {
*/
const mapDispatchToProps = { setWorkspaceAddVisibility: actions.setWorkspaceAddVisibility };

/**
*
* @param theme
* @returns {{ctrlBtn: {margin: (number|string)}}}
*/
const styles = theme => ({
fab: {
margin: theme.spacing(1),
},
fabPrimary: {
'&:focus': {
backgroundColor: theme.palette.primary.dark,
},
},
fabSecondary: {
'&:focus': {
backgroundColor: theme.palette.secondary.dark,
},
},
});

const enhance = compose(
withTranslation(),
withStyles(styles),
withWidth({ initialWidth: 'xs' }),
connect(mapStateToProps, mapDispatchToProps),
withPlugins('WorkspaceAddButton'),
Expand Down
24 changes: 0 additions & 24 deletions src/containers/WorkspaceArea.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { compose } from 'redux';
import { connect } from 'react-redux';
import { withTranslation } from 'react-i18next';
import { lighten, darken } from '@mui/material/styles';
import withStyles from '@mui/styles/withStyles';
import { withPlugins } from '../extend/withPlugins';
import { WorkspaceArea } from '../components/WorkspaceArea';
import { getConfig, getWindowIds, getWorkspace } from '../state/selectors';
Expand All @@ -21,30 +19,8 @@ const mapStateToProps = state => (
}
);

/**
*
* @param theme
* @returns {{background: {background: string}}}
*/
const styles = (theme) => {
const getBackgroundColor = theme.palette.mode === 'light' ? darken : lighten;

return {
viewer: {
background: getBackgroundColor(theme.palette.shades.light, 0.1),
bottom: 0,
left: 0,
overflow: 'hidden',
position: 'absolute',
right: 0,
top: 0,
},
};
};

const enhance = compose(
withTranslation(),
withStyles(styles),
connect(mapStateToProps),
withPlugins('WorkspaceArea'),
);
Expand Down

0 comments on commit c5603a4

Please sign in to comment.