import { clsx } from "clsx"; import { FC } from "react"; import { FieldPathByValue, FieldValues } from "react-hook-form"; import { FormFieldLayoutProps } from "../common/FormFieldLayout.js"; import { SelectFormField } from "./SelectFormField.js"; type Size = "small" | "normal"; const TextOption: FC<{ text: string; size: Size }> = ({ text, size }) => { return
{text}
; }; export function SelectStringFormField< TValues extends FieldValues, TValueType extends string | null = string | null, // can be configured with const string union for stricter types TName extends FieldPathByValue = FieldPathByValue< TValues, TValueType >, >({ options, size = "normal", ...props }: FormFieldLayoutProps & { name: TName; size?: Size; options: NonNullable[]; placeholder?: string; required?: boolean; }) { return ( ; label: string } > {...props} size={size} options={options.map((value) => ({ value, label: value }))} optionToFieldValue={(option) => option.value} fieldValueToOption={(value) => ({ value, label: value })} renderOption={(option) => } /> ); }