import { Wrapper, Button, Menu } from 'react-aria-menubutton'; import { MdArrowDropDown } from 'react-icons/md'; import { useWindowSize } from 'react-use'; import OptionList from './OptionList'; import styles from './Selector.module.css'; import type { OptionComponent } from './models'; const MENU_IDEAL_HEIGHT = 320; // 20rem const MENU_TOP = 87; // HACK: height of breadcrumbs bar + height of toolbar const MENU_BOTTOM = 16; // offset from bottom of viewport interface Props { label?: string; value: T; disabled?: boolean; onChange: (value: T) => void; options: Record | T[]; optionComponent: OptionComponent; } function Selector(props: Props) { const { label, value, disabled, onChange, options, optionComponent: Option, } = props; const { height: winHeight } = useWindowSize(); const menuMaxHeight = winHeight - MENU_TOP - MENU_BOTTOM; return (
{label && {label}} {Array.isArray(options) ? ( ) : (
    {Object.entries(options).map(([groupLabel, groupOptions]) => (
  • {groupLabel}
  • ))}
)}
); } export default Selector;