grommet 2.55.0 → 2.56.1

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 (190) hide show
  1. package/COPYRIGHT.md +3 -1
  2. package/components/Button/Button.js +7 -4
  3. package/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +86 -0
  4. package/components/Calendar/Calendar.js +2 -1
  5. package/components/Cards/Cards.js +1 -2
  6. package/components/DateTimeInput/DateTimeInput.js +1093 -0
  7. package/components/DateTimeInput/README.md +2 -0
  8. package/components/DateTimeInput/StyledDateTimeInput.js +74 -0
  9. package/components/DateTimeInput/index.d.ts +47 -0
  10. package/components/DateTimeInput/index.js +6 -0
  11. package/components/DateTimeInput/propTypes.js +42 -0
  12. package/components/DateTimeInput/stories/CustomThemed/Custom.stories.tsx +53 -0
  13. package/components/DateTimeInput/stories/Form.stories.tsx +44 -0
  14. package/components/DateTimeInput/stories/Inline.stories.tsx +45 -0
  15. package/components/DateTimeInput/stories/Locale.stories.tsx +59 -0
  16. package/components/DateTimeInput/stories/Simple.stories.tsx +23 -0
  17. package/components/Form/Form.js +7 -4
  18. package/components/Form/index.d.ts +3 -0
  19. package/components/Form/stories/AggregateValidation.stories.js +6 -8
  20. package/components/FormField/FormField.js +164 -91
  21. package/components/Grommet/index.d.ts +21 -0
  22. package/components/Grommet/propTypes.js +26 -0
  23. package/components/Stepper/StepConnector.js +38 -0
  24. package/components/Stepper/Stepper.js +303 -0
  25. package/components/Stepper/StepperContext.js +43 -0
  26. package/components/Stepper/StepperDescription.js +26 -0
  27. package/components/Stepper/StepperHelperText.js +44 -0
  28. package/components/Stepper/StepperIndicator.js +74 -0
  29. package/components/Stepper/StepperLabel.js +41 -0
  30. package/components/Stepper/StepperStep.js +137 -0
  31. package/components/Stepper/StyledStepper.js +162 -0
  32. package/components/Stepper/index.d.ts +80 -0
  33. package/components/Stepper/index.js +18 -0
  34. package/components/Stepper/propTypes.js +35 -0
  35. package/components/Stepper/stories/DisabledSteps.stories.js +45 -0
  36. package/components/Stepper/stories/ErrorStates.stories.js +45 -0
  37. package/components/Stepper/stories/HorizontalSteps.stories.js +50 -0
  38. package/components/Stepper/stories/Interactive.stories.js +60 -0
  39. package/components/Stepper/stories/KeyboardNavigation.stories.js +64 -0
  40. package/components/Stepper/stories/NestedSubSteps.stories.js +70 -0
  41. package/components/Stepper/stories/ReadOnly.stories.js +43 -0
  42. package/components/Stepper/stories/ThemingLightDark.stories.js +58 -0
  43. package/components/Stepper/stories/VerticalSteps.stories.js +67 -0
  44. package/components/Tab/Tab.js +19 -6
  45. package/components/Tabs/Tabs.js +156 -22
  46. package/components/TimeInput/README.md +2 -0
  47. package/components/TimeInput/StyledTimeInput.js +73 -0
  48. package/components/TimeInput/TimeInput.js +692 -0
  49. package/components/TimeInput/TimeInputPopup.js +489 -0
  50. package/components/TimeInput/index.d.ts +44 -0
  51. package/components/TimeInput/index.js +6 -0
  52. package/components/TimeInput/propTypes.js +39 -0
  53. package/components/TimeInput/stories/Controlled.stories.tsx +29 -0
  54. package/components/TimeInput/stories/Disabled.stories.tsx +13 -0
  55. package/components/TimeInput/stories/Form.stories.tsx +38 -0
  56. package/components/TimeInput/stories/ReadOnly.stories.tsx +13 -0
  57. package/components/TimeInput/stories/Simple.stories.tsx +19 -0
  58. package/components/TimeInput/stories/Step.stories.tsx +14 -0
  59. package/components/TimeInput/stories/ThemingLightDark.stories.tsx +22 -0
  60. package/components/TimeInput/stories/Uncontrolled.stories.tsx +22 -0
  61. package/components/TimeInput/useSectionedTimeField.js +358 -0
  62. package/components/TimeInput/utils.js +192 -0
  63. package/components/Wizard/StyledWizard.js +16 -0
  64. package/components/Wizard/Wizard.js +770 -0
  65. package/components/Wizard/WizardContent.js +90 -0
  66. package/components/Wizard/WizardContext.js +35 -0
  67. package/components/Wizard/WizardFooter.js +123 -0
  68. package/components/Wizard/WizardHeader.js +63 -0
  69. package/components/Wizard/WizardProgress.js +84 -0
  70. package/components/Wizard/WizardStepHeader.js +55 -0
  71. package/components/Wizard/index.d.ts +171 -0
  72. package/components/Wizard/index.js +19 -0
  73. package/components/Wizard/propTypes.js +56 -0
  74. package/components/Wizard/stories/BasicLinear.stories.js +71 -0
  75. package/components/Wizard/stories/Branching.stories.js +96 -0
  76. package/components/Wizard/stories/Composable.stories.js +75 -0
  77. package/components/Wizard/stories/Controlled.stories.js +136 -0
  78. package/components/Wizard/stories/LongContent.stories.js +118 -0
  79. package/components/Wizard/stories/Modal.stories.js +143 -0
  80. package/components/Wizard/stories/NestedSubSteps.stories.js +79 -0
  81. package/components/Wizard/stories/Validation.stories.js +123 -0
  82. package/components/index.d.ts +6 -0
  83. package/components/index.js +24 -0
  84. package/es6/components/Button/Button.js +7 -4
  85. package/es6/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +81 -0
  86. package/es6/components/Calendar/Calendar.js +2 -0
  87. package/es6/components/Cards/Cards.js +1 -2
  88. package/es6/components/DateTimeInput/DateTimeInput.js +1090 -0
  89. package/es6/components/DateTimeInput/README.md +2 -0
  90. package/es6/components/DateTimeInput/StyledDateTimeInput.js +68 -0
  91. package/es6/components/DateTimeInput/index.d.ts +47 -0
  92. package/es6/components/DateTimeInput/index.js +3 -0
  93. package/es6/components/DateTimeInput/propTypes.js +36 -0
  94. package/es6/components/DateTimeInput/stories/CustomThemed/Custom.stories.tsx +53 -0
  95. package/es6/components/DateTimeInput/stories/Form.stories.tsx +44 -0
  96. package/es6/components/DateTimeInput/stories/Inline.stories.tsx +45 -0
  97. package/es6/components/DateTimeInput/stories/Locale.stories.tsx +59 -0
  98. package/es6/components/DateTimeInput/stories/Simple.stories.tsx +23 -0
  99. package/es6/components/Form/Form.js +7 -3
  100. package/es6/components/Form/index.d.ts +3 -0
  101. package/es6/components/Form/stories/AggregateValidation.stories.js +6 -9
  102. package/es6/components/FormField/FormField.js +165 -91
  103. package/es6/components/Grommet/index.d.ts +21 -0
  104. package/es6/components/Grommet/propTypes.js +26 -0
  105. package/es6/components/Stepper/StepConnector.js +33 -0
  106. package/es6/components/Stepper/Stepper.js +301 -0
  107. package/es6/components/Stepper/StepperContext.js +39 -0
  108. package/es6/components/Stepper/StepperDescription.js +21 -0
  109. package/es6/components/Stepper/StepperHelperText.js +39 -0
  110. package/es6/components/Stepper/StepperIndicator.js +69 -0
  111. package/es6/components/Stepper/StepperLabel.js +36 -0
  112. package/es6/components/Stepper/StepperStep.js +133 -0
  113. package/es6/components/Stepper/StyledStepper.js +156 -0
  114. package/es6/components/Stepper/index.d.ts +80 -0
  115. package/es6/components/Stepper/index.js +6 -0
  116. package/es6/components/Stepper/propTypes.js +30 -0
  117. package/es6/components/Stepper/stories/DisabledSteps.stories.js +41 -0
  118. package/es6/components/Stepper/stories/ErrorStates.stories.js +41 -0
  119. package/es6/components/Stepper/stories/HorizontalSteps.stories.js +46 -0
  120. package/es6/components/Stepper/stories/Interactive.stories.js +56 -0
  121. package/es6/components/Stepper/stories/KeyboardNavigation.stories.js +60 -0
  122. package/es6/components/Stepper/stories/NestedSubSteps.stories.js +66 -0
  123. package/es6/components/Stepper/stories/ReadOnly.stories.js +39 -0
  124. package/es6/components/Stepper/stories/ThemingLightDark.stories.js +54 -0
  125. package/es6/components/Stepper/stories/VerticalSteps.stories.js +63 -0
  126. package/es6/components/Tab/Tab.js +19 -6
  127. package/es6/components/Tabs/Tabs.js +157 -23
  128. package/es6/components/TimeInput/README.md +2 -0
  129. package/es6/components/TimeInput/StyledTimeInput.js +68 -0
  130. package/es6/components/TimeInput/TimeInput.js +689 -0
  131. package/es6/components/TimeInput/TimeInputPopup.js +485 -0
  132. package/es6/components/TimeInput/index.d.ts +44 -0
  133. package/es6/components/TimeInput/index.js +1 -0
  134. package/es6/components/TimeInput/propTypes.js +33 -0
  135. package/es6/components/TimeInput/stories/Controlled.stories.tsx +29 -0
  136. package/es6/components/TimeInput/stories/Disabled.stories.tsx +13 -0
  137. package/es6/components/TimeInput/stories/Form.stories.tsx +38 -0
  138. package/es6/components/TimeInput/stories/ReadOnly.stories.tsx +13 -0
  139. package/es6/components/TimeInput/stories/Simple.stories.tsx +19 -0
  140. package/es6/components/TimeInput/stories/Step.stories.tsx +14 -0
  141. package/es6/components/TimeInput/stories/ThemingLightDark.stories.tsx +22 -0
  142. package/es6/components/TimeInput/stories/Uncontrolled.stories.tsx +22 -0
  143. package/es6/components/TimeInput/useSectionedTimeField.js +355 -0
  144. package/es6/components/TimeInput/utils.js +187 -0
  145. package/es6/components/Wizard/StyledWizard.js +11 -0
  146. package/es6/components/Wizard/Wizard.js +768 -0
  147. package/es6/components/Wizard/WizardContent.js +87 -0
  148. package/es6/components/Wizard/WizardContext.js +31 -0
  149. package/es6/components/Wizard/WizardFooter.js +120 -0
  150. package/es6/components/Wizard/WizardHeader.js +60 -0
  151. package/es6/components/Wizard/WizardProgress.js +80 -0
  152. package/es6/components/Wizard/WizardStepHeader.js +51 -0
  153. package/es6/components/Wizard/index.d.ts +171 -0
  154. package/es6/components/Wizard/index.js +7 -0
  155. package/es6/components/Wizard/propTypes.js +51 -0
  156. package/es6/components/Wizard/stories/BasicLinear.stories.js +67 -0
  157. package/es6/components/Wizard/stories/Branching.stories.js +93 -0
  158. package/es6/components/Wizard/stories/Composable.stories.js +72 -0
  159. package/es6/components/Wizard/stories/Controlled.stories.js +133 -0
  160. package/es6/components/Wizard/stories/LongContent.stories.js +115 -0
  161. package/es6/components/Wizard/stories/Modal.stories.js +141 -0
  162. package/es6/components/Wizard/stories/NestedSubSteps.stories.js +76 -0
  163. package/es6/components/Wizard/stories/Validation.stories.js +118 -0
  164. package/es6/components/index.d.ts +6 -0
  165. package/es6/components/index.js +6 -0
  166. package/es6/index.d.ts +6 -0
  167. package/es6/languages/default.json +48 -0
  168. package/es6/themes/base.d.ts +223 -0
  169. package/es6/themes/base.js +366 -0
  170. package/es6/utils/DOM.js +11 -2
  171. package/es6/utils/dates.js +10 -0
  172. package/es6/utils/sectionHelpers.js +57 -0
  173. package/es6/utils/useSectionedField.js +45 -0
  174. package/grommet.min.js +2 -1
  175. package/grommet.min.js.LICENSE.txt +1 -0
  176. package/grommet.min.js.map +1 -1
  177. package/index.d.ts +6 -0
  178. package/languages/default.json +48 -0
  179. package/package.json +57 -52
  180. package/themes/base.d.ts +223 -0
  181. package/themes/base.js +366 -1
  182. package/tools/license-header.js +2 -0
  183. package/utils/DOM.js +11 -2
  184. package/utils/dates.js +11 -1
  185. package/utils/sectionHelpers.js +61 -0
  186. package/utils/useSectionedField.js +50 -0
  187. package/components/TextInput/stories/CustomThemed/CustomSuggestions.stories.tsx +0 -180
  188. package/components/TextInput/stories/CustomThemed/Themed.stories.js +0 -79
  189. package/es6/components/TextInput/stories/CustomThemed/CustomSuggestions.stories.tsx +0 -180
  190. package/es6/components/TextInput/stories/CustomThemed/Themed.stories.js +0 -74
@@ -0,0 +1,301 @@
1
+ var _excluded = ["steps", "currentStep", "direction", "clickableSteps", "showDescription", "onStepClick", "aria-label", "children", "id"];
2
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
3
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
4
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
5
+ // SPDX-License-Identifier: Apache-2.0
6
+ import React, { forwardRef, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
7
+ import { Box } from '../Box';
8
+ import { MessageContext } from '../../contexts/MessageContext';
9
+ import { Keyboard } from '../Keyboard';
10
+ import { StepperContext } from './StepperContext';
11
+ import { StepperStep } from './StepperStep';
12
+ import { StepperPropTypes } from './propTypes';
13
+
14
+ // Flattens steps with parent/child relationships into a linear list
15
+ // for keyboard navigation and index-based tracking.
16
+ var flattenSteps = function flattenSteps(steps) {
17
+ var flat = [];
18
+ var hasSubSubSteps = false;
19
+ steps.forEach(function (step, parentIdx) {
20
+ var hasChildren = step.children && step.children.length > 0;
21
+ var isLastParent = parentIdx === steps.length - 1;
22
+ flat.push(_extends({}, step, {
23
+ isSubStep: false,
24
+ showConnector: !isLastParent,
25
+ childIds: hasChildren ? step.children.map(function (c) {
26
+ return c.id;
27
+ }) : []
28
+ }));
29
+ if (hasChildren) {
30
+ step.children.forEach(function (child) {
31
+ flat.push(_extends({}, child, {
32
+ isSubStep: true,
33
+ showConnector: false,
34
+ parentId: step.id,
35
+ childIds: []
36
+ }));
37
+ if (child.children && child.children.length > 0) {
38
+ hasSubSubSteps = true;
39
+ }
40
+ });
41
+ }
42
+ });
43
+ if (process.env.NODE_ENV !== 'production' && hasSubSubSteps) {
44
+ console.warn('Stepper: sub-steps with their own children are not supported.');
45
+ }
46
+ return flat;
47
+ };
48
+ var Stepper = /*#__PURE__*/forwardRef(function (_ref, ref) {
49
+ var _ref$steps = _ref.steps,
50
+ steps = _ref$steps === void 0 ? [] : _ref$steps,
51
+ currentStep = _ref.currentStep,
52
+ _ref$direction = _ref.direction,
53
+ directionProp = _ref$direction === void 0 ? 'horizontal' : _ref$direction,
54
+ _ref$clickableSteps = _ref.clickableSteps,
55
+ clickableSteps = _ref$clickableSteps === void 0 ? true : _ref$clickableSteps,
56
+ _ref$showDescription = _ref.showDescription,
57
+ showDescription = _ref$showDescription === void 0 ? true : _ref$showDescription,
58
+ onStepClick = _ref.onStepClick,
59
+ ariaLabel = _ref['aria-label'],
60
+ children = _ref.children,
61
+ id = _ref.id,
62
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
63
+ var _useContext = useContext(MessageContext),
64
+ format = _useContext.format;
65
+ var stepRefs = useRef(new Map());
66
+ var flatSteps = useMemo(function () {
67
+ return flattenSteps(steps);
68
+ }, [steps]);
69
+ var stepsRef = useRef(flatSteps);
70
+ stepsRef.current = flatSteps;
71
+ useEffect(function () {
72
+ if (process.env.NODE_ENV !== 'production') {
73
+ console.warn('Warning: Stepper is currently in beta. The API is subject ' + 'to change in future releases.');
74
+ }
75
+ }, []);
76
+
77
+ // Force vertical if steps have children
78
+ // (horizontal substeps not supported)
79
+ var hasSubSteps = steps.some(function (step) {
80
+ return step.children && step.children.length > 0;
81
+ });
82
+ var direction = hasSubSteps && directionProp === 'horizontal' ? 'vertical' : directionProp;
83
+
84
+ // Warn in dev about invalid state
85
+ if (process.env.NODE_ENV !== 'production') {
86
+ if (hasSubSteps && directionProp === 'horizontal') {
87
+ console.warn('Stepper: horizontal direction with sub-steps is not supported. ' + 'Falling back to vertical.');
88
+ }
89
+ if (currentStep) {
90
+ var currentStepObj = flatSteps.find(function (s) {
91
+ return s.id === currentStep;
92
+ });
93
+ if (!currentStepObj) {
94
+ console.warn('Stepper: currentStep "' + (currentStep + "\" does not match any ") + 'step id. Falling back to the ' + 'first non-disabled step.');
95
+ } else if (currentStepObj.status === 'disabled') {
96
+ console.warn("Stepper: currentStep \"" + currentStep + "\" matches a disabled step. " + "This is an invalid state. The step will render as disabled.");
97
+ }
98
+ }
99
+ }
100
+
101
+ // Determine effective current step (fallback to first non-disabled)
102
+ var effectiveCurrentStep = useMemo(function () {
103
+ var _flatSteps$;
104
+ var match = flatSteps.find(function (s) {
105
+ return s.id === currentStep;
106
+ });
107
+ if (match && match.status !== 'disabled') return currentStep;
108
+ var fallback = flatSteps.find(function (s) {
109
+ return s.status !== 'disabled';
110
+ });
111
+ return fallback ? fallback.id : ((_flatSteps$ = flatSteps[0]) == null ? void 0 : _flatSteps$.id) || '';
112
+ }, [currentStep, flatSteps]);
113
+
114
+ // Roving tabindex: only the focused step has tabIndex=0,
115
+ // all others have tabIndex=-1. A ref keeps the index synchronous
116
+ // for keyboard handlers that fire before React re-renders.
117
+ var currentIndex = flatSteps.findIndex(function (s) {
118
+ return s.id === effectiveCurrentStep;
119
+ });
120
+ var flatStepsLength = flatSteps.length;
121
+ var _useState = useState(currentIndex >= 0 ? currentIndex : 0),
122
+ focusedIndex = _useState[0],
123
+ setFocusedIndex = _useState[1];
124
+ var focusedIndexRef = useRef(focusedIndex);
125
+ var updateFocusedIndex = useCallback(function (idx) {
126
+ focusedIndexRef.current = idx;
127
+ setFocusedIndex(idx);
128
+ }, []);
129
+ var stepIndex = useCallback(function (stepId) {
130
+ return flatSteps.findIndex(function (s) {
131
+ return s.id === stepId;
132
+ });
133
+ }, [flatSteps]);
134
+ var isPriorStep = useCallback(function (stepId) {
135
+ var idx = stepIndex(stepId);
136
+ var curIdx = stepIndex(effectiveCurrentStep);
137
+ return idx < curIdx;
138
+ }, [stepIndex, effectiveCurrentStep]);
139
+ var isAfterStep = useCallback(function (stepId) {
140
+ var idx = stepIndex(stepId);
141
+ var curIdx = stepIndex(effectiveCurrentStep);
142
+ return idx > curIdx;
143
+ }, [stepIndex, effectiveCurrentStep]);
144
+ var isCurrentStep = useCallback(function (stepId) {
145
+ return stepId === effectiveCurrentStep;
146
+ }, [effectiveCurrentStep]);
147
+ var canNavigateTo = useCallback(function (stepId) {
148
+ var step = flatSteps.find(function (s) {
149
+ return s.id === stepId;
150
+ });
151
+ return clickableSteps && step && step.status !== 'disabled';
152
+ }, [flatSteps, clickableSteps]);
153
+ var contextValue = useMemo(function () {
154
+ return {
155
+ currentStep: effectiveCurrentStep,
156
+ steps: flatSteps,
157
+ direction: direction,
158
+ clickableSteps: clickableSteps,
159
+ onStepClick: onStepClick,
160
+ showDescription: showDescription,
161
+ stepIndex: stepIndex,
162
+ isPriorStep: isPriorStep,
163
+ isAfterStep: isAfterStep,
164
+ isCurrentStep: isCurrentStep,
165
+ canNavigateTo: canNavigateTo
166
+ };
167
+ }, [effectiveCurrentStep, flatSteps, direction, clickableSteps, onStepClick, showDescription, stepIndex, isPriorStep, isAfterStep, isCurrentStep, canNavigateTo]);
168
+
169
+ // Wraps around the step list to find the next step
170
+ // in the given direction (+1 forward, -1 backward).
171
+ var findNextEnabledIndex = useCallback(function (startIndex, delta) {
172
+ return (startIndex + delta + flatStepsLength) % flatStepsLength;
173
+ }, [flatStepsLength]);
174
+ var findFirstEnabledIndex = useCallback(function () {
175
+ return 0;
176
+ }, []);
177
+ var findLastEnabledIndex = useCallback(function () {
178
+ return flatStepsLength - 1;
179
+ }, [flatStepsLength]);
180
+ var moveFocus = useCallback(function (nextIndex) {
181
+ if (nextIndex !== undefined && nextIndex !== focusedIndexRef.current) {
182
+ updateFocusedIndex(nextIndex);
183
+ var nextButton = stepRefs.current.get(nextIndex);
184
+ if (nextButton) {
185
+ nextButton.focus();
186
+ }
187
+ }
188
+ }, [updateFocusedIndex]);
189
+ var onNext = useCallback(function () {
190
+ moveFocus(findNextEnabledIndex(focusedIndexRef.current, 1));
191
+ }, [findNextEnabledIndex, moveFocus]);
192
+ var onPrevious = useCallback(function () {
193
+ moveFocus(findNextEnabledIndex(focusedIndexRef.current, -1));
194
+ }, [findNextEnabledIndex, moveFocus]);
195
+ var handleKeyDown = useCallback(function (event) {
196
+ var isHorizontal = direction === 'horizontal';
197
+ switch (event.key) {
198
+ case 'ArrowRight':
199
+ if (isHorizontal) {
200
+ event.preventDefault();
201
+ onNext();
202
+ }
203
+ break;
204
+ case 'ArrowLeft':
205
+ if (isHorizontal) {
206
+ event.preventDefault();
207
+ onPrevious();
208
+ }
209
+ break;
210
+ case 'ArrowDown':
211
+ if (!isHorizontal) {
212
+ event.preventDefault();
213
+ onNext();
214
+ }
215
+ break;
216
+ case 'ArrowUp':
217
+ if (!isHorizontal) {
218
+ event.preventDefault();
219
+ onPrevious();
220
+ }
221
+ break;
222
+ case 'Home':
223
+ event.preventDefault();
224
+ moveFocus(findFirstEnabledIndex());
225
+ break;
226
+ case 'End':
227
+ event.preventDefault();
228
+ moveFocus(findLastEnabledIndex());
229
+ break;
230
+ default:
231
+ break;
232
+ }
233
+ }, [direction, onNext, onPrevious, findFirstEnabledIndex, findLastEnabledIndex, moveFocus]);
234
+ var renderDefaultSteps = function renderDefaultSteps() {
235
+ var flatIndex = 0;
236
+ var elements = [];
237
+ steps.forEach(function (step, parentIdx) {
238
+ var parentFlatIndex = flatIndex;
239
+ flatIndex += 1;
240
+ var childElements = step.children ? step.children.map(function (child) {
241
+ var childFlatIndex = flatIndex;
242
+ flatIndex += 1;
243
+ return /*#__PURE__*/React.createElement(StepperStep, {
244
+ key: child.id,
245
+ step: child,
246
+ stepNumber: childFlatIndex + 1,
247
+ isLast: false,
248
+ showConnector: false,
249
+ direction: direction,
250
+ focusedIndex: focusedIndex,
251
+ index: childFlatIndex,
252
+ isSubStep: true,
253
+ onFocusStep: updateFocusedIndex,
254
+ stepsRef: stepsRef,
255
+ stepRefs: stepRefs
256
+ });
257
+ }) : null;
258
+ var isLastParent = parentIdx === steps.length - 1;
259
+ elements.push(/*#__PURE__*/React.createElement(StepperStep, {
260
+ key: step.id,
261
+ step: step,
262
+ stepNumber: parentFlatIndex + 1,
263
+ isLast: isLastParent,
264
+ showConnector: direction === 'horizontal' ? !isLastParent : !isLastParent || !!childElements,
265
+ direction: direction,
266
+ focusedIndex: focusedIndex,
267
+ index: parentFlatIndex,
268
+ isSubStep: false,
269
+ onFocusStep: updateFocusedIndex,
270
+ stepsRef: stepsRef,
271
+ stepRefs: stepRefs,
272
+ subSteps: childElements
273
+ }));
274
+ });
275
+ return elements;
276
+ };
277
+ var stepperContent = /*#__PURE__*/React.createElement(Box, _extends({
278
+ ref: ref,
279
+ as: "ol",
280
+ "aria-label": ariaLabel || format({
281
+ id: 'stepper.progress'
282
+ }),
283
+ direction: direction === 'horizontal' ? 'row' : 'column',
284
+ fill: direction,
285
+ id: id,
286
+ overflow: "hidden",
287
+ pad: "none",
288
+ margin: "none",
289
+ style: {
290
+ listStyle: 'none'
291
+ }
292
+ }, rest), children || renderDefaultSteps());
293
+ return /*#__PURE__*/React.createElement(StepperContext.Provider, {
294
+ value: contextValue
295
+ }, clickableSteps ? /*#__PURE__*/React.createElement(Keyboard, {
296
+ onKeyDown: handleKeyDown
297
+ }, stepperContent) : stepperContent);
298
+ });
299
+ Stepper.displayName = 'Stepper';
300
+ Stepper.propTypes = StepperPropTypes;
301
+ export { Stepper };
@@ -0,0 +1,39 @@
1
+ import { createContext, useContext } from 'react';
2
+ export var StepperContext = /*#__PURE__*/createContext({
3
+ currentStep: '',
4
+ steps: [],
5
+ direction: 'horizontal',
6
+ clickableSteps: true,
7
+ onStepClick: undefined,
8
+ showDescription: true,
9
+ stepIndex: function stepIndex() {
10
+ return -1;
11
+ },
12
+ isPriorStep: function isPriorStep() {
13
+ return false;
14
+ },
15
+ isAfterStep: function isAfterStep() {
16
+ return false;
17
+ },
18
+ isCurrentStep: function isCurrentStep() {
19
+ return false;
20
+ },
21
+ canNavigateTo: function canNavigateTo() {
22
+ return false;
23
+ }
24
+ });
25
+
26
+ // Step-level context: provides the current step's data to subcomponents
27
+ export var StepItemContext = /*#__PURE__*/createContext({
28
+ step: null,
29
+ index: 0,
30
+ isLast: false,
31
+ isLabelRevealed: false,
32
+ isSubStep: false
33
+ });
34
+ export var useStepper = function useStepper() {
35
+ return useContext(StepperContext);
36
+ };
37
+ export var useStepItem = function useStepItem() {
38
+ return useContext(StepItemContext);
39
+ };
@@ -0,0 +1,21 @@
1
+ function _objectDestructuringEmpty(t) { if (null == t) throw new TypeError("Cannot destructure " + t); }
2
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
+ import React from 'react';
4
+ import { Text } from '../Text';
5
+ import { useStepper, useStepItem } from './StepperContext';
6
+ import { useThemeValue } from '../../utils/useThemeValue';
7
+ export var StepperDescription = function StepperDescription(_ref) {
8
+ var _theme$stepper;
9
+ var rest = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
10
+ var _useStepper = useStepper(),
11
+ direction = _useStepper.direction;
12
+ var _useThemeValue = useThemeValue(),
13
+ theme = _useThemeValue.theme;
14
+ var _useStepItem = useStepItem(),
15
+ step = _useStepItem.step;
16
+ if (!step || !step.description) return null;
17
+ var descriptionProps = (_theme$stepper = theme.stepper) == null ? void 0 : _theme$stepper.description;
18
+ return /*#__PURE__*/React.createElement(Text, _extends({}, descriptionProps, {
19
+ truncate: direction === 'horizontal'
20
+ }, rest), step.description);
21
+ };
@@ -0,0 +1,39 @@
1
+ var _excluded = ["variant"];
2
+ function _objectDestructuringEmpty(t) { if (null == t) throw new TypeError("Cannot destructure " + t); }
3
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
4
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
5
+ import React from 'react';
6
+ import { Text } from '../Text';
7
+ import { useStepItem } from './StepperContext';
8
+ import { useThemeValue } from '../../utils/useThemeValue';
9
+ var StepperHelperText = function StepperHelperText(_ref) {
10
+ var _theme$stepper, _theme$stepper2;
11
+ var variant = _ref.variant,
12
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
13
+ var _useThemeValue = useThemeValue(),
14
+ theme = _useThemeValue.theme;
15
+ var helperTextProps = (_theme$stepper = theme.stepper) == null ? void 0 : _theme$stepper.helperText;
16
+ var variantProps = variant ? ((_theme$stepper2 = theme.stepper) == null || (_theme$stepper2 = _theme$stepper2[variant]) == null ? void 0 : _theme$stepper2.helperText) || {} : {};
17
+ return /*#__PURE__*/React.createElement(Text, _extends({}, helperTextProps, variantProps, rest));
18
+ };
19
+ export var StepperError = function StepperError(_ref2) {
20
+ var rest = _extends({}, (_objectDestructuringEmpty(_ref2), _ref2));
21
+ var _useStepItem = useStepItem(),
22
+ step = _useStepItem.step;
23
+ if (!step || step.status !== 'error' || !step.errorMessage) return null;
24
+ return /*#__PURE__*/React.createElement(StepperHelperText, _extends({
25
+ id: "stepper-error-" + step.id,
26
+ role: "alert",
27
+ variant: "error"
28
+ }, rest), step.errorMessage);
29
+ };
30
+ export var StepperDisabledReason = function StepperDisabledReason(_ref3) {
31
+ var rest = _extends({}, (_objectDestructuringEmpty(_ref3), _ref3));
32
+ var _useStepItem2 = useStepItem(),
33
+ step = _useStepItem2.step;
34
+ if (!step || step.status !== 'disabled' || !step.disabledReason) return null;
35
+ return /*#__PURE__*/React.createElement(StepperHelperText, _extends({
36
+ id: "stepper-reason-" + step.id,
37
+ variant: "disabled"
38
+ }, rest), step.disabledReason);
39
+ };
@@ -0,0 +1,69 @@
1
+ function _objectDestructuringEmpty(t) { if (null == t) throw new TypeError("Cannot destructure " + t); }
2
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
+ import React from 'react';
4
+ import { useThemeValue } from '../../utils/useThemeValue';
5
+ import { useStepper, useStepItem } from './StepperContext';
6
+ import { StyledIndicator } from './StyledStepper';
7
+ var renderIcon = function renderIcon(Icon, props) {
8
+ if (!Icon) return null;
9
+ var iconProps = _extends({
10
+ color: 'currentColor'
11
+ }, props);
12
+ if (/*#__PURE__*/React.isValidElement(Icon)) {
13
+ return /*#__PURE__*/React.cloneElement(Icon, _extends({}, iconProps, {
14
+ 'aria-hidden': true
15
+ }));
16
+ }
17
+ return /*#__PURE__*/React.createElement(Icon, _extends({}, iconProps, {
18
+ "aria-hidden": true
19
+ }));
20
+ };
21
+
22
+ // Maps step status + current position to a visual state
23
+ // used by both the indicator and label components.
24
+ function getEffectiveState(status, isCurrent) {
25
+ if (status === 'disabled') return 'disabled';
26
+ if (isCurrent) {
27
+ if (status === 'completed') return 'currentCompleted';
28
+ if (status === 'error') return 'currentError';
29
+ return 'current';
30
+ }
31
+ if (status === 'completed') return 'completed';
32
+ if (status === 'error') return 'error';
33
+ return 'pending';
34
+ }
35
+ export var StepperIndicator = function StepperIndicator(_ref) {
36
+ var _step$children, _theme$stepper, _stateTheme, _stateTheme2;
37
+ var rest = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
38
+ var _useStepper = useStepper(),
39
+ currentStep = _useStepper.currentStep,
40
+ clickableSteps = _useStepper.clickableSteps;
41
+ var _useThemeValue = useThemeValue(),
42
+ theme = _useThemeValue.theme,
43
+ passThemeFlag = _useThemeValue.passThemeFlag;
44
+ var _useStepItem = useStepItem(),
45
+ step = _useStepItem.step,
46
+ isSubStep = _useStepItem.isSubStep;
47
+ if (!step) return null;
48
+ var isCurrent = currentStep === step.id;
49
+ var hasCurrentChild = !isSubStep && ((_step$children = step.children) == null ? void 0 : _step$children.some(function (c) {
50
+ return c.id === currentStep;
51
+ }));
52
+ var isHighlighted = isCurrent || hasCurrentChild;
53
+ var effectiveState = getEffectiveState(step.status, isHighlighted);
54
+ var stateTheme = ((_theme$stepper = theme.stepper) == null || (_theme$stepper = _theme$stepper[effectiveState]) == null ? void 0 : _theme$stepper.indicator) || {};
55
+ if (isSubStep && stateTheme.substep) {
56
+ stateTheme = _extends({}, stateTheme, stateTheme.substep);
57
+ }
58
+ var isDisabled = step.status === 'disabled';
59
+ var isClickable = clickableSteps && !isDisabled;
60
+ var iconSize = ((_stateTheme = stateTheme) == null ? void 0 : _stateTheme.iconSize) || (isSubStep ? 'xsmall' : 'small');
61
+ return /*#__PURE__*/React.createElement(StyledIndicator, _extends({
62
+ effectiveState: effectiveState,
63
+ isSubStep: isSubStep,
64
+ isClickable: isClickable
65
+ }, passThemeFlag, rest), renderIcon((_stateTheme2 = stateTheme) == null ? void 0 : _stateTheme2.icon, {
66
+ size: iconSize
67
+ }));
68
+ };
69
+ export { getEffectiveState };
@@ -0,0 +1,36 @@
1
+ function _objectDestructuringEmpty(t) { if (null == t) throw new TypeError("Cannot destructure " + t); }
2
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
+ import React from 'react';
4
+ import { Text } from '../Text';
5
+ import { useStepper, useStepItem } from './StepperContext';
6
+ import { getEffectiveState } from './StepperIndicator';
7
+ import { useThemeValue } from '../../utils/useThemeValue';
8
+ var getStateProps = function getStateProps(theme, effectiveState) {
9
+ var _theme$stepper;
10
+ return ((_theme$stepper = theme.stepper) == null || (_theme$stepper = _theme$stepper[effectiveState]) == null ? void 0 : _theme$stepper.label) || {};
11
+ };
12
+ export var StepperLabel = function StepperLabel(_ref) {
13
+ var _step$children, _theme$stepper2, _theme$stepper3;
14
+ var rest = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
15
+ var _useStepper = useStepper(),
16
+ currentStep = _useStepper.currentStep,
17
+ direction = _useStepper.direction;
18
+ var _useThemeValue = useThemeValue(),
19
+ theme = _useThemeValue.theme;
20
+ var _useStepItem = useStepItem(),
21
+ step = _useStepItem.step,
22
+ isSubStep = _useStepItem.isSubStep;
23
+ if (!step) return null;
24
+ var isCurrent = currentStep === step.id;
25
+ var hasCurrentChild = !isSubStep && ((_step$children = step.children) == null ? void 0 : _step$children.some(function (c) {
26
+ return c.id === currentStep;
27
+ }));
28
+ var isHighlighted = isCurrent || hasCurrentChild;
29
+ var effectiveState = getEffectiveState(step.status, isHighlighted);
30
+ var stateProps = getStateProps(theme, effectiveState);
31
+ var size = isSubStep ? ((_theme$stepper2 = theme.stepper) == null || (_theme$stepper2 = _theme$stepper2.label) == null || (_theme$stepper2 = _theme$stepper2.substep) == null ? void 0 : _theme$stepper2.size) || 'small' : ((_theme$stepper3 = theme.stepper) == null || (_theme$stepper3 = _theme$stepper3.label) == null ? void 0 : _theme$stepper3.size) || 'medium';
32
+ return /*#__PURE__*/React.createElement(Text, _extends({
33
+ size: size,
34
+ truncate: direction === 'horizontal'
35
+ }, stateProps, rest), step.title);
36
+ };
@@ -0,0 +1,133 @@
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ import React, { useContext, useMemo } from 'react';
5
+ import { MessageContext } from '../../contexts/MessageContext';
6
+ import { useThemeValue } from '../../utils/useThemeValue';
7
+ import { useStepper, StepItemContext } from './StepperContext';
8
+ import { StepperIndicator } from './StepperIndicator';
9
+ import { StepperLabel } from './StepperLabel';
10
+ import { StepperDescription } from './StepperDescription';
11
+ import { StepperError, StepperDisabledReason } from './StepperHelperText';
12
+ import { StepConnector } from './StepConnector';
13
+ import { StyledStepItem, StyledStepButton, StyledStepContent, StyledConnector, StyledSubStepsList } from './StyledStepper';
14
+ export var StepperStep = function StepperStep(_ref) {
15
+ var _step$children, _stepsRef$current;
16
+ var step = _ref.step,
17
+ stepNumber = _ref.stepNumber,
18
+ isLast = _ref.isLast,
19
+ showConnector = _ref.showConnector,
20
+ direction = _ref.direction,
21
+ focusedIndex = _ref.focusedIndex,
22
+ indexProp = _ref.index,
23
+ isSubStep = _ref.isSubStep,
24
+ subSteps = _ref.subSteps,
25
+ onFocusStep = _ref.onFocusStep,
26
+ stepsRef = _ref.stepsRef,
27
+ stepRefs = _ref.stepRefs;
28
+ var _useStepper = useStepper(),
29
+ currentStep = _useStepper.currentStep,
30
+ clickableSteps = _useStepper.clickableSteps,
31
+ showDescription = _useStepper.showDescription,
32
+ onStepClick = _useStepper.onStepClick,
33
+ steps = _useStepper.steps;
34
+ var _useContext = useContext(MessageContext),
35
+ format = _useContext.format;
36
+ var _useThemeValue = useThemeValue(),
37
+ passThemeFlag = _useThemeValue.passThemeFlag;
38
+ var index = indexProp !== undefined ? indexProp : steps.findIndex(function (s) {
39
+ return s.id === step.id;
40
+ });
41
+ var isCurrent = currentStep === step.id;
42
+ var hasCurrentChild = !isSubStep && ((_step$children = step.children) == null ? void 0 : _step$children.some(function (c) {
43
+ return c.id === currentStep;
44
+ }));
45
+ var isHighlighted = isCurrent || hasCurrentChild;
46
+ var isDisabled = step.status === 'disabled';
47
+ var isClickable = clickableSteps && !isDisabled;
48
+ var isReadOnly = !clickableSteps;
49
+ var stepItemValue = useMemo(function () {
50
+ return {
51
+ step: step,
52
+ index: index,
53
+ isLast: isLast,
54
+ isLabelRevealed: direction === 'vertical' || focusedIndex === index,
55
+ isSubStep: isSubStep
56
+ };
57
+ }, [step, index, isLast, direction, focusedIndex, isSubStep]);
58
+ var handleClick = function handleClick() {
59
+ if (isClickable && onStepClick) {
60
+ onStepClick(step.id);
61
+ }
62
+ };
63
+ var handleKeyDown = function handleKeyDown(e) {
64
+ if (e.key === 'Enter' || e.key === ' ') {
65
+ e.preventDefault();
66
+ if (isClickable && onStepClick) {
67
+ onStepClick(step.id);
68
+ }
69
+ }
70
+ };
71
+ var totalSteps = ((_stepsRef$current = stepsRef.current) == null ? void 0 : _stepsRef$current.length) || stepNumber;
72
+ var ariaLabel = step['aria-label'] || format({
73
+ id: 'stepper.step',
74
+ values: {
75
+ step: stepNumber,
76
+ total: totalSteps,
77
+ title: step.title
78
+ }
79
+ });
80
+ var describedBy = [];
81
+ if (step.errorMessage && step.status === 'error') {
82
+ describedBy.push("stepper-error-" + step.id);
83
+ }
84
+ if (step.disabledReason && step.status === 'disabled') {
85
+ describedBy.push("stepper-reason-" + step.id);
86
+ }
87
+ var focusableProps = isReadOnly ? {} : {
88
+ tabIndex: focusedIndex === index ? 0 : -1,
89
+ onClick: handleClick,
90
+ onKeyDown: handleKeyDown,
91
+ onFocus: function onFocus() {
92
+ if (onFocusStep) onFocusStep(index);
93
+ },
94
+ type: 'button'
95
+ };
96
+ return /*#__PURE__*/React.createElement(StepItemContext.Provider, {
97
+ value: stepItemValue
98
+ }, /*#__PURE__*/React.createElement(StyledStepItem, _extends({
99
+ direction: direction,
100
+ isSubStep: isSubStep,
101
+ isLast: isLast,
102
+ hasSubSteps: !!(subSteps != null && subSteps.length)
103
+ }, passThemeFlag), /*#__PURE__*/React.createElement(StyledStepButton, _extends({
104
+ as: isReadOnly ? 'div' : 'button',
105
+ role: isReadOnly ? 'group' : undefined,
106
+ ref: function ref(el) {
107
+ if (stepRefs) {
108
+ if (el) stepRefs.current.set(index, el);else stepRefs.current["delete"](index);
109
+ }
110
+ },
111
+ "aria-current": isHighlighted ? 'step' : undefined,
112
+ "aria-disabled": isDisabled || undefined,
113
+ "aria-label": ariaLabel,
114
+ "aria-describedby": describedBy.length > 0 ? describedBy.join(' ') : undefined,
115
+ isClickable: isClickable,
116
+ isDisabled: isDisabled,
117
+ isSubStep: isSubStep,
118
+ direction: direction
119
+ }, focusableProps, passThemeFlag), /*#__PURE__*/React.createElement(StepperIndicator, null), /*#__PURE__*/React.createElement(StyledStepContent, _extends({
120
+ direction: direction,
121
+ isSubStep: isSubStep,
122
+ hasDescription: !!step.description
123
+ }, passThemeFlag), /*#__PURE__*/React.createElement(StepperLabel, null), showDescription && /*#__PURE__*/React.createElement(StepperDescription, null), /*#__PURE__*/React.createElement(StepperError, null), /*#__PURE__*/React.createElement(StepperDisabledReason, null))), (showConnector !== undefined ? showConnector : !isLast) && !(subSteps != null && subSteps.length) && /*#__PURE__*/React.createElement(StyledConnector, _extends({
124
+ direction: direction,
125
+ status: step.status,
126
+ "aria-hidden": "true"
127
+ }, passThemeFlag)), !!(subSteps != null && subSteps.length) && /*#__PURE__*/React.createElement(StepConnector, {
128
+ step: step,
129
+ direction: direction
130
+ }, /*#__PURE__*/React.createElement(StyledSubStepsList, _extends({
131
+ direction: direction
132
+ }, passThemeFlag), subSteps))));
133
+ };