| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.WizardNavInternal = void 0; |
| 4 |
const jsx_runtime_1 = require("react/jsx-runtime"); |
| 5 |
const react_1 = require("react"); |
| 6 |
const types_1 = require("./types"); |
| 7 |
const WizardContext_1 = require("./WizardContext"); |
| 8 |
const WizardNav_1 = require("./WizardNav"); |
| 9 |
const WizardNavItem_1 = require("./WizardNavItem"); |
| 10 |
const WizardNavInternal = ({ nav, navAriaLabel, isVisitRequired, isProgressive, isNavExpanded }) => { |
| 11 |
const { activeStep, steps, goToStepByIndex } = (0, WizardContext_1.useWizardContext)(); |
| 12 |
const wizardNavProps = Object.assign({ isExpanded: isNavExpanded, 'aria-label': navAriaLabel || (nav === null || nav === void 0 ? void 0 : nav['aria-label']) || 'Wizard steps' }, ((nav === null || nav === void 0 ? void 0 : nav['aria-labelledby']) && { |
| 13 |
'aria-labelledby': nav['aria-labelledby'] |
| 14 |
})); |
| 15 |
return ((0, jsx_runtime_1.jsx)(WizardNav_1.WizardNav, Object.assign({}, wizardNavProps, { children: steps.map((step, stepIndex) => { |
| 16 |
var _a; |
| 17 |
const hasVisitedNextStep = steps.some((step) => step.index > stepIndex + 1 && step.isVisited); |
| 18 |
const isStepDisabled = step.isDisabled || (isVisitRequired && !step.isVisited && !hasVisitedNextStep); |
| 19 |
const customStepNavItem = (0, types_1.isCustomWizardNavItem)(step.navItem) && ((0, jsx_runtime_1.jsx)(react_1.Fragment, { children: typeof step.navItem === 'function' ? step.navItem(step, activeStep, steps, goToStepByIndex) : step.navItem }, step.id)); |
| 20 |
if ((0, types_1.isWizardParentStep)(step) && !step.isHidden) { |
| 21 |
let firstSubStepIndex; |
| 22 |
let hasActiveChild = false; |
| 23 |
const subNavItems = (_a = step.subStepIds) === null || _a === void 0 ? void 0 : _a.map((subStepId, _subStepIndex) => { |
| 24 |
const subStep = steps.find((step) => step.id === subStepId); |
| 25 |
const hasVisitedNextStep = steps.some((step) => step.index > subStep.index && step.isVisited); |
| 26 |
const isSubStepDisabled = subStep.isDisabled || (isVisitRequired && !subStep.isVisited && !hasVisitedNextStep); |
| 27 |
const customSubStepNavItem = (0, types_1.isCustomWizardNavItem)(subStep.navItem) && ((0, jsx_runtime_1.jsx)(react_1.Fragment, { children: typeof subStep.navItem === 'function' |
| 28 |
? subStep.navItem(subStep, activeStep, steps, goToStepByIndex) |
| 29 |
: subStep.navItem }, subStep.id)); |
| 30 |
// Don't render the sub-step navigation item if the hidden property is enabled |
| 31 |
if (subStep.isHidden) { |
| 32 |
return; |
| 33 |
} |
| 34 |
// Store the first visible sub-step index so that when its parent is clicked, the first sub-step is focused |
| 35 |
if (firstSubStepIndex === undefined) { |
| 36 |
firstSubStepIndex = subStep.index; |
| 37 |
} |
| 38 |
// When a sub-step is active, use this flag to set the parent step as active (isCurrent) |
| 39 |
if ((activeStep === null || activeStep === void 0 ? void 0 : activeStep.id) === subStep.id) { |
| 40 |
hasActiveChild = true; |
| 41 |
} |
| 42 |
if (!isProgressive || (isProgressive && subStep.index <= activeStep.index)) { |
| 43 |
return (customSubStepNavItem || ((0, jsx_runtime_1.jsx)(WizardNavItem_1.WizardNavItem, Object.assign({ id: subStep.id, content: subStep.name, isCurrent: (activeStep === null || activeStep === void 0 ? void 0 : activeStep.id) === subStep.id, isDisabled: isSubStepDisabled || isStepDisabled, isVisited: subStep.isVisited, stepIndex: subStep.index, onClick: () => goToStepByIndex(subStep.index), status: subStep.status }, subStep.navItem), subStep.id))); |
| 44 |
} |
| 45 |
}); |
| 46 |
const hasEnabledChildren = react_1.Children.toArray(subNavItems).some((child) => (0, react_1.isValidElement)(child) && !child.props.isDisabled); |
| 47 |
if (!isProgressive || (isProgressive && step.index <= activeStep.index)) { |
| 48 |
return (customStepNavItem || ((0, jsx_runtime_1.jsx)(WizardNavItem_1.WizardNavItem, Object.assign({ id: step.id, content: step.name, isExpandable: step.isExpandable, isCurrent: hasActiveChild, isDisabled: !hasEnabledChildren || isStepDisabled, isVisited: step.isVisited, stepIndex: firstSubStepIndex, onClick: () => goToStepByIndex(firstSubStepIndex), status: step.status }, step.navItem, { children: (0, jsx_runtime_1.jsx)(WizardNav_1.WizardNav, Object.assign({}, wizardNavProps, { isInnerList: true, children: subNavItems })) }), step.id))); |
| 49 |
} |
| 50 |
} |
| 51 |
if ((0, types_1.isWizardBasicStep)(step) && |
| 52 |
!step.isHidden && |
| 53 |
(!isProgressive || (isProgressive && step.index <= activeStep.index))) { |
| 54 |
return (customStepNavItem || ((0, jsx_runtime_1.jsx)(WizardNavItem_1.WizardNavItem, Object.assign({ id: step.id, content: step.name, isCurrent: (activeStep === null || activeStep === void 0 ? void 0 : activeStep.id) === step.id, isDisabled: isStepDisabled, isVisited: step.isVisited, stepIndex: step.index, onClick: () => goToStepByIndex(step.index), status: step.status }, step.navItem), step.id))); |
| 55 |
} |
| 56 |
}) }))); |
| 57 |
}; |
| 58 |
exports.WizardNavInternal = WizardNavInternal; |
| 59 |
//# sourceMappingURL=WizardNavInternal.js.map |