import { ListboxArrow, ListboxInput, ListboxList, ListboxPopover } from '@reach/listbox' import '@reach/listbox/styles.css' import { VisuallyHidden } from '@reach/visually-hidden' import { FunctionComponent } from 'react' import Icon from '@/Components/Icon/Icon' import { DropdownItem } from './DropdownItem' import StyledListboxButton from './StyledListboxButton' import StyledListboxOption from './StyledListboxOption' import { classNames } from '@standardnotes/snjs' type DropdownProps = { id: string label: string items: DropdownItem[] value: string onChange: (value: string, item: DropdownItem) => void disabled?: boolean classNameOverride?: { wrapper?: string button?: string popover?: string } fullWidth?: boolean portal?: boolean } type ListboxButtonProps = DropdownItem & { isExpanded: boolean } const CustomDropdownButton: FunctionComponent = ({ label, isExpanded, icon, iconClassName = '', }) => ( <>
{icon ? (
) : null}
{label}
) const Dropdown: FunctionComponent = ({ id, label, items, value, onChange, disabled, classNameOverride = {}, fullWidth, portal = true, }) => { const labelId = `${id}-label` const handleChange = (value: string) => { const selectedItem = items.find((item) => item.value === value) as DropdownItem onChange(value, selectedItem) } return (
{label} { const current = items.find((item) => item.value === value) const icon = current ? current?.icon : null const iconClassName = current ? current?.iconClassName : null return CustomDropdownButton({ value: value ? value : label.toLowerCase(), label, isExpanded, ...(icon ? { icon } : null), ...(iconClassName ? { iconClassName } : null), }) }} />
{items.map((item) => ( {item.icon ? (
) : null}
{item.label}
))}
) } export default Dropdown