@patternfly/react-core 4.249.0 → 4.250.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/esm/next/components/Select/Select.d.ts +28 -0
- package/dist/esm/next/components/Select/Select.d.ts.map +1 -0
- package/dist/esm/next/components/Select/Select.js +62 -0
- package/dist/esm/next/components/Select/Select.js.map +1 -0
- package/dist/esm/next/components/Select/SelectGroup.d.ts +12 -0
- package/dist/esm/next/components/Select/SelectGroup.d.ts.map +1 -0
- package/dist/esm/next/components/Select/SelectGroup.js +10 -0
- package/dist/esm/next/components/Select/SelectGroup.js.map +1 -0
- package/dist/esm/next/components/Select/SelectList.d.ts +10 -0
- package/dist/esm/next/components/Select/SelectList.d.ts.map +1 -0
- package/dist/esm/next/components/Select/SelectList.js +10 -0
- package/dist/esm/next/components/Select/SelectList.js.map +1 -0
- package/dist/esm/next/components/Select/SelectOption.d.ts +20 -0
- package/dist/esm/next/components/Select/SelectOption.d.ts.map +1 -0
- package/dist/esm/next/components/Select/SelectOption.js +10 -0
- package/dist/esm/next/components/Select/SelectOption.js.map +1 -0
- package/dist/esm/next/components/Select/index.d.ts +5 -0
- package/dist/esm/next/components/Select/index.d.ts.map +1 -0
- package/dist/esm/next/components/Select/index.js +5 -0
- package/dist/esm/next/components/Select/index.js.map +1 -0
- package/dist/esm/next/components/Wizard/Wizard.d.ts +9 -7
- package/dist/esm/next/components/Wizard/Wizard.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/Wizard.js +62 -48
- package/dist/esm/next/components/Wizard/Wizard.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardBody.d.ts +2 -2
- package/dist/esm/next/components/Wizard/WizardBody.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardBody.js +1 -1
- package/dist/esm/next/components/Wizard/WizardBody.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardContext.d.ts +21 -20
- package/dist/esm/next/components/Wizard/WizardContext.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardContext.js +63 -32
- package/dist/esm/next/components/Wizard/WizardContext.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardFooter.d.ts +20 -6
- package/dist/esm/next/components/Wizard/WizardFooter.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardFooter.js +13 -4
- package/dist/esm/next/components/Wizard/WizardFooter.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardHeader.d.ts +1 -1
- package/dist/esm/next/components/Wizard/WizardHeader.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardHeader.js +2 -2
- package/dist/esm/next/components/Wizard/WizardHeader.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardNav.d.ts +5 -5
- package/dist/esm/next/components/Wizard/WizardNav.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardNav.js +3 -4
- package/dist/esm/next/components/Wizard/WizardNav.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardNavInternal.d.ts +14 -0
- package/dist/esm/next/components/Wizard/WizardNavInternal.d.ts.map +1 -0
- package/dist/esm/next/components/Wizard/WizardNavInternal.js +49 -0
- package/dist/esm/next/components/Wizard/WizardNavInternal.js.map +1 -0
- package/dist/esm/next/components/Wizard/WizardNavItem.d.ts +12 -8
- package/dist/esm/next/components/Wizard/WizardNavItem.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardNavItem.js +23 -12
- package/dist/esm/next/components/Wizard/WizardNavItem.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardStep.d.ts +22 -6
- package/dist/esm/next/components/Wizard/WizardStep.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardStep.js +20 -1
- package/dist/esm/next/components/Wizard/WizardStep.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardToggle.d.ts +9 -15
- package/dist/esm/next/components/Wizard/WizardToggle.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardToggle.js +15 -50
- package/dist/esm/next/components/Wizard/WizardToggle.js.map +1 -1
- package/dist/esm/next/components/Wizard/hooks/useWizardFooter.d.ts +2 -2
- package/dist/esm/next/components/Wizard/hooks/useWizardFooter.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/hooks/useWizardFooter.js +3 -3
- package/dist/esm/next/components/Wizard/hooks/useWizardFooter.js.map +1 -1
- package/dist/esm/next/components/Wizard/types.d.ts +37 -46
- package/dist/esm/next/components/Wizard/types.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/types.js +10 -2
- package/dist/esm/next/components/Wizard/types.js.map +1 -1
- package/dist/esm/next/components/Wizard/utils.d.ts +4 -5
- package/dist/esm/next/components/Wizard/utils.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/utils.js +20 -13
- package/dist/esm/next/components/Wizard/utils.js.map +1 -1
- package/dist/esm/next/components/index.d.ts +2 -1
- package/dist/esm/next/components/index.d.ts.map +1 -1
- package/dist/esm/next/components/index.js +2 -1
- package/dist/esm/next/components/index.js.map +1 -1
- package/dist/js/next/components/Select/Select.d.ts +28 -0
- package/dist/js/next/components/Select/Select.d.ts.map +1 -0
- package/dist/js/next/components/Select/Select.js +65 -0
- package/dist/js/next/components/Select/Select.js.map +1 -0
- package/dist/js/next/components/Select/SelectGroup.d.ts +12 -0
- package/dist/js/next/components/Select/SelectGroup.d.ts.map +1 -0
- package/dist/js/next/components/Select/SelectGroup.js +14 -0
- package/dist/js/next/components/Select/SelectGroup.js.map +1 -0
- package/dist/js/next/components/Select/SelectList.d.ts +10 -0
- package/dist/js/next/components/Select/SelectList.d.ts.map +1 -0
- package/dist/js/next/components/Select/SelectList.js +14 -0
- package/dist/js/next/components/Select/SelectList.js.map +1 -0
- package/dist/js/next/components/Select/SelectOption.d.ts +20 -0
- package/dist/js/next/components/Select/SelectOption.d.ts.map +1 -0
- package/dist/js/next/components/Select/SelectOption.js +14 -0
- package/dist/js/next/components/Select/SelectOption.js.map +1 -0
- package/dist/js/next/components/Select/index.d.ts +5 -0
- package/dist/js/next/components/Select/index.d.ts.map +1 -0
- package/dist/js/next/components/Select/index.js +8 -0
- package/dist/js/next/components/Select/index.js.map +1 -0
- package/dist/js/next/components/Wizard/Wizard.d.ts +9 -7
- package/dist/js/next/components/Wizard/Wizard.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/Wizard.js +59 -45
- package/dist/js/next/components/Wizard/Wizard.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardBody.d.ts +2 -2
- package/dist/js/next/components/Wizard/WizardBody.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardBody.js +1 -1
- package/dist/js/next/components/Wizard/WizardBody.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardContext.d.ts +21 -20
- package/dist/js/next/components/Wizard/WizardContext.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardContext.js +61 -30
- package/dist/js/next/components/Wizard/WizardContext.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardFooter.d.ts +20 -6
- package/dist/js/next/components/Wizard/WizardFooter.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardFooter.js +15 -6
- package/dist/js/next/components/Wizard/WizardFooter.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardHeader.d.ts +1 -1
- package/dist/js/next/components/Wizard/WizardHeader.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardHeader.js +2 -2
- package/dist/js/next/components/Wizard/WizardHeader.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardNav.d.ts +5 -5
- package/dist/js/next/components/Wizard/WizardNav.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardNav.js +3 -4
- package/dist/js/next/components/Wizard/WizardNav.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardNavInternal.d.ts +14 -0
- package/dist/js/next/components/Wizard/WizardNavInternal.d.ts.map +1 -0
- package/dist/js/next/components/Wizard/WizardNavInternal.js +54 -0
- package/dist/js/next/components/Wizard/WizardNavInternal.js.map +1 -0
- package/dist/js/next/components/Wizard/WizardNavItem.d.ts +12 -8
- package/dist/js/next/components/Wizard/WizardNavItem.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardNavItem.js +23 -12
- package/dist/js/next/components/Wizard/WizardNavItem.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardStep.d.ts +22 -6
- package/dist/js/next/components/Wizard/WizardStep.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardStep.js +20 -1
- package/dist/js/next/components/Wizard/WizardStep.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardToggle.d.ts +9 -15
- package/dist/js/next/components/Wizard/WizardToggle.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardToggle.js +15 -51
- package/dist/js/next/components/Wizard/WizardToggle.js.map +1 -1
- package/dist/js/next/components/Wizard/hooks/useWizardFooter.d.ts +2 -2
- package/dist/js/next/components/Wizard/hooks/useWizardFooter.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/hooks/useWizardFooter.js +3 -3
- package/dist/js/next/components/Wizard/hooks/useWizardFooter.js.map +1 -1
- package/dist/js/next/components/Wizard/types.d.ts +37 -46
- package/dist/js/next/components/Wizard/types.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/types.js +12 -3
- package/dist/js/next/components/Wizard/types.js.map +1 -1
- package/dist/js/next/components/Wizard/utils.d.ts +4 -5
- package/dist/js/next/components/Wizard/utils.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/utils.js +24 -15
- package/dist/js/next/components/Wizard/utils.js.map +1 -1
- package/dist/js/next/components/index.d.ts +2 -1
- package/dist/js/next/components/index.d.ts.map +1 -1
- package/dist/js/next/components/index.js +2 -1
- package/dist/js/next/components/index.js.map +1 -1
- package/dist/umd/react-core.min.css +940 -940
- package/package.json +2 -2
- package/src/next/components/Select/Select.tsx +129 -0
- package/src/next/components/Select/SelectGroup.tsx +24 -0
- package/src/next/components/Select/SelectList.tsx +21 -0
- package/src/next/components/Select/SelectOption.tsx +31 -0
- package/src/next/components/Select/examples/Select.md +37 -0
- package/src/next/components/Select/examples/SelectBasic.tsx +54 -0
- package/src/next/components/Select/examples/SelectCheckbox.tsx +67 -0
- package/src/next/components/Select/examples/SelectGrouped.tsx +63 -0
- package/src/next/components/Select/examples/SelectMultiTypeahead.tsx +195 -0
- package/src/next/components/Select/examples/SelectTypeahead.tsx +191 -0
- package/src/next/components/Select/index.ts +4 -0
- package/src/next/components/Wizard/Wizard.tsx +107 -64
- package/src/next/components/Wizard/WizardBody.tsx +4 -4
- package/src/next/components/Wizard/WizardContext.tsx +117 -65
- package/src/next/components/Wizard/WizardFooter.tsx +39 -17
- package/src/next/components/Wizard/WizardHeader.tsx +6 -3
- package/src/next/components/Wizard/WizardNav.tsx +9 -10
- package/src/next/components/Wizard/WizardNavInternal.tsx +137 -0
- package/src/next/components/Wizard/WizardNavItem.tsx +47 -20
- package/src/next/components/Wizard/WizardStep.tsx +52 -7
- package/src/next/components/Wizard/WizardToggle.tsx +24 -142
- package/src/next/components/Wizard/__tests__/Wizard.test.tsx +10 -13
- package/src/next/components/Wizard/__tests__/WizardBody.test.tsx +3 -3
- package/src/next/components/Wizard/__tests__/WizardFooter.test.tsx +11 -14
- package/src/next/components/Wizard/__tests__/WizardStep.test.tsx +100 -0
- package/src/next/components/Wizard/__tests__/WizardToggle.test.tsx +4 -4
- package/src/next/components/Wizard/examples/Wizard.md +40 -15
- package/src/next/components/Wizard/examples/WizardBasic.tsx +2 -2
- package/src/next/components/Wizard/examples/WizardCustomNav.tsx +4 -4
- package/src/next/components/Wizard/examples/WizardKitchenSink.tsx +126 -60
- package/src/next/components/Wizard/hooks/__tests__/useWizardFooter.test.tsx +23 -34
- package/src/next/components/Wizard/hooks/useWizardFooter.tsx +5 -5
- package/src/next/components/Wizard/types.tsx +59 -53
- package/src/next/components/Wizard/utils.ts +25 -16
- package/src/next/components/index.ts +2 -1
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { WizardNavProps, WizardNavItemProps } from '../Wizard';
|
|
2
|
+
import { WizardNavProps, WizardNavItemProps, WizardFooterProps } from '../Wizard';
|
|
3
3
|
|
|
4
4
|
/** Type used to define 'basic' steps, or in other words, steps that are neither parents or children of parents. */
|
|
5
5
|
export interface WizardBasicStep {
|
|
6
|
-
/** Name of the step's
|
|
6
|
+
/** Name of the step's navigation item */
|
|
7
7
|
name: React.ReactNode;
|
|
8
8
|
/** Unique identifier */
|
|
9
9
|
id: string | number;
|
|
10
|
-
/** Flag to disable the step's
|
|
10
|
+
/** Flag to disable the step's navigation item */
|
|
11
11
|
isDisabled?: boolean;
|
|
12
12
|
/** Flag to represent whether the step has been visited (navigated to) */
|
|
13
|
-
|
|
14
|
-
/**
|
|
13
|
+
isVisited?: boolean;
|
|
14
|
+
/** Flag to determine whether the step is hidden */
|
|
15
|
+
isHidden?: boolean;
|
|
16
|
+
/** Content shown when the step's navigation item is selected. When treated as a parent step, only sub-step content will be shown. */
|
|
15
17
|
component?: React.ReactElement;
|
|
16
|
-
/**
|
|
17
|
-
navItem?:
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
/** Replaces the step's navigation item or its properties. */
|
|
19
|
+
navItem?: WizardNavItemType;
|
|
20
|
+
/** Replaces the step's footer. The step's footer takes precedance over the wizard's footer. */
|
|
21
|
+
footer?: React.ReactElement | Partial<WizardFooterProps>;
|
|
22
|
+
/** Used to determine icon next to the step's navItem */
|
|
23
|
+
status?: 'default' | 'error';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export enum WizardNavItemStatus {
|
|
27
|
+
Default = 'default',
|
|
28
|
+
Error = 'error'
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
/** Type used to define parent steps. */
|
|
29
32
|
export interface WizardParentStep extends WizardBasicStep {
|
|
30
33
|
/** Nested step IDs */
|
|
31
|
-
subStepIds: string[];
|
|
34
|
+
subStepIds: (string | number)[];
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
/** Type used to define sub-steps. */
|
|
@@ -37,34 +40,6 @@ export interface WizardSubStep extends WizardBasicStep {
|
|
|
37
40
|
parentId: string | number;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
/** Used to customize aspects of the Wizard's default navigation. */
|
|
41
|
-
export interface DefaultWizardNavProps {
|
|
42
|
-
/** Flag indicating nav items with sub steps are expandable */
|
|
43
|
-
isExpandable?: boolean;
|
|
44
|
-
/** Aria-label for the Nav */
|
|
45
|
-
ariaLabel?: string;
|
|
46
|
-
/** Sets aria-labelledby on nav element */
|
|
47
|
-
ariaLabelledBy?: string;
|
|
48
|
-
/** Disable step nav items until they are visited */
|
|
49
|
-
forceStepVisit?: boolean;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** Used to customize aspects of the Wizard's default footer. */
|
|
53
|
-
export interface DefaultWizardFooterProps {
|
|
54
|
-
/** The Next button text */
|
|
55
|
-
nextButtonText?: React.ReactNode;
|
|
56
|
-
/** The Back button text */
|
|
57
|
-
backButtonText?: React.ReactNode;
|
|
58
|
-
/** The Cancel button text */
|
|
59
|
-
cancelButtonText?: React.ReactNode;
|
|
60
|
-
/** Next button callback */
|
|
61
|
-
onNext?: () => WizardNavStepFunction | void;
|
|
62
|
-
/** Back button callback */
|
|
63
|
-
onBack?: () => WizardNavStepFunction | void;
|
|
64
|
-
/** Cancel link callback */
|
|
65
|
-
onClose?: () => void;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
43
|
/** Encompasses all step type variants that are internally controlled by the Wizard. */
|
|
69
44
|
export type WizardControlStep = WizardBasicStep | WizardParentStep | WizardSubStep;
|
|
70
45
|
|
|
@@ -72,26 +47,57 @@ export type WizardControlStep = WizardBasicStep | WizardParentStep | WizardSubSt
|
|
|
72
47
|
export type WizardNavStepFunction = (currentStep: WizardNavStepData, previousStep: WizardNavStepData) => void;
|
|
73
48
|
|
|
74
49
|
/** Data returned for either parameter of WizardNavStepFunction. */
|
|
75
|
-
export
|
|
50
|
+
export interface WizardNavStepData {
|
|
51
|
+
/** Unique identifier */
|
|
52
|
+
id: string | number;
|
|
53
|
+
/** Name of the step */
|
|
54
|
+
name: string;
|
|
55
|
+
/** Index of the step (starts at 1) */
|
|
56
|
+
index: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type WizardFooterType = Partial<WizardFooterProps> | CustomWizardFooterFunction | React.ReactElement;
|
|
60
|
+
export type WizardNavType = Partial<WizardNavProps> | CustomWizardNavFunction | React.ReactElement;
|
|
61
|
+
export type WizardNavItemType = Partial<WizardNavItemProps> | CustomWizardNavItemFunction | React.ReactElement;
|
|
76
62
|
|
|
77
63
|
/** Callback for the Wizard's 'nav' property. Returns element which replaces the Wizard's default navigation. */
|
|
78
64
|
export type CustomWizardNavFunction = (
|
|
79
65
|
isExpanded: boolean,
|
|
80
66
|
steps: WizardControlStep[],
|
|
81
|
-
|
|
67
|
+
currentStep: WizardControlStep,
|
|
82
68
|
goToStepByIndex: (index: number) => void
|
|
83
69
|
) => React.ReactElement<WizardNavProps>;
|
|
84
70
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
71
|
+
/** Callback for the Wizard's 'navItem' property. Returns element which replaces the WizardStep's default navigation item. */
|
|
72
|
+
export type CustomWizardNavItemFunction = (
|
|
73
|
+
step: WizardControlStep,
|
|
74
|
+
currentStep: WizardControlStep,
|
|
75
|
+
steps: WizardControlStep[],
|
|
76
|
+
goToStepByIndex: (index: number) => void
|
|
77
|
+
) => React.ReactElement<WizardNavItemProps>;
|
|
78
|
+
|
|
79
|
+
/** Callback for the Wizard's 'footer' property. Returns element which replaces the Wizard's default footer. */
|
|
80
|
+
export type CustomWizardFooterFunction = (
|
|
81
|
+
currentStep: WizardControlStep,
|
|
82
|
+
onNext: () => void,
|
|
83
|
+
onBack: () => void,
|
|
84
|
+
onClose: () => void
|
|
85
|
+
) => React.ReactElement<WizardFooterProps>;
|
|
86
|
+
|
|
87
|
+
export function isCustomWizardNav(nav: WizardNavType): nav is CustomWizardNavFunction | React.ReactElement {
|
|
88
|
+
return typeof nav === 'function' || React.isValidElement(nav);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function isCustomWizardNavItem(
|
|
92
|
+
navItem: WizardNavItemType
|
|
93
|
+
): navItem is CustomWizardNavItemFunction | React.ReactElement {
|
|
94
|
+
return typeof navItem === 'function' || React.isValidElement(navItem);
|
|
89
95
|
}
|
|
90
96
|
|
|
91
97
|
export function isCustomWizardFooter(
|
|
92
|
-
footer:
|
|
93
|
-
): footer is React.ReactElement {
|
|
94
|
-
return React.isValidElement(footer);
|
|
98
|
+
footer: WizardFooterType
|
|
99
|
+
): footer is CustomWizardFooterFunction | React.ReactElement {
|
|
100
|
+
return typeof footer === 'function' || React.isValidElement(footer);
|
|
95
101
|
}
|
|
96
102
|
|
|
97
103
|
export function isWizardBasicStep(step: WizardControlStep): step is WizardBasicStep {
|
|
@@ -3,32 +3,23 @@ import React from 'react';
|
|
|
3
3
|
import { WizardControlStep, WizardNavStepData } from './types';
|
|
4
4
|
import { WizardStep, WizardStepProps } from './WizardStep';
|
|
5
5
|
|
|
6
|
-
function hasWizardStepProps(props: WizardStepProps | any): props is WizardStepProps {
|
|
7
|
-
return props.name !== undefined && props.id !== undefined;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
6
|
/**
|
|
11
7
|
* Accumulate list of step & sub-step props pulled from child components
|
|
12
8
|
* @param children
|
|
13
9
|
* @returns WizardControlStep[]
|
|
14
10
|
*/
|
|
15
11
|
export const buildSteps = (children: React.ReactElement<WizardStepProps> | React.ReactElement<WizardStepProps>[]) =>
|
|
16
|
-
React.Children.toArray(children).reduce((acc: WizardControlStep[], child) => {
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
20
|
-
const { steps: subSteps, id, children, ...stepProps } = child.props as WizardStepProps;
|
|
12
|
+
React.Children.toArray(children).reduce((acc: WizardControlStep[], child: React.ReactChild | React.ReactFragment) => {
|
|
13
|
+
if (isWizardStep(child)) {
|
|
14
|
+
const { steps: subSteps, id } = child.props;
|
|
21
15
|
|
|
22
16
|
acc.push({
|
|
23
|
-
id,
|
|
24
17
|
component: child,
|
|
25
|
-
...
|
|
18
|
+
...normalizeStep(child.props),
|
|
26
19
|
...(subSteps && {
|
|
27
20
|
subStepIds: subSteps?.map(subStep => {
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
29
|
-
const { children, ...subStepProps } = subStep.props;
|
|
30
21
|
acc.push({
|
|
31
|
-
...
|
|
22
|
+
...normalizeStep(subStep.props),
|
|
32
23
|
component: subStep,
|
|
33
24
|
parentId: id
|
|
34
25
|
});
|
|
@@ -44,6 +35,24 @@ export const buildSteps = (children: React.ReactElement<WizardStepProps> | React
|
|
|
44
35
|
return acc;
|
|
45
36
|
}, []);
|
|
46
37
|
|
|
47
|
-
export
|
|
48
|
-
|
|
38
|
+
export function isWizardStep(
|
|
39
|
+
child: any | React.ReactElement<WizardStepProps>
|
|
40
|
+
): child is React.ReactElement<WizardStepProps> {
|
|
41
|
+
return (
|
|
42
|
+
(React.isValidElement(child) && (child as React.ReactElement<WizardStepProps>).type === WizardStep) ||
|
|
43
|
+
(child.props?.name !== undefined && child.props?.id !== undefined)
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
48
|
+
export const normalizeStep = ({ children, steps, body, ...controlStep }: WizardStepProps): WizardControlStep =>
|
|
49
|
+
controlStep;
|
|
50
|
+
|
|
51
|
+
export const normalizeNavStep = (navStep: WizardControlStep, steps: WizardControlStep[]): WizardNavStepData => ({
|
|
52
|
+
id: navStep.id,
|
|
53
|
+
name: navStep.name.toString(),
|
|
54
|
+
index: steps.indexOf(navStep) + 1
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export const getCurrentStep = (steps: WizardControlStep[], currentStepIndex: number) =>
|
|
49
58
|
steps.find((_, index) => index + 1 === currentStepIndex);
|