UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

60 lines (59 loc) 1.7 kB
"use client"; import { useCallback, useContext } from 'react'; import { convertJsxToString } from '../../../../shared/component-helper'; import WizardContext from '../Context/WizardContext'; import { useTranslation } from '../../hooks'; export function useCollectStepsData() { const { activeIndexRef, hasErrorInOtherStepRef, stepsRef, submitCountRef, writeStepsState, hasInvalidStepsState } = useContext(WizardContext) || {}; const translations = useTranslation(); const collectStepsData = useCallback(_ref => { let { id, index, inactive, title } = _ref; if (!hasInvalidStepsState) { return; } writeStepsState(index); const stringifiedTitle = title !== undefined ? convertJsxToString(title) : 'Title missing'; let status = undefined; let statusState = undefined; if (index !== activeIndexRef.current && !inactive) { if (hasInvalidStepsState(index, ['error'])) { status = translations.Step.stepHasError; statusState = 'error'; } else if (submitCountRef.current > 0 && hasInvalidStepsState(index, ['unknown'])) { status = 'Unknown state'; statusState = 'warn'; } } if (status) { hasErrorInOtherStepRef.current = true; } stepsRef.current.set(index, { index, id, title, stringifiedTitle, inactive, status, statusState }); return { title }; }, [activeIndexRef, hasErrorInOtherStepRef, hasInvalidStepsState, stepsRef, submitCountRef, translations.Step.stepHasError, writeStepsState]); return { collectStepsData }; } //# sourceMappingURL=useCollectStepsData.js.map