@patternfly/react-core 4.234.4 → 4.235.2
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 +27 -0
- package/dist/esm/next/components/Wizard/Wizard.d.ts +40 -0
- package/dist/esm/next/components/Wizard/Wizard.d.ts.map +1 -0
- package/dist/esm/next/components/Wizard/Wizard.js +86 -0
- package/dist/esm/next/components/Wizard/Wizard.js.map +1 -0
- package/dist/esm/next/components/Wizard/WizardBody.d.ts +20 -0
- package/dist/esm/next/components/Wizard/WizardBody.d.ts.map +1 -0
- package/dist/esm/next/components/Wizard/WizardBody.js +7 -0
- package/dist/esm/next/components/Wizard/WizardBody.js.map +1 -0
- package/dist/esm/next/components/Wizard/WizardContext.d.ts +49 -0
- package/dist/esm/next/components/Wizard/WizardContext.d.ts.map +1 -0
- package/dist/esm/next/components/Wizard/WizardContext.js +34 -0
- package/dist/esm/next/components/Wizard/WizardContext.js.map +1 -0
- package/dist/esm/next/components/Wizard/WizardFooter.d.ts +28 -0
- package/dist/esm/next/components/Wizard/WizardFooter.d.ts.map +1 -0
- package/dist/esm/next/components/Wizard/WizardFooter.js +11 -0
- package/dist/esm/next/components/Wizard/WizardFooter.js.map +1 -0
- package/dist/esm/next/components/Wizard/WizardHeader.d.ts +21 -0
- package/dist/esm/next/components/Wizard/WizardHeader.d.ts.map +1 -0
- package/dist/esm/next/components/Wizard/WizardHeader.js +13 -0
- package/dist/esm/next/components/Wizard/WizardHeader.js.map +1 -0
- package/dist/esm/next/components/Wizard/WizardNav.d.ts +15 -0
- package/dist/esm/next/components/Wizard/WizardNav.d.ts.map +1 -0
- package/dist/esm/next/components/Wizard/WizardNav.js +13 -0
- package/dist/esm/next/components/Wizard/WizardNav.js.map +1 -0
- package/dist/esm/next/components/Wizard/WizardNavItem.d.ts +25 -0
- package/dist/esm/next/components/Wizard/WizardNavItem.d.ts.map +1 -0
- package/dist/esm/next/components/Wizard/WizardNavItem.js +33 -0
- package/dist/esm/next/components/Wizard/WizardNavItem.js.map +1 -0
- package/dist/esm/next/components/Wizard/WizardStep.d.ts +20 -0
- package/dist/esm/next/components/Wizard/WizardStep.d.ts.map +1 -0
- package/dist/esm/next/components/Wizard/WizardStep.js +5 -0
- package/dist/esm/next/components/Wizard/WizardStep.js.map +1 -0
- package/dist/esm/next/components/Wizard/WizardToggle.d.ts +26 -0
- package/dist/esm/next/components/Wizard/WizardToggle.d.ts.map +1 -0
- package/dist/esm/next/components/Wizard/WizardToggle.js +81 -0
- package/dist/esm/next/components/Wizard/WizardToggle.js.map +1 -0
- package/dist/esm/next/components/Wizard/hooks/index.d.ts +2 -0
- package/dist/esm/next/components/Wizard/hooks/index.d.ts.map +1 -0
- package/dist/esm/next/components/Wizard/hooks/index.js +2 -0
- package/dist/esm/next/components/Wizard/hooks/index.js.map +1 -0
- package/dist/esm/next/components/Wizard/hooks/useWizardFooter.d.ts +8 -0
- package/dist/esm/next/components/Wizard/hooks/useWizardFooter.d.ts.map +1 -0
- package/dist/esm/next/components/Wizard/hooks/useWizardFooter.js +20 -0
- package/dist/esm/next/components/Wizard/hooks/useWizardFooter.js.map +1 -0
- package/dist/esm/next/components/Wizard/index.d.ts +12 -0
- package/dist/esm/next/components/Wizard/index.d.ts.map +1 -0
- package/dist/esm/next/components/Wizard/index.js +12 -0
- package/dist/esm/next/components/Wizard/index.js.map +1 -0
- package/dist/esm/next/components/Wizard/types.d.ts +69 -0
- package/dist/esm/next/components/Wizard/types.d.ts.map +1 -0
- package/dist/esm/next/components/Wizard/types.js +20 -0
- package/dist/esm/next/components/Wizard/types.js.map +1 -0
- package/dist/esm/next/components/Wizard/utils.d.ts +15 -0
- package/dist/esm/next/components/Wizard/utils.d.ts.map +1 -0
- package/dist/esm/next/components/Wizard/utils.js +35 -0
- package/dist/esm/next/components/Wizard/utils.js.map +1 -0
- package/dist/esm/next/components/index.d.ts +1 -1
- package/dist/esm/next/components/index.d.ts.map +1 -1
- package/dist/esm/next/components/index.js +1 -1
- package/dist/esm/next/components/index.js.map +1 -1
- package/dist/js/next/components/Wizard/Wizard.d.ts +40 -0
- package/dist/js/next/components/Wizard/Wizard.d.ts.map +1 -0
- package/dist/js/next/components/Wizard/Wizard.js +90 -0
- package/dist/js/next/components/Wizard/Wizard.js.map +1 -0
- package/dist/js/next/components/Wizard/WizardBody.d.ts +20 -0
- package/dist/js/next/components/Wizard/WizardBody.d.ts.map +1 -0
- package/dist/js/next/components/Wizard/WizardBody.js +12 -0
- package/dist/js/next/components/Wizard/WizardBody.js.map +1 -0
- package/dist/js/next/components/Wizard/WizardContext.d.ts +49 -0
- package/dist/js/next/components/Wizard/WizardContext.d.ts.map +1 -0
- package/dist/js/next/components/Wizard/WizardContext.js +40 -0
- package/dist/js/next/components/Wizard/WizardContext.js.map +1 -0
- package/dist/js/next/components/Wizard/WizardFooter.d.ts +28 -0
- package/dist/js/next/components/Wizard/WizardFooter.d.ts.map +1 -0
- package/dist/js/next/components/Wizard/WizardFooter.js +16 -0
- package/dist/js/next/components/Wizard/WizardFooter.js.map +1 -0
- package/dist/js/next/components/Wizard/WizardHeader.d.ts +21 -0
- package/dist/js/next/components/Wizard/WizardHeader.d.ts.map +1 -0
- package/dist/js/next/components/Wizard/WizardHeader.js +18 -0
- package/dist/js/next/components/Wizard/WizardHeader.js.map +1 -0
- package/dist/js/next/components/Wizard/WizardNav.d.ts +15 -0
- package/dist/js/next/components/Wizard/WizardNav.d.ts.map +1 -0
- package/dist/js/next/components/Wizard/WizardNav.js +18 -0
- package/dist/js/next/components/Wizard/WizardNav.js.map +1 -0
- package/dist/js/next/components/Wizard/WizardNavItem.d.ts +25 -0
- package/dist/js/next/components/Wizard/WizardNavItem.d.ts.map +1 -0
- package/dist/js/next/components/Wizard/WizardNavItem.js +37 -0
- package/dist/js/next/components/Wizard/WizardNavItem.js.map +1 -0
- package/dist/js/next/components/Wizard/WizardStep.d.ts +20 -0
- package/dist/js/next/components/Wizard/WizardStep.d.ts.map +1 -0
- package/dist/js/next/components/Wizard/WizardStep.js +10 -0
- package/dist/js/next/components/Wizard/WizardStep.js.map +1 -0
- package/dist/js/next/components/Wizard/WizardToggle.d.ts +26 -0
- package/dist/js/next/components/Wizard/WizardToggle.d.ts.map +1 -0
- package/dist/js/next/components/Wizard/WizardToggle.js +86 -0
- package/dist/js/next/components/Wizard/WizardToggle.js.map +1 -0
- package/dist/js/next/components/Wizard/hooks/index.d.ts +2 -0
- package/dist/js/next/components/Wizard/hooks/index.d.ts.map +1 -0
- package/dist/js/next/components/Wizard/hooks/index.js +6 -0
- package/dist/js/next/components/Wizard/hooks/index.js.map +1 -0
- package/dist/js/next/components/Wizard/hooks/useWizardFooter.d.ts +8 -0
- package/dist/js/next/components/Wizard/hooks/useWizardFooter.d.ts.map +1 -0
- package/dist/js/next/components/Wizard/hooks/useWizardFooter.js +25 -0
- package/dist/js/next/components/Wizard/hooks/useWizardFooter.js.map +1 -0
- package/dist/js/next/components/Wizard/index.d.ts +12 -0
- package/dist/js/next/components/Wizard/index.d.ts.map +1 -0
- package/dist/js/next/components/Wizard/index.js +17 -0
- package/dist/js/next/components/Wizard/index.js.map +1 -0
- package/dist/js/next/components/Wizard/types.d.ts +69 -0
- package/dist/js/next/components/Wizard/types.d.ts.map +1 -0
- package/dist/js/next/components/Wizard/types.js +29 -0
- package/dist/js/next/components/Wizard/types.js.map +1 -0
- package/dist/js/next/components/Wizard/utils.d.ts +15 -0
- package/dist/js/next/components/Wizard/utils.d.ts.map +1 -0
- package/dist/js/next/components/Wizard/utils.js +41 -0
- package/dist/js/next/components/Wizard/utils.js.map +1 -0
- package/dist/js/next/components/index.d.ts +1 -1
- package/dist/js/next/components/index.d.ts.map +1 -1
- package/dist/js/next/components/index.js +1 -1
- package/dist/js/next/components/index.js.map +1 -1
- package/dist/umd/react-core.css +991 -991
- package/dist/umd/react-core.js +509 -413
- package/dist/umd/react-core.min.css +70 -70
- package/dist/umd/react-core.min.js +5 -5
- package/package.json +10 -10
- package/src/components/Wizard/examples/Wizard.md +21 -4
- package/src/next/components/Wizard/Wizard.tsx +184 -0
- package/src/next/components/Wizard/WizardBody.tsx +34 -0
- package/src/next/components/Wizard/WizardContext.tsx +104 -0
- package/src/next/components/Wizard/WizardFooter.tsx +63 -0
- package/src/next/components/Wizard/WizardHeader.tsx +53 -0
- package/src/next/components/Wizard/WizardNav.tsx +41 -0
- package/src/next/components/Wizard/WizardNavItem.tsx +103 -0
- package/src/next/components/Wizard/WizardStep.tsx +23 -0
- package/src/next/components/Wizard/WizardToggle.tsx +209 -0
- package/src/next/components/Wizard/__tests__/Wizard.test.tsx +298 -0
- package/src/next/components/Wizard/examples/Wizard.md +125 -0
- package/src/next/components/Wizard/examples/WizardBasic.tsx +22 -0
- package/src/next/components/Wizard/examples/WizardCustomNav.tsx +46 -0
- package/src/next/components/Wizard/examples/WizardKitchenSink.tsx +170 -0
- package/src/next/components/Wizard/hooks/index.ts +1 -0
- package/src/next/components/Wizard/hooks/useWizardFooter.tsx +22 -0
- package/src/next/components/Wizard/index.ts +11 -0
- package/src/next/components/Wizard/types.tsx +101 -0
- package/src/next/components/Wizard/utils.ts +47 -0
- package/src/next/components/index.ts +1 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Wizard,
|
|
4
|
+
WizardStep,
|
|
5
|
+
WizardControlStep,
|
|
6
|
+
CustomWizardNavFunction,
|
|
7
|
+
WizardNav,
|
|
8
|
+
WizardNavItem
|
|
9
|
+
} from '@patternfly/react-core/next';
|
|
10
|
+
|
|
11
|
+
export const WizardCustomNav: React.FunctionComponent = () => {
|
|
12
|
+
const nav: CustomWizardNavFunction = (
|
|
13
|
+
isOpen: boolean,
|
|
14
|
+
steps: WizardControlStep[],
|
|
15
|
+
activeStep: WizardControlStep,
|
|
16
|
+
goToStepByIndex: (index: number) => void
|
|
17
|
+
) => (
|
|
18
|
+
<WizardNav isOpen={isOpen}>
|
|
19
|
+
{steps.map((step, index) => (
|
|
20
|
+
<WizardNavItem
|
|
21
|
+
key={step.id}
|
|
22
|
+
id={step.id}
|
|
23
|
+
content={step.name}
|
|
24
|
+
isCurrent={activeStep.id === step.id}
|
|
25
|
+
isDisabled={step.isDisabled}
|
|
26
|
+
step={index + 1}
|
|
27
|
+
onNavItemClick={goToStepByIndex}
|
|
28
|
+
/>
|
|
29
|
+
))}
|
|
30
|
+
</WizardNav>
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Wizard height={400} nav={nav}>
|
|
35
|
+
<WizardStep name="First step" id="cnav-first-step">
|
|
36
|
+
<p>Did you say...custom nav?</p>
|
|
37
|
+
</WizardStep>
|
|
38
|
+
<WizardStep name="Second step" id="cnav-second-step">
|
|
39
|
+
<p>Step 2 content</p>
|
|
40
|
+
</WizardStep>
|
|
41
|
+
<WizardStep name="Review" id="cnav-review-step" nextButtonText="Wrap it up">
|
|
42
|
+
<p>Review step content</p>
|
|
43
|
+
</WizardStep>
|
|
44
|
+
</Wizard>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
} from '@patternfly/react-core';
|
|
16
|
+
import {
|
|
17
|
+
Wizard,
|
|
18
|
+
WizardStep,
|
|
19
|
+
WizardBody,
|
|
20
|
+
WizardFooter,
|
|
21
|
+
WizardStepProps,
|
|
22
|
+
WizardControlStep,
|
|
23
|
+
useWizardFooter,
|
|
24
|
+
useWizardContext,
|
|
25
|
+
WizardNavStepFunction,
|
|
26
|
+
WizardNavStepData,
|
|
27
|
+
WizardNavItem,
|
|
28
|
+
WizardHeader
|
|
29
|
+
} from '@patternfly/react-core/next';
|
|
30
|
+
import { css } from '@patternfly/react-styles';
|
|
31
|
+
import styles from '@patternfly/react-styles/css/components/Wizard/wizard';
|
|
32
|
+
|
|
33
|
+
const CustomWizardFooter = () => {
|
|
34
|
+
const { activeStep, onNext, onBack, onClose } = useWizardContext();
|
|
35
|
+
return <WizardFooter activeStep={activeStep} onNext={onNext} onBack={onBack} onClose={onClose} />;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const CustomNavItem = () => {
|
|
39
|
+
const { steps, activeStep, goToStepByIndex } = useWizardContext();
|
|
40
|
+
const step = (steps.find(step => step.id === 'third-step') || {}) as WizardControlStep;
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<WizardNavItem
|
|
44
|
+
id={step.id}
|
|
45
|
+
content={<span style={{ color: 'var(--pf-global--default-color--200)' }}>Custom item</span>}
|
|
46
|
+
isCurrent={activeStep.id === step.id}
|
|
47
|
+
step={steps.indexOf(step) + 1}
|
|
48
|
+
isDisabled={step.isDisabled || !step.visited}
|
|
49
|
+
onNavItemClick={goToStepByIndex}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const StepContentWithDrawer = () => {
|
|
55
|
+
const [isDrawerExpanded, setIsDrawerExpanded] = React.useState(false);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<Drawer isInline isExpanded={isDrawerExpanded}>
|
|
59
|
+
<DrawerContent
|
|
60
|
+
panelContent={
|
|
61
|
+
<DrawerPanelContent widths={{ default: 'width_33' }} colorVariant={DrawerColorVariant.light200}>
|
|
62
|
+
<DrawerHead>
|
|
63
|
+
<span tabIndex={isDrawerExpanded ? 0 : -1}>drawer content</span>
|
|
64
|
+
<DrawerActions>
|
|
65
|
+
<DrawerCloseButton onClick={() => setIsDrawerExpanded(false)} />
|
|
66
|
+
</DrawerActions>
|
|
67
|
+
</DrawerHead>
|
|
68
|
+
</DrawerPanelContent>
|
|
69
|
+
}
|
|
70
|
+
>
|
|
71
|
+
<WizardBody>
|
|
72
|
+
<Flex direction={{ default: 'column' }}>
|
|
73
|
+
{!isDrawerExpanded && (
|
|
74
|
+
<Button isInline variant="link" onClick={() => setIsDrawerExpanded(prevExpanded => !prevExpanded)}>
|
|
75
|
+
Open drawer
|
|
76
|
+
</Button>
|
|
77
|
+
)}
|
|
78
|
+
|
|
79
|
+
<FormGroup fieldId="some-text-input" label="Text input label">
|
|
80
|
+
<TextInput aria-label="Some Text Input Label" />
|
|
81
|
+
</FormGroup>
|
|
82
|
+
</Flex>
|
|
83
|
+
</WizardBody>
|
|
84
|
+
</DrawerContent>
|
|
85
|
+
</Drawer>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const StepWithCustomFooter = () => {
|
|
90
|
+
const { onNext: goToNextStep, onBack, onClose } = useWizardContext();
|
|
91
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
92
|
+
|
|
93
|
+
async function onNext(goToStep: () => void) {
|
|
94
|
+
setIsLoading(true);
|
|
95
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
96
|
+
setIsLoading(false);
|
|
97
|
+
|
|
98
|
+
goToStep();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const footer = React.useMemo(
|
|
102
|
+
() => (
|
|
103
|
+
<div className={css(styles.wizardFooter)}>
|
|
104
|
+
<Button
|
|
105
|
+
variant="primary"
|
|
106
|
+
type="submit"
|
|
107
|
+
onClick={() => onNext(goToNextStep)}
|
|
108
|
+
isLoading={isLoading}
|
|
109
|
+
isDisabled={isLoading}
|
|
110
|
+
>
|
|
111
|
+
Async Next
|
|
112
|
+
</Button>
|
|
113
|
+
<Button variant="secondary" onClick={onBack}>
|
|
114
|
+
Back
|
|
115
|
+
</Button>
|
|
116
|
+
<Button variant="link" onClick={onClose}>
|
|
117
|
+
Cancel
|
|
118
|
+
</Button>
|
|
119
|
+
</div>
|
|
120
|
+
),
|
|
121
|
+
[isLoading, onBack, onClose, goToNextStep]
|
|
122
|
+
);
|
|
123
|
+
useWizardFooter(footer);
|
|
124
|
+
|
|
125
|
+
return <>Step 3 content w/ custom async footer</>;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const CustomStepFour = (props: WizardStepProps) => <div {...props} id={props.id.toString()} />;
|
|
129
|
+
|
|
130
|
+
export const WizardKitchenSink: React.FunctionComponent = () => {
|
|
131
|
+
const onNext: WizardNavStepFunction = (currentStep: WizardNavStepData, previousStep: WizardNavStepData) => {
|
|
132
|
+
// eslint-disable-next-line no-console
|
|
133
|
+
console.log('currentStep: ', currentStep, '\n previousStep: ', previousStep);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<Wizard
|
|
138
|
+
height={400}
|
|
139
|
+
header={<WizardHeader title="You're a wizard, Harry" closeButtonAriaLabel="Close header" />}
|
|
140
|
+
footer={<CustomWizardFooter />}
|
|
141
|
+
nav={{ forceStepVisit: true, isExpandable: true }}
|
|
142
|
+
onNext={onNext}
|
|
143
|
+
>
|
|
144
|
+
<WizardStep id="sink-first-step" name="First step" body={null}>
|
|
145
|
+
<StepContentWithDrawer />
|
|
146
|
+
</WizardStep>
|
|
147
|
+
<WizardStep
|
|
148
|
+
id="sink-second-step"
|
|
149
|
+
name="Second step"
|
|
150
|
+
steps={[
|
|
151
|
+
<WizardStep id="sink-sub-step-one" key="substep-one" name="Substep 1">
|
|
152
|
+
Substep 1 content
|
|
153
|
+
</WizardStep>,
|
|
154
|
+
<WizardStep id="sink-sub-step-two" key="substep-two" name="Substep 2">
|
|
155
|
+
Substep 2 content
|
|
156
|
+
</WizardStep>
|
|
157
|
+
]}
|
|
158
|
+
/>
|
|
159
|
+
<WizardStep id="sink-third-step" name="Third step" navItem={<CustomNavItem />}>
|
|
160
|
+
<StepWithCustomFooter />
|
|
161
|
+
</WizardStep>
|
|
162
|
+
<CustomStepFour id="sink-fourth-step" name="Fourth step">
|
|
163
|
+
<WizardBody>Step 4 content</WizardBody>
|
|
164
|
+
</CustomStepFour>
|
|
165
|
+
<WizardStep id="sink-review-step" name="Review" nextButtonText="Submit">
|
|
166
|
+
Review step content
|
|
167
|
+
</WizardStep>
|
|
168
|
+
</Wizard>
|
|
169
|
+
);
|
|
170
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useWizardFooter } from './useWizardFooter';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useWizardContext } from '../WizardContext';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Set a unique footer for the wizard. stepId is only required if inactive steps are hidden instead of unmounted.
|
|
6
|
+
* @param footer
|
|
7
|
+
* @param stepId
|
|
8
|
+
*/
|
|
9
|
+
export const useWizardFooter = (footer: React.ReactElement, stepId?: string | number) => {
|
|
10
|
+
const { activeStep, setFooter } = useWizardContext();
|
|
11
|
+
|
|
12
|
+
React.useEffect(() => {
|
|
13
|
+
if (!stepId || activeStep.id === stepId) {
|
|
14
|
+
setFooter(footer);
|
|
15
|
+
|
|
16
|
+
// Reset the footer on unmount.
|
|
17
|
+
return () => {
|
|
18
|
+
setFooter(null);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}, [activeStep, footer, setFooter, stepId]);
|
|
22
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './Wizard';
|
|
2
|
+
export * from './WizardBody';
|
|
3
|
+
export * from './WizardFooter';
|
|
4
|
+
export * from './WizardToggle';
|
|
5
|
+
export * from './WizardStep';
|
|
6
|
+
export * from './WizardNav';
|
|
7
|
+
export * from './WizardNavItem';
|
|
8
|
+
export * from './WizardHeader';
|
|
9
|
+
export * from './hooks';
|
|
10
|
+
export * from './types';
|
|
11
|
+
export { useWizardContext } from './WizardContext';
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { WizardNavProps, WizardNavItemProps } from '../Wizard';
|
|
3
|
+
|
|
4
|
+
/** Type used to define 'basic' steps, or in other words, steps that are neither parents or children of parents. */
|
|
5
|
+
export interface WizardBasicStep {
|
|
6
|
+
/** Name of the step's nav item */
|
|
7
|
+
name: React.ReactNode;
|
|
8
|
+
/** Unique identifier */
|
|
9
|
+
id: string | number;
|
|
10
|
+
/** Flag to disable the step's nav item */
|
|
11
|
+
isDisabled?: boolean;
|
|
12
|
+
/** Flag to represent whether the step has been visited (navigated to) */
|
|
13
|
+
visited?: boolean;
|
|
14
|
+
/** Content shown when the step's nav item is selected. When treated as a parent step, only sub-step content will be shown. */
|
|
15
|
+
component?: React.ReactElement;
|
|
16
|
+
/** (Unused if nav is controlled) Custom WizardNavItem */
|
|
17
|
+
navItem?: React.ReactElement<WizardNavItemProps>;
|
|
18
|
+
/** (Unused if footer is controlled) Can change the Next button text. If nextButtonText is also set for the Wizard, this step specific one overrides it. */
|
|
19
|
+
nextButtonText?: React.ReactNode;
|
|
20
|
+
/** (Unused if footer is controlled) The condition needed to disable the Next button */
|
|
21
|
+
disableNext?: boolean;
|
|
22
|
+
/** (Unused if footer is controlled) True to hide the Cancel button */
|
|
23
|
+
hideCancelButton?: boolean;
|
|
24
|
+
/** (Unused if footer is controlled) True to hide the Back button */
|
|
25
|
+
hideBackButton?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Type used to define parent steps. */
|
|
29
|
+
export interface WizardParentStep extends WizardBasicStep {
|
|
30
|
+
/** Nested step IDs */
|
|
31
|
+
subStepIds: string[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Type used to define sub-steps. */
|
|
35
|
+
export interface WizardSubStep extends WizardBasicStep {
|
|
36
|
+
/** Unique identifier of the parent step */
|
|
37
|
+
parentId: string | number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Used to customize aspects of the Wizard's default navigation. */
|
|
41
|
+
export interface DefaultWizardNavProps {
|
|
42
|
+
/** Flag indicating nav items with sub steps are expandable */
|
|
43
|
+
isExpandable?: boolean;
|
|
44
|
+
/** Aria-label for the Nav */
|
|
45
|
+
ariaLabel?: string;
|
|
46
|
+
/** Sets aria-labelledby on nav element */
|
|
47
|
+
ariaLabelledBy?: string;
|
|
48
|
+
/** Disable step nav items until they are visited */
|
|
49
|
+
forceStepVisit?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Used to customize aspects of the Wizard's default footer. */
|
|
53
|
+
export interface DefaultWizardFooterProps {
|
|
54
|
+
/** The Next button text */
|
|
55
|
+
nextButtonText?: React.ReactNode;
|
|
56
|
+
/** The Back button text */
|
|
57
|
+
backButtonText?: React.ReactNode;
|
|
58
|
+
/** The Cancel button text */
|
|
59
|
+
cancelButtonText?: React.ReactNode;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Encompasses all step type variants that are internally controlled by the Wizard. */
|
|
63
|
+
export type WizardControlStep = WizardBasicStep | WizardParentStep | WizardSubStep;
|
|
64
|
+
|
|
65
|
+
/** Callback for the Wizard's 'onNext', 'onBack', and 'onNavByIndex' properties. */
|
|
66
|
+
export type WizardNavStepFunction = (currentStep: WizardNavStepData, previousStep: WizardNavStepData) => void;
|
|
67
|
+
|
|
68
|
+
/** Data returned for either parameter of WizardNavStepFunction. */
|
|
69
|
+
export type WizardNavStepData = Pick<WizardControlStep, 'id' | 'name'>;
|
|
70
|
+
|
|
71
|
+
/** Callback for the Wizard's 'nav' property. Returns element which replaces the Wizard's default navigation. */
|
|
72
|
+
export type CustomWizardNavFunction = (
|
|
73
|
+
isOpen: boolean,
|
|
74
|
+
steps: WizardControlStep[],
|
|
75
|
+
activeStep: WizardControlStep,
|
|
76
|
+
goToStepByIndex: (index: number) => void
|
|
77
|
+
) => React.ReactElement<WizardNavProps>;
|
|
78
|
+
|
|
79
|
+
export function isCustomWizardNav(
|
|
80
|
+
nav: DefaultWizardNavProps | CustomWizardNavFunction
|
|
81
|
+
): nav is CustomWizardNavFunction {
|
|
82
|
+
return typeof nav === 'function';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function isCustomWizardFooter(
|
|
86
|
+
footer: DefaultWizardFooterProps | React.ReactElement
|
|
87
|
+
): footer is React.ReactElement {
|
|
88
|
+
return React.isValidElement(footer);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function isWizardBasicStep(step: WizardControlStep): step is WizardBasicStep {
|
|
92
|
+
return (step as WizardParentStep)?.subStepIds === undefined && !isWizardSubStep(step);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function isWizardSubStep(step: WizardControlStep): step is WizardSubStep {
|
|
96
|
+
return (step as WizardSubStep)?.parentId !== undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function isWizardParentStep(step: WizardControlStep): step is WizardParentStep {
|
|
100
|
+
return (step as WizardParentStep)?.subStepIds !== undefined;
|
|
101
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { WizardControlStep, WizardNavStepData } from './types';
|
|
4
|
+
import { WizardStep, WizardStepProps } from './WizardStep';
|
|
5
|
+
|
|
6
|
+
function hasWizardStepProps(props: WizardStepProps | any): props is WizardStepProps {
|
|
7
|
+
return props.name !== undefined && props.id !== undefined && props.children !== undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Accumulate list of step & sub-step props pulled from child components
|
|
12
|
+
* @param children
|
|
13
|
+
* @returns WizardControlStep[]
|
|
14
|
+
*/
|
|
15
|
+
export const buildSteps = (children: React.ReactElement<WizardStepProps> | React.ReactElement<WizardStepProps>[]) =>
|
|
16
|
+
React.Children.toArray(children).reduce((acc: WizardControlStep[], child) => {
|
|
17
|
+
if (React.isValidElement(child)) {
|
|
18
|
+
if (child.type === WizardStep || hasWizardStepProps(child.props)) {
|
|
19
|
+
// Omit "children" and use the whole "child" (WizardStep) for the component prop. Sub-steps will do the same.
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
21
|
+
const { steps: subSteps, id, children, ...stepProps } = child.props as WizardStepProps;
|
|
22
|
+
|
|
23
|
+
acc.push({
|
|
24
|
+
id,
|
|
25
|
+
component: child,
|
|
26
|
+
...stepProps,
|
|
27
|
+
...(subSteps && {
|
|
28
|
+
subStepIds: subSteps?.map(subStep => {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
30
|
+
const { children, ...subStepProps } = subStep.props;
|
|
31
|
+
acc.push({ ...subStepProps, component: subStep, parentId: id });
|
|
32
|
+
|
|
33
|
+
return subStep.props.id;
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
} else {
|
|
38
|
+
throw new Error('Wizard only accepts children of type WizardStep');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return acc;
|
|
43
|
+
}, []);
|
|
44
|
+
|
|
45
|
+
export const normalizeNavStep = ({ id, name }: WizardNavStepData) => ({ id, name });
|
|
46
|
+
export const getActiveStep = (steps: WizardControlStep[], currentStepIndex: number) =>
|
|
47
|
+
steps.find((_, index) => index + 1 === currentStepIndex);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './';
|
|
1
|
+
export * from './Wizard';
|