@patternfly/react-core 4.234.4 → 4.235.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 (145) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/esm/next/components/Wizard/Wizard.d.ts +40 -0
  3. package/dist/esm/next/components/Wizard/Wizard.d.ts.map +1 -0
  4. package/dist/esm/next/components/Wizard/Wizard.js +86 -0
  5. package/dist/esm/next/components/Wizard/Wizard.js.map +1 -0
  6. package/dist/esm/next/components/Wizard/WizardBody.d.ts +20 -0
  7. package/dist/esm/next/components/Wizard/WizardBody.d.ts.map +1 -0
  8. package/dist/esm/next/components/Wizard/WizardBody.js +7 -0
  9. package/dist/esm/next/components/Wizard/WizardBody.js.map +1 -0
  10. package/dist/esm/next/components/Wizard/WizardContext.d.ts +49 -0
  11. package/dist/esm/next/components/Wizard/WizardContext.d.ts.map +1 -0
  12. package/dist/esm/next/components/Wizard/WizardContext.js +34 -0
  13. package/dist/esm/next/components/Wizard/WizardContext.js.map +1 -0
  14. package/dist/esm/next/components/Wizard/WizardFooter.d.ts +28 -0
  15. package/dist/esm/next/components/Wizard/WizardFooter.d.ts.map +1 -0
  16. package/dist/esm/next/components/Wizard/WizardFooter.js +11 -0
  17. package/dist/esm/next/components/Wizard/WizardFooter.js.map +1 -0
  18. package/dist/esm/next/components/Wizard/WizardHeader.d.ts +21 -0
  19. package/dist/esm/next/components/Wizard/WizardHeader.d.ts.map +1 -0
  20. package/dist/esm/next/components/Wizard/WizardHeader.js +13 -0
  21. package/dist/esm/next/components/Wizard/WizardHeader.js.map +1 -0
  22. package/dist/esm/next/components/Wizard/WizardNav.d.ts +15 -0
  23. package/dist/esm/next/components/Wizard/WizardNav.d.ts.map +1 -0
  24. package/dist/esm/next/components/Wizard/WizardNav.js +13 -0
  25. package/dist/esm/next/components/Wizard/WizardNav.js.map +1 -0
  26. package/dist/esm/next/components/Wizard/WizardNavItem.d.ts +25 -0
  27. package/dist/esm/next/components/Wizard/WizardNavItem.d.ts.map +1 -0
  28. package/dist/esm/next/components/Wizard/WizardNavItem.js +33 -0
  29. package/dist/esm/next/components/Wizard/WizardNavItem.js.map +1 -0
  30. package/dist/esm/next/components/Wizard/WizardStep.d.ts +20 -0
  31. package/dist/esm/next/components/Wizard/WizardStep.d.ts.map +1 -0
  32. package/dist/esm/next/components/Wizard/WizardStep.js +5 -0
  33. package/dist/esm/next/components/Wizard/WizardStep.js.map +1 -0
  34. package/dist/esm/next/components/Wizard/WizardToggle.d.ts +26 -0
  35. package/dist/esm/next/components/Wizard/WizardToggle.d.ts.map +1 -0
  36. package/dist/esm/next/components/Wizard/WizardToggle.js +81 -0
  37. package/dist/esm/next/components/Wizard/WizardToggle.js.map +1 -0
  38. package/dist/esm/next/components/Wizard/hooks/index.d.ts +2 -0
  39. package/dist/esm/next/components/Wizard/hooks/index.d.ts.map +1 -0
  40. package/dist/esm/next/components/Wizard/hooks/index.js +2 -0
  41. package/dist/esm/next/components/Wizard/hooks/index.js.map +1 -0
  42. package/dist/esm/next/components/Wizard/hooks/useWizardFooter.d.ts +8 -0
  43. package/dist/esm/next/components/Wizard/hooks/useWizardFooter.d.ts.map +1 -0
  44. package/dist/esm/next/components/Wizard/hooks/useWizardFooter.js +20 -0
  45. package/dist/esm/next/components/Wizard/hooks/useWizardFooter.js.map +1 -0
  46. package/dist/esm/next/components/Wizard/index.d.ts +12 -0
  47. package/dist/esm/next/components/Wizard/index.d.ts.map +1 -0
  48. package/dist/esm/next/components/Wizard/index.js +12 -0
  49. package/dist/esm/next/components/Wizard/index.js.map +1 -0
  50. package/dist/esm/next/components/Wizard/types.d.ts +69 -0
  51. package/dist/esm/next/components/Wizard/types.d.ts.map +1 -0
  52. package/dist/esm/next/components/Wizard/types.js +20 -0
  53. package/dist/esm/next/components/Wizard/types.js.map +1 -0
  54. package/dist/esm/next/components/Wizard/utils.d.ts +15 -0
  55. package/dist/esm/next/components/Wizard/utils.d.ts.map +1 -0
  56. package/dist/esm/next/components/Wizard/utils.js +35 -0
  57. package/dist/esm/next/components/Wizard/utils.js.map +1 -0
  58. package/dist/esm/next/components/index.d.ts +1 -1
  59. package/dist/esm/next/components/index.d.ts.map +1 -1
  60. package/dist/esm/next/components/index.js +1 -1
  61. package/dist/esm/next/components/index.js.map +1 -1
  62. package/dist/js/next/components/Wizard/Wizard.d.ts +40 -0
  63. package/dist/js/next/components/Wizard/Wizard.d.ts.map +1 -0
  64. package/dist/js/next/components/Wizard/Wizard.js +90 -0
  65. package/dist/js/next/components/Wizard/Wizard.js.map +1 -0
  66. package/dist/js/next/components/Wizard/WizardBody.d.ts +20 -0
  67. package/dist/js/next/components/Wizard/WizardBody.d.ts.map +1 -0
  68. package/dist/js/next/components/Wizard/WizardBody.js +12 -0
  69. package/dist/js/next/components/Wizard/WizardBody.js.map +1 -0
  70. package/dist/js/next/components/Wizard/WizardContext.d.ts +49 -0
  71. package/dist/js/next/components/Wizard/WizardContext.d.ts.map +1 -0
  72. package/dist/js/next/components/Wizard/WizardContext.js +40 -0
  73. package/dist/js/next/components/Wizard/WizardContext.js.map +1 -0
  74. package/dist/js/next/components/Wizard/WizardFooter.d.ts +28 -0
  75. package/dist/js/next/components/Wizard/WizardFooter.d.ts.map +1 -0
  76. package/dist/js/next/components/Wizard/WizardFooter.js +16 -0
  77. package/dist/js/next/components/Wizard/WizardFooter.js.map +1 -0
  78. package/dist/js/next/components/Wizard/WizardHeader.d.ts +21 -0
  79. package/dist/js/next/components/Wizard/WizardHeader.d.ts.map +1 -0
  80. package/dist/js/next/components/Wizard/WizardHeader.js +18 -0
  81. package/dist/js/next/components/Wizard/WizardHeader.js.map +1 -0
  82. package/dist/js/next/components/Wizard/WizardNav.d.ts +15 -0
  83. package/dist/js/next/components/Wizard/WizardNav.d.ts.map +1 -0
  84. package/dist/js/next/components/Wizard/WizardNav.js +18 -0
  85. package/dist/js/next/components/Wizard/WizardNav.js.map +1 -0
  86. package/dist/js/next/components/Wizard/WizardNavItem.d.ts +25 -0
  87. package/dist/js/next/components/Wizard/WizardNavItem.d.ts.map +1 -0
  88. package/dist/js/next/components/Wizard/WizardNavItem.js +37 -0
  89. package/dist/js/next/components/Wizard/WizardNavItem.js.map +1 -0
  90. package/dist/js/next/components/Wizard/WizardStep.d.ts +20 -0
  91. package/dist/js/next/components/Wizard/WizardStep.d.ts.map +1 -0
  92. package/dist/js/next/components/Wizard/WizardStep.js +10 -0
  93. package/dist/js/next/components/Wizard/WizardStep.js.map +1 -0
  94. package/dist/js/next/components/Wizard/WizardToggle.d.ts +26 -0
  95. package/dist/js/next/components/Wizard/WizardToggle.d.ts.map +1 -0
  96. package/dist/js/next/components/Wizard/WizardToggle.js +86 -0
  97. package/dist/js/next/components/Wizard/WizardToggle.js.map +1 -0
  98. package/dist/js/next/components/Wizard/hooks/index.d.ts +2 -0
  99. package/dist/js/next/components/Wizard/hooks/index.d.ts.map +1 -0
  100. package/dist/js/next/components/Wizard/hooks/index.js +6 -0
  101. package/dist/js/next/components/Wizard/hooks/index.js.map +1 -0
  102. package/dist/js/next/components/Wizard/hooks/useWizardFooter.d.ts +8 -0
  103. package/dist/js/next/components/Wizard/hooks/useWizardFooter.d.ts.map +1 -0
  104. package/dist/js/next/components/Wizard/hooks/useWizardFooter.js +25 -0
  105. package/dist/js/next/components/Wizard/hooks/useWizardFooter.js.map +1 -0
  106. package/dist/js/next/components/Wizard/index.d.ts +12 -0
  107. package/dist/js/next/components/Wizard/index.d.ts.map +1 -0
  108. package/dist/js/next/components/Wizard/index.js +17 -0
  109. package/dist/js/next/components/Wizard/index.js.map +1 -0
  110. package/dist/js/next/components/Wizard/types.d.ts +69 -0
  111. package/dist/js/next/components/Wizard/types.d.ts.map +1 -0
  112. package/dist/js/next/components/Wizard/types.js +29 -0
  113. package/dist/js/next/components/Wizard/types.js.map +1 -0
  114. package/dist/js/next/components/Wizard/utils.d.ts +15 -0
  115. package/dist/js/next/components/Wizard/utils.d.ts.map +1 -0
  116. package/dist/js/next/components/Wizard/utils.js +41 -0
  117. package/dist/js/next/components/Wizard/utils.js.map +1 -0
  118. package/dist/js/next/components/index.d.ts +1 -1
  119. package/dist/js/next/components/index.d.ts.map +1 -1
  120. package/dist/js/next/components/index.js +1 -1
  121. package/dist/js/next/components/index.js.map +1 -1
  122. package/dist/umd/react-core.css +1055 -1055
  123. package/dist/umd/react-core.min.css +70 -70
  124. package/package.json +5 -5
  125. package/src/components/Wizard/examples/Wizard.md +21 -4
  126. package/src/next/components/Wizard/Wizard.tsx +184 -0
  127. package/src/next/components/Wizard/WizardBody.tsx +34 -0
  128. package/src/next/components/Wizard/WizardContext.tsx +104 -0
  129. package/src/next/components/Wizard/WizardFooter.tsx +63 -0
  130. package/src/next/components/Wizard/WizardHeader.tsx +53 -0
  131. package/src/next/components/Wizard/WizardNav.tsx +41 -0
  132. package/src/next/components/Wizard/WizardNavItem.tsx +103 -0
  133. package/src/next/components/Wizard/WizardStep.tsx +23 -0
  134. package/src/next/components/Wizard/WizardToggle.tsx +209 -0
  135. package/src/next/components/Wizard/__tests__/Wizard.test.tsx +298 -0
  136. package/src/next/components/Wizard/examples/Wizard.md +125 -0
  137. package/src/next/components/Wizard/examples/WizardBasic.tsx +22 -0
  138. package/src/next/components/Wizard/examples/WizardCustomNav.tsx +46 -0
  139. package/src/next/components/Wizard/examples/WizardKitchenSink.tsx +170 -0
  140. package/src/next/components/Wizard/hooks/index.ts +1 -0
  141. package/src/next/components/Wizard/hooks/useWizardFooter.tsx +22 -0
  142. package/src/next/components/Wizard/index.ts +11 -0
  143. package/src/next/components/Wizard/types.tsx +101 -0
  144. package/src/next/components/Wizard/utils.ts +47 -0
  145. package/src/next/components/index.ts +1 -1
@@ -0,0 +1,125 @@
1
+ ---
2
+ id: Wizard
3
+ section: components
4
+ cssPrefix: pf-c-wizard
5
+ propComponents:
6
+ [
7
+ 'Wizard',
8
+ 'WizardFooter',
9
+ 'WizardToggle',
10
+ 'WizardStep',
11
+ 'WizardBody',
12
+ 'WizardHeader',
13
+ 'WizardNav',
14
+ 'WizardNavItem',
15
+ 'WizardContextProps',
16
+ 'WizardBasicStep',
17
+ 'WizardParentStep',
18
+ 'WizardSubStep',
19
+ 'DefaultWizardNavProps',
20
+ 'DefaultWizardFooterProps',
21
+ ]
22
+ beta: true
23
+ ---
24
+
25
+ import {
26
+ FormGroup,
27
+ TextInput,
28
+ Drawer,
29
+ DrawerContent,
30
+ Button,
31
+ Flex,
32
+ DrawerPanelContent,
33
+ DrawerColorVariant,
34
+ DrawerHead,
35
+ DrawerActions,
36
+ DrawerCloseButton
37
+ } from '@patternfly/react-core';
38
+ import {
39
+ Wizard,
40
+ WizardFooter,
41
+ WizardToggle,
42
+ WizardStep,
43
+ WizardBody,
44
+ useWizardFooter,
45
+ useWizardContext,
46
+ WizardNavItem,
47
+ WizardNav,
48
+ WizardHeader
49
+ } from '@patternfly/react-core/next';
50
+ import { css } from '@patternfly/react-styles';
51
+ import styles from '@patternfly/react-styles/css/components/Wizard/wizard';
52
+
53
+ PatternFly has two implementations of a `Wizard`. This newer `Wizard` takes a more explicit and declarative approach compared to the older implementation, which can be found under the [React](/components/wizard/react) tab.
54
+
55
+ ## Examples
56
+
57
+ ### Basic
58
+
59
+ ```ts file="./WizardBasic.tsx"
60
+ ```
61
+
62
+ ### Custom navigation
63
+
64
+ The `Wizard`'s `nav` property can be used to build your own navigation.
65
+
66
+ ```
67
+ /** Callback for the Wizard's 'nav' property. Returns element which replaces the Wizard's default navigation. */
68
+ export type CustomWizardNavFunction = (
69
+ isOpen: boolean,
70
+ steps: WizardControlStep[],
71
+ activeStep: WizardControlStep,
72
+ goToStepByIndex: (index: number) => void
73
+ ) => React.ReactElement<WizardNavProps>;
74
+
75
+ /** Encompasses all step type variants that are internally controlled by the Wizard */
76
+ type WizardControlStep = WizardBasicStep | WizardParentStep | WizardSubStep;
77
+ ```
78
+
79
+ ```ts file="./WizardCustomNav.tsx"
80
+ ```
81
+
82
+ ### Kitchen sink
83
+
84
+ Includes a header, custom footer, sub-steps, step content with a drawer, custom nav item, and nav prevention until step visitation.
85
+
86
+ Custom operations when navigating between steps can be achieved by utilizing `onNext`, `onBack` or `onNavByIndex` properties whose callback functions return the 'id' and 'name' of the currently focused step (currentStep), and the previously focused step (previousStep).
87
+
88
+ ```
89
+ /** Callback for the Wizard's 'onNext', 'onBack', and 'onNavByIndex' properties */
90
+ type WizardNavStepFunction = (currentStep: WizardNavStepData, previousStep: WizardNavStepData) => void;
91
+
92
+ /** Data returned for either parameter of WizardNavStepFunction */
93
+ type WizardNavStepData = Pick<WizardControlStep, 'id' | 'name'>;
94
+ ```
95
+
96
+ ```ts file="./WizardKitchenSink.tsx"
97
+ ```
98
+
99
+ ## Hooks
100
+
101
+ ### useWizardFooter
102
+
103
+ Used to set a unique footer for the wizard on any given step. See step 3 of [Kitchen sink](#kitchen-sink) for a live example.
104
+
105
+ ```noLive
106
+ import { useWizardFooter } from '@patternfly/react-core/next';
107
+
108
+ const StepContent = () => {
109
+ useWizardFooter(<>Some footer</>);
110
+ return <>Step content</>;
111
+ }
112
+ ```
113
+
114
+ ### useWizardContext
115
+
116
+ Used to access any property of [WizardContext](#wizardcontextprops):
117
+
118
+ ```noLive
119
+ import { useWizardContext } from '@patternfly/react-core/next';
120
+
121
+ const StepContent = () => {
122
+ const { activeStep } = useWizardContext();
123
+ return <>This is the active step: {activeStep}</>;
124
+ }
125
+ ```
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { Wizard, WizardStep } from '@patternfly/react-core/next';
3
+
4
+ export const WizardBasic: React.FunctionComponent = () => (
5
+ <Wizard height={400}>
6
+ <WizardStep name="First step" id="basic-first-step">
7
+ <p>Step 1 content</p>
8
+ </WizardStep>
9
+ <WizardStep name="Second step" id="basic-second-step">
10
+ <p>Step 2 content</p>
11
+ </WizardStep>
12
+ <WizardStep name="Third step" id="basic-third-step">
13
+ <p>Step 3 content</p>
14
+ </WizardStep>
15
+ <WizardStep name="Fourth step" id="basic-fourth-step">
16
+ <p>Step 4 content</p>{' '}
17
+ </WizardStep>
18
+ <WizardStep name="Review" id="basic-review-step" nextButtonText="Finish">
19
+ <p>Review step content</p>
20
+ </WizardStep>
21
+ </Wizard>
22
+ );
@@ -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';