import classnames from 'classnames'; import type { LunaticComponentProps } from '../type'; import { Label } from '../shared/Label/Label'; import { slottableComponent } from '../shared/HOC/slottableComponent'; import { ComponentErrors, getComponentErrors, } from '../shared/ComponentErrors/ComponentErrors'; 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 Input({ handleChanges, response, errors, ...props }: LunaticComponentProps<'Input'>) { return ( handleChanges([{ name: response.name, value }])} errors={getComponentErrors(errors, props.id)} /> ); } type CustomProps = Omit< LunaticComponentProps<'Input'>, 'response' | 'handleChanges' | 'errors' > & { onChange: (v: string) => void; errors?: LunaticError[]; autoFocus?: boolean; }; export const CustomInput = slottableComponent('Input', (props) => { const { value, onChange, disabled, required, maxLength, label, description, id, errors, readOnly, declarations, autoFocus = false, } = props; const labelId = `label-${id}`; const charactersCountId = getCharactersCountId(id, maxLength); return (
onChange(e.target.value)} aria-required={required} required={required} maxLength={maxLength} aria-invalid={!!errors} onBlur={(e) => { e.target.setSelectionRange(0, 0); }} autoFocus={autoFocus} />
); });