Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
82 lines
2.1 KiB
TypeScript
82 lines
2.1 KiB
TypeScript
import * as React from 'react';
|
|
import List from '@mui/material/List';
|
|
import ListItemButton from '@mui/material/ListItemButton';
|
|
import ListItemText from '@mui/material/ListItemText';
|
|
import MenuItem from '@mui/material/MenuItem';
|
|
import Menu from '@mui/material/Menu';
|
|
|
|
const options = [
|
|
'Show some love to MUI',
|
|
'Show all notification content',
|
|
'Hide sensitive notification content',
|
|
'Hide all notification content',
|
|
];
|
|
|
|
export default function SimpleListMenu() {
|
|
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
|
|
const [selectedIndex, setSelectedIndex] = React.useState(1);
|
|
const open = Boolean(anchorEl);
|
|
const handleClickListItem = (event: React.MouseEvent<HTMLElement>) => {
|
|
setAnchorEl(event.currentTarget);
|
|
};
|
|
|
|
const handleMenuItemClick = (
|
|
event: React.MouseEvent<HTMLElement>,
|
|
index: number,
|
|
) => {
|
|
setSelectedIndex(index);
|
|
setAnchorEl(null);
|
|
};
|
|
|
|
const handleClose = () => {
|
|
setAnchorEl(null);
|
|
};
|
|
|
|
return (
|
|
<div>
|
|
<List
|
|
component="nav"
|
|
aria-label="Device settings"
|
|
sx={{ bgcolor: 'background.paper' }}
|
|
>
|
|
<ListItemButton
|
|
id="lock-button"
|
|
aria-haspopup="listbox"
|
|
aria-controls="lock-menu"
|
|
aria-label="when device is locked"
|
|
aria-expanded={open ? 'true' : undefined}
|
|
onClick={handleClickListItem}
|
|
>
|
|
<ListItemText
|
|
primary="When device is locked"
|
|
secondary={options[selectedIndex]}
|
|
/>
|
|
</ListItemButton>
|
|
</List>
|
|
<Menu
|
|
id="lock-menu"
|
|
anchorEl={anchorEl}
|
|
open={open}
|
|
onClose={handleClose}
|
|
slotProps={{
|
|
list: {
|
|
'aria-labelledby': 'lock-button',
|
|
role: 'listbox',
|
|
},
|
|
}}
|
|
>
|
|
{options.map((option, index) => (
|
|
<MenuItem
|
|
key={option}
|
|
disabled={index === 0}
|
|
selected={index === selectedIndex}
|
|
onClick={(event) => handleMenuItemClick(event, index)}
|
|
>
|
|
{option}
|
|
</MenuItem>
|
|
))}
|
|
</Menu>
|
|
</div>
|
|
);
|
|
}
|