2022-03-21 11:09:01 -07:00
|
|
|
import {
|
|
|
|
Menu,
|
|
|
|
MenuButton,
|
|
|
|
MenuItem,
|
|
|
|
MenuItems,
|
|
|
|
MenuPopover,
|
|
|
|
MenuLink,
|
2022-09-13 11:11:22 -07:00
|
|
|
MenuListProps,
|
2022-03-21 11:09:01 -07:00
|
|
|
} from '@reach/menu-button';
|
|
|
|
import { positionDefault, positionRight } from '@reach/popover';
|
2023-02-06 10:01:03 -08:00
|
|
|
import clsx from 'clsx';
|
2022-03-21 11:09:01 -07:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import './menu.css';
|
|
|
|
|
2022-09-13 11:11:22 -07:00
|
|
|
interface IMenuList extends Omit<MenuListProps, 'position'> {
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Position of the dropdown menu. */
|
2022-03-21 11:09:01 -07:00
|
|
|
position?: 'left' | 'right'
|
2022-09-13 11:11:22 -07:00
|
|
|
className?: string
|
2022-03-21 11:09:01 -07:00
|
|
|
}
|
|
|
|
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Renders children as a dropdown menu. */
|
2022-09-13 11:11:22 -07:00
|
|
|
const MenuList: React.FC<IMenuList> = (props) => {
|
|
|
|
const { position, className, ...filteredProps } = props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<MenuPopover position={props.position === 'left' ? positionDefault : positionRight}>
|
|
|
|
<MenuItems
|
|
|
|
onKeyDown={(event) => event.nativeEvent.stopImmediatePropagation()}
|
|
|
|
className={
|
2023-02-06 10:01:03 -08:00
|
|
|
clsx(className, 'py-1 bg-white dark:bg-primary-900 rounded-lg shadow-menu')
|
2022-09-13 11:11:22 -07:00
|
|
|
}
|
|
|
|
{...filteredProps}
|
|
|
|
/>
|
|
|
|
</MenuPopover>
|
|
|
|
);
|
|
|
|
};
|
2022-03-21 11:09:01 -07:00
|
|
|
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Divides menu items. */
|
2022-03-21 11:09:01 -07:00
|
|
|
const MenuDivider = () => <hr />;
|
|
|
|
|
|
|
|
export { Menu, MenuButton, MenuDivider, MenuItems, MenuItem, MenuList, MenuLink };
|