import type { CSSProperties, FunctionComponent, ReactNode } from 'react'; import { useLunatic } from '../use-lunatic/use-lunatic'; import type { LunaticChangesHandler, LunaticComponentDefinition, LunaticError, LunaticOptions, LunaticReducerState, } from '../use-lunatic/type'; import type { InterpretedOption } from '../use-lunatic/props/propOptions'; export type DurationFormat = 'PTnHnM' | 'PnYnM'; export type VtlExpression = { value: string; type: 'VTL' | 'VTL|MD' | 'TXT'; }; export type LunaticBaseProps = { id: string; handleChanges: LunaticChangesHandler; errors?: { [id: string]: LunaticError[] }; preferences?: LunaticOptions['preferences']; label?: ReactNode; disabled?: boolean; missing?: unknown; missingResponse?: { name: string; value?: unknown }; management?: LunaticOptions['management']; description?: ReactNode; shortcut?: boolean; required?: boolean; value: null | ValueType; readOnly?: boolean; className?: string; style?: CSSProperties; iteration?: number; shouldBeFiltered?: boolean; declarations?: { id: string; declarationType: | 'INSTRUCTION' | 'COMMENT' | 'HELP' | 'CODECARD' | 'WARNING' | 'STATEMENT'; position: string; label: ReactNode; }[]; features?: string[]; goNextPage?: () => void; goPreviousPage?: () => void; meta?: Record; // Function used by the wrapper to transform props, can be used to pass transformation through component (Loop, Question...) propsTransformer?: (v: any) => any; }; export type SuggesterOption = { children?: string[]; id?: string; description?: ReactNode; label?: ReactNode; value: string; niveau?: string; parent?: string; tokensMap?: Record; }; export type ComponentPropsByType = { InputNumber: LunaticBaseProps & { min?: number; max?: number; decimals?: number; unit?: string; response: { name: string }; componentType?: 'InputNumber'; }; Duration: LunaticBaseProps & { format: DurationFormat; response: { name: string }; componentType?: 'Duration'; }; Text: LunaticBaseProps & { componentType?: 'Text'; }; Input: LunaticBaseProps & { maxLength?: number; value: null | string; response: { name: string }; componentType?: 'Input'; }; Accordion: LunaticBaseProps & { componentType?: 'Accordion'; items: { label: ReactNode; body: ReactNode; }[]; }; Sequence: Pick< LunaticBaseProps, | 'id' | 'label' | 'style' | 'declarations' | 'description' | 'shouldBeFiltered' > & { componentType?: 'Sequence' }; Subsequence: Pick< LunaticBaseProps, 'id' | 'label' | 'declarations' | 'description' | 'shouldBeFiltered' > & { componentType?: 'Subsequence' }; Question: Pick< LunaticBaseProps, | 'propsTransformer' | 'label' | 'id' | 'description' | 'declarations' | 'errors' | 'disabled' | 'readOnly' | 'shouldBeFiltered' > & { components: LunaticComponentProps[]; componentType?: 'Question'; iteration?: number; value: Record; }; RosterForLoop: LunaticBaseProps & { lines: { min: number; max: number }; iterations: number; getComponents: (n: number) => LunaticComponentProps[]; executeExpression: LunaticReducerState['executeExpression']; value: Record; header?: Array<{ label: ReactNode; rowspan?: number; colspan?: number; }>; paginatedLoop?: boolean; componentType?: 'RosterForLoop'; }; Loop: LunaticBaseProps & { lines: { min: number; max: number }; iterations: number; getComponents: (n: number) => LunaticComponentProps[]; executeExpression: LunaticReducerState['executeExpression']; value: Record; header?: Array<{ label: ReactNode }>; paginatedLoop?: boolean; componentType?: 'Loop'; }; Table: LunaticBaseProps & { value: Record; header: Array<{ label: ReactNode; rowspan?: number; colspan?: number; }>; body: (LunaticComponentProps & { colspan?: number; rowspan?: number; })[][]; executeExpression: LunaticReducerState['executeExpression']; iteration: LunaticReducerState['pager']['iteration']; componentType?: 'Table'; }; Datepicker: LunaticBaseProps & { dateFormat: 'YYYY-MM-DD' | 'YYYY-MM' | 'YYYY'; min?: string; max?: string; response: { name: string }; componentType?: 'Datepicker'; }; CheckboxGroup: LunaticBaseProps> & { options: { id: string; label: ReactNode; name: string; checked: boolean; description?: ReactNode; onCheck: (b: boolean) => void; onDetailChange?: (v: string) => void; detailLabel?: ReactNode; detailMaxLength?: number; detailValue?: string | null; shouldBeFiltered?: boolean; }[]; orientation?: 'horizontal' | 'vertical'; detailAlwaysDisplayed?: boolean; componentType?: 'CheckboxGroup'; }; CheckboxOne: LunaticBaseProps & { options: Array; response: { name: string }; componentType?: 'CheckboxOne'; orientation?: 'horizontal' | 'vertical'; detailAlwaysDisplayed?: boolean; }; Switch: LunaticBaseProps & { response: { name: string }; statusLabel?: { true: string; false: string }; componentType?: 'Switch'; }; CheckboxBoolean: LunaticBaseProps & { response: { name: string }; componentType?: 'CheckboxBoolean'; }; Radio: LunaticBaseProps & { options: Array; checkboxStyle?: boolean; response: { name: string }; componentType?: 'Radio'; orientation?: 'horizontal' | 'vertical'; detailAlwaysDisplayed?: boolean; }; Roundabout: LunaticBaseProps & { iterations: number; goToPage: ReturnType['goToPage']; page: number; progressVariable: string; locked: boolean; items: { label?: ReactNode; progress: number; // -1: not completed, 0: started, 1: finished description?: ReactNode; disabled?: boolean; }[]; componentType?: 'Roundabout'; }; Dropdown: LunaticBaseProps & { options: Array<{ description?: ReactNode; label: ReactNode; value: string; shouldBeFiltered?: boolean; }>; response: { name: string }; componentType?: 'Dropdown'; }; Textarea: LunaticBaseProps & { cols?: number; placeHolder?: string; maxLength?: number; rows?: number; response: { name: string }; componentType?: 'Textarea'; }; FilterDescription: Pick, 'id' | 'label'> & { componentType?: 'FilterDescription'; }; PairwiseLinks: Omit & { components: LunaticComponentDefinition[]; features?: LunaticOptions['features']; executeExpression: LunaticReducerState['executeExpression']; size: number; symLinks: Record>; value: Record; getComponents: (x: number, y: number) => LunaticComponentProps[]; componentType?: 'PairwiseLinks'; }; Suggester: LunaticBaseProps & { componentType?: 'Suggester'; storeName: string; /** * @deprecated use createCustomizableField with ComboboxOptionRenderer as name. */ optionRenderer: FunctionComponent<{ option: SuggesterOption; placeholder?: string; search?: string; }>; /** * @deprecated use createCustomizableField with ComboboxLabelRenderer as name. */ labelRenderer: FunctionComponent<{ option?: SuggesterOption; selected?: boolean; search?: string; }>; focused: boolean; response: { name: string }; optionResponses?: { name: string; attribute: string }[]; arbitrary?: { response: { name: string }; }; arbitraryValue?: string; allowArbitrary?: boolean; executeExpression: LunaticReducerState['executeExpression']; iteration: LunaticReducerState['pager']['iteration']; }; Summary: LunaticBaseProps & { componentType?: 'Summary'; executeExpression: LunaticReducerState['executeExpression']; sections: Array<{ id: string; responses?: Array<{ id: string; label: VtlExpression; value: VtlExpression; }>; title?: VtlExpression; iterations?: VtlExpression; }>; }; }; export type LunaticComponentType = keyof ComponentPropsByType; export type LunaticComponentProps< T extends LunaticComponentType = LunaticComponentType, > = ComponentPropsByType[T];