'use client'; import { useMemo } from 'react'; import { Portal, Stack, Span, Select as UISelect, createListCollection, } from '@chakra-ui/react'; import type { Items } from '#app/types/ui'; interface SelectProps { defaultValue: string[]; value?: string[]; items: Items; placeholder?: string; emptyState?: string; width?: string | number; multiple?: boolean; disabled?: boolean; size?: 'xs' | 'sm' | 'md' | 'lg'; onChange?: (value: string[]) => void; onOpenChange?: (open: boolean) => void; } export const Select = ({ defaultValue, value, items, multiple = false, placeholder = 'Select', emptyState = 'No items found', width = '320px', disabled = false, size = 'sm', onChange, onOpenChange, }: SelectProps) => { const collection = useMemo( () => createListCollection({ items, }), [items], ); return ( onChange?.(details.value)} onOpenChange={(details) => onOpenChange?.(details.open)} size={size} multiple={multiple} width={width} disabled={disabled} > {collection.items.length === 0 ? ( {emptyState} ) : ( collection.items.map((item) => ( {item.label} {item.description && ( {item.description} )} )) )} ); };