Debian Codegraph @

node/@patternfly/react-core/dist/esm/components/Wizard/WizardNavInternal.js

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