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';
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'> {
/** 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={
2023-02-06 10:06:44 -08:00
clsx(className, 'shadow-menu rounded-lg bg-white py-1 dark:bg-primary-900')
2022-09-13 11:11:22 -07:00
}
{...filteredProps}
/>
</MenuPopover>
);
};
2022-03-21 11:09:01 -07:00
/** Divides menu items. */
const MenuDivider = () => <hr className='mx-2 my-1 border-t-2 border-gray-100 dark:border-gray-800' />;
2022-03-21 11:09:01 -07:00
export { Menu, MenuButton, MenuDivider, MenuItems, MenuItem, MenuList, MenuLink };