bigbuffet-rw/app/soapbox/components/ui/menu/menu.tsx

43 lines
1.1 KiB
TypeScript
Raw Normal View History

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';
2022-09-13 11:11:22 -07:00
import classNames 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'> {
/** 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
}
/** 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={
classNames(className, 'py-1 bg-white dark:bg-primary-900 rounded-lg shadow-menu')
}
{...filteredProps}
/>
</MenuPopover>
);
};
2022-03-21 11:09:01 -07:00
/** Divides menu items. */
2022-03-21 11:09:01 -07:00
const MenuDivider = () => <hr />;
export { Menu, MenuButton, MenuDivider, MenuItems, MenuItem, MenuList, MenuLink };