@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.
Files changed (227) hide show
  1. package/CHANGELOG.md +19 -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/components/Select/Select.d.ts +2 -0
  6. package/components/Select/Select.d.ts.map +1 -1
  7. package/components/Select/Select.js +3 -3
  8. package/components/Select/Select.js.map +1 -1
  9. package/components/Select/SelectToggle.d.ts +4 -14
  10. package/components/Select/SelectToggle.d.ts.map +1 -1
  11. package/components/Select/SelectToggle.js +11 -5
  12. package/components/Select/SelectToggle.js.map +1 -1
  13. package/dist/esm/components/Menu/MenuGroup.d.ts +1 -1
  14. package/dist/esm/components/Menu/MenuGroup.d.ts.map +1 -1
  15. package/dist/esm/components/Menu/MenuGroup.js.map +1 -1
  16. package/dist/esm/components/Select/Select.d.ts +2 -0
  17. package/dist/esm/components/Select/Select.d.ts.map +1 -1
  18. package/dist/esm/components/Select/Select.js +3 -3
  19. package/dist/esm/components/Select/Select.js.map +1 -1
  20. package/dist/esm/components/Select/SelectToggle.d.ts +4 -14
  21. package/dist/esm/components/Select/SelectToggle.d.ts.map +1 -1
  22. package/dist/esm/components/Select/SelectToggle.js +11 -5
  23. package/dist/esm/components/Select/SelectToggle.js.map +1 -1
  24. package/dist/esm/next/components/Wizard/Wizard.d.ts +11 -14
  25. package/dist/esm/next/components/Wizard/Wizard.d.ts.map +1 -1
  26. package/dist/esm/next/components/Wizard/Wizard.js +30 -23
  27. package/dist/esm/next/components/Wizard/Wizard.js.map +1 -1
  28. package/dist/esm/next/components/Wizard/WizardContext.d.ts +16 -16
  29. package/dist/esm/next/components/Wizard/WizardContext.d.ts.map +1 -1
  30. package/dist/esm/next/components/Wizard/WizardContext.js +17 -19
  31. package/dist/esm/next/components/Wizard/WizardContext.js.map +1 -1
  32. package/dist/esm/next/components/Wizard/WizardFooter.d.ts +8 -5
  33. package/dist/esm/next/components/Wizard/WizardFooter.d.ts.map +1 -1
  34. package/dist/esm/next/components/Wizard/WizardFooter.js +1 -1
  35. package/dist/esm/next/components/Wizard/WizardFooter.js.map +1 -1
  36. package/dist/esm/next/components/Wizard/WizardHeader.d.ts +1 -1
  37. package/dist/esm/next/components/Wizard/WizardHeader.d.ts.map +1 -1
  38. package/dist/esm/next/components/Wizard/WizardNavInternal.d.ts +2 -2
  39. package/dist/esm/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
  40. package/dist/esm/next/components/Wizard/WizardNavInternal.js +15 -9
  41. package/dist/esm/next/components/Wizard/WizardNavInternal.js.map +1 -1
  42. package/dist/esm/next/components/Wizard/WizardNavItem.d.ts +10 -4
  43. package/dist/esm/next/components/Wizard/WizardNavItem.d.ts.map +1 -1
  44. package/dist/esm/next/components/Wizard/WizardNavItem.js +10 -9
  45. package/dist/esm/next/components/Wizard/WizardNavItem.js.map +1 -1
  46. package/dist/esm/next/components/Wizard/WizardStep.d.ts +3 -3
  47. package/dist/esm/next/components/Wizard/WizardStep.d.ts.map +1 -1
  48. package/dist/esm/next/components/Wizard/WizardStep.js +4 -2
  49. package/dist/esm/next/components/Wizard/WizardStep.js.map +1 -1
  50. package/dist/esm/next/components/Wizard/WizardToggle.d.ts +4 -4
  51. package/dist/esm/next/components/Wizard/WizardToggle.d.ts.map +1 -1
  52. package/dist/esm/next/components/Wizard/WizardToggle.js +1 -1
  53. package/dist/esm/next/components/Wizard/WizardToggle.js.map +1 -1
  54. package/dist/esm/next/components/Wizard/hooks/index.d.ts +1 -0
  55. package/dist/esm/next/components/Wizard/hooks/index.d.ts.map +1 -1
  56. package/dist/esm/next/components/Wizard/hooks/index.js +1 -0
  57. package/dist/esm/next/components/Wizard/hooks/index.js.map +1 -1
  58. package/dist/esm/next/components/Wizard/hooks/useGetMergedSteps.d.ts +9 -0
  59. package/dist/esm/next/components/Wizard/hooks/useGetMergedSteps.d.ts.map +1 -0
  60. package/dist/esm/next/components/Wizard/hooks/useGetMergedSteps.js +33 -0
  61. package/dist/esm/next/components/Wizard/hooks/useGetMergedSteps.js.map +1 -0
  62. package/dist/esm/next/components/Wizard/index.d.ts +2 -2
  63. package/dist/esm/next/components/Wizard/index.d.ts.map +1 -1
  64. package/dist/esm/next/components/Wizard/index.js +2 -2
  65. package/dist/esm/next/components/Wizard/index.js.map +1 -1
  66. package/dist/esm/next/components/Wizard/types.d.ts +13 -19
  67. package/dist/esm/next/components/Wizard/types.d.ts.map +1 -1
  68. package/dist/esm/next/components/Wizard/types.js +6 -0
  69. package/dist/esm/next/components/Wizard/types.js.map +1 -1
  70. package/dist/esm/next/components/Wizard/utils.d.ts +5 -6
  71. package/dist/esm/next/components/Wizard/utils.d.ts.map +1 -1
  72. package/dist/esm/next/components/Wizard/utils.js +15 -22
  73. package/dist/esm/next/components/Wizard/utils.js.map +1 -1
  74. package/dist/js/components/Menu/MenuGroup.d.ts +1 -1
  75. package/dist/js/components/Menu/MenuGroup.d.ts.map +1 -1
  76. package/dist/js/components/Menu/MenuGroup.js.map +1 -1
  77. package/dist/js/components/Select/Select.d.ts +2 -0
  78. package/dist/js/components/Select/Select.d.ts.map +1 -1
  79. package/dist/js/components/Select/Select.js +3 -3
  80. package/dist/js/components/Select/Select.js.map +1 -1
  81. package/dist/js/components/Select/SelectToggle.d.ts +4 -14
  82. package/dist/js/components/Select/SelectToggle.d.ts.map +1 -1
  83. package/dist/js/components/Select/SelectToggle.js +11 -6
  84. package/dist/js/components/Select/SelectToggle.js.map +1 -1
  85. package/dist/js/next/components/Wizard/Wizard.d.ts +11 -14
  86. package/dist/js/next/components/Wizard/Wizard.d.ts.map +1 -1
  87. package/dist/js/next/components/Wizard/Wizard.js +28 -21
  88. package/dist/js/next/components/Wizard/Wizard.js.map +1 -1
  89. package/dist/js/next/components/Wizard/WizardContext.d.ts +16 -16
  90. package/dist/js/next/components/Wizard/WizardContext.d.ts.map +1 -1
  91. package/dist/js/next/components/Wizard/WizardContext.js +16 -17
  92. package/dist/js/next/components/Wizard/WizardContext.js.map +1 -1
  93. package/dist/js/next/components/Wizard/WizardFooter.d.ts +8 -5
  94. package/dist/js/next/components/Wizard/WizardFooter.d.ts.map +1 -1
  95. package/dist/js/next/components/Wizard/WizardFooter.js +1 -1
  96. package/dist/js/next/components/Wizard/WizardFooter.js.map +1 -1
  97. package/dist/js/next/components/Wizard/WizardHeader.d.ts +1 -1
  98. package/dist/js/next/components/Wizard/WizardHeader.d.ts.map +1 -1
  99. package/dist/js/next/components/Wizard/WizardNavInternal.d.ts +2 -2
  100. package/dist/js/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
  101. package/dist/js/next/components/Wizard/WizardNavInternal.js +15 -9
  102. package/dist/js/next/components/Wizard/WizardNavInternal.js.map +1 -1
  103. package/dist/js/next/components/Wizard/WizardNavItem.d.ts +10 -4
  104. package/dist/js/next/components/Wizard/WizardNavItem.d.ts.map +1 -1
  105. package/dist/js/next/components/Wizard/WizardNavItem.js +10 -8
  106. package/dist/js/next/components/Wizard/WizardNavItem.js.map +1 -1
  107. package/dist/js/next/components/Wizard/WizardStep.d.ts +3 -3
  108. package/dist/js/next/components/Wizard/WizardStep.d.ts.map +1 -1
  109. package/dist/js/next/components/Wizard/WizardStep.js +4 -2
  110. package/dist/js/next/components/Wizard/WizardStep.js.map +1 -1
  111. package/dist/js/next/components/Wizard/WizardToggle.d.ts +4 -4
  112. package/dist/js/next/components/Wizard/WizardToggle.d.ts.map +1 -1
  113. package/dist/js/next/components/Wizard/WizardToggle.js +1 -1
  114. package/dist/js/next/components/Wizard/WizardToggle.js.map +1 -1
  115. package/dist/js/next/components/Wizard/hooks/index.d.ts +1 -0
  116. package/dist/js/next/components/Wizard/hooks/index.d.ts.map +1 -1
  117. package/dist/js/next/components/Wizard/hooks/index.js +3 -1
  118. package/dist/js/next/components/Wizard/hooks/index.js.map +1 -1
  119. package/dist/js/next/components/Wizard/hooks/useGetMergedSteps.d.ts +9 -0
  120. package/dist/js/next/components/Wizard/hooks/useGetMergedSteps.d.ts.map +1 -0
  121. package/dist/js/next/components/Wizard/hooks/useGetMergedSteps.js +38 -0
  122. package/dist/js/next/components/Wizard/hooks/useGetMergedSteps.js.map +1 -0
  123. package/dist/js/next/components/Wizard/index.d.ts +2 -2
  124. package/dist/js/next/components/Wizard/index.d.ts.map +1 -1
  125. package/dist/js/next/components/Wizard/index.js +4 -2
  126. package/dist/js/next/components/Wizard/index.js.map +1 -1
  127. package/dist/js/next/components/Wizard/types.d.ts +13 -19
  128. package/dist/js/next/components/Wizard/types.d.ts.map +1 -1
  129. package/dist/js/next/components/Wizard/types.js +7 -1
  130. package/dist/js/next/components/Wizard/types.js.map +1 -1
  131. package/dist/js/next/components/Wizard/utils.d.ts +5 -6
  132. package/dist/js/next/components/Wizard/utils.d.ts.map +1 -1
  133. package/dist/js/next/components/Wizard/utils.js +17 -25
  134. package/dist/js/next/components/Wizard/utils.js.map +1 -1
  135. package/dist/umd/react-core.min.js +2 -2
  136. package/next/components/Wizard/Wizard.d.ts +11 -14
  137. package/next/components/Wizard/Wizard.d.ts.map +1 -1
  138. package/next/components/Wizard/Wizard.js +30 -23
  139. package/next/components/Wizard/Wizard.js.map +1 -1
  140. package/next/components/Wizard/WizardContext.d.ts +16 -16
  141. package/next/components/Wizard/WizardContext.d.ts.map +1 -1
  142. package/next/components/Wizard/WizardContext.js +17 -19
  143. package/next/components/Wizard/WizardContext.js.map +1 -1
  144. package/next/components/Wizard/WizardFooter.d.ts +8 -5
  145. package/next/components/Wizard/WizardFooter.d.ts.map +1 -1
  146. package/next/components/Wizard/WizardFooter.js +1 -1
  147. package/next/components/Wizard/WizardFooter.js.map +1 -1
  148. package/next/components/Wizard/WizardHeader.d.ts +1 -1
  149. package/next/components/Wizard/WizardHeader.d.ts.map +1 -1
  150. package/next/components/Wizard/WizardNavInternal.d.ts +2 -2
  151. package/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
  152. package/next/components/Wizard/WizardNavInternal.js +15 -9
  153. package/next/components/Wizard/WizardNavInternal.js.map +1 -1
  154. package/next/components/Wizard/WizardNavItem.d.ts +10 -4
  155. package/next/components/Wizard/WizardNavItem.d.ts.map +1 -1
  156. package/next/components/Wizard/WizardNavItem.js +10 -9
  157. package/next/components/Wizard/WizardNavItem.js.map +1 -1
  158. package/next/components/Wizard/WizardStep.d.ts +3 -3
  159. package/next/components/Wizard/WizardStep.d.ts.map +1 -1
  160. package/next/components/Wizard/WizardStep.js +4 -2
  161. package/next/components/Wizard/WizardStep.js.map +1 -1
  162. package/next/components/Wizard/WizardToggle.d.ts +4 -4
  163. package/next/components/Wizard/WizardToggle.d.ts.map +1 -1
  164. package/next/components/Wizard/WizardToggle.js +1 -1
  165. package/next/components/Wizard/WizardToggle.js.map +1 -1
  166. package/next/components/Wizard/hooks/index.d.ts +1 -0
  167. package/next/components/Wizard/hooks/index.d.ts.map +1 -1
  168. package/next/components/Wizard/hooks/index.js +1 -0
  169. package/next/components/Wizard/hooks/index.js.map +1 -1
  170. package/next/components/Wizard/hooks/useGetMergedSteps.d.ts +9 -0
  171. package/next/components/Wizard/hooks/useGetMergedSteps.d.ts.map +1 -0
  172. package/next/components/Wizard/hooks/useGetMergedSteps.js +33 -0
  173. package/next/components/Wizard/hooks/useGetMergedSteps.js.map +1 -0
  174. package/next/components/Wizard/index.d.ts +2 -2
  175. package/next/components/Wizard/index.d.ts.map +1 -1
  176. package/next/components/Wizard/index.js +2 -2
  177. package/next/components/Wizard/index.js.map +1 -1
  178. package/next/components/Wizard/types.d.ts +13 -19
  179. package/next/components/Wizard/types.d.ts.map +1 -1
  180. package/next/components/Wizard/types.js +6 -0
  181. package/next/components/Wizard/types.js.map +1 -1
  182. package/next/components/Wizard/utils.d.ts +5 -6
  183. package/next/components/Wizard/utils.d.ts.map +1 -1
  184. package/next/components/Wizard/utils.js +15 -22
  185. package/next/components/Wizard/utils.js.map +1 -1
  186. package/package.json +2 -2
  187. package/src/components/Menu/MenuGroup.tsx +2 -2
  188. package/src/components/Select/Select.tsx +4 -0
  189. package/src/components/Select/SelectToggle.tsx +14 -3
  190. package/src/components/Select/examples/Select.md +28 -0
  191. package/src/next/components/Wizard/Wizard.tsx +71 -46
  192. package/src/next/components/Wizard/WizardContext.tsx +38 -43
  193. package/src/next/components/Wizard/WizardFooter.tsx +10 -6
  194. package/src/next/components/Wizard/WizardHeader.tsx +1 -1
  195. package/src/next/components/Wizard/WizardNavInternal.tsx +51 -43
  196. package/src/next/components/Wizard/WizardNavItem.tsx +21 -14
  197. package/src/next/components/Wizard/WizardStep.tsx +8 -6
  198. package/src/next/components/Wizard/WizardToggle.tsx +5 -5
  199. package/src/next/components/Wizard/__tests__/Wizard.test.tsx +129 -26
  200. package/src/next/components/Wizard/__tests__/WizardStep.test.tsx +5 -5
  201. package/src/next/components/Wizard/__tests__/WizardToggle.test.tsx +2 -2
  202. package/src/next/components/Wizard/__tests__/utils.test.tsx +3 -17
  203. package/src/next/components/Wizard/examples/Wizard.md +69 -41
  204. package/src/next/components/Wizard/examples/WizardBasic.tsx +6 -12
  205. package/src/next/components/Wizard/examples/WizardBasicDisabledSteps.tsx +22 -0
  206. package/src/next/components/Wizard/examples/WizardEnabledOnFormValidation.tsx +84 -0
  207. package/src/next/components/Wizard/examples/WizardExpandableSteps.tsx +42 -0
  208. package/src/next/components/Wizard/examples/WizardGetCurrentStep.tsx +53 -0
  209. package/src/next/components/Wizard/examples/WizardProgressiveSteps.tsx +31 -0
  210. package/src/next/components/Wizard/examples/WizardStepDrawerContent.tsx +80 -0
  211. package/src/next/components/Wizard/examples/WizardStepErrorStatus.tsx +55 -0
  212. package/src/next/components/Wizard/examples/WizardStepVisitRequired.tsx +22 -0
  213. package/src/next/components/Wizard/examples/WizardToggleStepVisibility.tsx +57 -0
  214. package/src/next/components/Wizard/examples/WizardValidateOnButtonPress.tsx +183 -0
  215. package/src/next/components/Wizard/examples/WizardWithCustomFooter.tsx +107 -0
  216. package/src/next/components/Wizard/examples/{WizardCustomNav.tsx → WizardWithCustomNav.tsx} +11 -11
  217. package/src/next/components/Wizard/examples/WizardWithCustomNavItem.tsx +22 -0
  218. package/src/next/components/Wizard/examples/WizardWithHeader.tsx +26 -0
  219. package/src/next/components/Wizard/examples/WizardWithNavAnchors.tsx +46 -0
  220. package/src/next/components/Wizard/examples/WizardWithSubmitProgress.tsx +86 -0
  221. package/src/next/components/Wizard/examples/WizardWithinModal.tsx +41 -0
  222. package/src/next/components/Wizard/hooks/index.ts +1 -0
  223. package/src/next/components/Wizard/hooks/useGetMergedSteps.tsx +45 -0
  224. package/src/next/components/Wizard/index.ts +2 -2
  225. package/src/next/components/Wizard/types.tsx +19 -29
  226. package/src/next/components/Wizard/utils.ts +27 -33
  227. 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 sub-steps can collapse or not */
38
- isCollapsible?: boolean;
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 WizardControlStep = WizardBasicStep | WizardParentStep | WizardSubStep;
48
+ export type WizardStepType = WizardBasicStep | WizardParentStep | WizardSubStep;
49
49
 
50
- /** Callback for the Wizard's 'onNext', 'onBack', and 'onNavByIndex' properties. */
51
- export type WizardNavStepFunction = (
52
- currentStep: WizardNavStepData,
53
- previousStep: WizardNavStepData
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: WizardControlStep[],
74
- activeStep: WizardControlStep,
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: WizardControlStep,
81
- activeStep: WizardControlStep,
82
- steps: WizardControlStep[],
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: WizardControlStep,
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: WizardControlStep): step is WizardBasicStep {
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: WizardControlStep): step is WizardSubStep {
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: WizardControlStep): step is WizardParentStep {
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 { WizardControlStep, WizardNavStepData } from './types';
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 WizardControlStep[]
9
+ * @returns WizardStepType[]
10
10
  */
11
- export const buildSteps = (children: React.ReactElement<WizardStepProps> | React.ReactElement<WizardStepProps>[]) =>
12
- React.Children.toArray(children).reduce((acc: WizardControlStep[], child: React.ReactNode) => {
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 { steps: subSteps, id, isHidden, isDisabled } = child.props;
15
- const subControlledSteps: WizardControlStep[] = [];
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
- ...(stepIndex === 1 && { isVisited: true }),
23
- ...(subSteps && {
24
- subStepIds: subSteps?.map((subStep, subStepIndex) => {
25
- subControlledSteps.push({
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
- ...normalizeStep(subStep.props)
28
+ component: childStepComponent,
29
+ parentId: id,
30
+ ...(index === 0 && subStepIndex === 0 && { isVisited: true }),
31
+ ...normalizeStepProps(childStepComponent.props)
32
32
  });
33
33
 
34
- return subStep.props.id;
34
+ return childStepComponent.props.id;
35
35
  })
36
36
  }),
37
- ...normalizeStep(child.props)
37
+ ...normalizeStepProps(childProps)
38
38
  },
39
- ...subControlledSteps
39
+ ...subSteps
40
40
  );
41
41
  } else {
42
- throw new Error('Wizard only accepts children with required WizardStepProps.');
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
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
58
- export const normalizeStep = ({ children, steps, ...controlStep }: WizardStepProps): Omit<WizardControlStep, 'index'> =>
59
- controlStep;
60
-
61
- export const normalizeNavStep = (navStep: WizardControlStep): WizardNavStepData => ({
62
- id: navStep.id,
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: WizardControlStep[], activeStepIndex: number) =>
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
- };