import { Fragment } from 'react'; import type { LunaticComponentProps } from '../type'; import { Table, Tbody, Td, Tr, TableHeader } from '../shared/Table'; import { times } from '../../utils/array'; import { LunaticComponents } from '../LunaticComponents'; import { blockedInLoopComponents } from '../Loop/constant'; import { ComponentErrors, getComponentErrors, } from '../shared/ComponentErrors/ComponentErrors'; import { CustomLoop } from '../Loop/Loop'; import { useLoopUtils } from '../Loop/utils'; import { useLunaticComponentsOptions } from '../../use-lunatic/lunatic-context'; /** * Loop displayed as a table */ export const RosterForLoop = ( props: LunaticComponentProps<'RosterForLoop'> ) => { const { disableRosterForLoopDeleteRowButton } = useLunaticComponentsOptions(); const { min, max, nbRows, addRow, removeRow } = useLoopUtils(props); const { errors, // eslint-disable-next-line @typescript-eslint/no-unused-vars declarations, header, id, getComponents, // eslint-disable-next-line @typescript-eslint/no-unused-vars label, ...otherProps // These props will be passed down to the child components } = props; if (nbRows === 0) { return null; } let cols = 0; return ( {header && } {times(nbRows, (n) => { const components = getComponents(n); const lineErrors = getComponentErrors(props.errors, `${id}-${n}`); const hasLineErrors = !!lineErrors?.length; cols = components.length; return ( ({ ...otherProps, ...c, id: `${c.id}-${n}`, iteration: n, errors, })} wrapper={(props) => {hasLineErrors && ( {/* @ts-expect-error colSpan is not resolved */} )} ); })}
} />
); };