'use client'; import { LegacyRef } from 'react'; import { useFormStatus } from 'react-dom'; import Spinner from './Spinner'; import { clsx } from 'clsx/lite'; import { FieldSetType, AnnotatedTag } from '@/photo/form'; import TagInput from './TagInput'; export default function FieldSetWithStatus({ id, label, note, error, value, onChange, selectOptions, selectOptionsDefaultLabel, tagOptions, placeholder, loading, required, readOnly, capitalize, type = 'text', inputRef, }: { id: string label: string note?: string error?: string value: string onChange?: (value: string) => void selectOptions?: { value: string, label: string }[] selectOptionsDefaultLabel?: string tagOptions?: AnnotatedTag [] placeholder?: string loading?: boolean required?: boolean readOnly?: boolean capitalize?: boolean type?: FieldSetType inputRef?: LegacyRef }) { const { pending } = useFormStatus(); return (
{selectOptions ? : tagOptions ? : onChange?.(type === 'checkbox' ? e.target.value === 'true' ? 'false' : 'true' : e.target.value)} type={type} autoComplete="off" autoCapitalize={!capitalize ? 'off' : undefined} readOnly={readOnly || pending} className={clsx( type === 'text' && 'w-full', Boolean(error) && 'error', )} />}
); };