import { slottableComponent } from '../shared/HOC/slottableComponent'; import type { LunaticComponentProps } from '../type'; import type { ItemOf } from '../../type.utils'; import { Button } from '../shared/Button/Button'; import classnames from 'classnames'; import { ComponentErrors } from '../shared/ComponentErrors/ComponentErrors'; import type { LunaticError } from '../../use-lunatic/type'; import type { ReactNode } from 'react'; import { Declarations } from '../shared/Declarations/Declarations'; import { LabelDescription } from '../shared/LabelDescription'; type PropsItem = ItemOf['items']> & { onClick: () => void; iteration: number; locked: boolean; errors?: LunaticError[]; }; function RoundaboutItem({ label, progress, description, onClick, disabled, iteration, locked, errors, }: PropsItem) { return (
{label && ( )} {description && (
{description}
)}
{!disabled && ( )}
); } type Props = Pick< LunaticComponentProps<'Roundabout'>, 'declarations' | 'description' | 'label' | 'locked' | 'id' > & { goToIteration: (v: number) => void; errors?: LunaticError[]; items: { label?: ReactNode; progress: number; // -1: not completed, 0: started, 1: finished description?: ReactNode; disabled?: boolean; errors?: LunaticError[] | undefined; }[]; }; export const CustomRoundabout = slottableComponent( 'Roundabout', ({ declarations, description, id, items, goToIteration, label, locked, errors, }) => { return (
{label}
{items.map((item, k) => ( goToIteration(k)} locked={locked} /> ))}
); } ); function getButtonLabel(progress: number) { if (progress === 1) { return 'Complété'; } if (progress === 0) { return 'Modifier'; } return 'Commencer'; } function getButtonClass(progress: number) { if (progress === 1) { return 'lunatic-roundabout__button-completed'; } if (progress === 0) { return 'lunatic-roundabout__button-progress'; } return null; }