@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
61 lines (60 loc) • 1.73 kB
JavaScript
;
"use client";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useCollectStepsData = useCollectStepsData;
var _react = require("react");
var _componentHelper = require("../../../../shared/component-helper.js");
var _WizardContext = _interopRequireDefault(require("../Context/WizardContext.js"));
var _index = require("../../hooks/index.js");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function useCollectStepsData() {
const {
activeIndexRef,
hasErrorInOtherStepRef,
stepsRef,
hasInvalidStepsState
} = (0, _react.useContext)(_WizardContext.default) || {};
const translations = (0, _index.useTranslation)();
const collectStepsData = (0, _react.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 ? (0, _componentHelper.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