39 lines
962 B
TypeScript
39 lines
962 B
TypeScript
import FormField, { fieldDescribedBy } from '@/components/ui/FormField'
|
|
import Input from '@/components/ui/Input'
|
|
import Textarea from '@/components/ui/Textarea'
|
|
|
|
/**
|
|
* A controlled field of a creation form: it never commits, the form's own button does
|
|
* (BDR-050). The committed fields of existing elements are `TextField`.
|
|
*/
|
|
export default function DraftField({
|
|
id,
|
|
label,
|
|
value,
|
|
onChange,
|
|
multiline,
|
|
hint,
|
|
error,
|
|
}: {
|
|
id: string
|
|
label: string
|
|
value: string
|
|
onChange: (value: string) => void
|
|
multiline?: boolean
|
|
hint?: string
|
|
error?: string
|
|
}) {
|
|
const shared = {
|
|
id,
|
|
value,
|
|
onChange: (e: { target: { value: string } }) => onChange(e.target.value),
|
|
'aria-invalid': Boolean(error),
|
|
'aria-describedby': fieldDescribedBy(id, hint, error),
|
|
}
|
|
return (
|
|
<FormField id={id} label={label} hint={hint} error={error}>
|
|
{multiline ? <Textarea {...shared} /> : <Input {...shared} />}
|
|
</FormField>
|
|
)
|
|
}
|