Skip to content

Commit 252df83

Browse files
committed
fix: add @mui/material 7 to peerDependencies
fix #153
1 parent 51a2a4d commit 252df83

File tree

9 files changed

+344
-702
lines changed

9 files changed

+344
-702
lines changed

demo/Demo.js

Lines changed: 52 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,49 @@
11
import * as React from 'react'
2-
import { withStyles } from '@mui/styles'
32
import Code from '@mui/icons-material/Code'
43
import Collapse from '@mui/material/Collapse'
54
import Button from '@mui/material/Button'
65
import IconButton from '@mui/material/IconButton'
76
import Typography from '@mui/material/Typography'
87
import Tooltip from '@mui/material/Tooltip'
8+
import Box from '@mui/material/Box'
99

1010
const { useState, useCallback } = React
1111

12-
const styles = {
13-
title: {
14-
marginTop: 40,
15-
marginBottom: 0,
16-
},
17-
root: {
18-
margin: '20px auto',
19-
},
20-
toolbar: {
21-
display: 'flex',
22-
alignItems: 'center',
23-
},
24-
toolbarSpacer: {
25-
flex: '1 1 auto',
26-
},
27-
code: {
28-
margin: 0,
29-
padding: 20,
30-
backgroundColor: 'white',
31-
borderRadius: 4,
32-
},
33-
example: {
34-
backgroundColor: '#eee',
35-
borderRadius: 4,
36-
display: 'flex',
37-
alignContent: 'center',
38-
alignItems: 'center',
39-
justifyContent: 'center',
40-
padding: 40,
41-
},
42-
titleAnchor: {
43-
color: '#aaa',
44-
marginLeft: 10,
45-
textDecoration: 'none',
46-
visibility: 'hidden',
47-
'$title:hover > &': {
48-
visibility: 'visible',
49-
},
50-
},
51-
}
52-
53-
const Demo = ({
54-
headerId,
55-
classes,
56-
title,
57-
code,
58-
example,
59-
hooksCode,
60-
hooksExample,
61-
}) => {
12+
const Demo = ({ headerId, title, code, example, hooksCode, hooksExample }) => {
6213
const [showSource, setShowSource] = useState(false)
6314
const [api, setApi] = useState('hooks')
6415
const setRenderProps = useCallback(() => setApi('render-props'), [])
6516
const setHooks = useCallback(() => setApi('hooks'), [])
6617
return (
67-
<div className={classes.root}>
68-
<Typography variant="h4" className={classes.title} id={headerId}>
18+
<Box sx={{ margin: '20px auto' }}>
19+
<Typography
20+
variant="h4"
21+
sx={{
22+
marginTop: '40px',
23+
marginBottom: 0,
24+
'&:hover > a': {
25+
visibility: 'visible',
26+
},
27+
}}
28+
id={headerId}
29+
>
6930
{title}
7031
{headerId && (
71-
<a href={`#${headerId}`} className={classes.titleAnchor}>
32+
<Box
33+
component="a"
34+
href={`#${headerId}`}
35+
sx={{
36+
color: '#aaa',
37+
marginLeft: '10px',
38+
textDecoration: 'none',
39+
visibility: 'hidden',
40+
}}
41+
>
7242
#
73-
</a>
43+
</Box>
7444
)}
7545
</Typography>
76-
<div className={classes.toolbar}>
46+
<Box sx={{ display: 'flex', alignItems: 'center' }}>
7747
{code != null && hooksCode != null && (
7848
<React.Fragment>
7949
<Button
@@ -90,23 +60,41 @@ const Demo = ({
9060
</Button>
9161
</React.Fragment>
9262
)}
93-
<div className={classes.toolbarSpacer} />
63+
<Box sx={{ flex: '1 1 auto' }} />
9464
<Tooltip title="Show Source" placement="top">
9565
<IconButton onClick={() => setShowSource(!showSource)} size="large">
9666
<Code />
9767
</IconButton>
9868
</Tooltip>
99-
</div>
69+
</Box>
10070
<Collapse in={showSource}>
101-
<pre className={classes.code}>
71+
<Box
72+
component="pre"
73+
sx={{
74+
margin: 0,
75+
padding: '20px',
76+
backgroundColor: 'white',
77+
borderRadius: '4px',
78+
}}
79+
>
10280
{api === 'hooks' ? hooksCode || code : code || hooksCode}
103-
</pre>
81+
</Box>
10482
</Collapse>
105-
<div className={classes.example}>
83+
<Box
84+
sx={{
85+
backgroundColor: '#eee',
86+
borderRadius: '4px',
87+
display: 'flex',
88+
alignContent: 'center',
89+
alignItems: 'center',
90+
justifyContent: 'center',
91+
padding: '40px',
92+
}}
93+
>
10694
{api === 'hooks' ? hooksExample || example : example || hooksExample}
107-
</div>
108-
</div>
95+
</Box>
96+
</Box>
10997
)
11098
}
11199

112-
export default withStyles(styles)(Demo)
100+
export default Demo

demo/Root.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,16 @@ import ChainingEventHandlers from './examples/ChainingEventHandlers'
4848
import ChainingEventHandlersCode from '!!raw-loader!./examples/ChainingEventHandlers'
4949
import Demo from './Demo'
5050
import Typography from '@mui/material/Typography'
51-
import { withStyles } from '@mui/styles'
51+
import Box from '@mui/material/Box'
5252
import { StyledEngineProvider } from '@mui/material/styles'
5353
import { createTheme, ThemeProvider } from '@mui/material/styles'
5454

5555
const theme = createTheme()
5656

57-
const styles = {
58-
root: {
59-
margin: '0 auto',
60-
maxWidth: 800,
61-
},
62-
}
63-
6457
const Root = ({ classes }) => (
6558
<StyledEngineProvider>
6659
<ThemeProvider theme={theme}>
67-
<div className={classes.root}>
60+
<Box sx={{ margin: '0 auto', maxWidth: 800 }}>
6861
<Typography variant="h3">material-ui-popup-state demos</Typography>
6962
<Demo
7063
title="Left Click to open Menu"
@@ -136,7 +129,6 @@ const Root = ({ classes }) => (
136129
hooksExample={<HoverFocusMenuHooks />}
137130
hooksCode={HoverFocusMenuHooksCode}
138131
/>
139-
140132
<Demo
141133
title="Custom Anchor"
142134
headerId="custom-anchor"
@@ -165,9 +157,9 @@ const Root = ({ classes }) => (
165157
example={<ChainingEventHandlers />}
166158
code={ChainingEventHandlersCode}
167159
/>
168-
</div>
160+
</Box>
169161
</ThemeProvider>
170162
</StyledEngineProvider>
171163
)
172164

173-
export default withStyles(styles)(Root)
165+
export default Root

demo/examples/CascadingHoverMenus.hooks.js

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
11
import * as React from 'react'
2-
import { makeStyles } from '@mui/styles'
32
import HoverMenu from 'material-ui-popup-state/HoverMenu'
43
import MenuItem from '@mui/material/MenuItem'
54
import ChevronRight from '@mui/icons-material/ChevronRight'
65
import Button from '@mui/material/Button'
6+
import Box from '@mui/material/Box'
77
import {
88
usePopupState,
99
bindHover,
1010
bindFocus,
1111
bindMenu,
1212
} from 'material-ui-popup-state/hooks'
1313

14-
const useCascadingMenuStyles = makeStyles((theme) => ({
15-
submenu: {
16-
marginTop: theme.spacing(-1),
17-
},
18-
title: {
19-
flexGrow: 1,
20-
},
21-
moreArrow: {
22-
marginRight: theme.spacing(-1),
23-
},
24-
}))
25-
2614
const CascadingContext = React.createContext({
2715
parentPopupState: null,
2816
rootPopupState: null,
@@ -43,7 +31,6 @@ function CascadingMenuItem({ onClick, ...props }) {
4331
}
4432

4533
function CascadingSubmenu({ title, popupId, ...props }) {
46-
const classes = useCascadingMenuStyles()
4734
const { parentPopupState } = React.useContext(CascadingContext)
4835
const popupState = usePopupState({
4936
popupId,
@@ -53,12 +40,16 @@ function CascadingSubmenu({ title, popupId, ...props }) {
5340
return (
5441
<React.Fragment>
5542
<MenuItem {...bindHover(popupState)} {...bindFocus(popupState)}>
56-
<span className={classes.title}>{title}</span>
57-
<ChevronRight className={classes.moreArrow} />
43+
<Box component="span" sx={{ flexGrow: 1 }}>
44+
{title}
45+
</Box>
46+
<ChevronRight sx={{ marginRight: -1 }} />
5847
</MenuItem>
5948
<CascadingMenu
6049
{...props}
61-
classes={{ ...props.classes, paper: classes.submenu }}
50+
slotProps={{
51+
paper: { sx: { marginTop: -1 } },
52+
}}
6253
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
6354
transformOrigin={{ vertical: 'top', horizontal: 'left' }}
6455
popupState={popupState}

demo/examples/CascadingHoverMenus.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
import * as React from 'react'
2-
import { makeStyles } from '@mui/styles'
2+
import HoverMenu from 'material-ui-popup-state/HoverMenu'
33
import MenuItem from '@mui/material/MenuItem'
44
import ChevronRight from '@mui/icons-material/ChevronRight'
55
import Button from '@mui/material/Button'
6+
import Box from '@mui/material/Box'
67
import PopupState, { bindHover, bindMenu } from 'material-ui-popup-state'
7-
import HoverMenu from 'material-ui-popup-state/HoverMenu'
8-
9-
const useCascadingMenuStyles = makeStyles((theme) => ({
10-
submenu: {
11-
marginTop: theme.spacing(-1),
12-
},
13-
title: {
14-
flexGrow: 1,
15-
},
16-
moreArrow: {
17-
marginRight: theme.spacing(-1),
18-
},
19-
}))
208

219
const CascadingContext = React.createContext({
2210
parentPopupState: null,
@@ -38,7 +26,6 @@ function CascadingMenuItem({ onClick, ...props }) {
3826
}
3927

4028
function CascadingSubmenu({ title, popupId, ...props }) {
41-
const classes = useCascadingMenuStyles()
4229
const { parentPopupState } = React.useContext(CascadingContext)
4330
return (
4431
<PopupState
@@ -50,12 +37,16 @@ function CascadingSubmenu({ title, popupId, ...props }) {
5037
{(popupState) => (
5138
<React.Fragment>
5239
<MenuItem {...bindHover(popupState)}>
53-
<span className={classes.title}>{title}</span>
54-
<ChevronRight className={classes.moreArrow} />
40+
<Box component="span" sx={{ flexGrow: 1 }}>
41+
{title}
42+
</Box>
43+
<ChevronRight sx={{ marginRight: -1 }} />
5544
</MenuItem>
5645
<CascadingMenu
5746
{...props}
58-
classes={{ ...props.classes, paper: classes.submenu }}
47+
slotProps={{
48+
paper: { sx: { marginTop: -1 } },
49+
}}
5950
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
6051
transformOrigin={{ vertical: 'top', horizontal: 'left' }}
6152
popupState={popupState}

demo/examples/CustomAnchor.hooks.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import MenuItem from '@mui/material/MenuItem'
55
import Paper from '@mui/material/Paper'
66
import Typography from '@mui/material/Typography'
77
import List from '@mui/material/List'
8-
import ListItem from '@mui/material/ListItem'
8+
import ListItemButton from '@mui/material/ListItemButton'
99
import ListItemText from '@mui/material/ListItemText'
1010
import ListItemSecondaryAction from '@mui/material/ListItemSecondaryAction'
1111
import MoreVertIcon from '@mui/icons-material/MoreVert'
@@ -28,7 +28,7 @@ const CustomAnchor = () => (
2828

2929
<Paper>
3030
<List>
31-
<ListItem button ContainerProps={{ ref: anchorRef(popupState) }}>
31+
<ListItemButton ref={anchorRef(popupState)}>
3232
<ListItemText
3333
primary="Stuff"
3434
secondary="Last Modified Apr 9, 2019"
@@ -38,7 +38,7 @@ const CustomAnchor = () => (
3838
<MoreVertIcon />
3939
</IconButton>
4040
</ListItemSecondaryAction>
41-
</ListItem>
41+
</ListItemButton>
4242
</List>
4343
</Paper>
4444
<Menu
Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import React from 'react'
2-
import PropTypes from 'prop-types'
3-
import { withStyles } from '@mui/styles'
42
import Typography from '@mui/material/Typography'
53
import Button from '@mui/material/Button'
64
import Popover from '@mui/material/Popover'
@@ -10,13 +8,7 @@ import {
108
bindPopover,
119
} from 'material-ui-popup-state/hooks'
1210

13-
const styles = (theme) => ({
14-
typography: {
15-
margin: theme.spacing(2),
16-
},
17-
})
18-
19-
const TriggerPopover = ({ classes }) => {
11+
const TriggerPopover = () => {
2012
const popupState = usePopupState({
2113
variant: 'popover',
2214
popupId: 'demoPopover',
@@ -37,16 +29,10 @@ const TriggerPopover = ({ classes }) => {
3729
horizontal: 'center',
3830
}}
3931
>
40-
<Typography className={classes.typography}>
41-
The content of the Popover.
42-
</Typography>
32+
<Typography sx={{ margin: 2 }}>The content of the Popover.</Typography>
4333
</Popover>
4434
</div>
4535
)
4636
}
4737

48-
TriggerPopover.propTypes = {
49-
classes: PropTypes.object.isRequired,
50-
}
51-
52-
export default withStyles(styles)(TriggerPopover)
38+
export default TriggerPopover

0 commit comments

Comments
 (0)