Skip to content

Commit

Permalink
refactor :adapt to mui beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Domino987 committed Jul 1, 2021
1 parent 5fda984 commit 7ff8464
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 199 deletions.
214 changes: 93 additions & 121 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@babel/plugin-transform-runtime": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"@babel/preset-react": "^7.12.10",
"@material-ui/core": "^4.11.2",
"@material-ui/core": "^5.0.0-beta.0",
"@types/jest": "^26.0.20",
"@webpack-cli/serve": "^1.2.1",
"@wojtekmaj/enzyme-adapter-react-17": "^0.4.1",
Expand Down Expand Up @@ -101,21 +101,20 @@
},
"dependencies": {
"@babel/runtime": "^7.12.5",
"@date-io/core": "^1.3.13",
"@date-io/date-fns": "^1.3.13",
"@emotion/core": "^11.0.0",
"@emotion/react": "^11.0.0",
"@emotion/styled": "^11.0.0",
"@material-ui/lab": "^5.0.0-alpha.39",
"@material-ui/styles": "^5.0.0-beta.0",
"classnames": "^2.2.6",
"date-fns": "^2.16.1",
"debounce": "^1.2.0",
"fast-deep-equal": "^3.1.3",
"prop-types": "^15.7.2",
"react-beautiful-dnd": "^13.0.0",
"react-double-scrollbar": "0.0.15",
"@date-io/core": "^1.3.13",
"@material-ui/core": "^5.0.0-alpha.36",
"@material-ui/styles": "^5.0.0-alpha.35",
"@material-ui/lab": "^5.0.0-alpha.36",
"@emotion/core": "^11.0.0",
"@emotion/react": "^11.0.0",
"@emotion/styled": "^11.0.0"
"react-double-scrollbar": "0.0.15"
},
"peerDependencies": {
"react": ">=16.8.0",
Expand Down
26 changes: 14 additions & 12 deletions src/components/MTableHeader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import TableCell from '@material-ui/core/TableCell';
import TableSortLabel from '@material-ui/core/TableSortLabel';
import Checkbox from '@material-ui/core/Checkbox';
import { Draggable } from 'react-beautiful-dnd';
import { Tooltip } from '@material-ui/core';
import { withStyles } from '@material-ui/styles';
import { Tooltip, useTheme } from '@material-ui/core';
import { makeStyles } from '@material-ui/styles';
import * as CommonValues from '../../utils/common-values';

export function MTableHeader({ onColumnResized, ...props }) {
const classes = useStyles();
const [
{ resizingColumnDef, lastX, lastAdditionalWidth }, // Extract the props to use instead of the whole state object
setState
Expand Down Expand Up @@ -69,7 +70,7 @@ export function MTableHeader({ onColumnResized, ...props }) {
<TableCell
key="key-actions-column"
padding="checkbox"
className={props.classes.header}
className={classes.header}
style={{
...props.headerStyle,
width: width,
Expand Down Expand Up @@ -236,7 +237,7 @@ export function MTableHeader({ onColumnResized, ...props }) {
<TableCell
key={columnDef.tableData.id}
align={cellAlignment}
className={props.classes.header}
className={classes.header}
style={getCellStyle(columnDef)}
size={size}
>
Expand All @@ -256,7 +257,7 @@ export function MTableHeader({ onColumnResized, ...props }) {
<TableCell
padding="none"
key="key-selection-column"
className={props.classes.header}
className={classes.header}
style={{ ...props.headerStyle, width: selectionWidth }}
>
{props.showSelectAllCheckbox && (
Expand All @@ -282,7 +283,7 @@ export function MTableHeader({ onColumnResized, ...props }) {
<TableCell
padding="none"
key="key-detail-panel-column"
className={props.classes.header}
className={classes.header}
style={{ ...props.headerStyle }}
/>
);
Expand Down Expand Up @@ -322,7 +323,7 @@ export function MTableHeader({ onColumnResized, ...props }) {
<TableCell
padding="none"
key={'key-tree-data-header'}
className={props.classes.header}
className={classes.header}
style={{ ...props.headerStyle }}
/>
);
Expand All @@ -336,7 +337,7 @@ export function MTableHeader({ onColumnResized, ...props }) {
<TableCell
padding="checkbox"
key={'key-group-header' + columnDef.tableData.id}
className={props.classes.header}
className={classes.header}
/>
);
});
Expand Down Expand Up @@ -391,18 +392,19 @@ MTableHeader.propTypes = {
tooltip: PropTypes.string
};

export const styles = (theme) => ({
export const useStyles = makeStyles((theme) => ({
header: {
// display: 'inline-block',
position: 'sticky',
top: 0,
zIndex: 10,
backgroundColor: theme.palette.background.paper // Change according to theme,
}
});
}));

const MTableHeaderRef = React.forwardRef(function MTableHeaderRef(props, ref) {
return <MTableHeader {...props} forwardedRef={ref} />;
const theme = useTheme();
return <MTableHeader theme={theme} {...props} forwardedRef={ref} />;
});

export default withStyles(styles, { withTheme: true })(MTableHeaderRef);
export default MTableHeaderRef;
22 changes: 8 additions & 14 deletions src/components/MTablePagination/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/* eslint-disable no-unused-vars */
import IconButton from '@material-ui/core/IconButton';
import { withStyles } from '@material-ui/styles';
import { makeStyles } from '@material-ui/styles';
import Tooltip from '@material-ui/core/Tooltip';
import Typography from '@material-ui/core/Typography';
import PropTypes from 'prop-types';
import React from 'react';
import { useTheme } from '@material-ui/core';
/* eslint-enable no-unused-vars */

function MTablePagination(props) {
const classes = useStyles();
const theme = useTheme();
const handleFirstPageButtonClick = (event) => {
props.onPageChange(event, 0);
};
Expand All @@ -28,14 +31,7 @@ function MTablePagination(props) {
};

function render() {
const {
classes,
count,
page,
rowsPerPage,
theme,
showFirstLastPageButtons
} = props;
const { count, page, rowsPerPage, showFirstLastPageButtons } = props;

const localization = {
...MTablePagination.defaultProps.localization,
Expand Down Expand Up @@ -135,14 +131,14 @@ function MTablePagination(props) {
return render();
}

const actionsStyles = (theme) => ({
const useStyles = makeStyles((theme) => ({
root: {
flexShrink: 0,
color: theme.palette.text.secondary,
display: 'flex'
// lineHeight: '48px'
}
});
}));

MTablePagination.propTypes = {
onChangePage: PropTypes.func,
Expand Down Expand Up @@ -178,8 +174,6 @@ const MTableGroupRowRef = React.forwardRef(function MTablePaginationRef(
return <MTablePagination {...props} forwardedRef={ref} />;
});

const MTablePaginationOuter = withStyles(actionsStyles, { withTheme: true })(
MTableGroupRowRef
);
const MTablePaginationOuter = MTableGroupRowRef;

export default MTablePaginationOuter;
22 changes: 8 additions & 14 deletions src/components/MTableSteppedPaginationInner/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import IconButton from '@material-ui/core/IconButton';
import { withStyles } from '@material-ui/styles';
import { makeStyles } from '@material-ui/styles';
import Tooltip from '@material-ui/core/Tooltip';
import Box from '@material-ui/core/Box';
import Button from '@material-ui/core/Button';
import PropTypes from 'prop-types';
import React from 'react';
import { useTheme } from '@material-ui/core';

function MTablePaginationInner(props) {
const classes = useStyles();
const theme = useTheme();
const handleFirstPageButtonClick = (event) => {
props.onPageChange(event, 0);
};
Expand Down Expand Up @@ -58,14 +61,7 @@ function MTablePaginationInner(props) {
}

function render() {
const {
classes,
count,
page,
rowsPerPage,
theme,
showFirstLastPageButtons
} = props;
const { count, page, rowsPerPage, showFirstLastPageButtons } = props;

const localization = {
...MTablePaginationInner.defaultProps.localization,
Expand Down Expand Up @@ -143,13 +139,13 @@ function MTablePaginationInner(props) {
return render();
}

const actionsStyles = (theme) => ({
const useStyles = makeStyles((theme) => ({
root: {
flexShrink: 0,
color: theme.palette.text.secondary,
marginLeft: theme.spacing(2.5)
}
});
}));

MTablePaginationInner.propTypes = {
onPageChange: PropTypes.func,
Expand Down Expand Up @@ -183,8 +179,6 @@ const MTableSteppedPaginationRef = React.forwardRef(
}
);

const MTableSteppedPagination = withStyles(actionsStyles, { withTheme: true })(
MTableSteppedPaginationRef
);
const MTableSteppedPagination = MTableSteppedPaginationRef;

export default MTableSteppedPagination;
5 changes: 1 addition & 4 deletions src/components/MTableSummaryRow/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import { TableRow, TableCell } from '@material-ui/core';
import { withStyles } from '@material-ui/styles';
import { getStyle } from '../MTableCell/utils';
import * as CommonValues from '../../utils/common-values';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -113,6 +112,4 @@ MTableSummaryRow.propTypes = {
renderSummaryRow: PropTypes.func
};

export const styles = (theme) => ({});

export default withStyles(styles)(MTableSummaryRow);
export default MTableSummaryRow;
17 changes: 6 additions & 11 deletions src/components/MTableToolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import Toolbar from '@material-ui/core/Toolbar';
import Tooltip from '@material-ui/core/Tooltip';
import Typography from '@material-ui/core/Typography';
import { lighten } from '@material-ui/core';
import { withStyles } from '@material-ui/styles';
import { makeStyles } from '@material-ui/styles';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';

export function MTableToolbar(props) {
const classes = useStyles();
const [state, setState] = React.useState(() => ({
columnsButtonAnchorEl: null,
exportButtonAnchorEl: null,
Expand Down Expand Up @@ -70,7 +71,7 @@ export function MTableToolbar(props) {
className={
props.searchFieldAlignment === 'left' && props.showTitle === false
? null
: props.classes.searchField
: classes.searchField
}
value={state.searchText}
onChange={(event) => onSearchChange(event.target.value)}
Expand Down Expand Up @@ -115,7 +116,6 @@ export function MTableToolbar(props) {
...MTableToolbar.defaultProps.localization,
...props.localization
};
const { classes } = props;

return (
<div style={{ display: 'flex' }}>
Expand Down Expand Up @@ -258,8 +258,6 @@ export function MTableToolbar(props) {
}

function renderActions() {
const { classes } = props;

return (
<div className={classes.actions}>
<div>
Expand All @@ -272,7 +270,6 @@ export function MTableToolbar(props) {
}

function renderToolbarTitle(title) {
const { classes } = props;
const toolBarTitle =
// eslint-disable-next-line multiline-ternary
typeof title === 'string' ? (
Expand All @@ -294,7 +291,6 @@ export function MTableToolbar(props) {
}

function render() {
const { classes } = props;
const localization = {
...MTableToolbar.defaultProps.localization,
...props.localization
Expand Down Expand Up @@ -390,11 +386,10 @@ MTableToolbar.propTypes = {
handler: PropTypes.func
})
),
classes: PropTypes.object,
searchAutoFocus: PropTypes.bool
};

export const styles = (theme) => ({
export const useStyles = makeStyles((theme) => ({
root: {
paddingRight: theme.spacing(1),
paddingLeft: theme.spacing(2)
Expand Down Expand Up @@ -426,7 +421,7 @@ export const styles = (theme) => ({
paddingLeft: theme.spacing(1),
paddingRight: theme.spacing(1)
}
});
}));

const MTableToolbarRef = React.forwardRef(function MTableToolbarRef(
props,
Expand All @@ -435,4 +430,4 @@ const MTableToolbarRef = React.forwardRef(function MTableToolbarRef(
return <MTableToolbar {...props} forwardedRef={ref} />;
});

export default withStyles(styles)(MTableToolbarRef);
export default MTableToolbarRef;
4 changes: 3 additions & 1 deletion src/components/Overlay/OverlayError.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useTheme } from '@material-ui/core';

function OverlayError(props) {
const theme = useTheme();
return (
<div
ref={props.forwardedRef}
style={{
display: 'table',
width: '100%',
height: '100%',
backgroundColor: props.theme.palette.background.paper,
backgroundColor: theme.palette.background.paper,
opacity: 0.7
}}
>
Expand Down
5 changes: 3 additions & 2 deletions src/components/Overlay/OverlayLoading.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React from 'react';
import PropTypes from 'prop-types';
import { CircularProgress } from '@material-ui/core';
import { CircularProgress, useTheme } from '@material-ui/core';

function OverlayLoading(props) {
const theme = useTheme();
return (
<div
ref={props.forwardedRef}
style={{
display: 'table',
width: '100%',
height: '100%',
backgroundColor: props.theme.palette.background.paper,
backgroundColor: theme.palette.background.paper,
opacity: 0.7
}}
>
Expand Down
Loading

0 comments on commit 7ff8464

Please sign in to comment.