import type { LunaticComponentProps } from '../type'; import { ComponentErrors, getComponentErrors, } from '../shared/ComponentErrors/ComponentErrors'; import { CheckboxOption } from '../shared/Checkbox/CheckboxOption'; import { slottableComponent } from '../shared/HOC/slottableComponent'; import { Declarations } from '../shared/Declarations/Declarations'; import type { LunaticError } from '../../use-lunatic/type'; export function CheckboxBoolean({ handleChanges, response, errors, value, ...props }: LunaticComponentProps<'CheckboxBoolean'>) { const checked = !!value; return ( handleChanges([ { name: response.name, value: !checked, }, ]) } errors={getComponentErrors(errors, props.id)} /> ); } type CustomProps = Omit< LunaticComponentProps<'CheckboxBoolean'>, 'response' | 'handleChanges' | 'errors' | 'value' > & { onChange: () => void; errors?: LunaticError[]; checked?: boolean; }; export const CustomCheckboxBoolean = slottableComponent( 'CheckboxBoolean', (props) => { const { disabled, checked, id, onChange, label, declarations, description, errors, } = props; return (
{label} } description={description} invalid={!!errors} />
); } );