Debian Codegraph @

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

raw
1 import { __rest } from "tslib";
2 import { Children, isValidElement } from 'react';
3 import { isWizardParentStep, isWizardSubStep } from './types';
4 import { WizardStep } from './WizardStep';
5 /**
6 * Accumulate list of step & sub-step props pulled from child components
7 * @param children
8 * @returns WizardStepType[]
9 */
10 export const buildSteps = (children) => Children.toArray(children).reduce((acc, child, index) => {
11 if (isWizardStep(child)) {
12 const { props: childProps } = child;
13 const { steps: childStepComponents, id } = childProps;
14 const stepIndex = acc.length + 1;
15 const subSteps = [];
16 acc.push(Object.assign(Object.assign(Object.assign({ index: stepIndex, component: child }, (index === 0 && !(childStepComponents === null || childStepComponents === void 0 ? void 0 : childStepComponents.length) && { isVisited: true })), (childStepComponents && {
17 subStepIds: childStepComponents === null || childStepComponents === void 0 ? void 0 : childStepComponents.map((childStepComponent, subStepIndex) => {
18 subSteps.push(Object.assign(Object.assign({ index: stepIndex + subStepIndex + 1, component: childStepComponent, parentId: id }, (index === 0 && subStepIndex === 0 && { isVisited: true })), normalizeStepProps(childStepComponent.props)));
19 return childStepComponent.props.id;
20 })
21 })), normalizeStepProps(childProps)), ...subSteps);
22 }
23 else {
24 throw new Error('Wizard only accepts children of type WizardStep.');
25 }
26 return acc;
27 }, []);
28 export function isWizardStep(child) {
29 return isValidElement(child) && child.type === WizardStep;
30 }
31 // Omit "children" and "steps" when building steps for the Wizard's context
32 export const normalizeStepProps = (_a) => {
33 var { children: _children, steps: _steps } = _a, controlStep = __rest(_a, ["children", "steps"]);
34 return controlStep;
35 };
36 /**
37 * Determines whether a step is navigable based on disabled/hidden properties
38 * @param steps All steps
39 * @param step
40 * @returns boolean
41 */
42 export const isStepEnabled = (steps, step) => {
43 // Skip over parent steps since they are merely containers of sub-steps
44 if (!isWizardParentStep(step) && !step.isHidden && !step.isDisabled) {
45 if (isWizardSubStep(step)) {
46 const parentStep = steps.find((otherStep) => otherStep.id === step.parentId);
47 if (!parentStep.isHidden && !parentStep.isDisabled) {
48 return true;
49 }
50 }
51 else {
52 return true;
53 }
54 }
55 return false;
56 };
57 //# sourceMappingURL=utils.js.map