1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-19 17:52:45 +02:00
unleash.unleash/frontend/src/component/common/DropdownMenu/DropdownMenu.tsx
Nuno Góis 4167a60588
feat: biome lint frontend (#4903)
Follows up on https://github.com/Unleash/unleash/pull/4853 to add Biome
to the frontend as well.


![image](https://github.com/Unleash/unleash/assets/14320932/1906faf1-fc29-4172-a4d4-b2716d72cd65)

Added a few `biome-ignore` to speed up the process but we may want to
check and fix them in the future.
2023-10-02 13:25:46 +01:00

75 lines
1.7 KiB
TypeScript

import {
CSSProperties,
MouseEventHandler,
ReactNode,
useState,
VFC,
} from 'react';
import { Menu } from '@mui/material';
import { ArrowDropDown } from '@mui/icons-material';
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;