import { Field, Label, Combobox as HeadlessCombobox, ComboboxInput, ComboboxButton, ComboboxOptions, ComboboxOption, } from '@headlessui/react' import { CheckIcon, ChevronDownIcon } from '@heroicons/react/20/solid' import { useState, type ComponentProps, type ReactNode } from 'react' import { get, type FieldError, type FieldValues, type Path, type RegisterOptions, Controller, } from 'react-hook-form' import { useRemixFormContext } from 'remix-hook-form' import { twMerge } from 'tailwind-merge' type TComboboxOption = { code: string name: string id: string } type TInputProperties = ComponentProps< typeof HeadlessCombobox > & { id: string label?: ReactNode name: Path rules?: RegisterOptions placeholder?: string options?: TComboboxOption[] } export const Combobox = >( properties: TInputProperties, ) => { const { id, label, name, rules, disabled, placeholder, options, ...rest } = properties const { control, formState: { errors }, } = useRemixFormContext() const [query, setQuery] = useState('') const filteredOptions = query === '' ? options : options?.filter((option) => option.name.toLowerCase().includes(query.toLowerCase()), ) const error: FieldError = get(errors, name) return ( (
option?.name} onChange={(event) => setQuery(event.target.value)} className="focus:inheriten h-[42px] w-full rounded-md border border-[#DFDFDF] p-2" />
{filteredOptions?.map((person) => (
{person.name}
))}
)} />
) }