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,19 @@
1
+ import React from 'react';
2
+
3
+ import { Box, TimeInput } from 'grommet';
4
+
5
+ export const Simple = () => {
6
+ const onChange = ({ value }: { value?: string }) => {
7
+ console.log('onChange iso time:', value);
8
+ };
9
+
10
+ return (
11
+ <Box pad="large" width="medium">
12
+ <TimeInput format="12" onChange={onChange} />
13
+ </Box>
14
+ );
15
+ };
16
+
17
+ export default {
18
+ title: 'Input/TimeInput/Simple',
19
+ };
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+
3
+ import { Box, Text, TimeInput } from 'grommet';
4
+
5
+ export const Step = () => (
6
+ <Box pad="large" width="medium" gap="small">
7
+ <Text size="small">Minute options increment by 15 (00, 15, 30, 45).</Text>
8
+ <TimeInput format="24" defaultValue="10:30:00" minuteStep={15} />
9
+ </Box>
10
+ );
11
+
12
+ export default {
13
+ title: 'Input/TimeInput/Step',
14
+ };
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+
3
+ import { Box, Heading, ThemeContext, TimeInput } from 'grommet';
4
+
5
+ export const ThemingLightDark = () => (
6
+ <Box gap="xlarge">
7
+ <Box pad="xlarge" background="background-front">
8
+ <Heading level={3}>Light Theme</Heading>
9
+ <TimeInput format="12" defaultValue="12:34:56" />
10
+ </Box>
11
+ <ThemeContext.Extend value={{ dark: true }}>
12
+ <Box pad="xlarge" background="background-front">
13
+ <Heading level={3}>Dark Theme</Heading>
14
+ <TimeInput format="12" defaultValue="12:34:56" />
15
+ </Box>
16
+ </ThemeContext.Extend>
17
+ </Box>
18
+ );
19
+
20
+ export default {
21
+ title: 'Input/TimeInput/Theming Light Dark',
22
+ };
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+
3
+ import { Box, Text, TimeInput } from 'grommet';
4
+
5
+ export const Uncontrolled = () => {
6
+ const onChange = ({ value }: { value?: string }) => {
7
+ console.log('onChange iso time:', value);
8
+ };
9
+
10
+ return (
11
+ <Box pad="large" width="medium" gap="small">
12
+ <Text size="small">
13
+ Uncontrolled input (manages its own internal state).
14
+ </Text>
15
+ <TimeInput format="12" defaultValue="12:34:56" onChange={onChange} />
16
+ </Box>
17
+ );
18
+ };
19
+
20
+ export default {
21
+ title: 'Input/TimeInput/Uncontrolled',
22
+ };
@@ -0,0 +1,355 @@
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
+ /* eslint-disable no-nested-ternary */
5
+ import { useCallback, useMemo, useRef } from 'react';
6
+ import { useSectionedField } from '../../utils/useSectionedField';
7
+ import { defaultSections, hasAnyValue, isoTimeToSections, normalizeToIsoTime, pad, sectionKey, sectionMax, sectionMin, sectionsToIsoTime, SECTION_HOUR, SECTION_MINUTE, SECTION_PERIOD, SECTION_SECOND, defaultHourForFormat } from './utils';
8
+ var separatorBeforeSection = function separatorBeforeSection(section) {
9
+ return section === SECTION_PERIOD ? ' ' : ':';
10
+ };
11
+ var sectionToken = function sectionToken(section) {
12
+ if (section === SECTION_HOUR) return 'hh';
13
+ if (section === SECTION_MINUTE) return 'mm';
14
+ if (section === SECTION_SECOND) return 'ss';
15
+ return 'aa';
16
+ };
17
+ var sectionPattern = function sectionPattern(section) {
18
+ if (section === SECTION_PERIOD) return '(AM|PM)';
19
+ return '(\\d{1,2})';
20
+ };
21
+ var isNumericSection = function isNumericSection(section) {
22
+ return section !== SECTION_PERIOD;
23
+ };
24
+ var parseSectionsValue = function parseSectionsValue(value, format, sectionOrder) {
25
+ if (!value || typeof value !== 'string') return undefined;
26
+ var normalized = value.trim().toUpperCase();
27
+ if (!normalized || !sectionOrder.length) return undefined;
28
+ var pattern = sectionOrder.map(function (section, index) {
29
+ var sectionRegex = sectionPattern(section);
30
+ if (index === 0) return sectionRegex;
31
+ return separatorBeforeSection(section) + "\\s*" + sectionRegex;
32
+ }).join('');
33
+ var regex = new RegExp("^" + pattern + "$");
34
+ var match = normalized.match(regex);
35
+ if (!match) return undefined;
36
+ var parsed = defaultSections(format);
37
+ sectionOrder.forEach(function (section, index) {
38
+ var key = sectionKey(section);
39
+ var captured = match[index + 1];
40
+ if (section === SECTION_PERIOD) {
41
+ parsed[key] = captured;
42
+ } else {
43
+ var next = Number(captured);
44
+ if (!Number.isNaN(next)) parsed[key] = next;
45
+ }
46
+ });
47
+ for (var i = 0; i < sectionOrder.length; i += 1) {
48
+ var section = sectionOrder[i];
49
+ if (isNumericSection(section)) {
50
+ var key = sectionKey(section);
51
+ var next = parsed[key];
52
+ if (next === undefined || next < sectionMin(section, format) || next > sectionMax(section, format)) {
53
+ return undefined;
54
+ }
55
+ }
56
+ }
57
+ return parsed;
58
+ };
59
+ var formatSectionsValue = function formatSectionsValue(_ref) {
60
+ var sections = _ref.sections,
61
+ sectionOrder = _ref.sectionOrder,
62
+ _ref$includeTokens = _ref.includeTokens,
63
+ includeTokens = _ref$includeTokens === void 0 ? false : _ref$includeTokens;
64
+ return sectionOrder.map(function (section, index) {
65
+ var key = sectionKey(section);
66
+ var rawValue = sections[key];
67
+ var rendered = rawValue === undefined ? includeTokens ? sectionToken(section) : '' : section === SECTION_PERIOD ? rawValue : pad(rawValue);
68
+ if (index === 0) return rendered;
69
+ return "" + separatorBeforeSection(section) + rendered;
70
+ }).join('');
71
+ };
72
+ export var useSectionedTimeField = function useSectionedTimeField(_ref2) {
73
+ var format = _ref2.format,
74
+ sectionOrder = _ref2.sectionOrder,
75
+ _ref2$minuteStep = _ref2.minuteStep,
76
+ minuteStep = _ref2$minuteStep === void 0 ? 1 : _ref2$minuteStep,
77
+ value = _ref2.value,
78
+ onCommit = _ref2.onCommit,
79
+ onInvalid = _ref2.onInvalid;
80
+ var editStateRef = useRef({
81
+ section: SECTION_HOUR,
82
+ digits: 0,
83
+ previousValue: undefined,
84
+ firstDigit: undefined
85
+ });
86
+ var parseValue = useCallback(function (nextValue) {
87
+ return isoTimeToSections(normalizeToIsoTime(nextValue), format);
88
+ }, [format]);
89
+ var getDefaultValue = useCallback(function () {
90
+ return defaultSections(format);
91
+ }, [format]);
92
+ var _useSectionedField = useSectionedField({
93
+ value: value,
94
+ parseValue: parseValue,
95
+ defaultValue: getDefaultValue,
96
+ sectionOrder: sectionOrder
97
+ }),
98
+ activeSection = _useSectionedField.activeSection,
99
+ pendingDigits = _useSectionedField.pendingDigits,
100
+ preserveIncompleteSectionsRef = _useSectionedField.preserveIncompleteSectionsRef,
101
+ sections = _useSectionedField.sections,
102
+ setActiveSection = _useSectionedField.setActiveSection,
103
+ setPendingDigits = _useSectionedField.setPendingDigits,
104
+ setSections = _useSectionedField.setSections;
105
+ var displayValue = useMemo(function () {
106
+ if (!hasAnyValue(sections)) return '';
107
+
108
+ // Create a copy of sections with pending digits overlaid for display
109
+ var displaySections = _extends({}, sections);
110
+ var pendingSection = Object.keys(pendingDigits)[0];
111
+ if (pendingSection && pendingDigits[pendingSection] !== undefined) {
112
+ displaySections[pendingSection] = pendingDigits[pendingSection];
113
+ }
114
+ return formatSectionsValue({
115
+ sections: displaySections,
116
+ sectionOrder: sectionOrder,
117
+ includeTokens: true
118
+ });
119
+ }, [sectionOrder, sections, pendingDigits]);
120
+ var commitSections = useCallback(function (nextSections, changedSection) {
121
+ var _nextSections$second;
122
+ setSections(nextSections);
123
+ var complete = sectionOrder.every(function (section) {
124
+ return nextSections[sectionKey(section)] !== undefined;
125
+ });
126
+
127
+ // Check if all numeric sections are valid
128
+ var allValid = sectionOrder.every(function (section) {
129
+ if (!isNumericSection(section)) return true; // skip period
130
+ var key = sectionKey(section);
131
+ var sectionValue = nextSections[key];
132
+ var min = sectionMin(section, format);
133
+ var max = sectionMax(section, format);
134
+ return sectionValue >= min && sectionValue <= max;
135
+ });
136
+ var nextValue = complete && sectionOrder.length && allValid ? sectionsToIsoTime(_extends({}, nextSections, {
137
+ second: (_nextSections$second = nextSections.second) != null ? _nextSections$second : 0
138
+ }), format) : undefined;
139
+
140
+ // Mark as incomplete if: sections incomplete OR some invalid
141
+ var hasIncompleteSections = !complete || !allValid;
142
+ preserveIncompleteSectionsRef.current = hasIncompleteSections && hasAnyValue(nextSections);
143
+ onCommit(nextSections, nextValue, changedSection);
144
+ }, [format, onCommit, preserveIncompleteSectionsRef, sectionOrder, setSections]);
145
+ var setSectionValue = useCallback(function (section, rawValue) {
146
+ var _extends2;
147
+ var key = sectionKey(section);
148
+ var next = _extends({}, sections, (_extends2 = {}, _extends2[key] = rawValue, _extends2));
149
+ commitSections(next, section);
150
+ // Clear any pending first-digit overlay, since it's now stale
151
+ // relative to the section value we just committed.
152
+ setPendingDigits({});
153
+ }, [commitSections, sections, setPendingDigits]);
154
+ var moveSection = useCallback(function (direction) {
155
+ if (!sectionOrder.length) return activeSection;
156
+ var activeIndex = Math.max(0, sectionOrder.indexOf(activeSection));
157
+ var count = sectionOrder.length;
158
+ var nextIndex = (activeIndex + direction + count) % count;
159
+ var nextSection = sectionOrder[nextIndex];
160
+ setActiveSection(nextSection);
161
+ return nextSection;
162
+ }, [activeSection, sectionOrder, setActiveSection]);
163
+ var incrementSection = useCallback(function (section, delta) {
164
+ if (section === SECTION_PERIOD) {
165
+ setSectionValue(section, sections.period === 'AM' ? 'PM' : 'AM');
166
+ return;
167
+ }
168
+ var minValue = sectionMin(section, format);
169
+ var maxValue = sectionMax(section, format);
170
+ var key = sectionKey(section);
171
+ var current = sections[key];
172
+ var step = section === SECTION_MINUTE ? minuteStep : section === SECTION_SECOND ? 1 : 1;
173
+ var next;
174
+ if (step > 1 && (section === SECTION_MINUTE || section === SECTION_SECOND)) {
175
+ var options = Array.from({
176
+ length: Math.ceil((maxValue - minValue + 1) / step)
177
+ }, function (_, index) {
178
+ return minValue + index * step;
179
+ }).filter(function (valueAtIndex) {
180
+ return valueAtIndex <= maxValue;
181
+ });
182
+ var currentIndex = options.indexOf(current);
183
+ if (currentIndex !== -1) {
184
+ var wrappedIndex = ((currentIndex + delta) % options.length + options.length) % options.length;
185
+ next = options[wrappedIndex];
186
+ } else if (delta > 0) {
187
+ var _options$find;
188
+ next = (_options$find = options.find(function (option) {
189
+ return option > (current != null ? current : minValue - 1);
190
+ })) != null ? _options$find : options[0];
191
+ } else {
192
+ var _descending$find;
193
+ var descending = [].concat(options).reverse();
194
+ next = (_descending$find = descending.find(function (option) {
195
+ return option < (current != null ? current : maxValue + 1);
196
+ })) != null ? _descending$find : options[options.length - 1];
197
+ }
198
+ } else {
199
+ var base = current === undefined ? section === SECTION_HOUR ? defaultHourForFormat(format) : minValue : current;
200
+ next = base + delta;
201
+ if (next > maxValue) next = minValue;
202
+ if (next < minValue) next = maxValue;
203
+ }
204
+ setSectionValue(section, next);
205
+ }, [format, minuteStep, sections, setSectionValue]);
206
+ var applyDigit = useCallback(function (digit) {
207
+ if (activeSection === SECTION_PERIOD) return undefined;
208
+ var minValue = sectionMin(activeSection, format);
209
+ var maxValue = sectionMax(activeSection, format);
210
+ var key = sectionKey(activeSection);
211
+ var isSameSection = editStateRef.current.section === activeSection;
212
+ var isSecondDigit = isSameSection && editStateRef.current.digits === 1;
213
+ var currentRaw = sections[key] === undefined ? 0 : sections[key];
214
+ var nextValue;
215
+ if (isSecondDigit) {
216
+ var _editStateRef$current;
217
+ // Use the stored first digit from editState
218
+ var firstDigit = (_editStateRef$current = editStateRef.current.firstDigit) != null ? _editStateRef$current : currentRaw % 10;
219
+ nextValue = firstDigit * 10 + digit;
220
+ editStateRef.current = {
221
+ section: activeSection,
222
+ digits: 0,
223
+ previousValue: editStateRef.current.previousValue,
224
+ firstDigit: undefined
225
+ };
226
+ // Clear pending digits since we're committing now
227
+ setPendingDigits({});
228
+ } else {
229
+ var _setPendingDigits;
230
+ // First digit: store in pending for display only
231
+ nextValue = digit;
232
+ editStateRef.current = {
233
+ section: activeSection,
234
+ digits: 1,
235
+ previousValue: sections[key],
236
+ firstDigit: digit
237
+ };
238
+ // Show the first digit in pending state
239
+ setPendingDigits((_setPendingDigits = {}, _setPendingDigits[key] = digit, _setPendingDigits));
240
+ }
241
+
242
+ // For 2nd digit: validate combined value, but allow invalid 1st digit
243
+ // (allows "0X" patterns in formats where single "0" is invalid)
244
+ if (isSecondDigit && (nextValue < minValue || nextValue > maxValue)) {
245
+ var _editStateRef$current2;
246
+ // Combined value invalid. Try to use first digit for current section
247
+ // and apply second digit to next section (MUI behavior)
248
+ var _firstDigit = (_editStateRef$current2 = editStateRef.current.firstDigit) != null ? _editStateRef$current2 : currentRaw % 10;
249
+ if (_firstDigit >= minValue && _firstDigit <= maxValue) {
250
+ setSectionValue(activeSection, _firstDigit);
251
+
252
+ // Get next section and check if second digit is valid there
253
+ var currentSectionIndex = sectionOrder.indexOf(activeSection);
254
+ var nextSection = sectionOrder[currentSectionIndex + 1];
255
+ if (nextSection && isNumericSection(nextSection)) {
256
+ var nextMinValue = sectionMin(nextSection, format);
257
+ var nextMaxValue = sectionMax(nextSection, format);
258
+
259
+ // If second digit is valid for next section, apply it there
260
+ if (digit >= nextMinValue && digit <= nextMaxValue) {
261
+ setSectionValue(nextSection, digit);
262
+ // Now move to section after that
263
+ return moveSection(2);
264
+ }
265
+ }
266
+
267
+ // If second digit not valid for next section, just move to next
268
+ return moveSection(1);
269
+ }
270
+
271
+ // If even first digit alone is invalid, reject the entry
272
+ onInvalid == null || onInvalid();
273
+ setPendingDigits({});
274
+ return undefined;
275
+ }
276
+
277
+ // MUI Pattern: Determine if we should commit and move to next section
278
+ // shouldGoToNextSection = nextValue * 10 > max || digitCount === 2
279
+ var shouldMoveToNextSection = nextValue * 10 > maxValue || isSecondDigit;
280
+ setSectionValue(activeSection, nextValue);
281
+ if (shouldMoveToNextSection) {
282
+ // Don't move past the last section during digit entry
283
+ // (Tab navigation can still wrap, but digit entry stops at last
284
+ // section)
285
+ var currentIndex = sectionOrder.indexOf(activeSection);
286
+ var isLastSection = currentIndex === sectionOrder.length - 1;
287
+ if (!isLastSection) {
288
+ return moveSection(1);
289
+ }
290
+ }
291
+ return activeSection;
292
+ }, [activeSection, format, moveSection, onInvalid, sections, setSectionValue, setPendingDigits, sectionOrder]);
293
+ var clearActiveSection = useCallback(function () {
294
+ setSectionValue(activeSection, undefined);
295
+ }, [activeSection, setSectionValue]);
296
+ var parsePasted = useCallback(function (pasted) {
297
+ var parsed = parseSectionsValue(pasted, format, sectionOrder);
298
+ if (parsed) {
299
+ return parsed;
300
+ }
301
+ var digits = pasted.replace(/\D/g, '');
302
+ var numericSections = sectionOrder.filter(function (section) {
303
+ return section !== SECTION_PERIOD;
304
+ });
305
+ var hasExplicitPeriod = /\b(AM|PM)\b/i.test(pasted);
306
+ var shouldInferPeriod = format === '12' && sectionOrder.includes(SECTION_PERIOD) && !hasExplicitPeriod;
307
+ if (digits.length >= numericSections.length * 2 && numericSections.length) {
308
+ var next = _extends({}, sections);
309
+ for (var i = 0; i < numericSections.length; i += 1) {
310
+ var section = numericSections[i];
311
+ var parsedNumber = Number(digits.slice(i * 2, i * 2 + 2));
312
+ var minValue = section === SECTION_HOUR && shouldInferPeriod ? 0 : sectionMin(section, format);
313
+ var maxValue = section === SECTION_HOUR && shouldInferPeriod ? 23 : sectionMax(section, format);
314
+ if (Number.isNaN(parsedNumber) || parsedNumber < minValue || parsedNumber > maxValue) {
315
+ return undefined;
316
+ }
317
+ next[sectionKey(section)] = parsedNumber;
318
+ }
319
+ if (sectionOrder.includes(SECTION_PERIOD)) {
320
+ if (hasExplicitPeriod) {
321
+ next.period = /\bPM\b/i.test(pasted) ? 'PM' : 'AM';
322
+ } else if (shouldInferPeriod) {
323
+ var normalizedHour = next.hour;
324
+ if (normalizedHour === 0) {
325
+ next.hour = 12;
326
+ next.period = 'AM';
327
+ } else if (normalizedHour === 12) {
328
+ next.period = 'PM';
329
+ } else if (normalizedHour > 12) {
330
+ next.hour = normalizedHour - 12;
331
+ next.period = 'PM';
332
+ } else {
333
+ next.period = 'AM';
334
+ }
335
+ }
336
+ }
337
+ return next;
338
+ }
339
+ return undefined;
340
+ }, [format, sectionOrder, sections]);
341
+ return {
342
+ activeSection: activeSection,
343
+ clearActiveSection: clearActiveSection,
344
+ displayValue: displayValue,
345
+ incrementSection: incrementSection,
346
+ moveSection: moveSection,
347
+ parsePasted: parsePasted,
348
+ sections: sections,
349
+ setActiveSection: setActiveSection,
350
+ setSectionValue: setSectionValue,
351
+ applyDigit: applyDigit,
352
+ commitSections: commitSections,
353
+ pendingDigits: pendingDigits
354
+ };
355
+ };
@@ -0,0 +1,187 @@
1
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { getSectionKeyFromType, getSectionNameFromType } from '../../utils/sectionHelpers';
4
+ import { pad } from '../../utils/dates';
5
+ export var SECTION_HOUR = 0;
6
+ export var SECTION_MINUTE = 1;
7
+ export var SECTION_SECOND = 2;
8
+ export var SECTION_PERIOD = 3;
9
+ export { pad };
10
+ export var sectionTypeFromSection = function sectionTypeFromSection(section) {
11
+ if (section === SECTION_HOUR) return 'hours';
12
+ if (section === SECTION_MINUTE) return 'minutes';
13
+ if (section === SECTION_SECOND) return 'seconds';
14
+ return 'meridiem';
15
+ };
16
+ export var getSectionName = function getSectionName(section, format, formatMessage, messages) {
17
+ var sectionType = sectionTypeFromSection(section);
18
+ var sectionName = getSectionNameFromType({
19
+ sectionType: sectionType,
20
+ messagePrefix: 'timeInput',
21
+ formatMessage: formatMessage,
22
+ messages: messages
23
+ });
24
+ if (format !== '12' && sectionType === 'meridiem') return undefined;
25
+ return sectionName;
26
+ };
27
+ export var getRanges = function getRanges(format) {
28
+ if (format === '12') {
29
+ return [[0, 2], [3, 5], [6, 8], [9, 11]];
30
+ }
31
+ return [[0, 2], [3, 5], [6, 8]];
32
+ };
33
+
34
+ // TimeInput always transacts (value/defaultValue/onChange) in a canonical
35
+ // 24-hour ISO time string ("HH:MM:SS"), regardless of the display `format`
36
+ // prop.
37
+ export var ISO_TIME_REGEX = /^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)$/;
38
+ export var normalizeToIsoTime = function normalizeToIsoTime(value) {
39
+ if (typeof value !== 'string' || !value.trim()) return undefined;
40
+ var trimmed = value.trim();
41
+ if (ISO_TIME_REGEX.test(trimmed)) return trimmed;
42
+ var parsed = new Date(trimmed);
43
+ if (Number.isNaN(parsed.getTime())) return undefined;
44
+ return pad(parsed.getHours()) + ":" + pad(parsed.getMinutes()) + ":" + pad(parsed.getSeconds());
45
+ };
46
+
47
+ // Converts a canonical 24-hour ISO time string into the section shape the
48
+ // sectioned editor uses for display, deriving 12-hour + period fields when
49
+ // needed.
50
+ export var isoTimeToSections = function isoTimeToSections(isoTime, format) {
51
+ if (typeof isoTime !== 'string') return undefined;
52
+ var match = isoTime.match(ISO_TIME_REGEX);
53
+ if (!match) return undefined;
54
+ var hour24 = Number(match[1]);
55
+ var minute = Number(match[2]);
56
+ var second = Number(match[3]);
57
+ if (format === '12') {
58
+ var period = hour24 < 12 ? 'AM' : 'PM';
59
+ var hour = hour24 % 12 || 12;
60
+ return {
61
+ hour: hour,
62
+ minute: minute,
63
+ second: second,
64
+ period: period
65
+ };
66
+ }
67
+ return {
68
+ hour: hour24,
69
+ minute: minute,
70
+ second: second
71
+ };
72
+ };
73
+ export var sectionsToIsoTime = function sectionsToIsoTime(sections, format) {
74
+ if (sections.hour === undefined || sections.minute === undefined || sections.second === undefined) {
75
+ return undefined;
76
+ }
77
+ var hour24 = sections.hour;
78
+ if (format === '12') {
79
+ var period = sections.period || 'AM';
80
+ hour24 = sections.hour % 12;
81
+ if (period === 'PM') hour24 += 12;
82
+ }
83
+ return pad(hour24) + ":" + pad(sections.minute) + ":" + pad(sections.second);
84
+ };
85
+ export var parseTime = function parseTime(value, format) {
86
+ if (!value || typeof value !== 'string') return undefined;
87
+ var trimmed = value.trim().toUpperCase();
88
+ if (format === '12') {
89
+ var _match = trimmed.match(/^(\d{1,2}):(\d{2}):(\d{2})\s*(AM|PM)$/);
90
+ if (!_match) return undefined;
91
+ var _hour = Number(_match[1]);
92
+ var _minute = Number(_match[2]);
93
+ var _second = Number(_match[3]);
94
+ var period = _match[4];
95
+ if (Number.isNaN(_hour) || Number.isNaN(_minute) || Number.isNaN(_second) || _hour < 1 || _hour > 12 || _minute < 0 || _minute > 59 || _second < 0 || _second > 59) {
96
+ return undefined;
97
+ }
98
+ return {
99
+ hour: _hour,
100
+ minute: _minute,
101
+ second: _second,
102
+ period: period
103
+ };
104
+ }
105
+ var match = trimmed.match(/^(\d{1,2}):(\d{2}):(\d{2})$/);
106
+ if (!match) return undefined;
107
+ var hour = Number(match[1]);
108
+ var minute = Number(match[2]);
109
+ var second = Number(match[3]);
110
+ if (Number.isNaN(hour) || Number.isNaN(minute) || Number.isNaN(second) || hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59) {
111
+ return undefined;
112
+ }
113
+ return {
114
+ hour: hour,
115
+ minute: minute,
116
+ second: second
117
+ };
118
+ };
119
+ export var formatTime = function formatTime(time, format) {
120
+ if (!time) return undefined;
121
+ if (format === '12') {
122
+ return pad(time.hour) + ":" + pad(time.minute) + ":" + pad(time.second) + " " + (time.period || 'AM');
123
+ }
124
+ return pad(time.hour) + ":" + pad(time.minute) + ":" + pad(time.second);
125
+ };
126
+ export var defaultSections = function defaultSections(format) {
127
+ return format === '12' ? {
128
+ hour: undefined,
129
+ minute: undefined,
130
+ second: undefined,
131
+ period: undefined
132
+ } : {
133
+ hour: undefined,
134
+ minute: undefined,
135
+ second: undefined
136
+ };
137
+ };
138
+ export var hasAnyValue = function hasAnyValue(sections) {
139
+ return sections.hour !== undefined || sections.minute !== undefined || sections.second !== undefined || sections.period !== undefined;
140
+ };
141
+ export var sectionMax = function sectionMax(section, format) {
142
+ if (section === SECTION_HOUR) return format === '12' ? 12 : 23;
143
+ return 59;
144
+ };
145
+ export var sectionMin = function sectionMin(section, format) {
146
+ if (section === SECTION_HOUR) return format === '12' ? 1 : 0;
147
+ return 0;
148
+ };
149
+ export var defaultHourForFormat = function defaultHourForFormat(format) {
150
+ return format === '12' ? 12 : 0;
151
+ };
152
+ export var sectionKey = function sectionKey(section) {
153
+ var sectionType = sectionTypeFromSection(section);
154
+ return getSectionKeyFromType(sectionType);
155
+ };
156
+ export var getSectionAriaMeta = function getSectionAriaMeta(_ref) {
157
+ var _sections$key;
158
+ var section = _ref.section,
159
+ format = _ref.format,
160
+ sections = _ref.sections;
161
+ if (section === SECTION_PERIOD) {
162
+ return {
163
+ now: sections.period === 'PM' ? 1 : 0,
164
+ min: 0,
165
+ max: 1
166
+ };
167
+ }
168
+ var key = sectionKey(section);
169
+ var min = sectionMin(section, format);
170
+ var max = sectionMax(section, format);
171
+ var now = (_sections$key = sections[key]) != null ? _sections$key : section === SECTION_HOUR ? defaultHourForFormat(format) : min;
172
+ return {
173
+ now: now,
174
+ min: min,
175
+ max: max
176
+ };
177
+ };
178
+ export var getActiveSectionAriaMeta = function getActiveSectionAriaMeta(_ref2) {
179
+ var activeSection = _ref2.activeSection,
180
+ format = _ref2.format,
181
+ sections = _ref2.sections;
182
+ return getSectionAriaMeta({
183
+ section: activeSection,
184
+ format: format,
185
+ sections: sections
186
+ });
187
+ };
@@ -0,0 +1,11 @@
1
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import styled from 'styled-components';
4
+ import { styledComponentsConfig } from '../../utils';
5
+
6
+ // Programmatic focus target for step transitions (tabIndex={-1}); no visible
7
+ // focus indication — screen readers announce via aria-live on this element.
8
+ export var StyledWizardFocusAnchor = styled.div.withConfig(styledComponentsConfig).withConfig({
9
+ displayName: "StyledWizard__StyledWizardFocusAnchor",
10
+ componentId: "sc-1o4qqu4-0"
11
+ })(["outline:none;"]);