@patternfly/react-core 4.274.0 → 4.275.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/components/Menu/MenuGroup.d.ts +1 -1
  3. package/components/Menu/MenuGroup.d.ts.map +1 -1
  4. package/components/Menu/MenuGroup.js.map +1 -1
  5. package/components/Select/Select.d.ts +2 -0
  6. package/components/Select/Select.d.ts.map +1 -1
  7. package/components/Select/Select.js +3 -3
  8. package/components/Select/Select.js.map +1 -1
  9. package/components/Select/SelectToggle.d.ts +4 -14
  10. package/components/Select/SelectToggle.d.ts.map +1 -1
  11. package/components/Select/SelectToggle.js +11 -5
  12. package/components/Select/SelectToggle.js.map +1 -1
  13. package/dist/esm/components/Menu/MenuGroup.d.ts +1 -1
  14. package/dist/esm/components/Menu/MenuGroup.d.ts.map +1 -1
  15. package/dist/esm/components/Menu/MenuGroup.js.map +1 -1
  16. package/dist/esm/components/Select/Select.d.ts +2 -0
  17. package/dist/esm/components/Select/Select.d.ts.map +1 -1
  18. package/dist/esm/components/Select/Select.js +3 -3
  19. package/dist/esm/components/Select/Select.js.map +1 -1
  20. package/dist/esm/components/Select/SelectToggle.d.ts +4 -14
  21. package/dist/esm/components/Select/SelectToggle.d.ts.map +1 -1
  22. package/dist/esm/components/Select/SelectToggle.js +11 -5
  23. package/dist/esm/components/Select/SelectToggle.js.map +1 -1
  24. package/dist/esm/next/components/Wizard/Wizard.d.ts +11 -14
  25. package/dist/esm/next/components/Wizard/Wizard.d.ts.map +1 -1
  26. package/dist/esm/next/components/Wizard/Wizard.js +30 -23
  27. package/dist/esm/next/components/Wizard/Wizard.js.map +1 -1
  28. package/dist/esm/next/components/Wizard/WizardContext.d.ts +16 -16
  29. package/dist/esm/next/components/Wizard/WizardContext.d.ts.map +1 -1
  30. package/dist/esm/next/components/Wizard/WizardContext.js +17 -19
  31. package/dist/esm/next/components/Wizard/WizardContext.js.map +1 -1
  32. package/dist/esm/next/components/Wizard/WizardFooter.d.ts +8 -5
  33. package/dist/esm/next/components/Wizard/WizardFooter.d.ts.map +1 -1
  34. package/dist/esm/next/components/Wizard/WizardFooter.js +1 -1
  35. package/dist/esm/next/components/Wizard/WizardFooter.js.map +1 -1
  36. package/dist/esm/next/components/Wizard/WizardHeader.d.ts +1 -1
  37. package/dist/esm/next/components/Wizard/WizardHeader.d.ts.map +1 -1
  38. package/dist/esm/next/components/Wizard/WizardNavInternal.d.ts +2 -2
  39. package/dist/esm/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
  40. package/dist/esm/next/components/Wizard/WizardNavInternal.js +15 -9
  41. package/dist/esm/next/components/Wizard/WizardNavInternal.js.map +1 -1
  42. package/dist/esm/next/components/Wizard/WizardNavItem.d.ts +10 -4
  43. package/dist/esm/next/components/Wizard/WizardNavItem.d.ts.map +1 -1
  44. package/dist/esm/next/components/Wizard/WizardNavItem.js +10 -9
  45. package/dist/esm/next/components/Wizard/WizardNavItem.js.map +1 -1
  46. package/dist/esm/next/components/Wizard/WizardStep.d.ts +3 -3
  47. package/dist/esm/next/components/Wizard/WizardStep.d.ts.map +1 -1
  48. package/dist/esm/next/components/Wizard/WizardStep.js +4 -2
  49. package/dist/esm/next/components/Wizard/WizardStep.js.map +1 -1
  50. package/dist/esm/next/components/Wizard/WizardToggle.d.ts +4 -4
  51. package/dist/esm/next/components/Wizard/WizardToggle.d.ts.map +1 -1
  52. package/dist/esm/next/components/Wizard/WizardToggle.js +1 -1
  53. package/dist/esm/next/components/Wizard/WizardToggle.js.map +1 -1
  54. package/dist/esm/next/components/Wizard/hooks/index.d.ts +1 -0
  55. package/dist/esm/next/components/Wizard/hooks/index.d.ts.map +1 -1
  56. package/dist/esm/next/components/Wizard/hooks/index.js +1 -0
  57. package/dist/esm/next/components/Wizard/hooks/index.js.map +1 -1
  58. package/dist/esm/next/components/Wizard/hooks/useGetMergedSteps.d.ts +9 -0
  59. package/dist/esm/next/components/Wizard/hooks/useGetMergedSteps.d.ts.map +1 -0
  60. package/dist/esm/next/components/Wizard/hooks/useGetMergedSteps.js +33 -0
  61. package/dist/esm/next/components/Wizard/hooks/useGetMergedSteps.js.map +1 -0
  62. package/dist/esm/next/components/Wizard/index.d.ts +2 -2
  63. package/dist/esm/next/components/Wizard/index.d.ts.map +1 -1
  64. package/dist/esm/next/components/Wizard/index.js +2 -2
  65. package/dist/esm/next/components/Wizard/index.js.map +1 -1
  66. package/dist/esm/next/components/Wizard/types.d.ts +13 -19
  67. package/dist/esm/next/components/Wizard/types.d.ts.map +1 -1
  68. package/dist/esm/next/components/Wizard/types.js +6 -0
  69. package/dist/esm/next/components/Wizard/types.js.map +1 -1
  70. package/dist/esm/next/components/Wizard/utils.d.ts +5 -6
  71. package/dist/esm/next/components/Wizard/utils.d.ts.map +1 -1
  72. package/dist/esm/next/components/Wizard/utils.js +15 -22
  73. package/dist/esm/next/components/Wizard/utils.js.map +1 -1
  74. package/dist/js/components/Menu/MenuGroup.d.ts +1 -1
  75. package/dist/js/components/Menu/MenuGroup.d.ts.map +1 -1
  76. package/dist/js/components/Menu/MenuGroup.js.map +1 -1
  77. package/dist/js/components/Select/Select.d.ts +2 -0
  78. package/dist/js/components/Select/Select.d.ts.map +1 -1
  79. package/dist/js/components/Select/Select.js +3 -3
  80. package/dist/js/components/Select/Select.js.map +1 -1
  81. package/dist/js/components/Select/SelectToggle.d.ts +4 -14
  82. package/dist/js/components/Select/SelectToggle.d.ts.map +1 -1
  83. package/dist/js/components/Select/SelectToggle.js +11 -6
  84. package/dist/js/components/Select/SelectToggle.js.map +1 -1
  85. package/dist/js/next/components/Wizard/Wizard.d.ts +11 -14
  86. package/dist/js/next/components/Wizard/Wizard.d.ts.map +1 -1
  87. package/dist/js/next/components/Wizard/Wizard.js +28 -21
  88. package/dist/js/next/components/Wizard/Wizard.js.map +1 -1
  89. package/dist/js/next/components/Wizard/WizardContext.d.ts +16 -16
  90. package/dist/js/next/components/Wizard/WizardContext.d.ts.map +1 -1
  91. package/dist/js/next/components/Wizard/WizardContext.js +16 -17
  92. package/dist/js/next/components/Wizard/WizardContext.js.map +1 -1
  93. package/dist/js/next/components/Wizard/WizardFooter.d.ts +8 -5
  94. package/dist/js/next/components/Wizard/WizardFooter.d.ts.map +1 -1
  95. package/dist/js/next/components/Wizard/WizardFooter.js +1 -1
  96. package/dist/js/next/components/Wizard/WizardFooter.js.map +1 -1
  97. package/dist/js/next/components/Wizard/WizardHeader.d.ts +1 -1
  98. package/dist/js/next/components/Wizard/WizardHeader.d.ts.map +1 -1
  99. package/dist/js/next/components/Wizard/WizardNavInternal.d.ts +2 -2
  100. package/dist/js/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
  101. package/dist/js/next/components/Wizard/WizardNavInternal.js +15 -9
  102. package/dist/js/next/components/Wizard/WizardNavInternal.js.map +1 -1
  103. package/dist/js/next/components/Wizard/WizardNavItem.d.ts +10 -4
  104. package/dist/js/next/components/Wizard/WizardNavItem.d.ts.map +1 -1
  105. package/dist/js/next/components/Wizard/WizardNavItem.js +10 -8
  106. package/dist/js/next/components/Wizard/WizardNavItem.js.map +1 -1
  107. package/dist/js/next/components/Wizard/WizardStep.d.ts +3 -3
  108. package/dist/js/next/components/Wizard/WizardStep.d.ts.map +1 -1
  109. package/dist/js/next/components/Wizard/WizardStep.js +4 -2
  110. package/dist/js/next/components/Wizard/WizardStep.js.map +1 -1
  111. package/dist/js/next/components/Wizard/WizardToggle.d.ts +4 -4
  112. package/dist/js/next/components/Wizard/WizardToggle.d.ts.map +1 -1
  113. package/dist/js/next/components/Wizard/WizardToggle.js +1 -1
  114. package/dist/js/next/components/Wizard/WizardToggle.js.map +1 -1
  115. package/dist/js/next/components/Wizard/hooks/index.d.ts +1 -0
  116. package/dist/js/next/components/Wizard/hooks/index.d.ts.map +1 -1
  117. package/dist/js/next/components/Wizard/hooks/index.js +3 -1
  118. package/dist/js/next/components/Wizard/hooks/index.js.map +1 -1
  119. package/dist/js/next/components/Wizard/hooks/useGetMergedSteps.d.ts +9 -0
  120. package/dist/js/next/components/Wizard/hooks/useGetMergedSteps.d.ts.map +1 -0
  121. package/dist/js/next/components/Wizard/hooks/useGetMergedSteps.js +38 -0
  122. package/dist/js/next/components/Wizard/hooks/useGetMergedSteps.js.map +1 -0
  123. package/dist/js/next/components/Wizard/index.d.ts +2 -2
  124. package/dist/js/next/components/Wizard/index.d.ts.map +1 -1
  125. package/dist/js/next/components/Wizard/index.js +4 -2
  126. package/dist/js/next/components/Wizard/index.js.map +1 -1
  127. package/dist/js/next/components/Wizard/types.d.ts +13 -19
  128. package/dist/js/next/components/Wizard/types.d.ts.map +1 -1
  129. package/dist/js/next/components/Wizard/types.js +7 -1
  130. package/dist/js/next/components/Wizard/types.js.map +1 -1
  131. package/dist/js/next/components/Wizard/utils.d.ts +5 -6
  132. package/dist/js/next/components/Wizard/utils.d.ts.map +1 -1
  133. package/dist/js/next/components/Wizard/utils.js +17 -25
  134. package/dist/js/next/components/Wizard/utils.js.map +1 -1
  135. package/dist/umd/react-core.min.js +2 -2
  136. package/next/components/Wizard/Wizard.d.ts +11 -14
  137. package/next/components/Wizard/Wizard.d.ts.map +1 -1
  138. package/next/components/Wizard/Wizard.js +30 -23
  139. package/next/components/Wizard/Wizard.js.map +1 -1
  140. package/next/components/Wizard/WizardContext.d.ts +16 -16
  141. package/next/components/Wizard/WizardContext.d.ts.map +1 -1
  142. package/next/components/Wizard/WizardContext.js +17 -19
  143. package/next/components/Wizard/WizardContext.js.map +1 -1
  144. package/next/components/Wizard/WizardFooter.d.ts +8 -5
  145. package/next/components/Wizard/WizardFooter.d.ts.map +1 -1
  146. package/next/components/Wizard/WizardFooter.js +1 -1
  147. package/next/components/Wizard/WizardFooter.js.map +1 -1
  148. package/next/components/Wizard/WizardHeader.d.ts +1 -1
  149. package/next/components/Wizard/WizardHeader.d.ts.map +1 -1
  150. package/next/components/Wizard/WizardNavInternal.d.ts +2 -2
  151. package/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
  152. package/next/components/Wizard/WizardNavInternal.js +15 -9
  153. package/next/components/Wizard/WizardNavInternal.js.map +1 -1
  154. package/next/components/Wizard/WizardNavItem.d.ts +10 -4
  155. package/next/components/Wizard/WizardNavItem.d.ts.map +1 -1
  156. package/next/components/Wizard/WizardNavItem.js +10 -9
  157. package/next/components/Wizard/WizardNavItem.js.map +1 -1
  158. package/next/components/Wizard/WizardStep.d.ts +3 -3
  159. package/next/components/Wizard/WizardStep.d.ts.map +1 -1
  160. package/next/components/Wizard/WizardStep.js +4 -2
  161. package/next/components/Wizard/WizardStep.js.map +1 -1
  162. package/next/components/Wizard/WizardToggle.d.ts +4 -4
  163. package/next/components/Wizard/WizardToggle.d.ts.map +1 -1
  164. package/next/components/Wizard/WizardToggle.js +1 -1
  165. package/next/components/Wizard/WizardToggle.js.map +1 -1
  166. package/next/components/Wizard/hooks/index.d.ts +1 -0
  167. package/next/components/Wizard/hooks/index.d.ts.map +1 -1
  168. package/next/components/Wizard/hooks/index.js +1 -0
  169. package/next/components/Wizard/hooks/index.js.map +1 -1
  170. package/next/components/Wizard/hooks/useGetMergedSteps.d.ts +9 -0
  171. package/next/components/Wizard/hooks/useGetMergedSteps.d.ts.map +1 -0
  172. package/next/components/Wizard/hooks/useGetMergedSteps.js +33 -0
  173. package/next/components/Wizard/hooks/useGetMergedSteps.js.map +1 -0
  174. package/next/components/Wizard/index.d.ts +2 -2
  175. package/next/components/Wizard/index.d.ts.map +1 -1
  176. package/next/components/Wizard/index.js +2 -2
  177. package/next/components/Wizard/index.js.map +1 -1
  178. package/next/components/Wizard/types.d.ts +13 -19
  179. package/next/components/Wizard/types.d.ts.map +1 -1
  180. package/next/components/Wizard/types.js +6 -0
  181. package/next/components/Wizard/types.js.map +1 -1
  182. package/next/components/Wizard/utils.d.ts +5 -6
  183. package/next/components/Wizard/utils.d.ts.map +1 -1
  184. package/next/components/Wizard/utils.js +15 -22
  185. package/next/components/Wizard/utils.js.map +1 -1
  186. package/package.json +2 -2
  187. package/src/components/Menu/MenuGroup.tsx +2 -2
  188. package/src/components/Select/Select.tsx +4 -0
  189. package/src/components/Select/SelectToggle.tsx +14 -3
  190. package/src/components/Select/examples/Select.md +28 -0
  191. package/src/next/components/Wizard/Wizard.tsx +71 -46
  192. package/src/next/components/Wizard/WizardContext.tsx +38 -43
  193. package/src/next/components/Wizard/WizardFooter.tsx +10 -6
  194. package/src/next/components/Wizard/WizardHeader.tsx +1 -1
  195. package/src/next/components/Wizard/WizardNavInternal.tsx +51 -43
  196. package/src/next/components/Wizard/WizardNavItem.tsx +21 -14
  197. package/src/next/components/Wizard/WizardStep.tsx +8 -6
  198. package/src/next/components/Wizard/WizardToggle.tsx +5 -5
  199. package/src/next/components/Wizard/__tests__/Wizard.test.tsx +129 -26
  200. package/src/next/components/Wizard/__tests__/WizardStep.test.tsx +5 -5
  201. package/src/next/components/Wizard/__tests__/WizardToggle.test.tsx +2 -2
  202. package/src/next/components/Wizard/__tests__/utils.test.tsx +3 -17
  203. package/src/next/components/Wizard/examples/Wizard.md +69 -41
  204. package/src/next/components/Wizard/examples/WizardBasic.tsx +6 -12
  205. package/src/next/components/Wizard/examples/WizardBasicDisabledSteps.tsx +22 -0
  206. package/src/next/components/Wizard/examples/WizardEnabledOnFormValidation.tsx +84 -0
  207. package/src/next/components/Wizard/examples/WizardExpandableSteps.tsx +42 -0
  208. package/src/next/components/Wizard/examples/WizardGetCurrentStep.tsx +53 -0
  209. package/src/next/components/Wizard/examples/WizardProgressiveSteps.tsx +31 -0
  210. package/src/next/components/Wizard/examples/WizardStepDrawerContent.tsx +80 -0
  211. package/src/next/components/Wizard/examples/WizardStepErrorStatus.tsx +55 -0
  212. package/src/next/components/Wizard/examples/WizardStepVisitRequired.tsx +22 -0
  213. package/src/next/components/Wizard/examples/WizardToggleStepVisibility.tsx +57 -0
  214. package/src/next/components/Wizard/examples/WizardValidateOnButtonPress.tsx +183 -0
  215. package/src/next/components/Wizard/examples/WizardWithCustomFooter.tsx +107 -0
  216. package/src/next/components/Wizard/examples/{WizardCustomNav.tsx → WizardWithCustomNav.tsx} +11 -11
  217. package/src/next/components/Wizard/examples/WizardWithCustomNavItem.tsx +22 -0
  218. package/src/next/components/Wizard/examples/WizardWithHeader.tsx +26 -0
  219. package/src/next/components/Wizard/examples/WizardWithNavAnchors.tsx +46 -0
  220. package/src/next/components/Wizard/examples/WizardWithSubmitProgress.tsx +86 -0
  221. package/src/next/components/Wizard/examples/WizardWithinModal.tsx +41 -0
  222. package/src/next/components/Wizard/hooks/index.ts +1 -0
  223. package/src/next/components/Wizard/hooks/useGetMergedSteps.tsx +45 -0
  224. package/src/next/components/Wizard/index.ts +2 -2
  225. package/src/next/components/Wizard/types.tsx +19 -29
  226. package/src/next/components/Wizard/utils.ts +27 -33
  227. package/src/next/components/Wizard/examples/WizardKitchenSink.tsx +0 -243
@@ -0,0 +1,183 @@
1
+ import React from 'react';
2
+
3
+ import {
4
+ Button,
5
+ Alert,
6
+ EmptyState,
7
+ EmptyStateIcon,
8
+ Title,
9
+ EmptyStateBody,
10
+ Progress,
11
+ EmptyStateSecondaryActions,
12
+ Form,
13
+ FormGroup,
14
+ TextInput
15
+ } from '@patternfly/react-core';
16
+ import { Wizard, WizardStep, WizardFooterWrapper, useWizardContext } from '@patternfly/react-core/next';
17
+ import CogsIcon from '@patternfly/react-icons/dist/esm/icons/cogs-icon';
18
+
19
+ interface ValidationProgressProps {
20
+ onClose(): void;
21
+ }
22
+
23
+ const ValidationProgress: React.FunctionComponent<ValidationProgressProps> = ({ onClose }) => {
24
+ const [percentValidated, setPercentValidated] = React.useState(0);
25
+
26
+ const tick = React.useCallback(() => {
27
+ if (percentValidated < 100) {
28
+ setPercentValidated(prevValue => prevValue + 20);
29
+ }
30
+ }, [percentValidated]);
31
+
32
+ React.useEffect(() => {
33
+ const interval = setInterval(() => tick(), 1000);
34
+
35
+ return () => {
36
+ clearInterval(interval);
37
+ };
38
+ }, [tick]);
39
+
40
+ return (
41
+ <div className="pf-l-bullseye">
42
+ <EmptyState variant="large">
43
+ <EmptyStateIcon icon={CogsIcon} />
44
+ <Title headingLevel="h4" size="lg">
45
+ {percentValidated === 100 ? 'Validation complete' : 'Validating credentials'}
46
+ </Title>
47
+ <EmptyStateBody>
48
+ <Progress value={percentValidated} measureLocation="outside" aria-label="Wizard validation progress" />
49
+ </EmptyStateBody>
50
+ <EmptyStateBody>
51
+ Description can be used to further elaborate on the validation step, or give the user a better idea of how
52
+ long the process will take.
53
+ </EmptyStateBody>
54
+ <EmptyStateSecondaryActions>
55
+ <Button isDisabled={percentValidated !== 100} onClick={onClose}>
56
+ Log to console
57
+ </Button>
58
+ </EmptyStateSecondaryActions>
59
+ </EmptyState>
60
+ </div>
61
+ );
62
+ };
63
+
64
+ interface LastStepFooterProps {
65
+ isValid: boolean;
66
+ setIsSubmitted(isSubmitted: boolean): void;
67
+ setHasErrorOnSubmit(isSubmitted: boolean): void;
68
+ }
69
+
70
+ const LastStepFooter: React.FunctionComponent<LastStepFooterProps> = ({
71
+ isValid,
72
+ setIsSubmitted,
73
+ setHasErrorOnSubmit
74
+ }) => {
75
+ const { goToNextStep, goToPrevStep } = useWizardContext();
76
+
77
+ const onValidate = () => {
78
+ setIsSubmitted(true);
79
+
80
+ if (!isValid) {
81
+ setIsSubmitted(false);
82
+ setHasErrorOnSubmit(true);
83
+ } else {
84
+ goToNextStep();
85
+ }
86
+ };
87
+
88
+ return (
89
+ <WizardFooterWrapper>
90
+ <Button onClick={onValidate}>Validate</Button>
91
+ <Button variant="secondary" onClick={goToPrevStep}>
92
+ Back
93
+ </Button>
94
+ </WizardFooterWrapper>
95
+ );
96
+ };
97
+
98
+ interface SampleFormProps {
99
+ value: string;
100
+ isValid: boolean;
101
+ setValue: (value: string) => void;
102
+ setIsValid: (isValid: boolean) => void;
103
+ }
104
+
105
+ const SampleForm: React.FunctionComponent<SampleFormProps> = ({ value, isValid, setValue, setIsValid }) => {
106
+ const validated = isValid ? 'default' : 'error';
107
+
108
+ const handleTextInputChange = (value: string) => {
109
+ const isValid = /^\d+$/.test(value);
110
+
111
+ setValue(value);
112
+ setIsValid(isValid);
113
+ };
114
+
115
+ return (
116
+ <Form>
117
+ <FormGroup
118
+ label="Age:"
119
+ type="number"
120
+ helperText="Write your age in numbers."
121
+ helperTextInvalid="Age has to be a number"
122
+ fieldId="age"
123
+ validated={validated}
124
+ >
125
+ <TextInput
126
+ validated={validated}
127
+ value={value}
128
+ id="age"
129
+ aria-describedby="age-helper"
130
+ onChange={handleTextInputChange}
131
+ />
132
+ </FormGroup>
133
+ </Form>
134
+ );
135
+ };
136
+
137
+ export const WizardValidateOnButtonPress: React.FunctionComponent = () => {
138
+ const [ageValue, setAgeValue] = React.useState('Thirty');
139
+ const [isSubmitted, setIsSubmitted] = React.useState(false);
140
+ const [isFirstStepValid, setIsFirstStepValid] = React.useState(false);
141
+ const [hasErrorOnSubmit, setHasErrorOnSubmit] = React.useState(false);
142
+
143
+ // eslint-disable-next-line no-console
144
+ const onClose = () => console.log('Some close action occurs here.');
145
+
146
+ if (isSubmitted && isFirstStepValid) {
147
+ return <ValidationProgress onClose={onClose} />;
148
+ }
149
+
150
+ return (
151
+ <Wizard title="Validate on button press wizard" onClose={onClose} height={400}>
152
+ <WizardStep name="Step 1" id="validate-btn-step-1">
153
+ Step 1 content
154
+ </WizardStep>
155
+ <WizardStep name="Step 2" id="validate-btn-step-2">
156
+ Step 2 content
157
+ </WizardStep>
158
+ <WizardStep
159
+ name="Final Step"
160
+ id="validate-btn-finish-step"
161
+ footer={
162
+ <LastStepFooter
163
+ isValid={isFirstStepValid}
164
+ setIsSubmitted={setIsSubmitted}
165
+ setHasErrorOnSubmit={setHasErrorOnSubmit}
166
+ />
167
+ }
168
+ >
169
+ {hasErrorOnSubmit && (
170
+ <div style={{ padding: '15px 0' }}>
171
+ <Alert isInline variant="danger" title="Validation failed, please try again." />
172
+ </div>
173
+ )}
174
+ <SampleForm
175
+ value={ageValue}
176
+ setValue={value => setAgeValue(value)}
177
+ isValid={!hasErrorOnSubmit || isFirstStepValid}
178
+ setIsValid={setIsFirstStepValid}
179
+ />
180
+ </WizardStep>
181
+ </Wizard>
182
+ );
183
+ };
@@ -0,0 +1,107 @@
1
+ import React from 'react';
2
+
3
+ import { Button, Flex, FlexItem, Spinner } from '@patternfly/react-core';
4
+ import { useWizardContext, Wizard, WizardFooter, WizardFooterWrapper, WizardStep } from '@patternfly/react-core/next';
5
+
6
+ const CustomWizardFooter = () => {
7
+ const { activeStep, goToNextStep, goToPrevStep, close } = useWizardContext();
8
+
9
+ return (
10
+ <WizardFooter
11
+ activeStep={activeStep}
12
+ onNext={goToNextStep}
13
+ onBack={goToPrevStep}
14
+ onClose={close}
15
+ isBackDisabled={activeStep.index === 1}
16
+ />
17
+ );
18
+ };
19
+
20
+ const CustomStepTwoFooter = () => {
21
+ const { goToNextStep, goToPrevStep, close } = useWizardContext();
22
+ const [isLoading, setIsLoading] = React.useState(false);
23
+
24
+ async function onNext() {
25
+ setIsLoading(true);
26
+ await new Promise(resolve => setTimeout(resolve, 2000));
27
+ setIsLoading(false);
28
+
29
+ goToNextStep();
30
+ }
31
+
32
+ return (
33
+ <WizardFooterWrapper>
34
+ <Button variant="primary" onClick={onNext} isLoading={isLoading} isDisabled={isLoading}>
35
+ Async Next
36
+ </Button>
37
+ <Button variant="secondary" onClick={goToPrevStep} isDisabled={isLoading}>
38
+ Back
39
+ </Button>
40
+ <Button variant="link" onClick={close} isDisabled={isLoading}>
41
+ Cancel
42
+ </Button>
43
+ </WizardFooterWrapper>
44
+ );
45
+ };
46
+
47
+ interface ReviewStepContentProps {
48
+ isSubmitting: boolean | undefined;
49
+ }
50
+
51
+ const ReviewStepContent: React.FunctionComponent<ReviewStepContentProps> = ({ isSubmitting }) => {
52
+ if (isSubmitting === undefined) {
53
+ return <FlexItem alignSelf={{ default: 'alignSelfFlexStart' }}>Review step content</FlexItem>;
54
+ }
55
+
56
+ if (isSubmitting) {
57
+ return (
58
+ <>
59
+ <div>Calculating wizard score...</div>
60
+ <Spinner />
61
+ </>
62
+ );
63
+ }
64
+
65
+ return <>50 points to Gryffindor!</>;
66
+ };
67
+
68
+ export const WizardWithCustomFooter: React.FunctionComponent = () => {
69
+ const [isSubmitting, setIsSubmitting] = React.useState<boolean>();
70
+
71
+ async function onSubmit(): Promise<void> {
72
+ setIsSubmitting(true);
73
+
74
+ await new Promise(resolve => setTimeout(resolve, 5000));
75
+
76
+ setIsSubmitting(false);
77
+ }
78
+
79
+ return (
80
+ <Wizard height={400} title="Custom footer wizard" footer={<CustomWizardFooter />}>
81
+ <WizardStep name="Step 1" id="custom-footer-first-step">
82
+ Step 1 content
83
+ </WizardStep>
84
+ <WizardStep id="custom-footer-second-step" name="Step 2" footer={<CustomStepTwoFooter />}>
85
+ Step 2 content with a custom async footer
86
+ </WizardStep>
87
+ <WizardStep
88
+ id="custom-footer-review-step"
89
+ name="Review"
90
+ footer={{
91
+ nextButtonText: 'Submit',
92
+ onNext: onSubmit,
93
+ isNextDisabled: isSubmitting,
94
+ isBackDisabled: isSubmitting
95
+ }}
96
+ >
97
+ <Flex
98
+ direction={{ default: 'column' }}
99
+ alignItems={{ default: 'alignItemsCenter' }}
100
+ spaceItems={{ default: 'spaceItemsLg' }}
101
+ >
102
+ <ReviewStepContent isSubmitting={isSubmitting} />
103
+ </Flex>
104
+ </WizardStep>
105
+ </Wizard>
106
+ );
107
+ };
@@ -2,17 +2,17 @@ import React from 'react';
2
2
  import {
3
3
  Wizard,
4
4
  WizardStep,
5
- WizardControlStep,
5
+ WizardStepType,
6
6
  CustomWizardNavFunction,
7
7
  WizardNav,
8
8
  WizardNavItem
9
9
  } from '@patternfly/react-core/next';
10
10
 
11
- export const WizardCustomNav: React.FunctionComponent = () => {
11
+ export const WizardWithCustomNav: React.FunctionComponent = () => {
12
12
  const nav: CustomWizardNavFunction = (
13
13
  isExpanded: boolean,
14
- steps: WizardControlStep[],
15
- activeStep: WizardControlStep,
14
+ steps: WizardStepType[],
15
+ activeStep: WizardStepType,
16
16
  goToStepByIndex: (index: number) => void
17
17
  ) => (
18
18
  <WizardNav isExpanded={isExpanded}>
@@ -24,7 +24,7 @@ export const WizardCustomNav: React.FunctionComponent = () => {
24
24
  isCurrent={activeStep.id === step.id}
25
25
  isDisabled={step.isDisabled}
26
26
  stepIndex={step.index}
27
- onNavItemClick={goToStepByIndex}
27
+ onClick={() => goToStepByIndex(step.index)}
28
28
  />
29
29
  ))}
30
30
  </WizardNav>
@@ -32,14 +32,14 @@ export const WizardCustomNav: React.FunctionComponent = () => {
32
32
 
33
33
  return (
34
34
  <Wizard height={400} nav={nav}>
35
- <WizardStep name="First step" id="cnav-first-step">
36
- <p>Did you say...custom nav?</p>
35
+ <WizardStep name="Step 1" id="custom-nav-first-step">
36
+ Did you say...custom nav?
37
37
  </WizardStep>
38
- <WizardStep name="Second step" id="cnav-second-step">
39
- <p>Step 2 content</p>
38
+ <WizardStep name="Step 2" id="custom-nav-second-step">
39
+ Oh, you didn't?
40
40
  </WizardStep>
41
- <WizardStep name="Review" id="cnav-review-step" footer={{ nextButtonText: 'Wrap it up' }}>
42
- <p>Review step content</p>
41
+ <WizardStep name="Review" id="custom-nav-review-step" footer={{ nextButtonText: 'Wrap it up' }}>
42
+ Well, this is awkward.
43
43
  </WizardStep>
44
44
  </Wizard>
45
45
  );
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { Wizard, WizardStep } from '@patternfly/react-core/next';
3
+
4
+ export const WizardWithCustomNavItem: React.FunctionComponent = () => (
5
+ <Wizard height={400} title="Custom navigation item wizard">
6
+ <WizardStep name="Step 1" id="custom-nav-item-first-step">
7
+ Step 1 content
8
+ </WizardStep>
9
+ <WizardStep
10
+ id="custom-nav-item-second-step"
11
+ name="Step 2"
12
+ navItem={{
13
+ content: <span style={{ color: 'var(--pf-global--default-color--200)' }}>Custom item</span>
14
+ }}
15
+ >
16
+ Step 2 content with a custom navigation item
17
+ </WizardStep>
18
+ <WizardStep name="Review" id="custom-nav-item-review-step" footer={{ nextButtonText: 'Finish' }}>
19
+ Review step content
20
+ </WizardStep>
21
+ </Wizard>
22
+ );
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { Wizard, WizardHeader, WizardStep } from '@patternfly/react-core/next';
3
+
4
+ export const WizardWithHeader: React.FunctionComponent = () => (
5
+ <Wizard
6
+ height={400}
7
+ title="Header wizard"
8
+ header={
9
+ <WizardHeader
10
+ title="You're a wizard, Harry"
11
+ description="To be clear, all those not named Harry are not wizards."
12
+ closeButtonAriaLabel="Close header"
13
+ />
14
+ }
15
+ >
16
+ <WizardStep name="Step 1" id="header-first-step">
17
+ Step 1 content
18
+ </WizardStep>
19
+ <WizardStep name="Step 2" id="header-second-step">
20
+ Step 2 content
21
+ </WizardStep>
22
+ <WizardStep name="Review" id="header-review-step" footer={{ nextButtonText: 'Finish' }}>
23
+ Review step content
24
+ </WizardStep>
25
+ </Wizard>
26
+ );
@@ -0,0 +1,46 @@
1
+ import React from 'react';
2
+
3
+ import { Button } from '@patternfly/react-core';
4
+ import { Wizard, WizardStep } from '@patternfly/react-core/next';
5
+ import ExternalLinkAltIcon from '@patternfly/react-icons/dist/esm/icons/external-link-alt-icon';
6
+ import SlackHashIcon from '@patternfly/react-icons/dist/esm/icons/slack-hash-icon';
7
+
8
+ export const WizardWithNavAnchors: React.FunctionComponent = () => (
9
+ <Wizard height={400} title="Anchor link wizard">
10
+ <WizardStep
11
+ name={
12
+ <>
13
+ <ExternalLinkAltIcon /> PF3
14
+ </>
15
+ }
16
+ id="navanchors-pf3-step"
17
+ navItem={{ component: 'a', href: 'https://www.patternfly.org/v3', target: '_blank' }}
18
+ >
19
+ Step 1: Read about PF3
20
+ </WizardStep>
21
+ <WizardStep
22
+ name={
23
+ <>
24
+ <ExternalLinkAltIcon /> PF4
25
+ </>
26
+ }
27
+ id="navanchors-pf4-step"
28
+ navItem={{ component: 'a', href: 'https://www.patternfly.org/v4', target: '_blank' }}
29
+ >
30
+ Step 2: Read about PF4
31
+ </WizardStep>
32
+ <WizardStep
33
+ name={
34
+ <>
35
+ <SlackHashIcon /> Join us on slack
36
+ </>
37
+ }
38
+ id="navanchors-slack-step"
39
+ navItem={{ component: 'a', href: 'https://patternfly.slack.com', target: '_blank' }}
40
+ >
41
+ <Button variant="link" component="a" target="_blank" href="https://patternfly.slack.com">
42
+ Join the conversation
43
+ </Button>
44
+ </WizardStep>
45
+ </Wizard>
46
+ );
@@ -0,0 +1,86 @@
1
+ import React from 'react';
2
+ import {
3
+ EmptyState,
4
+ EmptyStateIcon,
5
+ EmptyStateBody,
6
+ EmptyStateSecondaryActions,
7
+ Title,
8
+ Progress,
9
+ Button
10
+ } from '@patternfly/react-core';
11
+ import { Wizard, WizardStep } from '@patternfly/react-core/next';
12
+ import CogsIcon from '@patternfly/react-icons/dist/esm/icons/cogs-icon';
13
+
14
+ interface ValidationProgressProps {
15
+ onClose(): void;
16
+ }
17
+
18
+ const ValidationProgress: React.FunctionComponent<ValidationProgressProps> = ({ onClose }) => {
19
+ const [percentValidated, setPercentValidated] = React.useState(0);
20
+
21
+ const tick = React.useCallback(() => {
22
+ if (percentValidated < 100) {
23
+ setPercentValidated(prevValue => prevValue + 20);
24
+ }
25
+ }, [percentValidated]);
26
+
27
+ React.useEffect(() => {
28
+ const interval = setInterval(() => tick(), 1000);
29
+
30
+ return () => {
31
+ clearInterval(interval);
32
+ };
33
+ }, [tick]);
34
+
35
+ return (
36
+ <div className="pf-l-bullseye">
37
+ <EmptyState variant="large">
38
+ <EmptyStateIcon icon={CogsIcon} />
39
+ <Title headingLevel="h4" size="lg">
40
+ {percentValidated === 100 ? 'Validation complete' : 'Validating credentials'}
41
+ </Title>
42
+ <EmptyStateBody>
43
+ <Progress value={percentValidated} measureLocation="outside" aria-label="Wizard validation progress" />
44
+ </EmptyStateBody>
45
+ <EmptyStateBody>
46
+ Description can be used to further elaborate on the validation step, or give the user a better idea of how
47
+ long the process will take.
48
+ </EmptyStateBody>
49
+ <EmptyStateSecondaryActions>
50
+ <Button isDisabled={percentValidated !== 100} onClick={onClose}>
51
+ Log to console
52
+ </Button>
53
+ </EmptyStateSecondaryActions>
54
+ </EmptyState>
55
+ </div>
56
+ );
57
+ };
58
+
59
+ export const WizardWithSubmitProgress: React.FunctionComponent = () => {
60
+ const [isSubmitted, setIsSubmitted] = React.useState(false);
61
+
62
+ // eslint-disable-next-line no-console
63
+ const onClose = () => console.log('Some close action occurs here.');
64
+
65
+ if (isSubmitted) {
66
+ return <ValidationProgress onClose={onClose} />;
67
+ }
68
+
69
+ return (
70
+ <Wizard height={400} title="Submit progress wizard" onClose={onClose}>
71
+ <WizardStep name="Step 1" id="submit-progress-step-1">
72
+ Step 1 content
73
+ </WizardStep>
74
+ <WizardStep name="Step 2" id="submit-progress-step-2">
75
+ Step 2 content
76
+ </WizardStep>
77
+ <WizardStep
78
+ name="Review"
79
+ id="submit-progress-review"
80
+ footer={{ nextButtonText: 'Finish', onNext: () => setIsSubmitted(true) }}
81
+ >
82
+ Review step content
83
+ </WizardStep>
84
+ </Wizard>
85
+ );
86
+ };
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import { Button, Modal, ModalVariant } from '@patternfly/react-core';
3
+ import { Wizard, WizardStep, WizardHeader } from '@patternfly/react-core/next';
4
+
5
+ export const WizardWithinModal = () => {
6
+ const [isModelOpen, setIsModalOpen] = React.useState(false);
7
+
8
+ return (
9
+ <>
10
+ <Button onClick={() => setIsModalOpen(true)}>Show Modal</Button>
11
+
12
+ <Modal
13
+ isOpen={isModelOpen}
14
+ showClose={false}
15
+ aria-label="Wizard modal"
16
+ hasNoBodyWrapper
17
+ variant={ModalVariant.medium}
18
+ >
19
+ <Wizard
20
+ height={400}
21
+ title="In modal wizard"
22
+ header={<WizardHeader title="Wizard in modal" description="Simple wizard description" />}
23
+ >
24
+ <WizardStep name="Step 1" id="in-modal-step-1">
25
+ Step 1 content
26
+ </WizardStep>
27
+ <WizardStep name="Step 2" id="in-modal-step-2">
28
+ Step 2 content
29
+ </WizardStep>
30
+ <WizardStep
31
+ name="Review"
32
+ id="in-modal-review-step"
33
+ footer={{ nextButtonText: 'Finish', onNext: () => setIsModalOpen(false) }}
34
+ >
35
+ Review step content
36
+ </WizardStep>
37
+ </Wizard>
38
+ </Modal>
39
+ </>
40
+ );
41
+ };
@@ -1 +1,2 @@
1
1
  export { useWizardFooter } from './useWizardFooter';
2
+ export { useGetMergedSteps } from './useGetMergedSteps';
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import isEqual from 'fast-deep-equal';
3
+ import { WizardStepType } from '../types';
4
+
5
+ /**
6
+ * Get stable ref of combined initial (prop provided) and current (context stored) steps.
7
+ * @param initialSteps
8
+ * @param currentSteps
9
+ * @returns WizardStepType[]
10
+ */
11
+ export const useGetMergedSteps = (initialSteps: WizardStepType[], currentSteps: WizardStepType[]): WizardStepType[] => {
12
+ const initialStepsRef = React.useRef(initialSteps);
13
+ const currentStepsRef = React.useRef(currentSteps);
14
+
15
+ // Check each value within the array of initialSteps (props) and currentSteps (context).
16
+ // If any value changes for either of these, update the reference.
17
+ if (!isEqual(initialStepsRef.current, initialSteps)) {
18
+ initialStepsRef.current = initialSteps;
19
+ }
20
+ if (!isEqual(currentStepsRef.current, currentSteps)) {
21
+ currentStepsRef.current = currentSteps;
22
+ }
23
+
24
+ // Combine both initial and current steps, where prop provided values
25
+ // take precedence over what's stored in context.
26
+ const mergedSteps = React.useMemo(
27
+ () =>
28
+ initialSteps.reduce((acc, initialStepProps, index) => {
29
+ const currentStepProps = currentSteps[index];
30
+
31
+ if (initialStepProps.id === currentStepProps.id) {
32
+ acc.push({
33
+ ...currentStepProps,
34
+ ...initialStepProps
35
+ });
36
+ }
37
+
38
+ return acc;
39
+ }, []),
40
+ // eslint-disable-next-line react-hooks/exhaustive-deps
41
+ [initialStepsRef.current, currentStepsRef.current]
42
+ );
43
+
44
+ return mergedSteps;
45
+ };
@@ -6,6 +6,6 @@ export * from './WizardStep';
6
6
  export * from './WizardNav';
7
7
  export * from './WizardNavItem';
8
8
  export * from './WizardHeader';
9
- export * from './hooks';
10
9
  export * from './types';
11
- export { useWizardContext } from './WizardContext';
10
+ export { useWizardFooter } from './hooks';
11
+ export { useWizardContext, WizardContext } from './WizardContext';