import { slottableComponent } from '../shared/HOC/slottableComponent'; import type { LunaticComponentProps } from '../type'; import { Label } from '../shared/Label/Label'; import { ComponentErrors, getComponentErrors, } from '../shared/ComponentErrors/ComponentErrors'; import { Declarations } from '../shared/Declarations/Declarations'; import type { LunaticError } from '../../use-lunatic/type'; import { CustomDatepickerFields } from './DatepickerFields'; export function Datepicker({ dateFormat = 'YYYY-MM-DD', response, handleChanges, errors, ...props }: LunaticComponentProps<'Datepicker'>) { const { id, iteration } = props; // We can have the same id (same variable) for different iterations in successive pages, we need to have unique key for remount correctly const datepickerFieldsKey = `${id}-${iteration}`; return ( handleChanges([{ name: response.name, value }])} errors={getComponentErrors(errors, props.id)} /> ); } type CustomProps = Omit< LunaticComponentProps<'Datepicker'>, 'response' | 'handleChanges' | 'errors' > & { onChange: (s: string | null) => void; errors?: LunaticError[]; }; export const CustomDatepicker = slottableComponent( 'Datepicker', (props) => { const { id, label, errors, description, declarations } = props; const labelId = `lunatic-datepicker-${id}`; return (
); } );