import React from 'react'; import { Button, FieldError, Header, Label, ListBox, ListBoxItem, ListBoxSection, Popover, Select as RACSelect, SelectValue, Text, type ListBoxItemProps, type ListBoxProps, type PopoverProps, type SectionProps, type SelectProps as RACSelectProps, type ValidationResult, } from 'react-aria-components'; import { ChevrondownIcon } from '../icons/ChevrondownIcon'; import { ChevronupIcon } from '../icons/ChevronupIcon'; export interface SelectItemObject { label: string; value: string; } interface SelectBaseProps extends Omit, 'children'> { label?: string; description?: string; errorMessage?: string | ((validation: ValidationResult) => string); items?: Iterable; children?: React.ReactNode | ((item: T) => React.ReactNode); } export interface SelectProps< T extends object = SelectItemObject, M extends 'single' | 'multiple' = 'single', > extends SelectBaseProps {} export type SelectPopoverContextValue = Pick< PopoverProps, 'className' | 'style' >; export const SelectPopoverContext = React.createContext(null); export function Select< T extends object = SelectItemObject, M extends 'single' | 'multiple' = 'single', >({ label, description, errorMessage, children, items, ...props }: SelectProps) { const popoverProps = React.useContext(SelectPopoverContext) ?? undefined; return ( {({ isOpen }) => ( <> {label && } {description && {description}} {errorMessage} {children ? children : (DefaultSelectItem as unknown as ( item: T, ) => React.ReactNode)} )} ); } function DefaultSelectItem(item: SelectItemObject) { return {item.value}; } export function SelectListBox(props: ListBoxProps) { return ; } export function SelectItem(props: ListBoxItemProps) { return ; } export function SelectSection(props: SectionProps) { return ; } export function SelectSectionHeader( props: React.ComponentProps, ) { return
; }