@patternfly/react-core 4.274.0 → 4.274.1

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.
Files changed (199) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/components/Menu/MenuGroup.d.ts +1 -1
  3. package/components/Menu/MenuGroup.d.ts.map +1 -1
  4. package/components/Menu/MenuGroup.js.map +1 -1
  5. package/dist/esm/components/Menu/MenuGroup.d.ts +1 -1
  6. package/dist/esm/components/Menu/MenuGroup.d.ts.map +1 -1
  7. package/dist/esm/components/Menu/MenuGroup.js.map +1 -1
  8. package/dist/esm/next/components/Wizard/Wizard.d.ts +11 -14
  9. package/dist/esm/next/components/Wizard/Wizard.d.ts.map +1 -1
  10. package/dist/esm/next/components/Wizard/Wizard.js +30 -23
  11. package/dist/esm/next/components/Wizard/Wizard.js.map +1 -1
  12. package/dist/esm/next/components/Wizard/WizardContext.d.ts +16 -16
  13. package/dist/esm/next/components/Wizard/WizardContext.d.ts.map +1 -1
  14. package/dist/esm/next/components/Wizard/WizardContext.js +17 -19
  15. package/dist/esm/next/components/Wizard/WizardContext.js.map +1 -1
  16. package/dist/esm/next/components/Wizard/WizardFooter.d.ts +8 -5
  17. package/dist/esm/next/components/Wizard/WizardFooter.d.ts.map +1 -1
  18. package/dist/esm/next/components/Wizard/WizardFooter.js +1 -1
  19. package/dist/esm/next/components/Wizard/WizardFooter.js.map +1 -1
  20. package/dist/esm/next/components/Wizard/WizardHeader.d.ts +1 -1
  21. package/dist/esm/next/components/Wizard/WizardHeader.d.ts.map +1 -1
  22. package/dist/esm/next/components/Wizard/WizardNavInternal.d.ts +2 -2
  23. package/dist/esm/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
  24. package/dist/esm/next/components/Wizard/WizardNavInternal.js +15 -9
  25. package/dist/esm/next/components/Wizard/WizardNavInternal.js.map +1 -1
  26. package/dist/esm/next/components/Wizard/WizardNavItem.d.ts +10 -4
  27. package/dist/esm/next/components/Wizard/WizardNavItem.d.ts.map +1 -1
  28. package/dist/esm/next/components/Wizard/WizardNavItem.js +10 -9
  29. package/dist/esm/next/components/Wizard/WizardNavItem.js.map +1 -1
  30. package/dist/esm/next/components/Wizard/WizardStep.d.ts +3 -3
  31. package/dist/esm/next/components/Wizard/WizardStep.d.ts.map +1 -1
  32. package/dist/esm/next/components/Wizard/WizardStep.js +4 -2
  33. package/dist/esm/next/components/Wizard/WizardStep.js.map +1 -1
  34. package/dist/esm/next/components/Wizard/WizardToggle.d.ts +4 -4
  35. package/dist/esm/next/components/Wizard/WizardToggle.d.ts.map +1 -1
  36. package/dist/esm/next/components/Wizard/WizardToggle.js +1 -1
  37. package/dist/esm/next/components/Wizard/WizardToggle.js.map +1 -1
  38. package/dist/esm/next/components/Wizard/hooks/index.d.ts +1 -0
  39. package/dist/esm/next/components/Wizard/hooks/index.d.ts.map +1 -1
  40. package/dist/esm/next/components/Wizard/hooks/index.js +1 -0
  41. package/dist/esm/next/components/Wizard/hooks/index.js.map +1 -1
  42. package/dist/esm/next/components/Wizard/hooks/useGetMergedSteps.d.ts +9 -0
  43. package/dist/esm/next/components/Wizard/hooks/useGetMergedSteps.d.ts.map +1 -0
  44. package/dist/esm/next/components/Wizard/hooks/useGetMergedSteps.js +33 -0
  45. package/dist/esm/next/components/Wizard/hooks/useGetMergedSteps.js.map +1 -0
  46. package/dist/esm/next/components/Wizard/index.d.ts +2 -2
  47. package/dist/esm/next/components/Wizard/index.d.ts.map +1 -1
  48. package/dist/esm/next/components/Wizard/index.js +2 -2
  49. package/dist/esm/next/components/Wizard/index.js.map +1 -1
  50. package/dist/esm/next/components/Wizard/types.d.ts +13 -19
  51. package/dist/esm/next/components/Wizard/types.d.ts.map +1 -1
  52. package/dist/esm/next/components/Wizard/types.js +6 -0
  53. package/dist/esm/next/components/Wizard/types.js.map +1 -1
  54. package/dist/esm/next/components/Wizard/utils.d.ts +5 -6
  55. package/dist/esm/next/components/Wizard/utils.d.ts.map +1 -1
  56. package/dist/esm/next/components/Wizard/utils.js +15 -22
  57. package/dist/esm/next/components/Wizard/utils.js.map +1 -1
  58. package/dist/js/components/Menu/MenuGroup.d.ts +1 -1
  59. package/dist/js/components/Menu/MenuGroup.d.ts.map +1 -1
  60. package/dist/js/components/Menu/MenuGroup.js.map +1 -1
  61. package/dist/js/next/components/Wizard/Wizard.d.ts +11 -14
  62. package/dist/js/next/components/Wizard/Wizard.d.ts.map +1 -1
  63. package/dist/js/next/components/Wizard/Wizard.js +28 -21
  64. package/dist/js/next/components/Wizard/Wizard.js.map +1 -1
  65. package/dist/js/next/components/Wizard/WizardContext.d.ts +16 -16
  66. package/dist/js/next/components/Wizard/WizardContext.d.ts.map +1 -1
  67. package/dist/js/next/components/Wizard/WizardContext.js +16 -17
  68. package/dist/js/next/components/Wizard/WizardContext.js.map +1 -1
  69. package/dist/js/next/components/Wizard/WizardFooter.d.ts +8 -5
  70. package/dist/js/next/components/Wizard/WizardFooter.d.ts.map +1 -1
  71. package/dist/js/next/components/Wizard/WizardFooter.js +1 -1
  72. package/dist/js/next/components/Wizard/WizardFooter.js.map +1 -1
  73. package/dist/js/next/components/Wizard/WizardHeader.d.ts +1 -1
  74. package/dist/js/next/components/Wizard/WizardHeader.d.ts.map +1 -1
  75. package/dist/js/next/components/Wizard/WizardNavInternal.d.ts +2 -2
  76. package/dist/js/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
  77. package/dist/js/next/components/Wizard/WizardNavInternal.js +15 -9
  78. package/dist/js/next/components/Wizard/WizardNavInternal.js.map +1 -1
  79. package/dist/js/next/components/Wizard/WizardNavItem.d.ts +10 -4
  80. package/dist/js/next/components/Wizard/WizardNavItem.d.ts.map +1 -1
  81. package/dist/js/next/components/Wizard/WizardNavItem.js +10 -8
  82. package/dist/js/next/components/Wizard/WizardNavItem.js.map +1 -1
  83. package/dist/js/next/components/Wizard/WizardStep.d.ts +3 -3
  84. package/dist/js/next/components/Wizard/WizardStep.d.ts.map +1 -1
  85. package/dist/js/next/components/Wizard/WizardStep.js +4 -2
  86. package/dist/js/next/components/Wizard/WizardStep.js.map +1 -1
  87. package/dist/js/next/components/Wizard/WizardToggle.d.ts +4 -4
  88. package/dist/js/next/components/Wizard/WizardToggle.d.ts.map +1 -1
  89. package/dist/js/next/components/Wizard/WizardToggle.js +1 -1
  90. package/dist/js/next/components/Wizard/WizardToggle.js.map +1 -1
  91. package/dist/js/next/components/Wizard/hooks/index.d.ts +1 -0
  92. package/dist/js/next/components/Wizard/hooks/index.d.ts.map +1 -1
  93. package/dist/js/next/components/Wizard/hooks/index.js +3 -1
  94. package/dist/js/next/components/Wizard/hooks/index.js.map +1 -1
  95. package/dist/js/next/components/Wizard/hooks/useGetMergedSteps.d.ts +9 -0
  96. package/dist/js/next/components/Wizard/hooks/useGetMergedSteps.d.ts.map +1 -0
  97. package/dist/js/next/components/Wizard/hooks/useGetMergedSteps.js +38 -0
  98. package/dist/js/next/components/Wizard/hooks/useGetMergedSteps.js.map +1 -0
  99. package/dist/js/next/components/Wizard/index.d.ts +2 -2
  100. package/dist/js/next/components/Wizard/index.d.ts.map +1 -1
  101. package/dist/js/next/components/Wizard/index.js +4 -2
  102. package/dist/js/next/components/Wizard/index.js.map +1 -1
  103. package/dist/js/next/components/Wizard/types.d.ts +13 -19
  104. package/dist/js/next/components/Wizard/types.d.ts.map +1 -1
  105. package/dist/js/next/components/Wizard/types.js +7 -1
  106. package/dist/js/next/components/Wizard/types.js.map +1 -1
  107. package/dist/js/next/components/Wizard/utils.d.ts +5 -6
  108. package/dist/js/next/components/Wizard/utils.d.ts.map +1 -1
  109. package/dist/js/next/components/Wizard/utils.js +17 -25
  110. package/dist/js/next/components/Wizard/utils.js.map +1 -1
  111. package/next/components/Wizard/Wizard.d.ts +11 -14
  112. package/next/components/Wizard/Wizard.d.ts.map +1 -1
  113. package/next/components/Wizard/Wizard.js +30 -23
  114. package/next/components/Wizard/Wizard.js.map +1 -1
  115. package/next/components/Wizard/WizardContext.d.ts +16 -16
  116. package/next/components/Wizard/WizardContext.d.ts.map +1 -1
  117. package/next/components/Wizard/WizardContext.js +17 -19
  118. package/next/components/Wizard/WizardContext.js.map +1 -1
  119. package/next/components/Wizard/WizardFooter.d.ts +8 -5
  120. package/next/components/Wizard/WizardFooter.d.ts.map +1 -1
  121. package/next/components/Wizard/WizardFooter.js +1 -1
  122. package/next/components/Wizard/WizardFooter.js.map +1 -1
  123. package/next/components/Wizard/WizardHeader.d.ts +1 -1
  124. package/next/components/Wizard/WizardHeader.d.ts.map +1 -1
  125. package/next/components/Wizard/WizardNavInternal.d.ts +2 -2
  126. package/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
  127. package/next/components/Wizard/WizardNavInternal.js +15 -9
  128. package/next/components/Wizard/WizardNavInternal.js.map +1 -1
  129. package/next/components/Wizard/WizardNavItem.d.ts +10 -4
  130. package/next/components/Wizard/WizardNavItem.d.ts.map +1 -1
  131. package/next/components/Wizard/WizardNavItem.js +10 -9
  132. package/next/components/Wizard/WizardNavItem.js.map +1 -1
  133. package/next/components/Wizard/WizardStep.d.ts +3 -3
  134. package/next/components/Wizard/WizardStep.d.ts.map +1 -1
  135. package/next/components/Wizard/WizardStep.js +4 -2
  136. package/next/components/Wizard/WizardStep.js.map +1 -1
  137. package/next/components/Wizard/WizardToggle.d.ts +4 -4
  138. package/next/components/Wizard/WizardToggle.d.ts.map +1 -1
  139. package/next/components/Wizard/WizardToggle.js +1 -1
  140. package/next/components/Wizard/WizardToggle.js.map +1 -1
  141. package/next/components/Wizard/hooks/index.d.ts +1 -0
  142. package/next/components/Wizard/hooks/index.d.ts.map +1 -1
  143. package/next/components/Wizard/hooks/index.js +1 -0
  144. package/next/components/Wizard/hooks/index.js.map +1 -1
  145. package/next/components/Wizard/hooks/useGetMergedSteps.d.ts +9 -0
  146. package/next/components/Wizard/hooks/useGetMergedSteps.d.ts.map +1 -0
  147. package/next/components/Wizard/hooks/useGetMergedSteps.js +33 -0
  148. package/next/components/Wizard/hooks/useGetMergedSteps.js.map +1 -0
  149. package/next/components/Wizard/index.d.ts +2 -2
  150. package/next/components/Wizard/index.d.ts.map +1 -1
  151. package/next/components/Wizard/index.js +2 -2
  152. package/next/components/Wizard/index.js.map +1 -1
  153. package/next/components/Wizard/types.d.ts +13 -19
  154. package/next/components/Wizard/types.d.ts.map +1 -1
  155. package/next/components/Wizard/types.js +6 -0
  156. package/next/components/Wizard/types.js.map +1 -1
  157. package/next/components/Wizard/utils.d.ts +5 -6
  158. package/next/components/Wizard/utils.d.ts.map +1 -1
  159. package/next/components/Wizard/utils.js +15 -22
  160. package/next/components/Wizard/utils.js.map +1 -1
  161. package/package.json +2 -2
  162. package/src/components/Menu/MenuGroup.tsx +2 -2
  163. package/src/next/components/Wizard/Wizard.tsx +71 -46
  164. package/src/next/components/Wizard/WizardContext.tsx +38 -43
  165. package/src/next/components/Wizard/WizardFooter.tsx +10 -6
  166. package/src/next/components/Wizard/WizardHeader.tsx +1 -1
  167. package/src/next/components/Wizard/WizardNavInternal.tsx +51 -43
  168. package/src/next/components/Wizard/WizardNavItem.tsx +21 -14
  169. package/src/next/components/Wizard/WizardStep.tsx +8 -6
  170. package/src/next/components/Wizard/WizardToggle.tsx +5 -5
  171. package/src/next/components/Wizard/__tests__/Wizard.test.tsx +129 -26
  172. package/src/next/components/Wizard/__tests__/WizardStep.test.tsx +5 -5
  173. package/src/next/components/Wizard/__tests__/WizardToggle.test.tsx +2 -2
  174. package/src/next/components/Wizard/__tests__/utils.test.tsx +3 -17
  175. package/src/next/components/Wizard/examples/Wizard.md +69 -41
  176. package/src/next/components/Wizard/examples/WizardBasic.tsx +6 -12
  177. package/src/next/components/Wizard/examples/WizardBasicDisabledSteps.tsx +22 -0
  178. package/src/next/components/Wizard/examples/WizardEnabledOnFormValidation.tsx +84 -0
  179. package/src/next/components/Wizard/examples/WizardExpandableSteps.tsx +42 -0
  180. package/src/next/components/Wizard/examples/WizardGetCurrentStep.tsx +53 -0
  181. package/src/next/components/Wizard/examples/WizardProgressiveSteps.tsx +31 -0
  182. package/src/next/components/Wizard/examples/WizardStepDrawerContent.tsx +80 -0
  183. package/src/next/components/Wizard/examples/WizardStepErrorStatus.tsx +55 -0
  184. package/src/next/components/Wizard/examples/WizardStepVisitRequired.tsx +22 -0
  185. package/src/next/components/Wizard/examples/WizardToggleStepVisibility.tsx +57 -0
  186. package/src/next/components/Wizard/examples/WizardValidateOnButtonPress.tsx +183 -0
  187. package/src/next/components/Wizard/examples/WizardWithCustomFooter.tsx +107 -0
  188. package/src/next/components/Wizard/examples/{WizardCustomNav.tsx → WizardWithCustomNav.tsx} +11 -11
  189. package/src/next/components/Wizard/examples/WizardWithCustomNavItem.tsx +22 -0
  190. package/src/next/components/Wizard/examples/WizardWithHeader.tsx +26 -0
  191. package/src/next/components/Wizard/examples/WizardWithNavAnchors.tsx +46 -0
  192. package/src/next/components/Wizard/examples/WizardWithSubmitProgress.tsx +86 -0
  193. package/src/next/components/Wizard/examples/WizardWithinModal.tsx +41 -0
  194. package/src/next/components/Wizard/hooks/index.ts +1 -0
  195. package/src/next/components/Wizard/hooks/useGetMergedSteps.tsx +45 -0
  196. package/src/next/components/Wizard/index.ts +2 -2
  197. package/src/next/components/Wizard/types.tsx +19 -29
  198. package/src/next/components/Wizard/utils.ts +27 -33
  199. package/src/next/components/Wizard/examples/WizardKitchenSink.tsx +0 -243
@@ -1,20 +1,18 @@
1
1
  import React from 'react';
2
- import findLastIndex from 'lodash/findLastIndex';
3
2
 
4
3
  import { css } from '@patternfly/react-styles';
5
4
  import styles from '@patternfly/react-styles/css/components/Wizard/wizard';
6
5
 
7
6
  import {
8
7
  isWizardParentStep,
9
- WizardNavStepFunction,
10
- WizardControlStep,
8
+ WizardStepType,
11
9
  isCustomWizardNav,
12
10
  WizardFooterType,
13
- WizardNavType
11
+ WizardNavType,
12
+ WizardStepChangeScope
14
13
  } from './types';
15
- import { buildSteps, normalizeNavStep } from './utils';
14
+ import { buildSteps } from './utils';
16
15
  import { useWizardContext, WizardContextProvider } from './WizardContext';
17
- import { WizardStepProps } from './WizardStep';
18
16
  import { WizardToggle } from './WizardToggle';
19
17
  import { WizardNavInternal } from './WizardNavInternal';
20
18
 
@@ -25,7 +23,7 @@ import { WizardNavInternal } from './WizardNavInternal';
25
23
 
26
24
  export interface WizardProps extends React.HTMLProps<HTMLDivElement> {
27
25
  /** Step components */
28
- children: React.ReactElement<WizardStepProps> | React.ReactElement<WizardStepProps>[];
26
+ children: React.ReactNode | React.ReactNode[];
29
27
  /** Wizard header */
30
28
  header?: React.ReactNode;
31
29
  /** Wizard footer */
@@ -40,18 +38,21 @@ export interface WizardProps extends React.HTMLProps<HTMLDivElement> {
40
38
  width?: number | string;
41
39
  /** Custom height of the wizard */
42
40
  height?: number | string;
43
- /** Disables navigation items that haven't been visited. Defaults to false */
44
- isStepVisitRequired?: boolean;
45
- /** Callback function when a step in the navigation is clicked */
46
- onNavByIndex?: WizardNavStepFunction;
47
- /** Callback function after next button is clicked */
48
- onNext?: WizardNavStepFunction;
49
- /** Callback function after back button is clicked */
50
- onBack?: WizardNavStepFunction;
41
+ /** Disables steps that haven't been visited. Defaults to false. */
42
+ isVisitRequired?: boolean;
43
+ /** Progressively shows steps, where all steps following the active step are hidden. Defaults to false. */
44
+ isProgressive?: boolean;
45
+ /** Callback function when navigating between steps */
46
+ onStepChange?: (
47
+ event: React.MouseEvent<HTMLButtonElement>,
48
+ currentStep: WizardStepType,
49
+ prevStep: WizardStepType,
50
+ scope: WizardStepChangeScope
51
+ ) => void | Promise<void>;
51
52
  /** Callback function to save at the end of the wizard, if not specified uses onClose */
52
- onSave?: () => void | Promise<void>;
53
+ onSave?: (event: React.MouseEvent<HTMLButtonElement>) => void | Promise<void>;
53
54
  /** Callback function to close the wizard */
54
- onClose?: () => void;
55
+ onClose?: (event: React.MouseEvent<HTMLButtonElement>) => void;
55
56
  }
56
57
 
57
58
  export const Wizard = ({
@@ -63,48 +64,61 @@ export const Wizard = ({
63
64
  header,
64
65
  nav,
65
66
  startIndex = 1,
66
- isStepVisitRequired = false,
67
- onNavByIndex,
68
- onNext,
69
- onBack,
67
+ isVisitRequired = false,
68
+ isProgressive = false,
69
+ onStepChange,
70
70
  onSave,
71
71
  onClose,
72
72
  ...wrapperProps
73
73
  }: WizardProps) => {
74
74
  const [activeStepIndex, setActiveStepIndex] = React.useState(startIndex);
75
75
  const initialSteps = buildSteps(children);
76
+ const firstStepRef = React.useRef(initialSteps[startIndex - 1]);
76
77
 
77
- const goToNextStep = (steps: WizardControlStep[] = initialSteps) => {
78
- const newStepIndex = steps.find(step => step.index > activeStepIndex && !step.isHidden && !isWizardParentStep(step))
79
- ?.index;
78
+ // When the startIndex maps to a parent step, focus on the first sub-step
79
+ React.useEffect(() => {
80
+ if (isWizardParentStep(firstStepRef.current)) {
81
+ setActiveStepIndex(startIndex + 1);
82
+ }
83
+ }, [startIndex]);
84
+
85
+ const goToNextStep = (event: React.MouseEvent<HTMLButtonElement>, steps: WizardStepType[] = initialSteps) => {
86
+ const newStep = steps.find(
87
+ step => step.index > activeStepIndex && !step.isHidden && !step.isDisabled && !isWizardParentStep(step)
88
+ );
80
89
 
81
- if (activeStepIndex >= steps.length || !newStepIndex) {
82
- return onSave ? onSave() : onClose?.();
90
+ if (activeStepIndex >= steps.length || !newStep?.index) {
91
+ return onSave ? onSave(event) : onClose?.(event);
83
92
  }
84
93
 
85
94
  const currStep = isWizardParentStep(steps[activeStepIndex]) ? steps[activeStepIndex + 1] : steps[activeStepIndex];
86
95
  const prevStep = steps[activeStepIndex - 1];
87
96
 
88
- setActiveStepIndex(newStepIndex);
89
- return onNext?.(normalizeNavStep(currStep), normalizeNavStep(prevStep));
97
+ setActiveStepIndex(newStep?.index);
98
+ onStepChange?.(event, currStep, prevStep, WizardStepChangeScope.Next);
90
99
  };
91
100
 
92
- const goToPrevStep = (steps: WizardControlStep[] = initialSteps) => {
93
- const newStepIndex =
94
- findLastIndex(
95
- steps,
96
- (step: WizardControlStep) => step.index < activeStepIndex && !step.isHidden && !isWizardParentStep(step)
97
- ) + 1;
101
+ const goToPrevStep = (event: React.MouseEvent<HTMLButtonElement>, steps: WizardStepType[] = initialSteps) => {
102
+ const newStep = [...steps]
103
+ .reverse()
104
+ .find(
105
+ (step: WizardStepType) =>
106
+ step.index < activeStepIndex && !step.isHidden && !step.isDisabled && !isWizardParentStep(step)
107
+ );
98
108
  const currStep = isWizardParentStep(steps[activeStepIndex - 2])
99
109
  ? steps[activeStepIndex - 3]
100
110
  : steps[activeStepIndex - 2];
101
111
  const prevStep = steps[activeStepIndex - 1];
102
112
 
103
- setActiveStepIndex(newStepIndex);
104
- return onBack?.(normalizeNavStep(currStep), normalizeNavStep(prevStep));
113
+ setActiveStepIndex(newStep?.index);
114
+ onStepChange?.(event, currStep, prevStep, WizardStepChangeScope.Back);
105
115
  };
106
116
 
107
- const goToStepByIndex = (steps: WizardControlStep[] = initialSteps, index: number) => {
117
+ const goToStepByIndex = (
118
+ event: React.MouseEvent<HTMLButtonElement>,
119
+ steps: WizardStepType[] = initialSteps,
120
+ index: number
121
+ ) => {
108
122
  const lastStepIndex = steps.length + 1;
109
123
 
110
124
  // Handle index when out of bounds or hidden
@@ -118,25 +132,25 @@ export const Wizard = ({
118
132
  const prevStep = steps[activeStepIndex - 1];
119
133
 
120
134
  setActiveStepIndex(index);
121
- return onNavByIndex?.(normalizeNavStep(currStep), normalizeNavStep(prevStep));
135
+ onStepChange?.(event, currStep, prevStep, WizardStepChangeScope.Nav);
122
136
  };
123
137
 
124
- const goToStepById = (steps: WizardControlStep[] = initialSteps, id: number | string) => {
138
+ const goToStepById = (steps: WizardStepType[] = initialSteps, id: number | string) => {
125
139
  const step = steps.find(step => step.id === id);
126
140
  const stepIndex = step?.index;
127
141
  const lastStepIndex = steps.length + 1;
128
142
 
129
- if (stepIndex > 0 && stepIndex < lastStepIndex && !step.isHidden) {
143
+ if (stepIndex > 0 && stepIndex < lastStepIndex && !step.isDisabled && !step.isHidden) {
130
144
  setActiveStepIndex(stepIndex);
131
145
  }
132
146
  };
133
147
 
134
- const goToStepByName = (steps: WizardControlStep[] = initialSteps, name: string) => {
148
+ const goToStepByName = (steps: WizardStepType[] = initialSteps, name: string) => {
135
149
  const step = steps.find(step => step.name === name);
136
150
  const stepIndex = step?.index;
137
151
  const lastStepIndex = steps.length + 1;
138
152
 
139
- if (stepIndex > 0 && stepIndex < lastStepIndex && !step.isHidden) {
153
+ if (stepIndex > 0 && stepIndex < lastStepIndex && !step.isDisabled && !step.isHidden) {
140
154
  setActiveStepIndex(stepIndex);
141
155
  }
142
156
  };
@@ -162,13 +176,17 @@ export const Wizard = ({
162
176
  {...wrapperProps}
163
177
  >
164
178
  {header}
165
- <WizardInternal nav={nav} isStepVisitRequired={isStepVisitRequired} />
179
+ <WizardInternal nav={nav} isVisitRequired={isVisitRequired} isProgressive={isProgressive} />
166
180
  </div>
167
181
  </WizardContextProvider>
168
182
  );
169
183
  };
170
184
 
171
- const WizardInternal = ({ nav, isStepVisitRequired }: Pick<WizardProps, 'nav' | 'isStepVisitRequired'>) => {
185
+ const WizardInternal = ({
186
+ nav,
187
+ isVisitRequired,
188
+ isProgressive
189
+ }: Pick<WizardProps, 'nav' | 'isVisitRequired' | 'isProgressive'>) => {
172
190
  const { activeStep, steps, footer, goToStepByIndex } = useWizardContext();
173
191
  const [isNavExpanded, setIsNavExpanded] = React.useState(false);
174
192
 
@@ -177,8 +195,15 @@ const WizardInternal = ({ nav, isStepVisitRequired }: Pick<WizardProps, 'nav' |
177
195
  return typeof nav === 'function' ? nav(isNavExpanded, steps, activeStep, goToStepByIndex) : nav;
178
196
  }
179
197
 
180
- return <WizardNavInternal nav={nav} isNavExpanded={isNavExpanded} isStepVisitRequired={isStepVisitRequired} />;
181
- }, [activeStep, isStepVisitRequired, goToStepByIndex, isNavExpanded, nav, steps]);
198
+ return (
199
+ <WizardNavInternal
200
+ nav={nav}
201
+ isNavExpanded={isNavExpanded}
202
+ isVisitRequired={isVisitRequired}
203
+ isProgressive={isProgressive}
204
+ />
205
+ );
206
+ }, [activeStep, isVisitRequired, isProgressive, goToStepByIndex, isNavExpanded, nav, steps]);
182
207
 
183
208
  return (
184
209
  <WizardToggle
@@ -1,22 +1,23 @@
1
1
  import React from 'react';
2
2
 
3
- import { isCustomWizardFooter, WizardControlStep, WizardFooterType } from './types';
3
+ import { isCustomWizardFooter, isWizardSubStep, WizardStepType, WizardFooterType } from './types';
4
4
  import { getActiveStep } from './utils';
5
+ import { useGetMergedSteps } from './hooks';
5
6
  import { WizardFooter, WizardFooterProps } from './WizardFooter';
6
7
 
7
8
  export interface WizardContextProps {
8
9
  /** List of steps */
9
- steps: WizardControlStep[];
10
+ steps: WizardStepType[];
10
11
  /** Current step */
11
- activeStep: WizardControlStep;
12
+ activeStep: WizardStepType;
12
13
  /** Footer element */
13
14
  footer: React.ReactElement;
15
+ /** Close the wizard */
16
+ close: () => void;
14
17
  /** Navigate to the next step */
15
- onNext: () => void | Promise<void>;
18
+ goToNextStep: () => void | Promise<void>;
16
19
  /** Navigate to the previous step */
17
- onBack: () => void | Promise<void>;
18
- /** Close the wizard */
19
- onClose: () => void;
20
+ goToPrevStep: () => void | Promise<void>;
20
21
  /** Navigate to step by ID */
21
22
  goToStepById: (id: number | string) => void;
22
23
  /** Navigate to step by name */
@@ -26,24 +27,28 @@ export interface WizardContextProps {
26
27
  /** Update the footer with any react element */
27
28
  setFooter: (footer: React.ReactElement | Partial<WizardFooterProps>) => void;
28
29
  /** Get step by ID */
29
- getStep: (stepId: number | string) => WizardControlStep;
30
+ getStep: (stepId: number | string) => WizardStepType;
30
31
  /** Set step by ID */
31
- setStep: (step: Pick<WizardControlStep, 'id'> & Partial<WizardControlStep>) => void;
32
+ setStep: (step: Pick<WizardStepType, 'id'> & Partial<WizardStepType>) => void;
32
33
  }
33
34
 
34
35
  export const WizardContext = React.createContext({} as WizardContextProps);
35
36
 
36
37
  export interface WizardContextProviderProps {
37
- steps: WizardControlStep[];
38
+ steps: WizardStepType[];
38
39
  activeStepIndex: number;
39
40
  footer: WizardFooterType;
40
41
  children: React.ReactElement;
41
- onNext(steps: WizardControlStep[]): void;
42
- onBack(steps: WizardControlStep[]): void;
43
- onClose(): void;
44
- goToStepById(steps: WizardControlStep[], id: number | string): void;
45
- goToStepByName(steps: WizardControlStep[], name: string): void;
46
- goToStepByIndex(steps: WizardControlStep[], index: number): void;
42
+ onNext(event: React.MouseEvent<HTMLButtonElement>, steps: WizardStepType[]): void;
43
+ onBack(event: React.MouseEvent<HTMLButtonElement>, steps: WizardStepType[]): void;
44
+ onClose(event: React.MouseEvent<HTMLButtonElement>): void;
45
+ goToStepById(steps: WizardStepType[], id: number | string): void;
46
+ goToStepByName(steps: WizardStepType[], name: string): void;
47
+ goToStepByIndex(
48
+ event: React.MouseEvent<HTMLButtonElement> | React.MouseEvent<HTMLAnchorElement>,
49
+ steps: WizardStepType[],
50
+ index: number
51
+ ): void;
47
52
  }
48
53
 
49
54
  export const WizardContextProvider: React.FunctionComponent<WizardContextProviderProps> = ({
@@ -62,25 +67,12 @@ export const WizardContextProvider: React.FunctionComponent<WizardContextProvide
62
67
  const [currentFooter, setCurrentFooter] = React.useState(
63
68
  typeof initialFooter !== 'function' ? initialFooter : undefined
64
69
  );
70
+ const steps = useGetMergedSteps(initialSteps, currentSteps);
71
+ const activeStep = React.useMemo(() => getActiveStep(steps, activeStepIndex), [activeStepIndex, steps]);
65
72
 
66
- // Combined initial and current state steps
67
- const steps = React.useMemo(
68
- () =>
69
- currentSteps.map((currentStepProps, index) => {
70
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
71
- const { isVisited, ...initialStepProps } = initialSteps[index];
72
-
73
- return {
74
- ...currentStepProps,
75
- ...initialStepProps
76
- };
77
- }),
78
- [initialSteps, currentSteps]
79
- );
80
- const activeStep = getActiveStep(steps, activeStepIndex);
81
-
82
- const goToNextStep = React.useCallback(() => onNext(steps), [onNext, steps]);
83
- const goToPrevStep = React.useCallback(() => onBack(steps), [onBack, steps]);
73
+ const close = React.useCallback(() => onClose(null), [onClose]);
74
+ const goToNextStep = React.useCallback(() => onNext(null, steps), [onNext, steps]);
75
+ const goToPrevStep = React.useCallback(() => onBack(null, steps), [onBack, steps]);
84
76
 
85
77
  const footer = React.useMemo(() => {
86
78
  const wizardFooter = activeStep?.footer || currentFooter || initialFooter;
@@ -89,7 +81,7 @@ export const WizardContextProvider: React.FunctionComponent<WizardContextProvide
89
81
  const customFooter = wizardFooter;
90
82
 
91
83
  return typeof customFooter === 'function'
92
- ? customFooter(activeStep, goToNextStep, goToPrevStep, onClose)
84
+ ? customFooter(activeStep, goToNextStep, goToPrevStep, close)
93
85
  : customFooter;
94
86
  }
95
87
 
@@ -98,17 +90,17 @@ export const WizardContextProvider: React.FunctionComponent<WizardContextProvide
98
90
  activeStep={activeStep}
99
91
  onNext={goToNextStep}
100
92
  onBack={goToPrevStep}
101
- onClose={onClose}
102
- isBackDisabled={activeStep?.id === steps[0]?.id}
93
+ onClose={close}
94
+ isBackDisabled={activeStep?.index === 1 || (isWizardSubStep(activeStep) && activeStep?.index === 2)}
103
95
  {...wizardFooter}
104
96
  />
105
97
  );
106
- }, [currentFooter, initialFooter, activeStep, goToNextStep, goToPrevStep, onClose, steps]);
98
+ }, [currentFooter, initialFooter, activeStep, goToNextStep, goToPrevStep, close]);
107
99
 
108
100
  const getStep = React.useCallback((stepId: string | number) => steps.find(step => step.id === stepId), [steps]);
109
101
 
110
102
  const setStep = React.useCallback(
111
- (step: Pick<WizardControlStep, 'id'> & Partial<WizardControlStep>) =>
103
+ (step: Pick<WizardStepType, 'id'> & Partial<WizardStepType>) =>
112
104
  setCurrentSteps(prevSteps =>
113
105
  prevSteps.map(prevStep => {
114
106
  if (prevStep.id === step.id) {
@@ -127,15 +119,18 @@ export const WizardContextProvider: React.FunctionComponent<WizardContextProvide
127
119
  steps,
128
120
  activeStep,
129
121
  footer,
130
- onClose,
122
+ close,
131
123
  getStep,
132
124
  setStep,
125
+ goToNextStep,
126
+ goToPrevStep,
133
127
  setFooter: setCurrentFooter,
134
- onNext: goToNextStep,
135
- onBack: goToPrevStep,
136
128
  goToStepById: React.useCallback(id => goToStepById(steps, id), [goToStepById, steps]),
137
129
  goToStepByName: React.useCallback(name => goToStepByName(steps, name), [goToStepByName, steps]),
138
- goToStepByIndex: React.useCallback(index => goToStepByIndex(steps, index), [goToStepByIndex, steps])
130
+ goToStepByIndex: React.useCallback((index: number) => goToStepByIndex(null, steps, index), [
131
+ goToStepByIndex,
132
+ steps
133
+ ])
139
134
  }}
140
135
  >
141
136
  {children}
@@ -4,7 +4,7 @@ import { css } from '@patternfly/react-styles';
4
4
  import styles from '@patternfly/react-styles/css/components/Wizard/wizard';
5
5
 
6
6
  import { Button, ButtonVariant } from '../../../components/Button';
7
- import { isCustomWizardFooter, WizardControlStep, WizardNavStepFunction } from './types';
7
+ import { isCustomWizardFooter, WizardStepType } from './types';
8
8
 
9
9
  /**
10
10
  * Hosts the standard structure of a footer with ties to the active step so that text for buttons can vary from step to step.
@@ -12,13 +12,13 @@ import { isCustomWizardFooter, WizardControlStep, WizardNavStepFunction } from '
12
12
 
13
13
  export interface WizardFooterProps {
14
14
  /** The active step */
15
- activeStep: WizardControlStep;
15
+ activeStep: WizardStepType;
16
16
  /** Next button callback */
17
- onNext: () => WizardNavStepFunction | void | Promise<void>;
17
+ onNext: (event: React.MouseEvent<HTMLButtonElement>) => void | Promise<void>;
18
18
  /** Back button callback */
19
- onBack: () => WizardNavStepFunction | void | Promise<void>;
19
+ onBack: (event: React.MouseEvent<HTMLButtonElement>) => void | Promise<void>;
20
20
  /** Cancel link callback */
21
- onClose: () => void;
21
+ onClose: (event: React.MouseEvent<HTMLButtonElement>) => void;
22
22
  /** Custom text for the Next button. The current step's nextButtonText takes precedence. */
23
23
  nextButtonText?: React.ReactNode;
24
24
  /** Custom text for the Back button */
@@ -35,6 +35,10 @@ export interface WizardFooterProps {
35
35
  isCancelHidden?: boolean;
36
36
  }
37
37
 
38
+ /**
39
+ * Applies default wizard footer styling any number of child elements.
40
+ */
41
+
38
42
  interface WizardFooterWrapperProps {
39
43
  children: React.ReactNode;
40
44
  }
@@ -44,7 +48,7 @@ export const WizardFooterWrapper = ({ children }: WizardFooterWrapperProps) => (
44
48
  );
45
49
 
46
50
  export const WizardFooter = ({ activeStep, ...internalProps }: WizardFooterProps) => {
47
- const activeStepFooter = !isCustomWizardFooter(activeStep.footer) && activeStep.footer;
51
+ const activeStepFooter = !isCustomWizardFooter(activeStep?.footer) && activeStep?.footer;
48
52
  return <InternalWizardFooter {...internalProps} {...activeStepFooter} />;
49
53
  };
50
54
 
@@ -7,7 +7,7 @@ import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon';
7
7
 
8
8
  export interface WizardHeaderProps {
9
9
  /** Callback function called when the X (Close) button is clicked */
10
- onClose?: () => void;
10
+ onClose?: (event: React.MouseEvent<HTMLButtonElement>) => void;
11
11
  /** Title of the wizard */
12
12
  title: string;
13
13
  /** Description of the wizard */
@@ -11,12 +11,12 @@ import { WizardNavItem } from './WizardNavItem';
11
11
  * This component is not exposed to consumers.
12
12
  */
13
13
 
14
- interface WizardNavInternalProps extends Pick<WizardProps, 'isStepVisitRequired'> {
14
+ interface WizardNavInternalProps extends Pick<WizardProps, 'isVisitRequired' | 'isProgressive'> {
15
15
  nav: Partial<WizardNavProps>;
16
16
  isNavExpanded: boolean;
17
17
  }
18
18
 
19
- export const WizardNavInternal = ({ nav, isStepVisitRequired, isNavExpanded }: WizardNavInternalProps) => {
19
+ export const WizardNavInternal = ({ nav, isVisitRequired, isProgressive, isNavExpanded }: WizardNavInternalProps) => {
20
20
  const { activeStep, steps, goToStepByIndex } = useWizardContext();
21
21
 
22
22
  const wizardNavProps: WizardNavProps = {
@@ -31,7 +31,7 @@ export const WizardNavInternal = ({ nav, isStepVisitRequired, isNavExpanded }: W
31
31
  <WizardNav {...wizardNavProps}>
32
32
  {steps.map((step, stepIndex) => {
33
33
  const hasVisitedNextStep = steps.some(step => step.index > stepIndex + 1 && step.isVisited);
34
- const isStepDisabled = step.isDisabled || (isStepVisitRequired && !step.isVisited && !hasVisitedNextStep);
34
+ const isStepDisabled = step.isDisabled || (isVisitRequired && !step.isVisited && !hasVisitedNextStep);
35
35
  const customStepNavItem = isCustomWizardNavItem(step.navItem) && (
36
36
  <React.Fragment key={step.id}>
37
37
  {typeof step.navItem === 'function' ? step.navItem(step, activeStep, steps, goToStepByIndex) : step.navItem}
@@ -46,7 +46,7 @@ export const WizardNavInternal = ({ nav, isStepVisitRequired, isNavExpanded }: W
46
46
  const subStep = steps.find(step => step.id === subStepId);
47
47
  const hasVisitedNextStep = steps.some(step => step.index > subStep.index && step.isVisited);
48
48
  const isSubStepDisabled =
49
- subStep.isDisabled || (isStepVisitRequired && !subStep.isVisited && !hasVisitedNextStep);
49
+ subStep.isDisabled || (isVisitRequired && !subStep.isVisited && !hasVisitedNextStep);
50
50
  const customSubStepNavItem = isCustomWizardNavItem(subStep.navItem) && (
51
51
  <React.Fragment key={subStep.id}>
52
52
  {typeof subStep.navItem === 'function'
@@ -70,51 +70,59 @@ export const WizardNavInternal = ({ nav, isStepVisitRequired, isNavExpanded }: W
70
70
  hasActiveChild = true;
71
71
  }
72
72
 
73
- return (
74
- customSubStepNavItem || (
75
- <WizardNavItem
76
- key={subStep.id}
77
- id={subStep.id}
78
- content={subStep.name}
79
- isCurrent={activeStep?.id === subStep.id}
80
- isDisabled={isSubStepDisabled}
81
- isVisited={subStep.isVisited}
82
- stepIndex={subStep.index}
83
- onNavItemClick={goToStepByIndex}
84
- status={subStep.status}
85
- {...subStep.navItem}
86
- />
87
- )
88
- );
73
+ if (!isProgressive || (isProgressive && subStep.index <= activeStep.index)) {
74
+ return (
75
+ customSubStepNavItem || (
76
+ <WizardNavItem
77
+ key={subStep.id}
78
+ id={subStep.id}
79
+ content={subStep.name}
80
+ isCurrent={activeStep?.id === subStep.id}
81
+ isDisabled={isSubStepDisabled}
82
+ isVisited={subStep.isVisited}
83
+ stepIndex={subStep.index}
84
+ onClick={() => goToStepByIndex(subStep.index)}
85
+ status={subStep.status}
86
+ {...subStep.navItem}
87
+ />
88
+ )
89
+ );
90
+ }
89
91
  });
90
92
  const hasEnabledChildren = React.Children.toArray(subNavItems).some(
91
93
  child => React.isValidElement(child) && !child.props.isDisabled
92
94
  );
93
95
 
94
- return (
95
- customStepNavItem || (
96
- <WizardNavItem
97
- key={step.id}
98
- id={step.id}
99
- content={step.name}
100
- isExpandable={step.isCollapsible ?? true}
101
- isCurrent={hasActiveChild}
102
- isDisabled={!hasEnabledChildren}
103
- isVisited={step.isVisited}
104
- stepIndex={firstSubStepIndex}
105
- onNavItemClick={goToStepByIndex}
106
- status={step.status}
107
- {...step.navItem}
108
- >
109
- <WizardNav {...wizardNavProps} isInnerList>
110
- {subNavItems}
111
- </WizardNav>
112
- </WizardNavItem>
113
- )
114
- );
96
+ if (!isProgressive || (isProgressive && step.index <= activeStep.index)) {
97
+ return (
98
+ customStepNavItem || (
99
+ <WizardNavItem
100
+ key={step.id}
101
+ id={step.id}
102
+ content={step.name}
103
+ isExpandable={step.isExpandable}
104
+ isCurrent={hasActiveChild}
105
+ isDisabled={!hasEnabledChildren}
106
+ isVisited={step.isVisited}
107
+ stepIndex={firstSubStepIndex}
108
+ onClick={() => goToStepByIndex(firstSubStepIndex)}
109
+ status={step.status}
110
+ {...step.navItem}
111
+ >
112
+ <WizardNav {...wizardNavProps} isInnerList>
113
+ {subNavItems}
114
+ </WizardNav>
115
+ </WizardNavItem>
116
+ )
117
+ );
118
+ }
115
119
  }
116
120
 
117
- if (isWizardBasicStep(step) && !step.isHidden) {
121
+ if (
122
+ isWizardBasicStep(step) &&
123
+ !step.isHidden &&
124
+ (!isProgressive || (isProgressive && step.index <= activeStep.index))
125
+ ) {
118
126
  return (
119
127
  customStepNavItem || (
120
128
  <WizardNavItem
@@ -125,7 +133,7 @@ export const WizardNavInternal = ({ nav, isStepVisitRequired, isNavExpanded }: W
125
133
  isDisabled={isStepDisabled}
126
134
  isVisited={step.isVisited}
127
135
  stepIndex={step.index}
128
- onNavItemClick={goToStepByIndex}
136
+ onClick={() => goToStepByIndex(step.index)}
129
137
  status={step.status}
130
138
  {...step.navItem}
131
139
  />
@@ -5,9 +5,10 @@ import styles from '@patternfly/react-styles/css/components/Wizard/wizard';
5
5
  import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
6
6
  import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon';
7
7
 
8
+ import { OUIAProps, useOUIAProps } from '../../../helpers';
8
9
  import { WizardNavItemStatus } from './types';
9
10
 
10
- export interface WizardNavItemProps {
11
+ export interface WizardNavItemProps extends OUIAProps {
11
12
  /** Can nest a WizardNav component for substeps */
12
13
  children?: React.ReactNode;
13
14
  /** The content to display in the navigation item */
@@ -21,11 +22,13 @@ export interface WizardNavItemProps {
21
22
  /** The step index passed into the onNavItemClick callback */
22
23
  stepIndex: number;
23
24
  /** Callback for when the navigation item is clicked */
24
- onNavItemClick?: (stepIndex: number) => any;
25
+ onClick?: (event: React.MouseEvent<HTMLButtonElement> | React.MouseEvent<HTMLAnchorElement>, index: number) => any;
25
26
  /** Component used to render WizardNavItem */
26
- navItemComponent?: 'button' | 'a';
27
+ component?: 'button' | 'a';
27
28
  /** An optional url to use for when using an anchor component */
28
29
  href?: string;
30
+ /** Where to display the linked URL when using an anchor component */
31
+ target?: React.HTMLAttributeAnchorTarget;
29
32
  /** Flag indicating that this NavItem has child steps and is expandable */
30
33
  isExpandable?: boolean;
31
34
  /** The id for the navigation item */
@@ -34,29 +37,31 @@ export interface WizardNavItemProps {
34
37
  status?: 'default' | 'error';
35
38
  }
36
39
 
37
- export const WizardNavItem: React.FunctionComponent<WizardNavItemProps> = ({
40
+ export const WizardNavItem = ({
38
41
  children = null,
39
42
  content = '',
40
43
  isCurrent = false,
41
44
  isDisabled = false,
42
45
  isVisited = false,
43
46
  stepIndex,
44
- onNavItemClick = () => undefined,
45
- navItemComponent = 'button',
46
- href = null,
47
+ onClick,
48
+ component: NavItemComponent = 'button',
49
+ href,
47
50
  isExpandable = false,
48
51
  id,
49
52
  status = 'default',
50
- ...rest
53
+ target,
54
+ ouiaId,
55
+ ouiaSafe = true
51
56
  }: WizardNavItemProps) => {
52
- const NavItemComponent = navItemComponent;
53
57
  const [isExpanded, setIsExpanded] = React.useState(false);
58
+ const ouiaProps = useOUIAProps(WizardNavItem.displayName, ouiaId, ouiaSafe);
54
59
 
55
60
  React.useEffect(() => {
56
61
  setIsExpanded(isCurrent);
57
62
  }, [isCurrent]);
58
63
 
59
- if (navItemComponent === 'a' && !href && process.env.NODE_ENV !== 'production') {
64
+ if (NavItemComponent === 'a' && !href && process.env.NODE_ENV !== 'production') {
60
65
  // eslint-disable-next-line no-console
61
66
  console.error('WizardNavItem: When using an anchor, please provide an href');
62
67
  }
@@ -87,12 +92,13 @@ export const WizardNavItem: React.FunctionComponent<WizardNavItemProps> = ({
87
92
  )}
88
93
  >
89
94
  <NavItemComponent
90
- {...rest}
91
- {...(navItemComponent === 'a' ? { tabIndex: isDisabled ? -1 : undefined, href } : { disabled: isDisabled })}
95
+ {...(NavItemComponent === 'a'
96
+ ? { tabIndex: isDisabled ? -1 : undefined, href, target }
97
+ : { disabled: isDisabled })}
92
98
  {...(id && { id: id.toString() })}
93
99
  onClick={e => {
94
- e.preventDefault();
95
- isExpandable ? setIsExpanded(!isExpanded || isCurrent) : onNavItemClick(stepIndex);
100
+ e.stopPropagation();
101
+ isExpandable ? setIsExpanded(!isExpanded || isCurrent) : onClick?.(e, stepIndex);
96
102
  }}
97
103
  className={css(
98
104
  styles.wizardNavLink,
@@ -103,6 +109,7 @@ export const WizardNavItem: React.FunctionComponent<WizardNavItemProps> = ({
103
109
  aria-current={isCurrent && !children ? 'step' : false}
104
110
  {...(isExpandable && { 'aria-expanded': isExpanded })}
105
111
  {...(ariaLabel && { 'aria-label': ariaLabel })}
112
+ {...ouiaProps}
106
113
  >
107
114
  {isExpandable ? (
108
115
  <>