Skip to content

Commit

Permalink
[Menu] Use ButtonBase in MenuItem (#26591)
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp authored Jun 16, 2021
1 parent 25a37ee commit 1406f51
Show file tree
Hide file tree
Showing 25 changed files with 768 additions and 164 deletions.
2 changes: 1 addition & 1 deletion docs/pages/api-docs/list-item-button.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"spread": true,
"forwardsRefTo": "HTMLDivElement",
"filename": "/packages/material-ui/src/ListItemButton/ListItemButton.js",
"inheritance": null,
"inheritance": { "component": "ButtonBase", "pathname": "/api/button-base/" },
"demos": "<ul><li><a href=\"/components/lists/\">Lists</a></li></ul>",
"styledComponent": true,
"cssComponent": false
Expand Down
14 changes: 10 additions & 4 deletions docs/pages/api-docs/menu-item.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
{
"props": {
"autoFocus": { "type": { "name": "bool" } },
"children": { "type": { "name": "node" } },
"classes": { "type": { "name": "object" } },
"component": { "type": { "name": "elementType" } },
"dense": { "type": { "name": "bool" } },
"disableGutters": { "type": { "name": "bool" } },
"ListItemClasses": { "type": { "name": "object" } },
"divider": { "type": { "name": "bool" } },
"focusVisibleClassName": { "type": { "name": "string" } },
"sx": { "type": { "name": "object" } }
},
"name": "MenuItem",
"styles": {
"classes": ["root", "gutters", "selected", "dense"],
"globalClasses": { "selected": "Mui-selected" },
"classes": ["root", "focusVisible", "dense", "disabled", "divider", "gutters", "selected"],
"globalClasses": {
"focusVisible": "Mui-focusVisible",
"disabled": "Mui-disabled",
"selected": "Mui-selected"
},
"name": "MuiMenuItem"
},
"spread": true,
"forwardsRefTo": "HTMLLIElement",
"filename": "/packages/material-ui/src/MenuItem/MenuItem.js",
"inheritance": { "component": "ListItem", "pathname": "/api/list-item/" },
"inheritance": { "component": "ButtonBase", "pathname": "/api/button-base/" },
"demos": "<ul><li><a href=\"/components/menus/\">Menus</a></li></ul>",
"styledComponent": true,
"cssComponent": false
Expand Down
97 changes: 97 additions & 0 deletions docs/src/pages/components/menus/AccountMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';
import Avatar from '@material-ui/core/Avatar';
import Menu from '@material-ui/core/Menu';
import MenuItem from '@material-ui/core/MenuItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import Divider from '@material-ui/core/Divider';
import IconButton from '@material-ui/core/IconButton';
import Typography from '@material-ui/core/Typography';
import Tooltip from '@material-ui/core/Tooltip';
import PersonAdd from '@material-ui/icons/PersonAdd';
import Settings from '@material-ui/icons/Settings';
import Logout from '@material-ui/icons/Logout';

export default function AccountMenu() {
const [anchorEl, setAnchorEl] = React.useState(null);
const open = Boolean(anchorEl);
const handleClick = (event) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
return (
<React.Fragment>
<Box sx={{ display: 'flex', alignItems: 'center', textAlign: 'center' }}>
<Typography sx={{ minWidth: 100 }}>Contact</Typography>
<Typography sx={{ minWidth: 100 }}>Profile</Typography>
<Tooltip title="Account settings">
<IconButton onClick={handleClick} size="small" sx={{ ml: 2 }}>
<Avatar sx={{ width: 32, height: 32 }}>M</Avatar>
</IconButton>
</Tooltip>
</Box>
<Menu
anchorEl={anchorEl}
open={open}
onClose={handleClose}
onClick={handleClose}
PaperProps={{
elevation: 0,
sx: {
overflow: 'visible',
filter: 'drop-shadow(0px 2px 8px rgba(0,0,0,0.32))',
mt: 1.5,
'& .MuiAvatar-root': {
width: 32,
height: 32,
ml: -0.5,
mr: 1,
},
'&:before': {
content: '""',
display: 'block',
position: 'absolute',
top: 0,
right: 14,
width: 10,
height: 10,
bgcolor: 'background.paper',
transform: 'translateY(-50%) rotate(45deg)',
zIndex: 0,
},
},
}}
transformOrigin={{ horizontal: 'right', vertical: 'top' }}
anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}
>
<MenuItem>
<Avatar /> Profile
</MenuItem>
<MenuItem>
<Avatar /> My account
</MenuItem>
<Divider />
<MenuItem>
<ListItemIcon>
<PersonAdd fontSize="small" />
</ListItemIcon>
Add another account
</MenuItem>
<MenuItem>
<ListItemIcon>
<Settings fontSize="small" />
</ListItemIcon>
Settings
</MenuItem>
<MenuItem>
<ListItemIcon>
<Logout fontSize="small" />
</ListItemIcon>
Logout
</MenuItem>
</Menu>
</React.Fragment>
);
}
97 changes: 97 additions & 0 deletions docs/src/pages/components/menus/AccountMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';
import Avatar from '@material-ui/core/Avatar';
import Menu from '@material-ui/core/Menu';
import MenuItem from '@material-ui/core/MenuItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import Divider from '@material-ui/core/Divider';
import IconButton from '@material-ui/core/IconButton';
import Typography from '@material-ui/core/Typography';
import Tooltip from '@material-ui/core/Tooltip';
import PersonAdd from '@material-ui/icons/PersonAdd';
import Settings from '@material-ui/icons/Settings';
import Logout from '@material-ui/icons/Logout';

export default function AccountMenu() {
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const open = Boolean(anchorEl);
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
return (
<React.Fragment>
<Box sx={{ display: 'flex', alignItems: 'center', textAlign: 'center' }}>
<Typography sx={{ minWidth: 100 }}>Contact</Typography>
<Typography sx={{ minWidth: 100 }}>Profile</Typography>
<Tooltip title="Account settings">
<IconButton onClick={handleClick} size="small" sx={{ ml: 2 }}>
<Avatar sx={{ width: 32, height: 32 }}>M</Avatar>
</IconButton>
</Tooltip>
</Box>
<Menu
anchorEl={anchorEl}
open={open}
onClose={handleClose}
onClick={handleClose}
PaperProps={{
elevation: 0,
sx: {
overflow: 'visible',
filter: 'drop-shadow(0px 2px 8px rgba(0,0,0,0.32))',
mt: 1.5,
'& .MuiAvatar-root': {
width: 32,
height: 32,
ml: -0.5,
mr: 1,
},
'&:before': {
content: '""',
display: 'block',
position: 'absolute',
top: 0,
right: 14,
width: 10,
height: 10,
bgcolor: 'background.paper',
transform: 'translateY(-50%) rotate(45deg)',
zIndex: 0,
},
},
}}
transformOrigin={{ horizontal: 'right', vertical: 'top' }}
anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}
>
<MenuItem>
<Avatar /> Profile
</MenuItem>
<MenuItem>
<Avatar /> My account
</MenuItem>
<Divider />
<MenuItem>
<ListItemIcon>
<PersonAdd fontSize="small" />
</ListItemIcon>
Add another account
</MenuItem>
<MenuItem>
<ListItemIcon>
<Settings fontSize="small" />
</ListItemIcon>
Settings
</MenuItem>
<MenuItem>
<ListItemIcon>
<Logout fontSize="small" />
</ListItemIcon>
Logout
</MenuItem>
</Menu>
</React.Fragment>
);
}
5 changes: 2 additions & 3 deletions docs/src/pages/components/menus/CustomizedMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ const StyledMenu = styled((props) => (
theme.palette.mode === 'light' ? 'rgb(55, 65, 81)' : theme.palette.grey[300],
boxShadow:
'rgb(255, 255, 255) 0px 0px 0px 0px, rgba(0, 0, 0, 0.05) 0px 0px 0px 1px, rgba(0, 0, 0, 0.1) 0px 10px 15px -3px, rgba(0, 0, 0, 0.05) 0px 4px 6px -2px',
'& .MuiList-root': {
'& .MuiMenu-list': {
padding: '4px 0',
},
'& .MuiListItem-root': {
...theme.typography.body1,
'& .MuiMenuItem-root': {
'& .MuiSvgIcon-root': {
fontSize: 18,
color: theme.palette.text.secondary,
Expand Down
5 changes: 2 additions & 3 deletions docs/src/pages/components/menus/CustomizedMenus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ const StyledMenu = styled((props: MenuProps) => (
theme.palette.mode === 'light' ? 'rgb(55, 65, 81)' : theme.palette.grey[300],
boxShadow:
'rgb(255, 255, 255) 0px 0px 0px 0px, rgba(0, 0, 0, 0.05) 0px 0px 0px 1px, rgba(0, 0, 0, 0.1) 0px 10px 15px -3px, rgba(0, 0, 0, 0.05) 0px 4px 6px -2px',
'& .MuiList-root': {
'& .MuiMenu-list': {
padding: '4px 0',
},
'& .MuiListItem-root': {
...theme.typography.body1,
'& .MuiMenuItem-root': {
'& .MuiSvgIcon-root': {
fontSize: 18,
color: theme.palette.text.secondary,
Expand Down
43 changes: 43 additions & 0 deletions docs/src/pages/components/menus/DenseMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as React from 'react';
import Paper from '@material-ui/core/Paper';
import Divider from '@material-ui/core/Divider';
import MenuList from '@material-ui/core/MenuList';
import MenuItem from '@material-ui/core/MenuItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import Check from '@material-ui/icons/Check';

export default function DenseMenu() {
return (
<Paper sx={{ width: 320 }}>
<MenuList dense>
<MenuItem>
<ListItemText inset>Single</ListItemText>
</MenuItem>
<MenuItem>
<ListItemText inset>1.15</ListItemText>
</MenuItem>
<MenuItem>
<ListItemText inset>Double</ListItemText>
</MenuItem>
<MenuItem>
<ListItemIcon>
<Check />
</ListItemIcon>
Custom: 1.2
</MenuItem>
<Divider />
<MenuItem>
<ListItemText>Add space before paragraph</ListItemText>
</MenuItem>
<MenuItem>
<ListItemText>Add space after paragraph</ListItemText>
</MenuItem>
<Divider />
<MenuItem>
<ListItemText>Custom spacing...</ListItemText>
</MenuItem>
</MenuList>
</Paper>
);
}
43 changes: 43 additions & 0 deletions docs/src/pages/components/menus/DenseMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as React from 'react';
import Paper from '@material-ui/core/Paper';
import Divider from '@material-ui/core/Divider';
import MenuList from '@material-ui/core/MenuList';
import MenuItem from '@material-ui/core/MenuItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import Check from '@material-ui/icons/Check';

export default function DenseMenu() {
return (
<Paper sx={{ width: 320 }}>
<MenuList dense>
<MenuItem>
<ListItemText inset>Single</ListItemText>
</MenuItem>
<MenuItem>
<ListItemText inset>1.15</ListItemText>
</MenuItem>
<MenuItem>
<ListItemText inset>Double</ListItemText>
</MenuItem>
<MenuItem>
<ListItemIcon>
<Check />
</ListItemIcon>
Custom: 1.2
</MenuItem>
<Divider />
<MenuItem>
<ListItemText>Add space before paragraph</ListItemText>
</MenuItem>
<MenuItem>
<ListItemText>Add space after paragraph</ListItemText>
</MenuItem>
<Divider />
<MenuItem>
<ListItemText>Custom spacing...</ListItemText>
</MenuItem>
</MenuList>
</Paper>
);
}
Loading

0 comments on commit 1406f51

Please sign in to comment.