1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-27 11:02:16 +01:00
unleash.unleash/frontend/src/component/common/DropdownMenu/DropdownMenu.tsx
Christopher Kolstad 53354224fc
chore: Bump biome and configure husky (#6589)
Upgrades biome to 1.6.1, and updates husky pre-commit hook.

Most changes here are making type imports explicit.
2024-03-18 13:58:05 +01:00

75 lines
1.7 KiB
TypeScript

import {
type CSSProperties,
type MouseEventHandler,
type ReactNode,
useState,
type VFC,
} from 'react';
import { Menu } from '@mui/material';
import ArrowDropDown from '@mui/icons-material/ArrowDropDown';
import { DropdownButton } from './DropdownButton/DropdownButton';
export interface IDropdownMenuProps {
renderOptions: () => ReactNode;
id: string;
title?: string;
callback?: MouseEventHandler;
icon?: ReactNode;
label: string;
startIcon?: ReactNode;
style?: CSSProperties;
}
const DropdownMenu: VFC<IDropdownMenuProps> = ({
renderOptions,
id,
title,
callback,
icon = <ArrowDropDown titleAccess='Toggle' />,
label,
style,
startIcon,
...rest
}) => {
const [anchor, setAnchor] = useState<Element | null>(null);
const handleOpen: MouseEventHandler<HTMLButtonElement> = (e) => {
setAnchor(e.currentTarget);
};
const handleClose: MouseEventHandler<HTMLDivElement> = (e) => {
if (callback && typeof callback === 'function') {
callback(e);
}
setAnchor(null);
};
return (
<>
<DropdownButton
id={id}
label={label}
title={title}
startIcon={startIcon}
onClick={handleOpen}
style={style}
aria-controls={id}
aria-expanded={Boolean(anchor)}
icon={icon}
{...rest}
/>
<Menu
id={id}
onClick={handleClose}
anchorEl={anchor}
open={Boolean(anchor)}
>
{renderOptions()}
</Menu>
</>
);
};
export default DropdownMenu;