import type { LunaticComponentProps } from '../type'; import { Label } from '../shared/Label/Label'; import { ComponentErrors, getComponentErrors, } from '../shared/ComponentErrors/ComponentErrors'; import { slottableComponent } from '../shared/HOC/slottableComponent'; import { Declarations } from '../shared/Declarations/Declarations'; import type { LunaticError } from '../../use-lunatic/type'; import { CharactersCount } from '../shared/CharactersCount/CharactersCount'; import { getCharactersCountId } from '../shared/utils/getCharactersCountId'; export function Textarea({ handleChanges, response, errors, ...props }: LunaticComponentProps<'Textarea'>) { return ( handleChanges([{ name: response.name, value }])} errors={getComponentErrors(errors, props.id)} /> ); } type CustomProps = Omit< LunaticComponentProps<'Textarea'>, 'response' | 'handleChanges' | 'errors' > & { onChange: (v: string) => void; errors?: LunaticError[]; }; export const CustomTextarea = slottableComponent( 'Textarea', (props) => { const { value, onChange, disabled, required, maxLength, label, description, id, errors, readOnly, declarations, rows, cols, placeHolder, } = props; const labelId = `label-${id}`; const charactersCountId = getCharactersCountId(id, maxLength); return (