@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.
- package/CHANGELOG.md +19 -0
- package/dist/esm/components/Card/Card.d.ts +2 -2
- package/dist/esm/components/Card/Card.d.ts.map +1 -1
- package/dist/esm/components/DataList/DataList.d.ts +1 -1
- package/dist/esm/components/DataList/DataList.d.ts.map +1 -1
- package/dist/esm/components/DataList/DataListItem.d.ts +1 -1
- package/dist/esm/components/DataList/DataListItem.d.ts.map +1 -1
- package/dist/esm/components/MultipleFileUpload/MultipleFileUploadStatusItem.d.ts +2 -0
- package/dist/esm/components/MultipleFileUpload/MultipleFileUploadStatusItem.d.ts.map +1 -1
- package/dist/esm/components/MultipleFileUpload/MultipleFileUploadStatusItem.js +7 -1
- package/dist/esm/components/MultipleFileUpload/MultipleFileUploadStatusItem.js.map +1 -1
- package/dist/esm/components/Popover/Popover.d.ts +3 -3
- package/dist/esm/components/Popover/Popover.d.ts.map +1 -1
- package/dist/esm/components/Wizard/Wizard.d.ts +4 -4
- package/dist/esm/components/Wizard/Wizard.d.ts.map +1 -1
- package/dist/esm/components/Wizard/WizardToggle.d.ts +2 -2
- package/dist/esm/components/Wizard/WizardToggle.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/Wizard.d.ts +1 -3
- package/dist/esm/next/components/Wizard/Wizard.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/Wizard.js +36 -45
- package/dist/esm/next/components/Wizard/Wizard.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardBody.d.ts +2 -2
- package/dist/esm/next/components/Wizard/WizardBody.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardBody.js +2 -2
- package/dist/esm/next/components/Wizard/WizardBody.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardContext.d.ts +2 -7
- package/dist/esm/next/components/Wizard/WizardContext.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardContext.js +18 -39
- package/dist/esm/next/components/Wizard/WizardContext.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardFooter.d.ts +3 -3
- package/dist/esm/next/components/Wizard/WizardFooter.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardFooter.js +3 -3
- package/dist/esm/next/components/Wizard/WizardFooter.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardNavInternal.js +12 -12
- package/dist/esm/next/components/Wizard/WizardNavInternal.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardStep.d.ts +1 -3
- package/dist/esm/next/components/Wizard/WizardStep.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardStep.js +10 -18
- package/dist/esm/next/components/Wizard/WizardStep.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardToggle.d.ts +2 -4
- package/dist/esm/next/components/Wizard/WizardToggle.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardToggle.js +19 -16
- package/dist/esm/next/components/Wizard/WizardToggle.js.map +1 -1
- package/dist/esm/next/components/Wizard/hooks/useWizardFooter.js +3 -3
- package/dist/esm/next/components/Wizard/hooks/useWizardFooter.js.map +1 -1
- package/dist/esm/next/components/Wizard/types.d.ts +5 -3
- package/dist/esm/next/components/Wizard/types.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/types.js.map +1 -1
- package/dist/esm/next/components/Wizard/utils.d.ts +3 -3
- package/dist/esm/next/components/Wizard/utils.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/utils.js +14 -11
- package/dist/esm/next/components/Wizard/utils.js.map +1 -1
- package/dist/js/components/Card/Card.d.ts +2 -2
- package/dist/js/components/Card/Card.d.ts.map +1 -1
- package/dist/js/components/DataList/DataList.d.ts +1 -1
- package/dist/js/components/DataList/DataList.d.ts.map +1 -1
- package/dist/js/components/DataList/DataListItem.d.ts +1 -1
- package/dist/js/components/DataList/DataListItem.d.ts.map +1 -1
- package/dist/js/components/MultipleFileUpload/MultipleFileUploadStatusItem.d.ts +2 -0
- package/dist/js/components/MultipleFileUpload/MultipleFileUploadStatusItem.d.ts.map +1 -1
- package/dist/js/components/MultipleFileUpload/MultipleFileUploadStatusItem.js +7 -1
- package/dist/js/components/MultipleFileUpload/MultipleFileUploadStatusItem.js.map +1 -1
- package/dist/js/components/Popover/Popover.d.ts +3 -3
- package/dist/js/components/Popover/Popover.d.ts.map +1 -1
- package/dist/js/components/Wizard/Wizard.d.ts +4 -4
- package/dist/js/components/Wizard/Wizard.d.ts.map +1 -1
- package/dist/js/components/Wizard/WizardToggle.d.ts +2 -2
- package/dist/js/components/Wizard/WizardToggle.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/Wizard.d.ts +1 -3
- package/dist/js/next/components/Wizard/Wizard.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/Wizard.js +36 -45
- package/dist/js/next/components/Wizard/Wizard.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardBody.d.ts +2 -2
- package/dist/js/next/components/Wizard/WizardBody.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardBody.js +2 -2
- package/dist/js/next/components/Wizard/WizardBody.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardContext.d.ts +2 -7
- package/dist/js/next/components/Wizard/WizardContext.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardContext.js +15 -37
- package/dist/js/next/components/Wizard/WizardContext.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardFooter.d.ts +3 -3
- package/dist/js/next/components/Wizard/WizardFooter.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardFooter.js +3 -3
- package/dist/js/next/components/Wizard/WizardFooter.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardNavInternal.js +12 -12
- package/dist/js/next/components/Wizard/WizardNavInternal.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardStep.d.ts +1 -3
- package/dist/js/next/components/Wizard/WizardStep.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardStep.js +9 -18
- package/dist/js/next/components/Wizard/WizardStep.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardToggle.d.ts +2 -4
- package/dist/js/next/components/Wizard/WizardToggle.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardToggle.js +18 -16
- package/dist/js/next/components/Wizard/WizardToggle.js.map +1 -1
- package/dist/js/next/components/Wizard/hooks/useWizardFooter.js +3 -3
- package/dist/js/next/components/Wizard/hooks/useWizardFooter.js.map +1 -1
- package/dist/js/next/components/Wizard/types.d.ts +5 -3
- package/dist/js/next/components/Wizard/types.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/types.js.map +1 -1
- package/dist/js/next/components/Wizard/utils.d.ts +3 -3
- package/dist/js/next/components/Wizard/utils.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/utils.js +16 -13
- package/dist/js/next/components/Wizard/utils.js.map +1 -1
- package/dist/umd/react-core.min.css +137 -137
- package/dist/umd/react-core.min.js +1 -1
- package/package.json +2 -2
- package/src/components/AlertGroup/examples/AlertGroup.md +2 -2
- package/src/components/CalendarMonth/examples/CalendarMonth.md +0 -1
- package/src/components/Card/Card.tsx +2 -2
- package/src/components/DataList/DataList.tsx +1 -1
- package/src/components/DataList/DataListItem.tsx +1 -1
- package/src/components/DualListSelector/examples/DualListSelector.md +0 -1
- package/src/components/LabelGroup/examples/LabelGroup.md +2 -3
- package/src/components/Masthead/examples/Masthead.md +0 -1
- package/src/components/Menu/examples/Menu.md +1 -1
- package/src/components/MenuToggle/examples/MenuToggle.md +0 -1
- package/src/components/MultipleFileUpload/MultipleFileUploadStatusItem.tsx +10 -0
- package/src/components/MultipleFileUpload/__tests__/MultipleFileUploadStatusItem.test.tsx +33 -1
- package/src/components/MultipleFileUpload/__tests__/__snapshots__/MultipleFileUploadStatusItem.test.tsx.snap +269 -3
- package/src/components/MultipleFileUpload/examples/MultipleFileUpload.md +0 -1
- package/src/components/NotificationDrawer/examples/NotificationDrawer.md +0 -1
- package/src/components/Panel/examples/Panel.md +0 -1
- package/src/components/Popover/Popover.tsx +3 -3
- package/src/components/Popover/examples/Popover.md +2 -2
- package/src/components/Select/examples/Select.md +2 -2
- package/src/components/Slider/examples/Slider.md +0 -1
- package/src/components/TextArea/examples/TextArea.md +1 -1
- package/src/components/TextInput/examples/TextInput.md +1 -1
- package/src/components/TreeView/examples/TreeView.md +0 -1
- package/src/components/Wizard/Wizard.tsx +4 -4
- package/src/components/Wizard/WizardToggle.tsx +2 -2
- package/src/components/Wizard/examples/Wizard.md +12 -8
- package/src/demos/MultipleFileUploadDemos.md +0 -1
- package/src/demos/NotificationDrawer/NotificationDrawer.md +0 -1
- package/src/next/components/Wizard/Wizard.tsx +35 -54
- package/src/next/components/Wizard/WizardBody.tsx +3 -3
- package/src/next/components/Wizard/WizardContext.tsx +29 -61
- package/src/next/components/Wizard/WizardFooter.tsx +6 -6
- package/src/next/components/Wizard/WizardNavInternal.tsx +18 -17
- package/src/next/components/Wizard/WizardStep.tsx +19 -30
- package/src/next/components/Wizard/WizardToggle.tsx +22 -24
- package/src/next/components/Wizard/__tests__/Wizard.test.tsx +1 -21
- package/src/next/components/Wizard/__tests__/WizardBody.test.tsx +2 -2
- package/src/next/components/Wizard/__tests__/WizardFooter.test.tsx +5 -5
- package/src/next/components/Wizard/__tests__/WizardStep.test.tsx +22 -76
- package/src/next/components/Wizard/__tests__/WizardToggle.test.tsx +7 -11
- package/src/next/components/Wizard/__tests__/utils.test.tsx +3 -3
- package/src/next/components/Wizard/examples/Wizard.md +4 -4
- package/src/next/components/Wizard/examples/WizardCustomNav.tsx +4 -4
- package/src/next/components/Wizard/examples/WizardKitchenSink.tsx +74 -85
- package/src/next/components/Wizard/hooks/__tests__/useWizardFooter.test.tsx +4 -4
- package/src/next/components/Wizard/hooks/useWizardFooter.tsx +3 -3
- package/src/next/components/Wizard/types.tsx +5 -3
- 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
|
-
|
|
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 {
|
|
64
|
+
const { activeStep, onNext, onBack, onClose } = useWizardContext();
|
|
64
65
|
|
|
65
66
|
return (
|
|
66
67
|
<WizardFooter
|
|
67
|
-
|
|
68
|
+
activeStep={activeStep}
|
|
68
69
|
onNext={onNext}
|
|
69
70
|
onBack={onBack}
|
|
70
71
|
onClose={onClose}
|
|
71
|
-
isBackDisabled={
|
|
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
|
|
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
|
-
<
|
|
142
|
-
|
|
143
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
|
20
|
-
useWizardContextSpy.mockReturnValueOnce({ setFooter,
|
|
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
|
|
27
|
-
useWizardContextSpy.mockReturnValueOnce({ setFooter,
|
|
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 {
|
|
12
|
+
const { activeStep, setFooter } = useWizardContext();
|
|
13
13
|
|
|
14
14
|
React.useEffect(() => {
|
|
15
|
-
if (footer && (!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
|
-
}, [
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
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,
|
|
58
|
+
export const normalizeStep = ({ children, steps, ...controlStep }: WizardStepProps): Omit<WizardControlStep, 'index'> =>
|
|
49
59
|
controlStep;
|
|
50
60
|
|
|
51
|
-
export const normalizeNavStep = (navStep: WizardControlStep
|
|
61
|
+
export const normalizeNavStep = (navStep: WizardControlStep): WizardNavStepData => ({
|
|
52
62
|
id: navStep.id,
|
|
53
|
-
|
|
54
|
-
|
|
63
|
+
index: navStep.index,
|
|
64
|
+
name: navStep.name.toString()
|
|
55
65
|
});
|
|
56
66
|
|
|
57
|
-
export const
|
|
58
|
-
steps.find(
|
|
67
|
+
export const getActiveStep = (steps: WizardControlStep[], activeStepIndex: number) =>
|
|
68
|
+
steps.find(step => step.index === activeStepIndex);
|