@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
55 lines (54 loc) • 1.46 kB
JavaScript
"use client";
import { useCallback, useContext } from 'react';
import { convertJsxToString } from "../../../../shared/component-helper.js";
import WizardContext from "../Context/WizardContext.js";
import { useTranslation } from "../../hooks/index.js";
export function useCollectStepsData() {
const {
activeIndexRef,
hasErrorInOtherStepRef,
stepsRef,
hasInvalidStepsState
} = useContext(WizardContext) || {};
const translations = useTranslation();
const collectStepsData = useCallback(({
id,
index,
inactive,
title,
keepInDOM
}) => {
if (!hasInvalidStepsState) {
return;
}
let status = undefined;
let statusState = undefined;
if (index !== activeIndexRef.current && !inactive) {
if (hasInvalidStepsState(index, ['error'])) {
status = translations.Step.stepHasError;
statusState = 'error';
}
}
if (status) {
hasErrorInOtherStepRef.current = true;
}
const stringifiedTitle = title !== undefined ? convertJsxToString(title) : 'Title missing';
stepsRef.current.set(index, {
index,
id,
title,
stringifiedTitle,
inactive,
status,
statusState,
keepInDOM
});
return {
title
};
}, [activeIndexRef, hasErrorInOtherStepRef, hasInvalidStepsState, stepsRef, translations.Step.stepHasError]);
return {
collectStepsData
};
}
//# sourceMappingURL=useCollectStepsData.js.map