import type { FC, ReactElement } from 'react' import type { ExtractProps } from '../types' import type { SelectButtonProps } from './SelectButton' import type { SelectLabelProps } from './SelectLabel' import type { SelectOptionProps } from './SelectOption' import type { SelectOptionsProps } from './SelectOptions' import { Listbox, Transition } from '@headlessui/react' import classNames from 'classnames' import { cloneElement, Fragment } from 'react' import SelectButton from './SelectButton' import SelectLabel from './SelectLabel' import SelectOption from './SelectOption' import SelectOptions from './SelectOptions' type SelectProps = ExtractProps & { button: ReactElement label?: ReactElement> children: ReactElement> } const SelectRoot: FC = ({ className, value, onChange, disabled, horizontal, button, multiple, children, label, }) => { return ( {({ open }: { open: boolean }) => (
{label && label}
{cloneElement(button, { open })} {children}
)}
) } export const Select: FC & { Button: FC Label: FC Option: FC Options: FC } = Object.assign(SelectRoot, { Button: SelectButton, Label: SelectLabel, Option: SelectOption, Options: SelectOptions, })