@patternfly/react-core 4.255.1 → 4.256.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 (156) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/esm/components/Card/Card.d.ts +2 -2
  3. package/dist/esm/components/Card/Card.d.ts.map +1 -1
  4. package/dist/esm/components/DataList/DataList.d.ts +1 -1
  5. package/dist/esm/components/DataList/DataList.d.ts.map +1 -1
  6. package/dist/esm/components/DataList/DataListItem.d.ts +1 -1
  7. package/dist/esm/components/DataList/DataListItem.d.ts.map +1 -1
  8. package/dist/esm/components/MultipleFileUpload/MultipleFileUploadStatusItem.d.ts +2 -0
  9. package/dist/esm/components/MultipleFileUpload/MultipleFileUploadStatusItem.d.ts.map +1 -1
  10. package/dist/esm/components/MultipleFileUpload/MultipleFileUploadStatusItem.js +7 -1
  11. package/dist/esm/components/MultipleFileUpload/MultipleFileUploadStatusItem.js.map +1 -1
  12. package/dist/esm/components/Popover/Popover.d.ts +3 -3
  13. package/dist/esm/components/Popover/Popover.d.ts.map +1 -1
  14. package/dist/esm/components/Wizard/Wizard.d.ts +4 -4
  15. package/dist/esm/components/Wizard/Wizard.d.ts.map +1 -1
  16. package/dist/esm/components/Wizard/WizardToggle.d.ts +2 -2
  17. package/dist/esm/components/Wizard/WizardToggle.d.ts.map +1 -1
  18. package/dist/esm/next/components/Wizard/Wizard.d.ts +1 -3
  19. package/dist/esm/next/components/Wizard/Wizard.d.ts.map +1 -1
  20. package/dist/esm/next/components/Wizard/Wizard.js +36 -45
  21. package/dist/esm/next/components/Wizard/Wizard.js.map +1 -1
  22. package/dist/esm/next/components/Wizard/WizardBody.d.ts +2 -2
  23. package/dist/esm/next/components/Wizard/WizardBody.d.ts.map +1 -1
  24. package/dist/esm/next/components/Wizard/WizardBody.js +2 -2
  25. package/dist/esm/next/components/Wizard/WizardBody.js.map +1 -1
  26. package/dist/esm/next/components/Wizard/WizardContext.d.ts +2 -7
  27. package/dist/esm/next/components/Wizard/WizardContext.d.ts.map +1 -1
  28. package/dist/esm/next/components/Wizard/WizardContext.js +18 -39
  29. package/dist/esm/next/components/Wizard/WizardContext.js.map +1 -1
  30. package/dist/esm/next/components/Wizard/WizardFooter.d.ts +3 -3
  31. package/dist/esm/next/components/Wizard/WizardFooter.d.ts.map +1 -1
  32. package/dist/esm/next/components/Wizard/WizardFooter.js +3 -3
  33. package/dist/esm/next/components/Wizard/WizardFooter.js.map +1 -1
  34. package/dist/esm/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
  35. package/dist/esm/next/components/Wizard/WizardNavInternal.js +12 -12
  36. package/dist/esm/next/components/Wizard/WizardNavInternal.js.map +1 -1
  37. package/dist/esm/next/components/Wizard/WizardStep.d.ts +1 -3
  38. package/dist/esm/next/components/Wizard/WizardStep.d.ts.map +1 -1
  39. package/dist/esm/next/components/Wizard/WizardStep.js +10 -18
  40. package/dist/esm/next/components/Wizard/WizardStep.js.map +1 -1
  41. package/dist/esm/next/components/Wizard/WizardToggle.d.ts +2 -4
  42. package/dist/esm/next/components/Wizard/WizardToggle.d.ts.map +1 -1
  43. package/dist/esm/next/components/Wizard/WizardToggle.js +19 -16
  44. package/dist/esm/next/components/Wizard/WizardToggle.js.map +1 -1
  45. package/dist/esm/next/components/Wizard/hooks/useWizardFooter.js +3 -3
  46. package/dist/esm/next/components/Wizard/hooks/useWizardFooter.js.map +1 -1
  47. package/dist/esm/next/components/Wizard/types.d.ts +5 -3
  48. package/dist/esm/next/components/Wizard/types.d.ts.map +1 -1
  49. package/dist/esm/next/components/Wizard/types.js.map +1 -1
  50. package/dist/esm/next/components/Wizard/utils.d.ts +3 -3
  51. package/dist/esm/next/components/Wizard/utils.d.ts.map +1 -1
  52. package/dist/esm/next/components/Wizard/utils.js +14 -11
  53. package/dist/esm/next/components/Wizard/utils.js.map +1 -1
  54. package/dist/js/components/Card/Card.d.ts +2 -2
  55. package/dist/js/components/Card/Card.d.ts.map +1 -1
  56. package/dist/js/components/DataList/DataList.d.ts +1 -1
  57. package/dist/js/components/DataList/DataList.d.ts.map +1 -1
  58. package/dist/js/components/DataList/DataListItem.d.ts +1 -1
  59. package/dist/js/components/DataList/DataListItem.d.ts.map +1 -1
  60. package/dist/js/components/MultipleFileUpload/MultipleFileUploadStatusItem.d.ts +2 -0
  61. package/dist/js/components/MultipleFileUpload/MultipleFileUploadStatusItem.d.ts.map +1 -1
  62. package/dist/js/components/MultipleFileUpload/MultipleFileUploadStatusItem.js +7 -1
  63. package/dist/js/components/MultipleFileUpload/MultipleFileUploadStatusItem.js.map +1 -1
  64. package/dist/js/components/Popover/Popover.d.ts +3 -3
  65. package/dist/js/components/Popover/Popover.d.ts.map +1 -1
  66. package/dist/js/components/Wizard/Wizard.d.ts +4 -4
  67. package/dist/js/components/Wizard/Wizard.d.ts.map +1 -1
  68. package/dist/js/components/Wizard/WizardToggle.d.ts +2 -2
  69. package/dist/js/components/Wizard/WizardToggle.d.ts.map +1 -1
  70. package/dist/js/next/components/Wizard/Wizard.d.ts +1 -3
  71. package/dist/js/next/components/Wizard/Wizard.d.ts.map +1 -1
  72. package/dist/js/next/components/Wizard/Wizard.js +36 -45
  73. package/dist/js/next/components/Wizard/Wizard.js.map +1 -1
  74. package/dist/js/next/components/Wizard/WizardBody.d.ts +2 -2
  75. package/dist/js/next/components/Wizard/WizardBody.d.ts.map +1 -1
  76. package/dist/js/next/components/Wizard/WizardBody.js +2 -2
  77. package/dist/js/next/components/Wizard/WizardBody.js.map +1 -1
  78. package/dist/js/next/components/Wizard/WizardContext.d.ts +2 -7
  79. package/dist/js/next/components/Wizard/WizardContext.d.ts.map +1 -1
  80. package/dist/js/next/components/Wizard/WizardContext.js +15 -37
  81. package/dist/js/next/components/Wizard/WizardContext.js.map +1 -1
  82. package/dist/js/next/components/Wizard/WizardFooter.d.ts +3 -3
  83. package/dist/js/next/components/Wizard/WizardFooter.d.ts.map +1 -1
  84. package/dist/js/next/components/Wizard/WizardFooter.js +3 -3
  85. package/dist/js/next/components/Wizard/WizardFooter.js.map +1 -1
  86. package/dist/js/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
  87. package/dist/js/next/components/Wizard/WizardNavInternal.js +12 -12
  88. package/dist/js/next/components/Wizard/WizardNavInternal.js.map +1 -1
  89. package/dist/js/next/components/Wizard/WizardStep.d.ts +1 -3
  90. package/dist/js/next/components/Wizard/WizardStep.d.ts.map +1 -1
  91. package/dist/js/next/components/Wizard/WizardStep.js +9 -18
  92. package/dist/js/next/components/Wizard/WizardStep.js.map +1 -1
  93. package/dist/js/next/components/Wizard/WizardToggle.d.ts +2 -4
  94. package/dist/js/next/components/Wizard/WizardToggle.d.ts.map +1 -1
  95. package/dist/js/next/components/Wizard/WizardToggle.js +18 -16
  96. package/dist/js/next/components/Wizard/WizardToggle.js.map +1 -1
  97. package/dist/js/next/components/Wizard/hooks/useWizardFooter.js +3 -3
  98. package/dist/js/next/components/Wizard/hooks/useWizardFooter.js.map +1 -1
  99. package/dist/js/next/components/Wizard/types.d.ts +5 -3
  100. package/dist/js/next/components/Wizard/types.d.ts.map +1 -1
  101. package/dist/js/next/components/Wizard/types.js.map +1 -1
  102. package/dist/js/next/components/Wizard/utils.d.ts +3 -3
  103. package/dist/js/next/components/Wizard/utils.d.ts.map +1 -1
  104. package/dist/js/next/components/Wizard/utils.js +16 -13
  105. package/dist/js/next/components/Wizard/utils.js.map +1 -1
  106. package/dist/umd/react-core.min.css +137 -137
  107. package/dist/umd/react-core.min.js +1 -1
  108. package/package.json +2 -2
  109. package/src/components/AlertGroup/examples/AlertGroup.md +2 -2
  110. package/src/components/CalendarMonth/examples/CalendarMonth.md +0 -1
  111. package/src/components/Card/Card.tsx +2 -2
  112. package/src/components/DataList/DataList.tsx +1 -1
  113. package/src/components/DataList/DataListItem.tsx +1 -1
  114. package/src/components/DualListSelector/examples/DualListSelector.md +0 -1
  115. package/src/components/LabelGroup/examples/LabelGroup.md +2 -3
  116. package/src/components/Masthead/examples/Masthead.md +0 -1
  117. package/src/components/Menu/examples/Menu.md +1 -1
  118. package/src/components/MenuToggle/examples/MenuToggle.md +0 -1
  119. package/src/components/MultipleFileUpload/MultipleFileUploadStatusItem.tsx +10 -0
  120. package/src/components/MultipleFileUpload/__tests__/MultipleFileUploadStatusItem.test.tsx +33 -1
  121. package/src/components/MultipleFileUpload/__tests__/__snapshots__/MultipleFileUploadStatusItem.test.tsx.snap +269 -3
  122. package/src/components/MultipleFileUpload/examples/MultipleFileUpload.md +0 -1
  123. package/src/components/NotificationDrawer/examples/NotificationDrawer.md +0 -1
  124. package/src/components/Panel/examples/Panel.md +0 -1
  125. package/src/components/Popover/Popover.tsx +3 -3
  126. package/src/components/Popover/examples/Popover.md +2 -2
  127. package/src/components/Select/examples/Select.md +2 -2
  128. package/src/components/Slider/examples/Slider.md +0 -1
  129. package/src/components/TextArea/examples/TextArea.md +1 -1
  130. package/src/components/TextInput/examples/TextInput.md +1 -1
  131. package/src/components/TreeView/examples/TreeView.md +0 -1
  132. package/src/components/Wizard/Wizard.tsx +4 -4
  133. package/src/components/Wizard/WizardToggle.tsx +2 -2
  134. package/src/components/Wizard/examples/Wizard.md +12 -8
  135. package/src/demos/MultipleFileUploadDemos.md +0 -1
  136. package/src/demos/NotificationDrawer/NotificationDrawer.md +0 -1
  137. package/src/next/components/Wizard/Wizard.tsx +35 -54
  138. package/src/next/components/Wizard/WizardBody.tsx +3 -3
  139. package/src/next/components/Wizard/WizardContext.tsx +29 -61
  140. package/src/next/components/Wizard/WizardFooter.tsx +6 -6
  141. package/src/next/components/Wizard/WizardNavInternal.tsx +18 -17
  142. package/src/next/components/Wizard/WizardStep.tsx +19 -30
  143. package/src/next/components/Wizard/WizardToggle.tsx +22 -24
  144. package/src/next/components/Wizard/__tests__/Wizard.test.tsx +1 -21
  145. package/src/next/components/Wizard/__tests__/WizardBody.test.tsx +2 -2
  146. package/src/next/components/Wizard/__tests__/WizardFooter.test.tsx +5 -5
  147. package/src/next/components/Wizard/__tests__/WizardStep.test.tsx +22 -76
  148. package/src/next/components/Wizard/__tests__/WizardToggle.test.tsx +7 -11
  149. package/src/next/components/Wizard/__tests__/utils.test.tsx +3 -3
  150. package/src/next/components/Wizard/examples/Wizard.md +4 -4
  151. package/src/next/components/Wizard/examples/WizardCustomNav.tsx +4 -4
  152. package/src/next/components/Wizard/examples/WizardKitchenSink.tsx +74 -85
  153. package/src/next/components/Wizard/hooks/__tests__/useWizardFooter.test.tsx +4 -4
  154. package/src/next/components/Wizard/hooks/useWizardFooter.tsx +3 -3
  155. package/src/next/components/Wizard/types.tsx +5 -3
  156. package/src/next/components/Wizard/utils.ts +35 -25
@@ -19,14 +19,11 @@ import {
19
19
  WizardStep,
20
20
  WizardBody,
21
21
  WizardFooter,
22
- WizardStepProps,
23
22
  useWizardContext,
24
- WizardNavStepFunction,
25
- WizardNavStepData,
26
- WizardNavItem,
27
23
  WizardHeader,
28
24
  WizardFooterWrapper,
29
- WizardNavItemType
25
+ WizardNavStepFunction,
26
+ WizardNavStepData
30
27
  } from '@patternfly/react-core/next';
31
28
 
32
29
  const StepId = {
@@ -45,30 +42,34 @@ interface SomeContextProps {
45
42
  setIsToggleStepChecked(isHidden: boolean): void;
46
43
  setErrorMessage(error: string | undefined): void;
47
44
  }
45
+ type SomeContextRenderProps = Pick<SomeContextProps, 'isToggleStepChecked' | 'errorMessage'>;
46
+ interface SomeContextProviderProps {
47
+ children: (context: SomeContextRenderProps) => React.ReactElement;
48
+ }
48
49
 
49
50
  const SomeContext = React.createContext({} as SomeContextProps);
50
51
 
51
- const SomeContextProvider = ({ children }) => {
52
+ const SomeContextProvider = ({ children }: SomeContextProviderProps) => {
52
53
  const [isToggleStepChecked, setIsToggleStepChecked] = React.useState(false);
53
54
  const [errorMessage, setErrorMessage] = React.useState<string>();
54
55
 
55
56
  return (
56
57
  <SomeContext.Provider value={{ isToggleStepChecked, errorMessage, setIsToggleStepChecked, setErrorMessage }}>
57
- {children}
58
+ {children({ isToggleStepChecked, errorMessage })}
58
59
  </SomeContext.Provider>
59
60
  );
60
61
  };
61
62
 
62
63
  const CustomWizardFooter = () => {
63
- const { currentStep, currentStepIndex, onNext, onBack, onClose } = useWizardContext();
64
+ const { activeStep, onNext, onBack, onClose } = useWizardContext();
64
65
 
65
66
  return (
66
67
  <WizardFooter
67
- currentStep={currentStep}
68
+ activeStep={activeStep}
68
69
  onNext={onNext}
69
70
  onBack={onBack}
70
71
  onClose={onClose}
71
- isBackDisabled={currentStepIndex === 1}
72
+ isBackDisabled={activeStep.index === 1}
72
73
  />
73
74
  );
74
75
  };
@@ -108,7 +109,7 @@ const StepContentWithDrawer = () => {
108
109
  );
109
110
  };
110
111
 
111
- const StepWithCustomFooter = (props: WizardStepProps) => {
112
+ const CustomStepThreeFooter = () => {
112
113
  const { onNext: goToNextStep, onBack, onClose } = useWizardContext();
113
114
  const [isLoading, setIsLoading] = React.useState(false);
114
115
 
@@ -120,51 +121,26 @@ const StepWithCustomFooter = (props: WizardStepProps) => {
120
121
  goToStep();
121
122
  }
122
123
 
123
- const footer = React.useMemo(
124
- () => (
125
- <WizardFooterWrapper>
126
- <Button variant="primary" onClick={() => onNext(goToNextStep)} isLoading={isLoading} isDisabled={isLoading}>
127
- Async Next
128
- </Button>
129
- <Button variant="secondary" onClick={onBack}>
130
- Back
131
- </Button>
132
- <Button variant="link" onClick={onClose}>
133
- Cancel
134
- </Button>
135
- </WizardFooterWrapper>
136
- ),
137
- [goToNextStep, isLoading, onBack, onClose]
138
- );
139
-
140
124
  return (
141
- <WizardStep {...props} footer={footer}>
142
- Step 3 content w/ custom async footer
143
- </WizardStep>
125
+ <WizardFooterWrapper>
126
+ <Button variant="primary" onClick={() => onNext(goToNextStep)} isLoading={isLoading} isDisabled={isLoading}>
127
+ Async Next
128
+ </Button>
129
+ <Button variant="secondary" onClick={onBack} isDisabled={isLoading}>
130
+ Back
131
+ </Button>
132
+ <Button variant="link" onClick={onClose} isDisabled={isLoading}>
133
+ Cancel
134
+ </Button>
135
+ </WizardFooterWrapper>
144
136
  );
145
137
  };
146
138
 
147
- const StepWithContextActions = (props: WizardStepProps) => {
139
+ const StepContentWithActions = () => {
148
140
  const { isToggleStepChecked, errorMessage, setIsToggleStepChecked, setErrorMessage } = React.useContext(SomeContext);
149
141
 
150
- const navItem: WizardNavItemType = React.useCallback(
151
- (step, currentStep, steps, goToStepByIndex) => (
152
- <WizardNavItem
153
- id={step.id}
154
- content={step.name}
155
- isCurrent={currentStep.id === step.id}
156
- stepIndex={steps.indexOf(step) + 1}
157
- isDisabled={step.isDisabled || !step.isVisited}
158
- isVisited={step.isVisited}
159
- onNavItemClick={goToStepByIndex}
160
- status={errorMessage ? 'error' : 'default'}
161
- />
162
- ),
163
- [errorMessage]
164
- );
165
-
166
142
  return (
167
- <WizardStep {...props} navItem={navItem}>
143
+ <>
168
144
  <Checkbox
169
145
  label="Give this step an error status"
170
146
  isChecked={!!errorMessage}
@@ -179,50 +155,63 @@ const StepWithContextActions = (props: WizardStepProps) => {
179
155
  id="toggle-hide-step-checkbox"
180
156
  name="Toggle Hide Step Checkbox"
181
157
  />
182
- </WizardStep>
158
+ </>
183
159
  );
184
160
  };
185
161
 
186
- const StepToHide = (props: WizardStepProps) => {
187
- const { isToggleStepChecked } = React.useContext(SomeContext);
188
- return <WizardStep {...props} isHidden={isToggleStepChecked} />;
189
- };
190
-
191
162
  export const WizardKitchenSink: React.FunctionComponent = () => {
192
163
  const onNext: WizardNavStepFunction = (_currentStep: WizardNavStepData, _previousStep: WizardNavStepData) => {};
193
164
 
194
165
  return (
195
166
  <SomeContextProvider>
196
- <Wizard
197
- height={400}
198
- header={<WizardHeader title="You're a wizard, Harry" closeButtonAriaLabel="Close header" />}
199
- footer={<CustomWizardFooter />}
200
- isStepVisitRequired
201
- onNext={onNext}
202
- hasUnmountedSteps={false}
203
- >
204
- <WizardStep id={StepId.StepOne} name="Step 1" body={null} status="error">
205
- <StepContentWithDrawer />
206
- </WizardStep>
207
- <WizardStep
208
- id={StepId.StepTwo}
209
- name="Step 2"
210
- steps={[
211
- <StepWithContextActions id={StepId.StepTwoSubOne} key={StepId.StepTwoSubOne} name="Substep 1" />,
212
- <StepToHide id={StepId.StepTwoSubTwo} key={StepId.StepTwoSubTwo} name="Substep 2">
213
- Substep 2 content
214
- </StepToHide>
215
- ]}
216
- />
217
- <StepWithCustomFooter
218
- id={StepId.StepThree}
219
- name="Step 3"
220
- navItem={{ content: <span style={{ color: 'var(--pf-global--default-color--200)' }}>Custom item</span> }}
221
- />
222
- <WizardStep id={StepId.ReviewStep} name="Review" footer={{ nextButtonText: 'Submit' }}>
223
- Review step content
224
- </WizardStep>
225
- </Wizard>
167
+ {({ isToggleStepChecked, errorMessage }) => (
168
+ <Wizard
169
+ height={400}
170
+ header={<WizardHeader title="You're a wizard, Harry" closeButtonAriaLabel="Close header" />}
171
+ footer={<CustomWizardFooter />}
172
+ onNext={onNext}
173
+ isStepVisitRequired
174
+ >
175
+ <WizardStep id={StepId.StepOne} name="Step 1" body={null} status="error">
176
+ <StepContentWithDrawer />
177
+ </WizardStep>
178
+ <WizardStep
179
+ id={StepId.StepTwo}
180
+ name="Step 2"
181
+ steps={[
182
+ <WizardStep
183
+ status={errorMessage ? 'error' : 'default'}
184
+ id={StepId.StepTwoSubOne}
185
+ key={StepId.StepTwoSubOne}
186
+ name="Substep 1"
187
+ >
188
+ <StepContentWithActions />
189
+ </WizardStep>,
190
+ <WizardStep
191
+ id={StepId.StepTwoSubTwo}
192
+ key={StepId.StepTwoSubTwo}
193
+ name="Substep 2"
194
+ isHidden={isToggleStepChecked}
195
+ >
196
+ Substep 2 content
197
+ </WizardStep>
198
+ ]}
199
+ />
200
+ <WizardStep
201
+ id={StepId.StepThree}
202
+ name="Step 3"
203
+ navItem={{
204
+ content: <span style={{ color: 'var(--pf-global--default-color--200)' }}>Custom item</span>
205
+ }}
206
+ footer={<CustomStepThreeFooter />}
207
+ >
208
+ Step 3 content w/ custom async footer
209
+ </WizardStep>
210
+ <WizardStep id={StepId.ReviewStep} name="Review" footer={{ nextButtonText: 'Submit' }}>
211
+ Review step content
212
+ </WizardStep>
213
+ </Wizard>
214
+ )}
226
215
  </SomeContextProvider>
227
216
  );
228
217
  };
@@ -16,15 +16,15 @@ test('sets the footer when one is provided without a stepId', () => {
16
16
  expect(setFooter).toHaveBeenCalledWith(customFooter);
17
17
  });
18
18
 
19
- test(`sets the footer when the provided stepId matches the currentStep's id`, () => {
20
- useWizardContextSpy.mockReturnValueOnce({ setFooter, currentStep: { id: 'curr-step-id' } } as any);
19
+ test(`sets the footer when the provided stepId matches the activeStep's id`, () => {
20
+ useWizardContextSpy.mockReturnValueOnce({ setFooter, activeStep: { id: 'curr-step-id' } } as any);
21
21
 
22
22
  renderHook(() => useWizardFooter(customFooter, 'curr-step-id'));
23
23
  expect(setFooter).toHaveBeenCalledWith(customFooter);
24
24
  });
25
25
 
26
- test(`does not set the footer when the provided stepId does not match the currentStep's id`, () => {
27
- useWizardContextSpy.mockReturnValueOnce({ setFooter, currentStep: { id: 'curr-step-id' } } as any);
26
+ test(`does not set the footer when the provided stepId does not match the activeStep's id`, () => {
27
+ useWizardContextSpy.mockReturnValueOnce({ setFooter, activeStep: { id: 'curr-step-id' } } as any);
28
28
 
29
29
  renderHook(() => useWizardFooter(customFooter, 'some-other-step-id'));
30
30
  expect(setFooter).not.toHaveBeenCalled();
@@ -9,10 +9,10 @@ import { WizardFooterProps } from '../WizardFooter';
9
9
  * @param stepId
10
10
  */
11
11
  export const useWizardFooter = (footer: React.ReactElement | Partial<WizardFooterProps>, stepId?: string | number) => {
12
- const { currentStep, setFooter } = useWizardContext();
12
+ const { activeStep, setFooter } = useWizardContext();
13
13
 
14
14
  React.useEffect(() => {
15
- if (footer && (!stepId || currentStep?.id === stepId)) {
15
+ if (footer && (!stepId || activeStep?.id === stepId)) {
16
16
  setFooter(footer);
17
17
 
18
18
  // Reset the footer on unmount.
@@ -20,5 +20,5 @@ export const useWizardFooter = (footer: React.ReactElement | Partial<WizardFoote
20
20
  setFooter(null);
21
21
  };
22
22
  }
23
- }, [currentStep, footer, setFooter, stepId]);
23
+ }, [activeStep, footer, setFooter, stepId]);
24
24
  };
@@ -7,6 +7,8 @@ export interface WizardBasicStep {
7
7
  name: React.ReactNode;
8
8
  /** Unique identifier */
9
9
  id: string | number;
10
+ /** Order index of step (starts at 1) */
11
+ index: number;
10
12
  /** Flag to disable the step's navigation item */
11
13
  isDisabled?: boolean;
12
14
  /** Flag to represent whether the step has been visited (navigated to) */
@@ -64,21 +66,21 @@ export type WizardNavItemType = Partial<WizardNavItemProps> | CustomWizardNavIte
64
66
  export type CustomWizardNavFunction = (
65
67
  isExpanded: boolean,
66
68
  steps: WizardControlStep[],
67
- currentStep: WizardControlStep,
69
+ activeStep: WizardControlStep,
68
70
  goToStepByIndex: (index: number) => void
69
71
  ) => React.ReactElement<WizardNavProps>;
70
72
 
71
73
  /** Callback for the Wizard's 'navItem' property. Returns element which replaces the WizardStep's default navigation item. */
72
74
  export type CustomWizardNavItemFunction = (
73
75
  step: WizardControlStep,
74
- currentStep: WizardControlStep,
76
+ activeStep: WizardControlStep,
75
77
  steps: WizardControlStep[],
76
78
  goToStepByIndex: (index: number) => void
77
79
  ) => React.ReactElement<WizardNavItemProps>;
78
80
 
79
81
  /** Callback for the Wizard's 'footer' property. Returns element which replaces the Wizard's default footer. */
80
82
  export type CustomWizardFooterFunction = (
81
- currentStep: WizardControlStep,
83
+ activeStep: WizardControlStep,
82
84
  onNext: () => void,
83
85
  onBack: () => void,
84
86
  onClose: () => void
@@ -9,27 +9,37 @@ import { WizardStep, WizardStepProps } from './WizardStep';
9
9
  * @returns WizardControlStep[]
10
10
  */
11
11
  export const buildSteps = (children: React.ReactElement<WizardStepProps> | React.ReactElement<WizardStepProps>[]) =>
12
- React.Children.toArray(children).reduce((acc: WizardControlStep[], child: React.ReactChild | React.ReactFragment) => {
12
+ React.Children.toArray(children).reduce((acc: WizardControlStep[], child: React.ReactNode) => {
13
13
  if (isWizardStep(child)) {
14
- const { steps: subSteps, id } = child.props;
15
-
16
- acc.push({
17
- component: child,
18
- ...normalizeStep(child.props),
19
- ...(subSteps && {
20
- subStepIds: subSteps?.map(subStep => {
21
- acc.push({
22
- ...normalizeStep(subStep.props),
23
- component: subStep,
24
- parentId: id
25
- });
26
-
27
- return subStep.props.id;
28
- })
29
- })
30
- });
14
+ const { steps: subSteps, id, isHidden, isDisabled } = child.props;
15
+ const subControlledSteps: WizardControlStep[] = [];
16
+ const stepIndex = acc.length + 1;
17
+
18
+ acc.push(
19
+ {
20
+ index: stepIndex,
21
+ 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,
30
+ index: stepIndex + subStepIndex + 1,
31
+ ...normalizeStep(subStep.props)
32
+ });
33
+
34
+ return subStep.props.id;
35
+ })
36
+ }),
37
+ ...normalizeStep(child.props)
38
+ },
39
+ ...subControlledSteps
40
+ );
31
41
  } else {
32
- throw new Error('Wizard only accepts children of type WizardStep');
42
+ throw new Error('Wizard only accepts children with required WizardStepProps.');
33
43
  }
34
44
 
35
45
  return acc;
@@ -45,14 +55,14 @@ export function isWizardStep(
45
55
  }
46
56
 
47
57
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
48
- export const normalizeStep = ({ children, steps, body, ...controlStep }: WizardStepProps): WizardControlStep =>
58
+ export const normalizeStep = ({ children, steps, ...controlStep }: WizardStepProps): Omit<WizardControlStep, 'index'> =>
49
59
  controlStep;
50
60
 
51
- export const normalizeNavStep = (navStep: WizardControlStep, steps: WizardControlStep[]): WizardNavStepData => ({
61
+ export const normalizeNavStep = (navStep: WizardControlStep): WizardNavStepData => ({
52
62
  id: navStep.id,
53
- name: navStep.name.toString(),
54
- index: steps.indexOf(navStep) + 1
63
+ index: navStep.index,
64
+ name: navStep.name.toString()
55
65
  });
56
66
 
57
- export const getCurrentStep = (steps: WizardControlStep[], currentStepIndex: number) =>
58
- steps.find((_, index) => index + 1 === currentStepIndex);
67
+ export const getActiveStep = (steps: WizardControlStep[], activeStepIndex: number) =>
68
+ steps.find(step => step.index === activeStepIndex);