Created
May 31, 2021 11:37
-
-
Save 8ui/838111786120890e1989920fad99c7f2 to your computer and use it in GitHub Desktop.
TableSettings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import Settings from "@material-ui/icons/Settings"; | |
import IconButton from "@material-ui/core/IconButton"; | |
import Menu from "@material-ui/core/Menu"; | |
import ListItem from "@material-ui/core/ListItem"; | |
import ListItemIcon from "@material-ui/core/ListItemIcon"; | |
import ListItemText from "@material-ui/core/ListItemText"; | |
import ListSubheader from "@material-ui/core/ListSubheader"; | |
import Checkbox from "@material-ui/core/Checkbox"; | |
import {observer} from "mobx-react-lite"; | |
const TableSettings = ({fields, onSwitch}) => { | |
const [anchorEl, setAnchorEl] = React.useState(null); | |
const open = Boolean(anchorEl); | |
const handleClick = (event) => { | |
setAnchorEl(event.currentTarget); | |
}; | |
const handleClose = () => { | |
setAnchorEl(null); | |
}; | |
return ( | |
<> | |
<IconButton | |
edge="end" | |
aria-label="more" | |
aria-controls="products-table-settings-more" | |
aria-haspopup="true" | |
onClick={handleClick} | |
> | |
<Settings /> | |
</IconButton> | |
<Menu | |
id="products-table-settings" | |
anchorEl={anchorEl} | |
keepMounted | |
open={open} | |
onClose={handleClose} | |
MenuListProps={{ | |
subheader: ( | |
<ListSubheader | |
disableSticky | |
component="div" | |
id="nested-list-subheader" | |
> | |
Настройки таблицы | |
</ListSubheader> | |
) | |
}} | |
> | |
{fields.map(f => ( | |
<ListItem | |
key={f} | |
dense | |
button | |
disabled={f.hold} | |
role={undefined} | |
onClick={() => onSwitch(f)} | |
> | |
<ListItemIcon> | |
<Checkbox | |
edge="start" | |
checked={f.active} | |
tabIndex={-1} | |
disableRipple | |
inputProps={{ 'aria-labelledby': f }} | |
/> | |
</ListItemIcon> | |
<ListItemText primary={f.label} /> | |
</ListItem> | |
))} | |
</Menu> | |
</> | |
) | |
} | |
export default observer(TableSettings) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment