@patternfly/react-core 4.274.0 → 4.275.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 +19 -0
- package/components/Menu/MenuGroup.d.ts +1 -1
- package/components/Menu/MenuGroup.d.ts.map +1 -1
- package/components/Menu/MenuGroup.js.map +1 -1
- package/components/Select/Select.d.ts +2 -0
- package/components/Select/Select.d.ts.map +1 -1
- package/components/Select/Select.js +3 -3
- package/components/Select/Select.js.map +1 -1
- package/components/Select/SelectToggle.d.ts +4 -14
- package/components/Select/SelectToggle.d.ts.map +1 -1
- package/components/Select/SelectToggle.js +11 -5
- package/components/Select/SelectToggle.js.map +1 -1
- package/dist/esm/components/Menu/MenuGroup.d.ts +1 -1
- package/dist/esm/components/Menu/MenuGroup.d.ts.map +1 -1
- package/dist/esm/components/Menu/MenuGroup.js.map +1 -1
- package/dist/esm/components/Select/Select.d.ts +2 -0
- package/dist/esm/components/Select/Select.d.ts.map +1 -1
- package/dist/esm/components/Select/Select.js +3 -3
- package/dist/esm/components/Select/Select.js.map +1 -1
- package/dist/esm/components/Select/SelectToggle.d.ts +4 -14
- package/dist/esm/components/Select/SelectToggle.d.ts.map +1 -1
- package/dist/esm/components/Select/SelectToggle.js +11 -5
- package/dist/esm/components/Select/SelectToggle.js.map +1 -1
- package/dist/esm/next/components/Wizard/Wizard.d.ts +11 -14
- package/dist/esm/next/components/Wizard/Wizard.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/Wizard.js +30 -23
- package/dist/esm/next/components/Wizard/Wizard.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardContext.d.ts +16 -16
- package/dist/esm/next/components/Wizard/WizardContext.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardContext.js +17 -19
- package/dist/esm/next/components/Wizard/WizardContext.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardFooter.d.ts +8 -5
- package/dist/esm/next/components/Wizard/WizardFooter.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardFooter.js +1 -1
- 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/WizardNavInternal.d.ts +2 -2
- package/dist/esm/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardNavInternal.js +15 -9
- package/dist/esm/next/components/Wizard/WizardNavInternal.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardNavItem.d.ts +10 -4
- package/dist/esm/next/components/Wizard/WizardNavItem.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardNavItem.js +10 -9
- package/dist/esm/next/components/Wizard/WizardNavItem.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardStep.d.ts +3 -3
- package/dist/esm/next/components/Wizard/WizardStep.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardStep.js +4 -2
- package/dist/esm/next/components/Wizard/WizardStep.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardToggle.d.ts +4 -4
- package/dist/esm/next/components/Wizard/WizardToggle.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardToggle.js +1 -1
- package/dist/esm/next/components/Wizard/WizardToggle.js.map +1 -1
- package/dist/esm/next/components/Wizard/hooks/index.d.ts +1 -0
- package/dist/esm/next/components/Wizard/hooks/index.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/hooks/index.js +1 -0
- package/dist/esm/next/components/Wizard/hooks/index.js.map +1 -1
- package/dist/esm/next/components/Wizard/hooks/useGetMergedSteps.d.ts +9 -0
- package/dist/esm/next/components/Wizard/hooks/useGetMergedSteps.d.ts.map +1 -0
- package/dist/esm/next/components/Wizard/hooks/useGetMergedSteps.js +33 -0
- package/dist/esm/next/components/Wizard/hooks/useGetMergedSteps.js.map +1 -0
- package/dist/esm/next/components/Wizard/index.d.ts +2 -2
- package/dist/esm/next/components/Wizard/index.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/index.js +2 -2
- package/dist/esm/next/components/Wizard/index.js.map +1 -1
- package/dist/esm/next/components/Wizard/types.d.ts +13 -19
- package/dist/esm/next/components/Wizard/types.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/types.js +6 -0
- package/dist/esm/next/components/Wizard/types.js.map +1 -1
- package/dist/esm/next/components/Wizard/utils.d.ts +5 -6
- package/dist/esm/next/components/Wizard/utils.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/utils.js +15 -22
- package/dist/esm/next/components/Wizard/utils.js.map +1 -1
- package/dist/js/components/Menu/MenuGroup.d.ts +1 -1
- package/dist/js/components/Menu/MenuGroup.d.ts.map +1 -1
- package/dist/js/components/Menu/MenuGroup.js.map +1 -1
- package/dist/js/components/Select/Select.d.ts +2 -0
- package/dist/js/components/Select/Select.d.ts.map +1 -1
- package/dist/js/components/Select/Select.js +3 -3
- package/dist/js/components/Select/Select.js.map +1 -1
- package/dist/js/components/Select/SelectToggle.d.ts +4 -14
- package/dist/js/components/Select/SelectToggle.d.ts.map +1 -1
- package/dist/js/components/Select/SelectToggle.js +11 -6
- package/dist/js/components/Select/SelectToggle.js.map +1 -1
- package/dist/js/next/components/Wizard/Wizard.d.ts +11 -14
- package/dist/js/next/components/Wizard/Wizard.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/Wizard.js +28 -21
- package/dist/js/next/components/Wizard/Wizard.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardContext.d.ts +16 -16
- package/dist/js/next/components/Wizard/WizardContext.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardContext.js +16 -17
- package/dist/js/next/components/Wizard/WizardContext.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardFooter.d.ts +8 -5
- package/dist/js/next/components/Wizard/WizardFooter.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardFooter.js +1 -1
- 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/WizardNavInternal.d.ts +2 -2
- package/dist/js/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardNavInternal.js +15 -9
- package/dist/js/next/components/Wizard/WizardNavInternal.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardNavItem.d.ts +10 -4
- package/dist/js/next/components/Wizard/WizardNavItem.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardNavItem.js +10 -8
- package/dist/js/next/components/Wizard/WizardNavItem.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardStep.d.ts +3 -3
- package/dist/js/next/components/Wizard/WizardStep.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardStep.js +4 -2
- package/dist/js/next/components/Wizard/WizardStep.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardToggle.d.ts +4 -4
- package/dist/js/next/components/Wizard/WizardToggle.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardToggle.js +1 -1
- package/dist/js/next/components/Wizard/WizardToggle.js.map +1 -1
- package/dist/js/next/components/Wizard/hooks/index.d.ts +1 -0
- package/dist/js/next/components/Wizard/hooks/index.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/hooks/index.js +3 -1
- package/dist/js/next/components/Wizard/hooks/index.js.map +1 -1
- package/dist/js/next/components/Wizard/hooks/useGetMergedSteps.d.ts +9 -0
- package/dist/js/next/components/Wizard/hooks/useGetMergedSteps.d.ts.map +1 -0
- package/dist/js/next/components/Wizard/hooks/useGetMergedSteps.js +38 -0
- package/dist/js/next/components/Wizard/hooks/useGetMergedSteps.js.map +1 -0
- package/dist/js/next/components/Wizard/index.d.ts +2 -2
- package/dist/js/next/components/Wizard/index.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/index.js +4 -2
- package/dist/js/next/components/Wizard/index.js.map +1 -1
- package/dist/js/next/components/Wizard/types.d.ts +13 -19
- package/dist/js/next/components/Wizard/types.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/types.js +7 -1
- package/dist/js/next/components/Wizard/types.js.map +1 -1
- package/dist/js/next/components/Wizard/utils.d.ts +5 -6
- package/dist/js/next/components/Wizard/utils.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/utils.js +17 -25
- package/dist/js/next/components/Wizard/utils.js.map +1 -1
- package/dist/umd/react-core.min.js +2 -2
- package/next/components/Wizard/Wizard.d.ts +11 -14
- package/next/components/Wizard/Wizard.d.ts.map +1 -1
- package/next/components/Wizard/Wizard.js +30 -23
- package/next/components/Wizard/Wizard.js.map +1 -1
- package/next/components/Wizard/WizardContext.d.ts +16 -16
- package/next/components/Wizard/WizardContext.d.ts.map +1 -1
- package/next/components/Wizard/WizardContext.js +17 -19
- package/next/components/Wizard/WizardContext.js.map +1 -1
- package/next/components/Wizard/WizardFooter.d.ts +8 -5
- package/next/components/Wizard/WizardFooter.d.ts.map +1 -1
- package/next/components/Wizard/WizardFooter.js +1 -1
- package/next/components/Wizard/WizardFooter.js.map +1 -1
- package/next/components/Wizard/WizardHeader.d.ts +1 -1
- package/next/components/Wizard/WizardHeader.d.ts.map +1 -1
- package/next/components/Wizard/WizardNavInternal.d.ts +2 -2
- package/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
- package/next/components/Wizard/WizardNavInternal.js +15 -9
- package/next/components/Wizard/WizardNavInternal.js.map +1 -1
- package/next/components/Wizard/WizardNavItem.d.ts +10 -4
- package/next/components/Wizard/WizardNavItem.d.ts.map +1 -1
- package/next/components/Wizard/WizardNavItem.js +10 -9
- package/next/components/Wizard/WizardNavItem.js.map +1 -1
- package/next/components/Wizard/WizardStep.d.ts +3 -3
- package/next/components/Wizard/WizardStep.d.ts.map +1 -1
- package/next/components/Wizard/WizardStep.js +4 -2
- package/next/components/Wizard/WizardStep.js.map +1 -1
- package/next/components/Wizard/WizardToggle.d.ts +4 -4
- package/next/components/Wizard/WizardToggle.d.ts.map +1 -1
- package/next/components/Wizard/WizardToggle.js +1 -1
- package/next/components/Wizard/WizardToggle.js.map +1 -1
- package/next/components/Wizard/hooks/index.d.ts +1 -0
- package/next/components/Wizard/hooks/index.d.ts.map +1 -1
- package/next/components/Wizard/hooks/index.js +1 -0
- package/next/components/Wizard/hooks/index.js.map +1 -1
- package/next/components/Wizard/hooks/useGetMergedSteps.d.ts +9 -0
- package/next/components/Wizard/hooks/useGetMergedSteps.d.ts.map +1 -0
- package/next/components/Wizard/hooks/useGetMergedSteps.js +33 -0
- package/next/components/Wizard/hooks/useGetMergedSteps.js.map +1 -0
- package/next/components/Wizard/index.d.ts +2 -2
- package/next/components/Wizard/index.d.ts.map +1 -1
- package/next/components/Wizard/index.js +2 -2
- package/next/components/Wizard/index.js.map +1 -1
- package/next/components/Wizard/types.d.ts +13 -19
- package/next/components/Wizard/types.d.ts.map +1 -1
- package/next/components/Wizard/types.js +6 -0
- package/next/components/Wizard/types.js.map +1 -1
- package/next/components/Wizard/utils.d.ts +5 -6
- package/next/components/Wizard/utils.d.ts.map +1 -1
- package/next/components/Wizard/utils.js +15 -22
- package/next/components/Wizard/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Menu/MenuGroup.tsx +2 -2
- package/src/components/Select/Select.tsx +4 -0
- package/src/components/Select/SelectToggle.tsx +14 -3
- package/src/components/Select/examples/Select.md +28 -0
- package/src/next/components/Wizard/Wizard.tsx +71 -46
- package/src/next/components/Wizard/WizardContext.tsx +38 -43
- package/src/next/components/Wizard/WizardFooter.tsx +10 -6
- package/src/next/components/Wizard/WizardHeader.tsx +1 -1
- package/src/next/components/Wizard/WizardNavInternal.tsx +51 -43
- package/src/next/components/Wizard/WizardNavItem.tsx +21 -14
- package/src/next/components/Wizard/WizardStep.tsx +8 -6
- package/src/next/components/Wizard/WizardToggle.tsx +5 -5
- package/src/next/components/Wizard/__tests__/Wizard.test.tsx +129 -26
- package/src/next/components/Wizard/__tests__/WizardStep.test.tsx +5 -5
- package/src/next/components/Wizard/__tests__/WizardToggle.test.tsx +2 -2
- package/src/next/components/Wizard/__tests__/utils.test.tsx +3 -17
- package/src/next/components/Wizard/examples/Wizard.md +69 -41
- package/src/next/components/Wizard/examples/WizardBasic.tsx +6 -12
- package/src/next/components/Wizard/examples/WizardBasicDisabledSteps.tsx +22 -0
- package/src/next/components/Wizard/examples/WizardEnabledOnFormValidation.tsx +84 -0
- package/src/next/components/Wizard/examples/WizardExpandableSteps.tsx +42 -0
- package/src/next/components/Wizard/examples/WizardGetCurrentStep.tsx +53 -0
- package/src/next/components/Wizard/examples/WizardProgressiveSteps.tsx +31 -0
- package/src/next/components/Wizard/examples/WizardStepDrawerContent.tsx +80 -0
- package/src/next/components/Wizard/examples/WizardStepErrorStatus.tsx +55 -0
- package/src/next/components/Wizard/examples/WizardStepVisitRequired.tsx +22 -0
- package/src/next/components/Wizard/examples/WizardToggleStepVisibility.tsx +57 -0
- package/src/next/components/Wizard/examples/WizardValidateOnButtonPress.tsx +183 -0
- package/src/next/components/Wizard/examples/WizardWithCustomFooter.tsx +107 -0
- package/src/next/components/Wizard/examples/{WizardCustomNav.tsx → WizardWithCustomNav.tsx} +11 -11
- package/src/next/components/Wizard/examples/WizardWithCustomNavItem.tsx +22 -0
- package/src/next/components/Wizard/examples/WizardWithHeader.tsx +26 -0
- package/src/next/components/Wizard/examples/WizardWithNavAnchors.tsx +46 -0
- package/src/next/components/Wizard/examples/WizardWithSubmitProgress.tsx +86 -0
- package/src/next/components/Wizard/examples/WizardWithinModal.tsx +41 -0
- package/src/next/components/Wizard/hooks/index.ts +1 -0
- package/src/next/components/Wizard/hooks/useGetMergedSteps.tsx +45 -0
- package/src/next/components/Wizard/index.ts +2 -2
- package/src/next/components/Wizard/types.tsx +19 -29
- package/src/next/components/Wizard/utils.ts +27 -33
- package/src/next/components/Wizard/examples/WizardKitchenSink.tsx +0 -243
|
@@ -34,8 +34,8 @@ export enum WizardNavItemStatus {
|
|
|
34
34
|
export interface WizardParentStep extends WizardBasicStep {
|
|
35
35
|
/** Nested step IDs */
|
|
36
36
|
subStepIds: (string | number)[];
|
|
37
|
-
/** Flag to determine whether
|
|
38
|
-
|
|
37
|
+
/** Flag to determine whether the step can expand or not. */
|
|
38
|
+
isExpandable?: boolean;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/** Type used to define sub-steps. */
|
|
@@ -45,22 +45,12 @@ export interface WizardSubStep extends WizardBasicStep {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/** Encompasses all step type variants that are internally controlled by the Wizard. */
|
|
48
|
-
export type
|
|
48
|
+
export type WizardStepType = WizardBasicStep | WizardParentStep | WizardSubStep;
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
) => void | Promise<void>;
|
|
55
|
-
|
|
56
|
-
/** Data returned for either parameter of WizardNavStepFunction. */
|
|
57
|
-
export interface WizardNavStepData {
|
|
58
|
-
/** Unique identifier */
|
|
59
|
-
id: string | number;
|
|
60
|
-
/** Name of the step */
|
|
61
|
-
name: string;
|
|
62
|
-
/** Index of the step (starts at 1) */
|
|
63
|
-
index: number;
|
|
50
|
+
export enum WizardStepChangeScope {
|
|
51
|
+
Next = 'next',
|
|
52
|
+
Back = 'back',
|
|
53
|
+
Nav = 'nav'
|
|
64
54
|
}
|
|
65
55
|
|
|
66
56
|
export type WizardFooterType = Partial<WizardFooterProps> | CustomWizardFooterFunction | React.ReactElement;
|
|
@@ -70,25 +60,25 @@ export type WizardNavItemType = Partial<WizardNavItemProps> | CustomWizardNavIte
|
|
|
70
60
|
/** Callback for the Wizard's 'nav' property. Returns element which replaces the Wizard's default navigation. */
|
|
71
61
|
export type CustomWizardNavFunction = (
|
|
72
62
|
isExpanded: boolean,
|
|
73
|
-
steps:
|
|
74
|
-
activeStep:
|
|
63
|
+
steps: WizardStepType[],
|
|
64
|
+
activeStep: WizardStepType,
|
|
75
65
|
goToStepByIndex: (index: number) => void
|
|
76
66
|
) => React.ReactElement<WizardNavProps>;
|
|
77
67
|
|
|
78
68
|
/** Callback for the Wizard's 'navItem' property. Returns element which replaces the WizardStep's default navigation item. */
|
|
79
69
|
export type CustomWizardNavItemFunction = (
|
|
80
|
-
step:
|
|
81
|
-
activeStep:
|
|
82
|
-
steps:
|
|
70
|
+
step: WizardStepType,
|
|
71
|
+
activeStep: WizardStepType,
|
|
72
|
+
steps: WizardStepType[],
|
|
83
73
|
goToStepByIndex: (index: number) => void
|
|
84
74
|
) => React.ReactElement<WizardNavItemProps>;
|
|
85
75
|
|
|
86
76
|
/** Callback for the Wizard's 'footer' property. Returns element which replaces the Wizard's default footer. */
|
|
87
77
|
export type CustomWizardFooterFunction = (
|
|
88
|
-
activeStep:
|
|
89
|
-
onNext: () => void | Promise<void>,
|
|
90
|
-
onBack: () => void | Promise<void>,
|
|
91
|
-
onClose: () => void | Promise<void>
|
|
78
|
+
activeStep: WizardStepType,
|
|
79
|
+
onNext: (event: React.MouseEvent<HTMLButtonElement>) => void | Promise<void>,
|
|
80
|
+
onBack: (event: React.MouseEvent<HTMLButtonElement>) => void | Promise<void>,
|
|
81
|
+
onClose: (event: React.MouseEvent<HTMLButtonElement>) => void | Promise<void>
|
|
92
82
|
) => React.ReactElement<WizardFooterProps>;
|
|
93
83
|
|
|
94
84
|
export function isCustomWizardNav(nav: WizardNavType): nav is CustomWizardNavFunction | React.ReactElement {
|
|
@@ -107,14 +97,14 @@ export function isCustomWizardFooter(
|
|
|
107
97
|
return typeof footer === 'function' || React.isValidElement(footer);
|
|
108
98
|
}
|
|
109
99
|
|
|
110
|
-
export function isWizardBasicStep(step:
|
|
100
|
+
export function isWizardBasicStep(step: WizardStepType): step is WizardBasicStep {
|
|
111
101
|
return (step as WizardParentStep)?.subStepIds === undefined && !isWizardSubStep(step);
|
|
112
102
|
}
|
|
113
103
|
|
|
114
|
-
export function isWizardSubStep(step:
|
|
104
|
+
export function isWizardSubStep(step: WizardStepType): step is WizardSubStep {
|
|
115
105
|
return (step as WizardSubStep)?.parentId !== undefined;
|
|
116
106
|
}
|
|
117
107
|
|
|
118
|
-
export function isWizardParentStep(step:
|
|
108
|
+
export function isWizardParentStep(step: WizardStepType): step is WizardParentStep {
|
|
119
109
|
return (step as WizardParentStep)?.subStepIds !== undefined;
|
|
120
110
|
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { WizardStepType } from './types';
|
|
4
4
|
import { WizardStep, WizardStepProps } from './WizardStep';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Accumulate list of step & sub-step props pulled from child components
|
|
8
8
|
* @param children
|
|
9
|
-
* @returns
|
|
9
|
+
* @returns WizardStepType[]
|
|
10
10
|
*/
|
|
11
|
-
export const buildSteps = (children: React.
|
|
12
|
-
React.Children.toArray(children).reduce((acc:
|
|
11
|
+
export const buildSteps = (children: React.ReactNode | React.ReactNode[]) =>
|
|
12
|
+
React.Children.toArray(children).reduce((acc: WizardStepType[], child: React.ReactNode, index: number) => {
|
|
13
13
|
if (isWizardStep(child)) {
|
|
14
|
-
const {
|
|
15
|
-
const
|
|
14
|
+
const { props: childProps } = child;
|
|
15
|
+
const { steps: childStepComponents, id } = childProps;
|
|
16
16
|
const stepIndex = acc.length + 1;
|
|
17
|
+
const subSteps: WizardStepType[] = [];
|
|
17
18
|
|
|
18
19
|
acc.push(
|
|
19
20
|
{
|
|
20
21
|
index: stepIndex,
|
|
21
22
|
component: child,
|
|
22
|
-
...(
|
|
23
|
-
...(
|
|
24
|
-
subStepIds:
|
|
25
|
-
|
|
26
|
-
isHidden,
|
|
27
|
-
isDisabled,
|
|
28
|
-
component: subStep,
|
|
29
|
-
parentId: id,
|
|
23
|
+
...(index === 0 && !childStepComponents?.length && { isVisited: true }),
|
|
24
|
+
...(childStepComponents && {
|
|
25
|
+
subStepIds: childStepComponents?.map((childStepComponent, subStepIndex) => {
|
|
26
|
+
subSteps.push({
|
|
30
27
|
index: stepIndex + subStepIndex + 1,
|
|
31
|
-
|
|
28
|
+
component: childStepComponent,
|
|
29
|
+
parentId: id,
|
|
30
|
+
...(index === 0 && subStepIndex === 0 && { isVisited: true }),
|
|
31
|
+
...normalizeStepProps(childStepComponent.props)
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
return
|
|
34
|
+
return childStepComponent.props.id;
|
|
35
35
|
})
|
|
36
36
|
}),
|
|
37
|
-
...
|
|
37
|
+
...normalizeStepProps(childProps)
|
|
38
38
|
},
|
|
39
|
-
...
|
|
39
|
+
...subSteps
|
|
40
40
|
);
|
|
41
41
|
} else {
|
|
42
|
-
throw new Error('Wizard only accepts children
|
|
42
|
+
throw new Error('Wizard only accepts children of type WizardStep.');
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
return acc;
|
|
@@ -48,21 +48,15 @@ export const buildSteps = (children: React.ReactElement<WizardStepProps> | React
|
|
|
48
48
|
export function isWizardStep(
|
|
49
49
|
child: any | React.ReactElement<WizardStepProps>
|
|
50
50
|
): child is React.ReactElement<WizardStepProps> {
|
|
51
|
-
return (
|
|
52
|
-
(React.isValidElement(child) && (child as React.ReactElement<WizardStepProps>).type === WizardStep) ||
|
|
53
|
-
(child.props?.name !== undefined && child.props?.id !== undefined)
|
|
54
|
-
);
|
|
51
|
+
return React.isValidElement(child) && (child as React.ReactElement<WizardStepProps>).type === WizardStep;
|
|
55
52
|
}
|
|
56
53
|
|
|
57
|
-
//
|
|
58
|
-
export const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
index: navStep.index,
|
|
64
|
-
name: navStep.name.toString()
|
|
65
|
-
});
|
|
54
|
+
// Omit "children" and "steps" when building steps for the Wizard's context
|
|
55
|
+
export const normalizeStepProps = ({
|
|
56
|
+
children: _children,
|
|
57
|
+
steps: _steps,
|
|
58
|
+
...controlStep
|
|
59
|
+
}: WizardStepProps): Omit<WizardStepType, 'index'> => controlStep;
|
|
66
60
|
|
|
67
|
-
export const getActiveStep = (steps:
|
|
61
|
+
export const getActiveStep = (steps: WizardStepType[], activeStepIndex: number) =>
|
|
68
62
|
steps.find(step => step.index === activeStepIndex);
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
FormGroup,
|
|
5
|
-
TextInput,
|
|
6
|
-
Drawer,
|
|
7
|
-
DrawerContent,
|
|
8
|
-
Button,
|
|
9
|
-
Flex,
|
|
10
|
-
DrawerPanelContent,
|
|
11
|
-
DrawerColorVariant,
|
|
12
|
-
DrawerHead,
|
|
13
|
-
DrawerActions,
|
|
14
|
-
DrawerCloseButton,
|
|
15
|
-
Checkbox
|
|
16
|
-
} from '@patternfly/react-core';
|
|
17
|
-
import {
|
|
18
|
-
Wizard,
|
|
19
|
-
WizardStep,
|
|
20
|
-
WizardBody,
|
|
21
|
-
WizardFooter,
|
|
22
|
-
useWizardContext,
|
|
23
|
-
WizardHeader,
|
|
24
|
-
WizardFooterWrapper,
|
|
25
|
-
WizardNavStepFunction,
|
|
26
|
-
WizardNavStepData
|
|
27
|
-
} from '@patternfly/react-core/next';
|
|
28
|
-
|
|
29
|
-
const StepId = {
|
|
30
|
-
StepOne: 'sink-step-1',
|
|
31
|
-
StepTwo: 'sink-step-2',
|
|
32
|
-
StepTwoSubOne: 'sink-step-2-1',
|
|
33
|
-
StepTwoSubTwo: 'sink-step-2-2',
|
|
34
|
-
StepThree: 'sink-step-3',
|
|
35
|
-
StepFour: 'sink-step-4',
|
|
36
|
-
ReviewStep: 'sink-review-step'
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
interface SomeContextProps {
|
|
40
|
-
isToggleStepChecked: boolean;
|
|
41
|
-
errorMessage: string | undefined;
|
|
42
|
-
setIsToggleStepChecked(isHidden: boolean): void;
|
|
43
|
-
setErrorMessage(error: string | undefined): void;
|
|
44
|
-
}
|
|
45
|
-
type SomeContextRenderProps = Pick<SomeContextProps, 'isToggleStepChecked' | 'errorMessage'>;
|
|
46
|
-
interface SomeContextProviderProps {
|
|
47
|
-
children: (context: SomeContextRenderProps) => React.ReactElement;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const SomeContext = React.createContext({} as SomeContextProps);
|
|
51
|
-
|
|
52
|
-
const SomeContextProvider = ({ children }: SomeContextProviderProps) => {
|
|
53
|
-
const [isToggleStepChecked, setIsToggleStepChecked] = React.useState(false);
|
|
54
|
-
const [errorMessage, setErrorMessage] = React.useState<string>();
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<SomeContext.Provider value={{ isToggleStepChecked, errorMessage, setIsToggleStepChecked, setErrorMessage }}>
|
|
58
|
-
{children({ isToggleStepChecked, errorMessage })}
|
|
59
|
-
</SomeContext.Provider>
|
|
60
|
-
);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const CustomWizardFooter = () => {
|
|
64
|
-
const { activeStep, onNext, onBack, onClose } = useWizardContext();
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<WizardFooter
|
|
68
|
-
activeStep={activeStep}
|
|
69
|
-
onNext={onNext}
|
|
70
|
-
onBack={onBack}
|
|
71
|
-
onClose={onClose}
|
|
72
|
-
isBackDisabled={activeStep.index === 1}
|
|
73
|
-
/>
|
|
74
|
-
);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const StepContentWithDrawer = () => {
|
|
78
|
-
const [isDrawerExpanded, setIsDrawerExpanded] = React.useState(false);
|
|
79
|
-
const drawerRef = React.useRef<HTMLSpanElement>(null);
|
|
80
|
-
|
|
81
|
-
const onWizardExpand = () => {
|
|
82
|
-
drawerRef.current && drawerRef.current.focus();
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
return (
|
|
86
|
-
<Drawer isInline isExpanded={isDrawerExpanded} onExpand={onWizardExpand}>
|
|
87
|
-
<DrawerContent
|
|
88
|
-
panelContent={
|
|
89
|
-
<DrawerPanelContent widths={{ default: 'width_33' }} colorVariant={DrawerColorVariant.light200}>
|
|
90
|
-
<DrawerHead>
|
|
91
|
-
<span tabIndex={isDrawerExpanded ? 0 : -1} ref={drawerRef}>
|
|
92
|
-
drawer content
|
|
93
|
-
</span>
|
|
94
|
-
<DrawerActions>
|
|
95
|
-
<DrawerCloseButton onClick={() => setIsDrawerExpanded(false)} />
|
|
96
|
-
</DrawerActions>
|
|
97
|
-
</DrawerHead>
|
|
98
|
-
</DrawerPanelContent>
|
|
99
|
-
}
|
|
100
|
-
>
|
|
101
|
-
<WizardBody>
|
|
102
|
-
<Flex direction={{ default: 'column' }}>
|
|
103
|
-
{!isDrawerExpanded && (
|
|
104
|
-
<Button isInline variant="link" onClick={() => setIsDrawerExpanded(prevExpanded => !prevExpanded)}>
|
|
105
|
-
Open drawer
|
|
106
|
-
</Button>
|
|
107
|
-
)}
|
|
108
|
-
|
|
109
|
-
<FormGroup fieldId="some-text-input" label="Text input label">
|
|
110
|
-
<TextInput aria-label="Some Text Input Label" />
|
|
111
|
-
</FormGroup>
|
|
112
|
-
</Flex>
|
|
113
|
-
</WizardBody>
|
|
114
|
-
</DrawerContent>
|
|
115
|
-
</Drawer>
|
|
116
|
-
);
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const CustomStepThreeFooter = () => {
|
|
120
|
-
const { onNext: goToNextStep, onBack, onClose } = useWizardContext();
|
|
121
|
-
const [isLoading, setIsLoading] = React.useState(false);
|
|
122
|
-
|
|
123
|
-
async function onNext(goToStep: () => void) {
|
|
124
|
-
setIsLoading(true);
|
|
125
|
-
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
126
|
-
setIsLoading(false);
|
|
127
|
-
|
|
128
|
-
goToStep();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return (
|
|
132
|
-
<WizardFooterWrapper>
|
|
133
|
-
<Button variant="primary" onClick={() => onNext(goToNextStep)} isLoading={isLoading} isDisabled={isLoading}>
|
|
134
|
-
Async Next
|
|
135
|
-
</Button>
|
|
136
|
-
<Button variant="secondary" onClick={onBack} isDisabled={isLoading}>
|
|
137
|
-
Back
|
|
138
|
-
</Button>
|
|
139
|
-
<Button variant="link" onClick={onClose} isDisabled={isLoading}>
|
|
140
|
-
Cancel
|
|
141
|
-
</Button>
|
|
142
|
-
</WizardFooterWrapper>
|
|
143
|
-
);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const StepContentWithActions = () => {
|
|
147
|
-
const { isToggleStepChecked, errorMessage, setIsToggleStepChecked, setErrorMessage } = React.useContext(SomeContext);
|
|
148
|
-
|
|
149
|
-
return (
|
|
150
|
-
<>
|
|
151
|
-
<Checkbox
|
|
152
|
-
label="Give this step an error status"
|
|
153
|
-
isChecked={!!errorMessage}
|
|
154
|
-
onChange={checked => setErrorMessage(checked ? 'Some error message' : undefined)}
|
|
155
|
-
id="toggle-error-checkbox"
|
|
156
|
-
name="Toggle Error Checkbox"
|
|
157
|
-
/>
|
|
158
|
-
<Checkbox
|
|
159
|
-
label="Toggle visibility of the next step"
|
|
160
|
-
isChecked={isToggleStepChecked}
|
|
161
|
-
onChange={checked => setIsToggleStepChecked(checked)}
|
|
162
|
-
id="toggle-hide-step-checkbox"
|
|
163
|
-
name="Toggle Hide Step Checkbox"
|
|
164
|
-
/>
|
|
165
|
-
</>
|
|
166
|
-
);
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
export const WizardKitchenSink: React.FunctionComponent = () => {
|
|
170
|
-
const onNext: WizardNavStepFunction = (_currentStep: WizardNavStepData, _previousStep: WizardNavStepData) => {};
|
|
171
|
-
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
172
|
-
|
|
173
|
-
async function onSubmit(): Promise<void> {
|
|
174
|
-
setIsSubmitting(true);
|
|
175
|
-
|
|
176
|
-
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
177
|
-
|
|
178
|
-
setIsSubmitting(false);
|
|
179
|
-
alert('50 points to Gryffindor!');
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return (
|
|
183
|
-
<SomeContextProvider>
|
|
184
|
-
{({ isToggleStepChecked, errorMessage }) => (
|
|
185
|
-
<Wizard
|
|
186
|
-
height={400}
|
|
187
|
-
header={<WizardHeader title="You're a wizard, Harry" closeButtonAriaLabel="Close header" />}
|
|
188
|
-
footer={<CustomWizardFooter />}
|
|
189
|
-
onNext={onNext}
|
|
190
|
-
isStepVisitRequired
|
|
191
|
-
>
|
|
192
|
-
<WizardStep id={StepId.StepOne} name="Step 1" body={null} status="error">
|
|
193
|
-
<StepContentWithDrawer />
|
|
194
|
-
</WizardStep>
|
|
195
|
-
<WizardStep
|
|
196
|
-
id={StepId.StepTwo}
|
|
197
|
-
name="Step 2"
|
|
198
|
-
steps={[
|
|
199
|
-
<WizardStep
|
|
200
|
-
status={errorMessage ? 'error' : 'default'}
|
|
201
|
-
id={StepId.StepTwoSubOne}
|
|
202
|
-
key={StepId.StepTwoSubOne}
|
|
203
|
-
name="Substep 1"
|
|
204
|
-
>
|
|
205
|
-
<StepContentWithActions />
|
|
206
|
-
</WizardStep>,
|
|
207
|
-
<WizardStep
|
|
208
|
-
id={StepId.StepTwoSubTwo}
|
|
209
|
-
key={StepId.StepTwoSubTwo}
|
|
210
|
-
name="Substep 2"
|
|
211
|
-
isHidden={isToggleStepChecked}
|
|
212
|
-
>
|
|
213
|
-
Substep 2 content
|
|
214
|
-
</WizardStep>
|
|
215
|
-
]}
|
|
216
|
-
/>
|
|
217
|
-
<WizardStep
|
|
218
|
-
id={StepId.StepThree}
|
|
219
|
-
name="Step 3"
|
|
220
|
-
navItem={{
|
|
221
|
-
content: <span style={{ color: 'var(--pf-global--default-color--200)' }}>Custom item</span>
|
|
222
|
-
}}
|
|
223
|
-
footer={<CustomStepThreeFooter />}
|
|
224
|
-
>
|
|
225
|
-
Step 3 content w/ custom async footer
|
|
226
|
-
</WizardStep>
|
|
227
|
-
<WizardStep
|
|
228
|
-
id={StepId.ReviewStep}
|
|
229
|
-
name="Review"
|
|
230
|
-
footer={{
|
|
231
|
-
nextButtonText: 'Submit',
|
|
232
|
-
onNext: onSubmit,
|
|
233
|
-
isNextDisabled: isSubmitting,
|
|
234
|
-
isBackDisabled: isSubmitting
|
|
235
|
-
}}
|
|
236
|
-
>
|
|
237
|
-
{isSubmitting ? 'Calculating wizard score...' : 'Review step content'}
|
|
238
|
-
</WizardStep>
|
|
239
|
-
</Wizard>
|
|
240
|
-
)}
|
|
241
|
-
</SomeContextProvider>
|
|
242
|
-
);
|
|
243
|
-
};
|