diff options
author | Anton Tananaev <anton@traccar.org> | 2023-01-30 09:22:18 -0800 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2023-01-30 09:22:18 -0800 |
commit | ea34943121cab989e5ced540139c4fd39527cbde (patch) | |
tree | ec583de0c793784efde358c76b907ce15d068b1a /modern/src/common | |
parent | a8b6bf4f917ed1a453585eb51445e28bdc107d11 (diff) | |
download | trackermap-web-ea34943121cab989e5ced540139c4fd39527cbde.tar.gz trackermap-web-ea34943121cab989e5ced540139c4fd39527cbde.tar.bz2 trackermap-web-ea34943121cab989e5ced540139c4fd39527cbde.zip |
Reports split button
Diffstat (limited to 'modern/src/common')
-rw-r--r-- | modern/src/common/components/SplitButton.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/modern/src/common/components/SplitButton.js b/modern/src/common/components/SplitButton.js new file mode 100644 index 00000000..bdf12870 --- /dev/null +++ b/modern/src/common/components/SplitButton.js @@ -0,0 +1,45 @@ +import React, { useRef, useState } from 'react'; +import { Button, ButtonGroup, Menu, MenuItem, Typography } from '@mui/material'; +import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown'; + +const SplitButton = ({ fullWidth, variant, color, disabled, onClick, options }) => { + const anchorRef = useRef(); + const [menuAnchorEl, setMenuAnchorEl] = useState(null); + const [selected, setSelected] = useState(Object.keys(options)[0]); + + return ( + <> + <ButtonGroup fullWidth={fullWidth} variant={variant} color={color} disabled={disabled} ref={anchorRef}> + <Button onClick={() => onClick(selected)}> + <Typography variant="button" noWrap>{options[selected]}</Typography> + </Button> + <Button fullWidth={false} size="small" onClick={() => setMenuAnchorEl(anchorRef.current)}> + <ArrowDropDownIcon /> + </Button> + </ButtonGroup> + <Menu + open={!!menuAnchorEl} + anchorEl={menuAnchorEl} + onClose={() => setMenuAnchorEl(null)} + anchorOrigin={{ + vertical: 'bottom', + horizontal: 'right', + }} + > + {Object.entries(options).map(([key, value]) => ( + <MenuItem + key={key} + onClick={() => { + setSelected(key); + setMenuAnchorEl(null); + }} + > + {value} + </MenuItem> + ))} + </Menu> + </> + ); +}; + +export default SplitButton; |