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,689 @@
1
+ var _excluded = ["defaultValue", "disabled", "format", "id", "inline", "messages", "minuteStep", "name", "onChange", "onPartialChange", "readOnly", "showSeconds", "value"],
2
+ _excluded2 = ["plain", "focusIndicator"];
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
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
6
+ // SPDX-License-Identifier: Apache-2.0
7
+ import React, { forwardRef, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
8
+ import { Clock as GrommetClockIcon } from 'grommet-icons/icons/Clock';
9
+ import { AnnounceContext } from '../../contexts/AnnounceContext';
10
+ import { MessageContext } from '../../contexts/MessageContext';
11
+ import { useForwardedRef } from '../../utils';
12
+ import { normalizeStep } from '../../utils/dates';
13
+ import { useThemeValue } from '../../utils/useThemeValue';
14
+ import { getSectionKeyFromType, getSectionTokenFromType } from '../../utils/sectionHelpers';
15
+ import { Box } from '../Box';
16
+ import { Button } from '../Button';
17
+ import { FormContext } from '../Form';
18
+ import { Keyboard } from '../Keyboard';
19
+ import { StyledTimeInputDisplay, StyledTimeInputField, StyledTimeInputSegment, StyledTimeInputSeparator, StyledTimeInputContainer, StyledTimeInput } from './StyledTimeInput';
20
+ import { TimeInputPopup } from './TimeInputPopup';
21
+ import { TimeInputPropTypes } from './propTypes';
22
+ import { useSectionedTimeField } from './useSectionedTimeField';
23
+ import { getSectionAriaMeta, getSectionName, pad, sectionTypeFromSection, SECTION_HOUR, SECTION_MINUTE, SECTION_PERIOD, SECTION_SECOND } from './utils';
24
+ var getDisplaySectionKey = function getDisplaySectionKey(section) {
25
+ if (section === SECTION_HOUR) return 'hour';
26
+ if (section === SECTION_MINUTE) return 'minute';
27
+ if (section === SECTION_SECOND) return 'second';
28
+ return 'period';
29
+ };
30
+ var getDisplaySectionPrefix = function getDisplaySectionPrefix(section, index) {
31
+ if (index === 0) return '';
32
+ return section === SECTION_PERIOD ? ' ' : ':';
33
+ };
34
+ var getDisplaySectionText = function getDisplaySectionText(_ref) {
35
+ var key = _ref.key,
36
+ section = _ref.section,
37
+ sections = _ref.sections;
38
+ if (sections[key] === undefined) return getSectionTokenFromType(sectionTypeFromSection(section));
39
+ if (section === SECTION_PERIOD) return sections[key];
40
+ return pad(sections[key]);
41
+ };
42
+ var getSectionOrder = function getSectionOrder(format, showSeconds) {
43
+ if (showSeconds === void 0) {
44
+ showSeconds = format === '12';
45
+ }
46
+ var numericSections = showSeconds ? [SECTION_HOUR, SECTION_MINUTE, SECTION_SECOND] : [SECTION_HOUR, SECTION_MINUTE];
47
+ if (format === '12') {
48
+ return [].concat(numericSections, [SECTION_PERIOD]);
49
+ }
50
+ return numericSections;
51
+ };
52
+ var buildPlaceholder = function buildPlaceholder(sectionOrder) {
53
+ return sectionOrder.map(function (section, index) {
54
+ var token = getSectionTokenFromType(sectionTypeFromSection(section));
55
+ if (index === 0) return token;
56
+ return "" + (section === SECTION_PERIOD ? ' ' : ':') + token;
57
+ }).join('');
58
+ };
59
+
60
+ // When `format` isn't explicitly provided, default to the 12/24-hour
61
+ // convention the browser's default locale uses, rather than hardcoding one.
62
+ var getDefaultFormat = function getDefaultFormat() {
63
+ try {
64
+ var _Intl$DateTimeFormat$ = new Intl.DateTimeFormat(undefined, {
65
+ hour: 'numeric'
66
+ }).resolvedOptions(),
67
+ hour12 = _Intl$DateTimeFormat$.hour12;
68
+ return hour12 ? '12' : '24';
69
+ } catch (_unused) {
70
+ return '24';
71
+ }
72
+ };
73
+ var DEFAULT_FORMAT = getDefaultFormat();
74
+ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
75
+ var _theme$timeInput, _theme$global, _theme$timeInput2;
76
+ var defaultValue = _ref2.defaultValue,
77
+ disabled = _ref2.disabled,
78
+ _ref2$format = _ref2.format,
79
+ format = _ref2$format === void 0 ? DEFAULT_FORMAT : _ref2$format,
80
+ id = _ref2.id,
81
+ _ref2$inline = _ref2.inline,
82
+ inline = _ref2$inline === void 0 ? false : _ref2$inline,
83
+ messages = _ref2.messages,
84
+ _ref2$minuteStep = _ref2.minuteStep,
85
+ minuteStep = _ref2$minuteStep === void 0 ? 1 : _ref2$minuteStep,
86
+ name = _ref2.name,
87
+ onChange = _ref2.onChange,
88
+ onPartialChange = _ref2.onPartialChange,
89
+ _ref2$readOnly = _ref2.readOnly,
90
+ readOnly = _ref2$readOnly === void 0 ? false : _ref2$readOnly,
91
+ showSeconds = _ref2.showSeconds,
92
+ valueArg = _ref2.value,
93
+ rest = _objectWithoutPropertiesLoose(_ref2, _excluded);
94
+ var _useThemeValue = useThemeValue(),
95
+ theme = _useThemeValue.theme,
96
+ passThemeFlag = _useThemeValue.passThemeFlag;
97
+ var announce = useContext(AnnounceContext);
98
+ var _useContext = useContext(MessageContext),
99
+ formatMessage = _useContext.format;
100
+ var formContext = useContext(FormContext);
101
+ var useFormInput = formContext.useFormInput;
102
+ var inputRef = useForwardedRef(refArg);
103
+ var containerRef = useRef();
104
+ var _useFormInput = useFormInput({
105
+ name: name,
106
+ value: valueArg,
107
+ initialValue: defaultValue || ''
108
+ }),
109
+ value = _useFormInput[0],
110
+ setValue = _useFormInput[1];
111
+ useEffect(function () {
112
+ if (process.env.NODE_ENV !== 'production') {
113
+ console.warn('Warning: TimeInput is currently in beta. The API is subject ' + 'to change in future releases.');
114
+ }
115
+ }, []);
116
+ var _formContext$useFormF = formContext.useFormField({}),
117
+ inForm = _formContext$useFormF.inForm;
118
+ var formFieldLabelId = inForm && id ? "grommet-" + id + "__label" : undefined;
119
+ var groupLabel = formFieldLabelId ? undefined : formatMessage({
120
+ id: 'timeInput.inputLabel',
121
+ messages: messages
122
+ });
123
+ var _useState = useState(false),
124
+ open = _useState[0],
125
+ setOpen = _useState[1];
126
+ var _useState2 = useState(false),
127
+ iconFocused = _useState2[0],
128
+ setIconFocused = _useState2[1];
129
+ var _useState3 = useState(false),
130
+ segmentFocused = _useState3[0],
131
+ setSegmentFocused = _useState3[1];
132
+ var segmentRefs = useRef({});
133
+ var plainProp = rest.plain,
134
+ focusIndicatorProp = rest.focusIndicator,
135
+ inputRest = _objectWithoutPropertiesLoose(rest, _excluded2);
136
+ var normalizedMinuteStep = useMemo(function () {
137
+ return normalizeStep(minuteStep);
138
+ }, [minuteStep]);
139
+ var resolvedShowSeconds = showSeconds !== undefined ? showSeconds : format === '12';
140
+ var handleInvalid = useCallback(function () {
141
+ var error = formatMessage({
142
+ id: 'timeInput.invalidTime',
143
+ messages: messages
144
+ });
145
+ announce(error, 'assertive');
146
+ }, [announce, formatMessage, messages]);
147
+ var announceCurrentValue = useCallback(function (nextSections) {
148
+ if (nextSections.hour === undefined || nextSections.minute === undefined || nextSections.second === undefined) return;
149
+ var period = format === '12' ? " " + (nextSections.period || 'AM') : '';
150
+ announce(formatMessage({
151
+ id: 'timeInput.currentValue',
152
+ messages: messages,
153
+ values: {
154
+ hour: nextSections.hour,
155
+ minute: nextSections.minute,
156
+ second: nextSections.second,
157
+ period: period
158
+ }
159
+ }), 'polite');
160
+ }, [announce, format, formatMessage, messages]);
161
+ var sectionOrder = useMemo(function () {
162
+ return getSectionOrder(format, resolvedShowSeconds);
163
+ }, [format, resolvedShowSeconds]);
164
+ var firstSection = sectionOrder[0] || SECTION_HOUR;
165
+ var lastSection = sectionOrder[sectionOrder.length - 1] || SECTION_HOUR;
166
+ var _useSectionedTimeFiel = useSectionedTimeField({
167
+ format: format,
168
+ sectionOrder: sectionOrder,
169
+ minuteStep: normalizedMinuteStep,
170
+ value: value,
171
+ onCommit: function onCommit(_nextSections, nextValue, _changedSection) {
172
+ // Fire partial change on every commit so consumers can update
173
+ // display state even before all sections are filled.
174
+ onPartialChange == null || onPartialChange(_nextSections, _changedSection);
175
+ if (!nextValue) {
176
+ setValue('');
177
+ onChange == null || onChange({
178
+ value: undefined
179
+ });
180
+ return;
181
+ }
182
+ setValue(nextValue);
183
+ onChange == null || onChange({
184
+ value: nextValue
185
+ });
186
+ announceCurrentValue(_nextSections);
187
+ },
188
+ onInvalid: handleInvalid
189
+ }),
190
+ activeSection = _useSectionedTimeFiel.activeSection,
191
+ applyDigit = _useSectionedTimeFiel.applyDigit,
192
+ clearActiveSection = _useSectionedTimeFiel.clearActiveSection,
193
+ commitSections = _useSectionedTimeFiel.commitSections,
194
+ displayValue = _useSectionedTimeFiel.displayValue,
195
+ incrementSection = _useSectionedTimeFiel.incrementSection,
196
+ moveSection = _useSectionedTimeFiel.moveSection,
197
+ parsePasted = _useSectionedTimeFiel.parsePasted,
198
+ sections = _useSectionedTimeFiel.sections,
199
+ setActiveSection = _useSectionedTimeFiel.setActiveSection,
200
+ setSectionValue = _useSectionedTimeFiel.setSectionValue,
201
+ pendingDigits = _useSectionedTimeFiel.pendingDigits;
202
+
203
+ // Builds the announcement text for a given section: its current value
204
+ // (e.g. "3 hours") if it has one, or just the section name (e.g. "hours
205
+ // selected") when it doesn't yet. Called explicitly on every navigation
206
+ // and edit interaction so screen readers hear meaningful feedback instead
207
+ // of the raw separator/placeholder characters in the native input value.
208
+ var getSectionValueAnnouncement = useCallback(function (section) {
209
+ var sectionName = getSectionName(section, format, formatMessage, messages);
210
+ if (section === SECTION_PERIOD) {
211
+ if (sections.period === undefined) {
212
+ return formatMessage({
213
+ id: 'timeInput.activeSection',
214
+ messages: messages,
215
+ values: {
216
+ section: sectionName
217
+ }
218
+ });
219
+ }
220
+ return formatMessage({
221
+ id: 'timeInput.activePeriodValue',
222
+ messages: messages,
223
+ values: {
224
+ period: sections.period
225
+ }
226
+ });
227
+ }
228
+ var sectionKey = getSectionKeyFromType(sectionTypeFromSection(section));
229
+ var sectionValue = sections[sectionKey];
230
+ if (sectionValue === undefined) {
231
+ return formatMessage({
232
+ id: 'timeInput.activeSection',
233
+ messages: messages,
234
+ values: {
235
+ section: sectionName
236
+ }
237
+ });
238
+ }
239
+ return formatMessage({
240
+ id: 'timeInput.activeSectionValue',
241
+ messages: messages,
242
+ values: {
243
+ value: sectionValue,
244
+ section: sectionName
245
+ }
246
+ });
247
+ }, [format, formatMessage, messages, sections]);
248
+ var focusSection = useCallback(function (section) {
249
+ var target = segmentRefs.current[section];
250
+ if (target) {
251
+ target.focus();
252
+ }
253
+ }, []);
254
+ var placeholder = useMemo(function () {
255
+ return buildPlaceholder(sectionOrder);
256
+ }, [sectionOrder]);
257
+ var inputValue = displayValue || placeholder;
258
+ var hasDisplayValue = !!displayValue;
259
+ var displaySections = useMemo(function () {
260
+ // Merge sections with pending digits for display
261
+ var displaySectionsData = _extends({}, sections);
262
+ var pendingSection = Object.keys(pendingDigits)[0];
263
+ if (pendingSection && pendingDigits[pendingSection] !== undefined) {
264
+ displaySectionsData[pendingSection] = pendingDigits[pendingSection];
265
+ }
266
+ return sectionOrder.map(function (section, index) {
267
+ var key = getDisplaySectionKey(section);
268
+ return {
269
+ section: section,
270
+ prefix: getDisplaySectionPrefix(section, index),
271
+ text: getDisplaySectionText({
272
+ key: key,
273
+ section: section,
274
+ sections: displaySectionsData
275
+ }),
276
+ filled: displaySectionsData[key] !== undefined
277
+ };
278
+ });
279
+ }, [sectionOrder, sections, pendingDigits]);
280
+ var onDisplaySectionMouseDown = useCallback(function (section, event) {
281
+ if (readOnly) return;
282
+ if (disabled) return;
283
+ if (event.button !== 0) return;
284
+ if (event.defaultPrevented) return;
285
+ event.preventDefault();
286
+ event.stopPropagation();
287
+ setSegmentFocused(true);
288
+ setActiveSection(section);
289
+ focusSection(section);
290
+ }, [disabled, focusSection, readOnly, setSegmentFocused, setActiveSection]);
291
+ var onDisplayMouseDown = useCallback(function (event) {
292
+ var _sectionNode$dataset;
293
+ if (readOnly) return;
294
+ if (event.button !== 0) return;
295
+ if (event.defaultPrevented) return;
296
+ var sectionNode = event.target.closest == null ? void 0 : event.target.closest('[data-section]');
297
+ if ((sectionNode == null || (_sectionNode$dataset = sectionNode.dataset) == null ? void 0 : _sectionNode$dataset.section) !== undefined) {
298
+ var section = Number(sectionNode.dataset.section);
299
+ if (!Number.isNaN(section)) {
300
+ onDisplaySectionMouseDown(section, event);
301
+ return;
302
+ }
303
+ }
304
+ var nodes = Array.from(event.currentTarget.querySelectorAll('[data-section]'));
305
+ if (nodes.length) {
306
+ var _sectionFromBounds$no;
307
+ var x = event.clientX;
308
+ var sectionsWithRects = nodes.map(function (node) {
309
+ return {
310
+ node: node,
311
+ rect: node.getBoundingClientRect()
312
+ };
313
+ }).sort(function (a, b) {
314
+ return a.rect.left - b.rect.left;
315
+ });
316
+ var sectionFromBounds = sectionsWithRects.find(function (_ref3) {
317
+ var rect = _ref3.rect;
318
+ return x >= rect.left && x <= rect.right;
319
+ });
320
+ if ((sectionFromBounds == null || (_sectionFromBounds$no = sectionFromBounds.node) == null || (_sectionFromBounds$no = _sectionFromBounds$no.dataset) == null ? void 0 : _sectionFromBounds$no.section) !== undefined) {
321
+ var _section = Number(sectionFromBounds.node.dataset.section);
322
+ if (!Number.isNaN(_section)) {
323
+ onDisplaySectionMouseDown(_section, event);
324
+ return;
325
+ }
326
+ }
327
+ var zones = sectionsWithRects.map(function (_ref4, index) {
328
+ var rect = _ref4.rect;
329
+ var prev = sectionsWithRects[index - 1];
330
+ var next = sectionsWithRects[index + 1];
331
+ var start = prev !== undefined ? (prev.rect.right + rect.left) / 2 : Number.NEGATIVE_INFINITY;
332
+ var end = next !== undefined ? (rect.right + next.rect.left) / 2 : Number.POSITIVE_INFINITY;
333
+ return {
334
+ index: index,
335
+ start: start,
336
+ end: end
337
+ };
338
+ });
339
+ var zone = zones.find(function (_ref5) {
340
+ var start = _ref5.start,
341
+ end = _ref5.end;
342
+ return x >= start && x <= end;
343
+ }) || zones[0] || null;
344
+ if (zone) {
345
+ var _sectionsWithRects$zo, _matched$dataset;
346
+ var matched = (_sectionsWithRects$zo = sectionsWithRects[zone.index]) == null ? void 0 : _sectionsWithRects$zo.node;
347
+ if ((matched == null || (_matched$dataset = matched.dataset) == null ? void 0 : _matched$dataset.section) !== undefined) {
348
+ var _section2 = Number(matched.dataset.section);
349
+ if (!Number.isNaN(_section2)) {
350
+ onDisplaySectionMouseDown(_section2, event);
351
+ return;
352
+ }
353
+ }
354
+ }
355
+ }
356
+ event.preventDefault();
357
+ setSegmentFocused(true);
358
+ setActiveSection(firstSection);
359
+ focusSection(firstSection);
360
+ }, [firstSection, focusSection, onDisplaySectionMouseDown, readOnly, setSegmentFocused, setActiveSection]);
361
+ var openPicker = useCallback(function () {
362
+ if (disabled || readOnly) return;
363
+ setActiveSection(firstSection);
364
+ setOpen(true);
365
+ }, [disabled, firstSection, readOnly, setActiveSection]);
366
+ var closePicker = useCallback(function () {
367
+ setOpen(false);
368
+ setTimeout(function () {
369
+ focusSection(activeSection);
370
+ }, 0);
371
+ }, [activeSection, focusSection]);
372
+ var onSegmentFocus = useCallback(function (section) {
373
+ if (!segmentFocused && !readOnly && !disabled && !open) {
374
+ announce(formatMessage({
375
+ id: 'timeInput.openDrop',
376
+ messages: messages
377
+ }));
378
+ }
379
+ setSegmentFocused(true);
380
+ if (readOnly || disabled) return;
381
+ setActiveSection(section);
382
+ }, [announce, disabled, formatMessage, messages, open, readOnly, segmentFocused, setActiveSection]);
383
+ var onSegmentBlur = useCallback(function () {
384
+ requestAnimationFrame(function () {
385
+ var _document = document,
386
+ activeElement = _document.activeElement;
387
+ var isSegmentFocused = Object.values(segmentRefs.current).includes(activeElement);
388
+ if (!isSegmentFocused && activeElement === document.body && !readOnly && !disabled) {
389
+ focusSection(activeSection);
390
+ return;
391
+ }
392
+ if (!isSegmentFocused) {
393
+ setSegmentFocused(false);
394
+ }
395
+ });
396
+ }, [activeSection, disabled, focusSection, readOnly]);
397
+ var onSegmentKeyDown = useCallback(function (section, event) {
398
+ if (readOnly || disabled) return;
399
+ var key = event.key;
400
+ if (activeSection !== section) {
401
+ setActiveSection(section);
402
+ }
403
+ if (key === 'ArrowRight') {
404
+ event.preventDefault();
405
+ var next = moveSection(1);
406
+ setActiveSection(next);
407
+ focusSection(next);
408
+ return;
409
+ }
410
+ if (key === 'ArrowLeft') {
411
+ event.preventDefault();
412
+ var _next = moveSection(-1);
413
+ setActiveSection(_next);
414
+ focusSection(_next);
415
+ return;
416
+ }
417
+ if (key === 'Home') {
418
+ event.preventDefault();
419
+ setActiveSection(firstSection);
420
+ focusSection(firstSection);
421
+ return;
422
+ }
423
+ if (key === 'End') {
424
+ event.preventDefault();
425
+ setActiveSection(lastSection);
426
+ focusSection(lastSection);
427
+ return;
428
+ }
429
+ if (key === 'ArrowUp') {
430
+ event.preventDefault();
431
+ incrementSection(section, open ? -1 : 1);
432
+ return;
433
+ }
434
+ if (key === 'ArrowDown') {
435
+ if (event.altKey) {
436
+ event.preventDefault();
437
+ openPicker();
438
+ return;
439
+ }
440
+ event.preventDefault();
441
+ incrementSection(section, open ? 1 : -1);
442
+ return;
443
+ }
444
+ if (key === 'Delete' || key === 'Backspace') {
445
+ event.preventDefault();
446
+ clearActiveSection();
447
+ return;
448
+ }
449
+ if (key === 'Enter') {
450
+ event.preventDefault();
451
+ if (open) closePicker();
452
+ return;
453
+ }
454
+ if (key === 'Escape' && open) {
455
+ event.preventDefault();
456
+ closePicker();
457
+ return;
458
+ }
459
+ if (key === ' ' || key === 'Spacebar') {
460
+ event.preventDefault();
461
+ openPicker();
462
+ return;
463
+ }
464
+ if (format === '12' && section === SECTION_PERIOD) {
465
+ var lower = key.toLowerCase();
466
+ if (lower === 'a') {
467
+ event.preventDefault();
468
+ setSectionValue(SECTION_PERIOD, 'AM');
469
+ } else if (lower === 'p') {
470
+ event.preventDefault();
471
+ setSectionValue(SECTION_PERIOD, 'PM');
472
+ }
473
+ return;
474
+ }
475
+ if (/^\d$/.test(key)) {
476
+ event.preventDefault();
477
+ var _next2 = applyDigit(Number(key));
478
+ var targetSection = _next2 != null ? _next2 : section;
479
+ setActiveSection(targetSection);
480
+ if (targetSection === section) {
481
+ event.currentTarget.focus();
482
+ } else {
483
+ focusSection(targetSection);
484
+ }
485
+ }
486
+ }, [activeSection, applyDigit, clearActiveSection, closePicker, disabled, firstSection, focusSection, format, incrementSection, lastSection, moveSection, open, openPicker, readOnly, setActiveSection, setSectionValue]);
487
+ useEffect(function () {
488
+ if (!segmentFocused) return;
489
+ if (readOnly || disabled) return;
490
+ var activeSegment = segmentRefs.current[activeSection];
491
+ if (activeSegment && document.activeElement !== activeSegment) {
492
+ activeSegment.focus();
493
+ }
494
+ }, [activeSection, disabled, readOnly, segmentFocused]);
495
+ var onSegmentPaste = useCallback(function (event) {
496
+ if (readOnly) {
497
+ event.preventDefault();
498
+ return;
499
+ }
500
+ var pasted = event.clipboardData.getData('text');
501
+ var parsed = parsePasted(pasted);
502
+ if (!parsed) {
503
+ handleInvalid();
504
+ event.preventDefault();
505
+ return;
506
+ }
507
+ commitSections(parsed);
508
+ event.preventDefault();
509
+ }, [commitSections, handleInvalid, parsePasted, readOnly]);
510
+ var hoursOptions = useMemo(function () {
511
+ return format === '12' ? [12].concat(Array.from({
512
+ length: 11
513
+ }, function (_, index) {
514
+ return index + 1;
515
+ })) : Array.from({
516
+ length: 24
517
+ }, function (_, index) {
518
+ return index;
519
+ });
520
+ }, [format]);
521
+ var minuteOptions = useMemo(function () {
522
+ return Array.from({
523
+ length: Math.ceil(60 / normalizedMinuteStep)
524
+ }, function (_, index) {
525
+ return index * normalizedMinuteStep;
526
+ }).filter(function (valueAtIndex) {
527
+ return valueAtIndex < 60;
528
+ });
529
+ }, [normalizedMinuteStep]);
530
+ var secondOptions = useMemo(function () {
531
+ return Array.from({
532
+ length: 60
533
+ }, function (_, index) {
534
+ return index;
535
+ });
536
+ }, []);
537
+ var showActiveSection = (segmentFocused || open) && !readOnly && !disabled;
538
+ if (inline) {
539
+ return /*#__PURE__*/React.createElement(TimeInputPopup, _extends({
540
+ inline: true,
541
+ activeSection: activeSection,
542
+ format: format,
543
+ formatMessage: formatMessage,
544
+ hoursOptions: hoursOptions,
545
+ incrementSection: incrementSection,
546
+ messages: messages,
547
+ minuteOptions: minuteOptions,
548
+ sectionOrder: sectionOrder,
549
+ secondOptions: secondOptions,
550
+ sections: sections,
551
+ setActiveSection: setActiveSection,
552
+ setSectionValue: setSectionValue
553
+ }, inputRest));
554
+ }
555
+ return /*#__PURE__*/React.createElement(Keyboard, {
556
+ onEsc: open ? closePicker : undefined
557
+ }, /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(StyledTimeInputContainer, _extends({
558
+ ref: containerRef,
559
+ direction: "row",
560
+ border: !plainProp,
561
+ fill: true,
562
+ round: ((_theme$timeInput = theme.timeInput) == null || (_theme$timeInput = _theme$timeInput.container) == null ? void 0 : _theme$timeInput.round) || ((_theme$global = theme.global) == null || (_theme$global = _theme$global.control) == null || (_theme$global = _theme$global.border) == null ? void 0 : _theme$global.radius),
563
+ disabled: disabled,
564
+ readOnlyProp: readOnly,
565
+ focusIndicator: (focusIndicatorProp != null ? focusIndicatorProp : true) && !iconFocused
566
+ }, passThemeFlag), /*#__PURE__*/React.createElement(StyledTimeInputField, passThemeFlag, /*#__PURE__*/React.createElement(StyledTimeInputDisplay, _extends({
567
+ role: "group",
568
+ "aria-label": groupLabel,
569
+ "aria-labelledby": formFieldLabelId,
570
+ onMouseDown: onDisplayMouseDown
571
+ }, passThemeFlag), displaySections.map(function (_ref6) {
572
+ var section = _ref6.section,
573
+ prefix = _ref6.prefix,
574
+ text = _ref6.text,
575
+ filled = _ref6.filled;
576
+ return /*#__PURE__*/React.createElement(React.Fragment, {
577
+ key: section
578
+ }, !!prefix && /*#__PURE__*/React.createElement(StyledTimeInputSeparator, _extends({
579
+ $filled: hasDisplayValue
580
+ }, passThemeFlag), prefix), /*#__PURE__*/React.createElement(StyledTimeInputSegment, _extends({
581
+ ref: function ref(segmentNode) {
582
+ segmentRefs.current[section] = segmentNode;
583
+ },
584
+ tabIndex: !readOnly && !disabled && activeSection === section ? 0 : -1,
585
+ $active: showActiveSection && activeSection === section,
586
+ $filled: filled,
587
+ onFocus: function onFocus() {
588
+ return onSegmentFocus(section);
589
+ },
590
+ onBlur: onSegmentBlur,
591
+ onKeyDown: function onKeyDown(event) {
592
+ return onSegmentKeyDown(section, event);
593
+ },
594
+ onPaste: onSegmentPaste,
595
+ "data-active": showActiveSection && activeSection === section,
596
+ "data-testid": showActiveSection && activeSection === section ? 'time-input-active-section' : undefined,
597
+ "data-section": section
598
+ }, passThemeFlag, {
599
+ "aria-label": getSectionName(section, format, formatMessage, messages),
600
+ role: "spinbutton",
601
+ "aria-disabled": disabled || undefined,
602
+ "aria-readonly": readOnly || undefined,
603
+ "aria-valuenow": getSectionAriaMeta({
604
+ section: section,
605
+ format: format,
606
+ sections: sections
607
+ }).now,
608
+ "aria-valuemin": getSectionAriaMeta({
609
+ section: section,
610
+ format: format,
611
+ sections: sections
612
+ }).min,
613
+ "aria-valuemax": getSectionAriaMeta({
614
+ section: section,
615
+ format: format,
616
+ sections: sections
617
+ }).max,
618
+ "aria-valuetext": getSectionValueAnnouncement(section)
619
+ }), text));
620
+ })), /*#__PURE__*/React.createElement(StyledTimeInput, _extends({
621
+ tabIndex: -1
622
+ }, inputRest, {
623
+ id: id,
624
+ ref: inputRef,
625
+ value: inputValue,
626
+ "aria-hidden": "true",
627
+ disabled: disabled,
628
+ readOnly: true,
629
+ focusIndicator: false,
630
+ plain: true
631
+ }))), name && /*#__PURE__*/React.createElement("input", {
632
+ "aria-hidden": "true",
633
+ name: name,
634
+ readOnly: true,
635
+ tabIndex: -1,
636
+ type: "hidden",
637
+ value: value || ''
638
+ }), !readOnly && /*#__PURE__*/React.createElement(Button, {
639
+ icon: /*#__PURE__*/React.createElement(GrommetClockIcon, null),
640
+ plain: true,
641
+ disabled: disabled,
642
+ margin: (_theme$timeInput2 = theme.timeInput) == null || (_theme$timeInput2 = _theme$timeInput2.button) == null ? void 0 : _theme$timeInput2.margin,
643
+ "aria-label": formatMessage({
644
+ id: 'timeInput.chooseTime',
645
+ messages: messages
646
+ }),
647
+ "aria-haspopup": "dialog",
648
+ "aria-expanded": open,
649
+ "aria-controls": id ? id + "__drop" : undefined,
650
+ onFocus: function onFocus() {
651
+ setIconFocused(true);
652
+ },
653
+ onBlur: function onBlur() {
654
+ setIconFocused(false);
655
+ },
656
+ onClick: open ? closePicker : openPicker
657
+ })), open && /*#__PURE__*/React.createElement(TimeInputPopup, {
658
+ activeSection: activeSection,
659
+ align: {
660
+ top: 'bottom',
661
+ left: 'left'
662
+ },
663
+ dropProps: {
664
+ stretch: false
665
+ },
666
+ format: format,
667
+ formatMessage: formatMessage,
668
+ hoursOptions: hoursOptions,
669
+ id: id,
670
+ incrementSection: incrementSection,
671
+ label: formatMessage({
672
+ id: 'timeInput.chooseTime',
673
+ messages: messages
674
+ }),
675
+ messages: messages,
676
+ minuteOptions: minuteOptions,
677
+ sectionOrder: sectionOrder,
678
+ onClose: closePicker,
679
+ onFocusLeave: closePicker,
680
+ secondOptions: secondOptions,
681
+ sections: sections,
682
+ setActiveSection: setActiveSection,
683
+ setSectionValue: setSectionValue,
684
+ target: containerRef.current
685
+ })));
686
+ });
687
+ TimeInput.displayName = 'TimeInput';
688
+ TimeInput.propTypes = TimeInputPropTypes;
689
+ export { TimeInput };