grommet 2.54.0 → 2.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/components/Button/Button.js +7 -4
  2. package/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +86 -0
  3. package/components/Calendar/Calendar.js +24 -16
  4. package/components/Calendar/index.d.ts +1 -1
  5. package/components/Calendar/stories/CustomHeader.stories.js +6 -1
  6. package/components/Calendar/stories/CustomThemed/CustomSizeHeading.stories.js +6 -1
  7. package/components/Calendar/stories/Dual.stories.js +23 -11
  8. package/components/Calendar/stories/HeaderLevel.stories.js +6 -1
  9. package/components/Calendar/stories/Multiple.stories.js +8 -3
  10. package/components/Calendar/stories/Simple.stories.js +6 -1
  11. package/components/Cards/Cards.js +164 -10
  12. package/components/Cards/StyledCellContainer.js +29 -0
  13. package/components/Cards/index.d.ts +4 -1
  14. package/components/Cards/propTypes.js +2 -0
  15. package/components/Cards/stories/Sizable.stories.js +70 -0
  16. package/components/Cards/stories/onOrder.stories.js +69 -0
  17. package/components/DataFilter/DataFilter.js +21 -28
  18. package/components/DateInput/DateInput.js +57 -24
  19. package/components/DateInput/index.d.ts +1 -0
  20. package/components/DateInput/utils.js +2 -2
  21. package/components/Drop/DropContainer.js +59 -3
  22. package/components/FileInput/FileInput.js +3 -0
  23. package/components/Form/stories/CustomThemed/FieldCustomStates.stories.js +7 -1
  24. package/components/Form/stories/FieldStates.stories.js +7 -1
  25. package/components/FormField/FormField.js +1 -1
  26. package/components/Grommet/Grommet.js +2 -1
  27. package/components/Grommet/index.d.ts +27 -0
  28. package/components/Grommet/propTypes.js +33 -1
  29. package/components/Layer/LayerContainer.d.ts +40 -0
  30. package/components/Select/stories/ChildrenRender.stories.js +28 -55
  31. package/components/SelectMultiple/stories/typescript/Children.stories.tsx +24 -48
  32. package/components/SelectMultiple/stories/typescript/ValueLabel.stories.tsx +88 -0
  33. package/components/Stepper/StepConnector.js +68 -0
  34. package/components/Stepper/Stepper.js +309 -0
  35. package/components/Stepper/StepperContext.js +43 -0
  36. package/components/Stepper/StepperDescription.js +26 -0
  37. package/components/Stepper/StepperHelperText.js +44 -0
  38. package/components/Stepper/StepperIndicator.js +74 -0
  39. package/components/Stepper/StepperLabel.js +41 -0
  40. package/components/Stepper/StepperStep.js +127 -0
  41. package/components/Stepper/StyledStepper.js +124 -0
  42. package/components/Stepper/index.d.ts +80 -0
  43. package/components/Stepper/index.js +18 -0
  44. package/components/Stepper/propTypes.js +35 -0
  45. package/components/Stepper/stories/DisabledSteps.stories.js +45 -0
  46. package/components/Stepper/stories/ErrorStates.stories.js +45 -0
  47. package/components/Stepper/stories/HorizontalSteps.stories.js +50 -0
  48. package/components/Stepper/stories/Interactive.stories.js +60 -0
  49. package/components/Stepper/stories/KeyboardNavigation.stories.js +64 -0
  50. package/components/Stepper/stories/NestedSubSteps.stories.js +70 -0
  51. package/components/Stepper/stories/ReadOnly.stories.js +43 -0
  52. package/components/Stepper/stories/ThemingLightDark.stories.js +58 -0
  53. package/components/Stepper/stories/VerticalSteps.stories.js +67 -0
  54. package/components/Tab/Tab.js +19 -6
  55. package/components/Tabs/Tabs.js +156 -22
  56. package/components/Tag/Tag.js +4 -3
  57. package/components/Tag/index.d.ts +5 -4
  58. package/components/Tag/propTypes.js +3 -2
  59. package/components/TextInput/StyledTextInput.js +4 -2
  60. package/components/TextInput/TextInput.js +1 -0
  61. package/components/TimeInput/README.md +2 -0
  62. package/components/TimeInput/StyledTimeInput.js +73 -0
  63. package/components/TimeInput/TimeInput.js +689 -0
  64. package/components/TimeInput/TimeInputPopup.js +393 -0
  65. package/components/TimeInput/index.d.ts +41 -0
  66. package/components/TimeInput/index.js +6 -0
  67. package/components/TimeInput/propTypes.js +35 -0
  68. package/components/TimeInput/stories/Controlled.stories.tsx +29 -0
  69. package/components/TimeInput/stories/Disabled.stories.tsx +13 -0
  70. package/components/TimeInput/stories/Form.stories.tsx +38 -0
  71. package/components/TimeInput/stories/ReadOnly.stories.tsx +13 -0
  72. package/components/TimeInput/stories/Simple.stories.tsx +19 -0
  73. package/components/TimeInput/stories/Step.stories.tsx +14 -0
  74. package/components/TimeInput/stories/ThemingLightDark.stories.tsx +22 -0
  75. package/components/TimeInput/stories/Uncontrolled.stories.tsx +22 -0
  76. package/components/TimeInput/useSectionedTimeField.js +359 -0
  77. package/components/TimeInput/utils.js +187 -0
  78. package/components/index.d.ts +2 -0
  79. package/components/index.js +12 -0
  80. package/es6/components/Button/Button.js +7 -4
  81. package/es6/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +81 -0
  82. package/es6/components/Calendar/Calendar.js +24 -16
  83. package/es6/components/Calendar/index.d.ts +1 -1
  84. package/es6/components/Calendar/stories/CustomHeader.stories.js +6 -1
  85. package/es6/components/Calendar/stories/CustomThemed/CustomSizeHeading.stories.js +6 -1
  86. package/es6/components/Calendar/stories/Dual.stories.js +23 -11
  87. package/es6/components/Calendar/stories/HeaderLevel.stories.js +6 -1
  88. package/es6/components/Calendar/stories/Multiple.stories.js +8 -3
  89. package/es6/components/Calendar/stories/Simple.stories.js +6 -1
  90. package/es6/components/Cards/Cards.js +165 -12
  91. package/es6/components/Cards/StyledCellContainer.js +24 -0
  92. package/es6/components/Cards/index.d.ts +4 -1
  93. package/es6/components/Cards/propTypes.js +2 -0
  94. package/es6/components/Cards/stories/Sizable.stories.js +65 -0
  95. package/es6/components/Cards/stories/onOrder.stories.js +64 -0
  96. package/es6/components/DataFilter/DataFilter.js +21 -28
  97. package/es6/components/DateInput/DateInput.js +57 -24
  98. package/es6/components/DateInput/index.d.ts +1 -0
  99. package/es6/components/DateInput/utils.js +2 -2
  100. package/es6/components/Drop/DropContainer.js +59 -3
  101. package/es6/components/FileInput/FileInput.js +3 -0
  102. package/es6/components/Form/stories/CustomThemed/FieldCustomStates.stories.js +7 -1
  103. package/es6/components/Form/stories/FieldStates.stories.js +7 -1
  104. package/es6/components/FormField/FormField.js +1 -1
  105. package/es6/components/Grommet/Grommet.js +2 -1
  106. package/es6/components/Grommet/index.d.ts +27 -0
  107. package/es6/components/Grommet/propTypes.js +33 -1
  108. package/es6/components/Layer/LayerContainer.d.ts +40 -0
  109. package/es6/components/Select/stories/ChildrenRender.stories.js +29 -56
  110. package/es6/components/SelectMultiple/stories/typescript/Children.stories.tsx +24 -48
  111. package/es6/components/SelectMultiple/stories/typescript/ValueLabel.stories.tsx +88 -0
  112. package/es6/components/Stepper/StepConnector.js +63 -0
  113. package/es6/components/Stepper/Stepper.js +306 -0
  114. package/es6/components/Stepper/StepperContext.js +39 -0
  115. package/es6/components/Stepper/StepperDescription.js +21 -0
  116. package/es6/components/Stepper/StepperHelperText.js +39 -0
  117. package/es6/components/Stepper/StepperIndicator.js +69 -0
  118. package/es6/components/Stepper/StepperLabel.js +36 -0
  119. package/es6/components/Stepper/StepperStep.js +122 -0
  120. package/es6/components/Stepper/StyledStepper.js +120 -0
  121. package/es6/components/Stepper/index.d.ts +80 -0
  122. package/es6/components/Stepper/index.js +6 -0
  123. package/es6/components/Stepper/propTypes.js +30 -0
  124. package/es6/components/Stepper/stories/DisabledSteps.stories.js +41 -0
  125. package/es6/components/Stepper/stories/ErrorStates.stories.js +41 -0
  126. package/es6/components/Stepper/stories/HorizontalSteps.stories.js +46 -0
  127. package/es6/components/Stepper/stories/Interactive.stories.js +56 -0
  128. package/es6/components/Stepper/stories/KeyboardNavigation.stories.js +60 -0
  129. package/es6/components/Stepper/stories/NestedSubSteps.stories.js +66 -0
  130. package/es6/components/Stepper/stories/ReadOnly.stories.js +39 -0
  131. package/es6/components/Stepper/stories/ThemingLightDark.stories.js +54 -0
  132. package/es6/components/Stepper/stories/VerticalSteps.stories.js +63 -0
  133. package/es6/components/Tab/Tab.js +19 -6
  134. package/es6/components/Tabs/Tabs.js +157 -23
  135. package/es6/components/Tag/Tag.js +4 -3
  136. package/es6/components/Tag/index.d.ts +5 -4
  137. package/es6/components/Tag/propTypes.js +3 -2
  138. package/es6/components/TextInput/StyledTextInput.js +4 -2
  139. package/es6/components/TextInput/TextInput.js +1 -0
  140. package/es6/components/TimeInput/README.md +2 -0
  141. package/es6/components/TimeInput/StyledTimeInput.js +68 -0
  142. package/es6/components/TimeInput/TimeInput.js +685 -0
  143. package/es6/components/TimeInput/TimeInputPopup.js +389 -0
  144. package/es6/components/TimeInput/index.d.ts +41 -0
  145. package/es6/components/TimeInput/index.js +1 -0
  146. package/es6/components/TimeInput/propTypes.js +30 -0
  147. package/es6/components/TimeInput/stories/Controlled.stories.tsx +29 -0
  148. package/es6/components/TimeInput/stories/Disabled.stories.tsx +13 -0
  149. package/es6/components/TimeInput/stories/Form.stories.tsx +38 -0
  150. package/es6/components/TimeInput/stories/ReadOnly.stories.tsx +13 -0
  151. package/es6/components/TimeInput/stories/Simple.stories.tsx +19 -0
  152. package/es6/components/TimeInput/stories/Step.stories.tsx +14 -0
  153. package/es6/components/TimeInput/stories/ThemingLightDark.stories.tsx +22 -0
  154. package/es6/components/TimeInput/stories/Uncontrolled.stories.tsx +22 -0
  155. package/es6/components/TimeInput/useSectionedTimeField.js +356 -0
  156. package/es6/components/TimeInput/utils.js +183 -0
  157. package/es6/components/index.d.ts +2 -0
  158. package/es6/components/index.js +2 -0
  159. package/es6/index.d.ts +2 -0
  160. package/es6/languages/default.json +27 -1
  161. package/es6/themes/base.d.ts +109 -0
  162. package/es6/themes/base.js +208 -0
  163. package/es6/utils/index.d.ts +1 -0
  164. package/es6/utils/styles.js +23 -12
  165. package/grommet.min.js +1 -1
  166. package/grommet.min.js.map +1 -1
  167. package/index.d.ts +2 -0
  168. package/languages/default.json +27 -1
  169. package/package.json +51 -53
  170. package/themes/base.d.ts +109 -0
  171. package/themes/base.js +208 -0
  172. package/utils/index.d.ts +1 -0
  173. package/utils/styles.js +23 -12
  174. package/components/TextInput/stories/CustomThemed/CustomSuggestions.stories.tsx +0 -180
  175. package/components/TextInput/stories/CustomThemed/Themed.stories.js +0 -79
  176. package/es6/components/TextInput/stories/CustomThemed/CustomSuggestions.stories.tsx +0 -180
  177. package/es6/components/TextInput/stories/CustomThemed/Themed.stories.js +0 -74
@@ -0,0 +1,689 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.TimeInput = void 0;
5
+ var _react = _interopRequireWildcard(require("react"));
6
+ var _Clock = require("grommet-icons/icons/Clock");
7
+ var _AnnounceContext = require("../../contexts/AnnounceContext");
8
+ var _MessageContext = require("../../contexts/MessageContext");
9
+ var _utils = require("../../utils");
10
+ var _useThemeValue2 = require("../../utils/useThemeValue");
11
+ var _Box = require("../Box");
12
+ var _Button = require("../Button");
13
+ var _Form = require("../Form");
14
+ var _Keyboard = require("../Keyboard");
15
+ var _StyledTimeInput = require("./StyledTimeInput");
16
+ var _TimeInputPopup = require("./TimeInputPopup");
17
+ var _propTypes = require("./propTypes");
18
+ var _useSectionedTimeField = require("./useSectionedTimeField");
19
+ var _utils2 = require("./utils");
20
+ var _excluded = ["defaultValue", "disabled", "format", "id", "messages", "minuteStep", "name", "onChange", "readOnly", "value"],
21
+ _excluded2 = ["plain", "focusIndicator"];
22
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
23
+ 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); }
24
+ 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; }
25
+ var sectionTypeToSection = {
26
+ hours: _utils2.SECTION_HOUR,
27
+ minutes: _utils2.SECTION_MINUTE,
28
+ seconds: _utils2.SECTION_SECOND,
29
+ meridiem: _utils2.SECTION_PERIOD
30
+ };
31
+ var getSectionKey = function getSectionKey(section) {
32
+ if (section === _utils2.SECTION_HOUR) return 'hour';
33
+ if (section === _utils2.SECTION_MINUTE) return 'minute';
34
+ if (section === _utils2.SECTION_SECOND) return 'second';
35
+ return 'period';
36
+ };
37
+ var getSectionToken = function getSectionToken(section) {
38
+ if (section === _utils2.SECTION_HOUR) return 'hh';
39
+ if (section === _utils2.SECTION_MINUTE) return 'mm';
40
+ if (section === _utils2.SECTION_SECOND) return 'ss';
41
+ return 'aa';
42
+ };
43
+ var getDisplaySectionKey = function getDisplaySectionKey(section) {
44
+ if (section === _utils2.SECTION_HOUR) return 'hour';
45
+ if (section === _utils2.SECTION_MINUTE) return 'minute';
46
+ if (section === _utils2.SECTION_SECOND) return 'second';
47
+ return 'period';
48
+ };
49
+ var getDisplaySectionPrefix = function getDisplaySectionPrefix(section, index) {
50
+ if (index === 0) return '';
51
+ return section === _utils2.SECTION_PERIOD ? ' ' : ':';
52
+ };
53
+ var getDisplaySectionText = function getDisplaySectionText(_ref) {
54
+ var key = _ref.key,
55
+ section = _ref.section,
56
+ sections = _ref.sections;
57
+ if (sections[key] === undefined) return getSectionToken(section);
58
+ if (section === _utils2.SECTION_PERIOD) return sections[key];
59
+ return (0, _utils2.pad)(sections[key]);
60
+ };
61
+ var getSectionOrder = function getSectionOrder(format, views) {
62
+ var normalizedViews = Array.isArray(views) && views.length ? views : ['hours', 'minutes', 'seconds'];
63
+ var numericSections = normalizedViews.filter(function (view) {
64
+ return view !== 'meridiem';
65
+ }).map(function (view) {
66
+ return sectionTypeToSection[view];
67
+ }).filter(function (section) {
68
+ return section !== undefined;
69
+ });
70
+ if (format === '12') {
71
+ var includePeriod = normalizedViews.includes('meridiem') || normalizedViews.includes('hours');
72
+ if (includePeriod) return [].concat(numericSections, [_utils2.SECTION_PERIOD]);
73
+ }
74
+ return numericSections;
75
+ };
76
+ var buildPlaceholder = function buildPlaceholder(sectionOrder) {
77
+ return sectionOrder.map(function (section, index) {
78
+ var token = getSectionToken(section);
79
+ if (index === 0) return token;
80
+ return "" + (section === _utils2.SECTION_PERIOD ? ' ' : ':') + token;
81
+ }).join('');
82
+ };
83
+ var normalizeStep = function normalizeStep(step) {
84
+ var parsed = Number(step);
85
+ if (!Number.isFinite(parsed) || parsed <= 0) return 1;
86
+ return Math.max(1, Math.floor(parsed));
87
+ };
88
+
89
+ // When `format` isn't explicitly provided, default to the 12/24-hour
90
+ // convention the browser's default locale uses, rather than hardcoding one.
91
+ var getDefaultFormat = function getDefaultFormat() {
92
+ try {
93
+ var _Intl$DateTimeFormat$ = new Intl.DateTimeFormat(undefined, {
94
+ hour: 'numeric'
95
+ }).resolvedOptions(),
96
+ hour12 = _Intl$DateTimeFormat$.hour12;
97
+ return hour12 ? '12' : '24';
98
+ } catch (_unused) {
99
+ return '24';
100
+ }
101
+ };
102
+ var DEFAULT_FORMAT = getDefaultFormat();
103
+ var TimeInput = exports.TimeInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, refArg) {
104
+ var _theme$timeInput, _theme$global, _theme$timeInput2;
105
+ var defaultValue = _ref2.defaultValue,
106
+ disabled = _ref2.disabled,
107
+ _ref2$format = _ref2.format,
108
+ format = _ref2$format === void 0 ? DEFAULT_FORMAT : _ref2$format,
109
+ id = _ref2.id,
110
+ messages = _ref2.messages,
111
+ _ref2$minuteStep = _ref2.minuteStep,
112
+ minuteStep = _ref2$minuteStep === void 0 ? 1 : _ref2$minuteStep,
113
+ name = _ref2.name,
114
+ onChange = _ref2.onChange,
115
+ _ref2$readOnly = _ref2.readOnly,
116
+ readOnly = _ref2$readOnly === void 0 ? false : _ref2$readOnly,
117
+ valueArg = _ref2.value,
118
+ rest = _objectWithoutPropertiesLoose(_ref2, _excluded);
119
+ var _useThemeValue = (0, _useThemeValue2.useThemeValue)(),
120
+ theme = _useThemeValue.theme,
121
+ passThemeFlag = _useThemeValue.passThemeFlag;
122
+ var announce = (0, _react.useContext)(_AnnounceContext.AnnounceContext);
123
+ var _useContext = (0, _react.useContext)(_MessageContext.MessageContext),
124
+ formatMessage = _useContext.format;
125
+ var formContext = (0, _react.useContext)(_Form.FormContext);
126
+ var useFormInput = formContext.useFormInput;
127
+ var inputRef = (0, _utils.useForwardedRef)(refArg);
128
+ var containerRef = (0, _react.useRef)();
129
+ var _useFormInput = useFormInput({
130
+ name: name,
131
+ value: valueArg,
132
+ initialValue: defaultValue || ''
133
+ }),
134
+ value = _useFormInput[0],
135
+ setValue = _useFormInput[1];
136
+ (0, _react.useEffect)(function () {
137
+ if (process.env.NODE_ENV !== 'production') {
138
+ console.warn('Warning: TimeInput is currently in beta. The API is subject ' + 'to change in future releases.');
139
+ }
140
+ }, []);
141
+ var _formContext$useFormF = formContext.useFormField({}),
142
+ inForm = _formContext$useFormF.inForm;
143
+ var formFieldLabelId = inForm && id ? "grommet-" + id + "__label" : undefined;
144
+ var groupLabel = formFieldLabelId ? undefined : formatMessage({
145
+ id: 'timeInput.inputLabel',
146
+ messages: messages
147
+ });
148
+ var _useState = (0, _react.useState)(false),
149
+ open = _useState[0],
150
+ setOpen = _useState[1];
151
+ var _useState2 = (0, _react.useState)(false),
152
+ iconFocused = _useState2[0],
153
+ setIconFocused = _useState2[1];
154
+ var _useState3 = (0, _react.useState)(false),
155
+ segmentFocused = _useState3[0],
156
+ setSegmentFocused = _useState3[1];
157
+ var segmentRefs = (0, _react.useRef)({});
158
+ var plainProp = rest.plain,
159
+ focusIndicatorProp = rest.focusIndicator,
160
+ inputRest = _objectWithoutPropertiesLoose(rest, _excluded2);
161
+ var normalizedMinuteStep = (0, _react.useMemo)(function () {
162
+ return normalizeStep(minuteStep);
163
+ }, [minuteStep]);
164
+ var handleInvalid = (0, _react.useCallback)(function () {
165
+ var error = formatMessage({
166
+ id: 'timeInput.invalidTime',
167
+ messages: messages
168
+ });
169
+ announce(error, 'assertive');
170
+ }, [announce, formatMessage, messages]);
171
+ var announceCurrentValue = (0, _react.useCallback)(function (nextSections) {
172
+ if (nextSections.hour === undefined || nextSections.minute === undefined || nextSections.second === undefined) return;
173
+ var period = format === '12' ? " " + (nextSections.period || 'AM') : '';
174
+ announce(formatMessage({
175
+ id: 'timeInput.currentValue',
176
+ messages: messages,
177
+ values: {
178
+ hour: nextSections.hour,
179
+ minute: nextSections.minute,
180
+ second: nextSections.second,
181
+ period: period
182
+ }
183
+ }), 'polite');
184
+ }, [announce, format, formatMessage, messages]);
185
+ var sectionOrder = (0, _react.useMemo)(function () {
186
+ return getSectionOrder(format);
187
+ }, [format]);
188
+ var firstSection = sectionOrder[0] || _utils2.SECTION_HOUR;
189
+ var lastSection = sectionOrder[sectionOrder.length - 1] || _utils2.SECTION_HOUR;
190
+ var _useSectionedTimeFiel = (0, _useSectionedTimeField.useSectionedTimeField)({
191
+ format: format,
192
+ sectionOrder: sectionOrder,
193
+ minuteStep: normalizedMinuteStep,
194
+ value: value,
195
+ onCommit: function onCommit(_nextSections, nextValue) {
196
+ if (!nextValue) {
197
+ setValue('');
198
+ onChange == null || onChange({
199
+ value: undefined
200
+ });
201
+ return;
202
+ }
203
+ setValue(nextValue);
204
+ onChange == null || onChange({
205
+ value: nextValue
206
+ });
207
+ announceCurrentValue(_nextSections);
208
+ },
209
+ onInvalid: handleInvalid
210
+ }),
211
+ activeSection = _useSectionedTimeFiel.activeSection,
212
+ applyDigit = _useSectionedTimeFiel.applyDigit,
213
+ clearActiveSection = _useSectionedTimeFiel.clearActiveSection,
214
+ commitSections = _useSectionedTimeFiel.commitSections,
215
+ displayValue = _useSectionedTimeFiel.displayValue,
216
+ incrementSection = _useSectionedTimeFiel.incrementSection,
217
+ moveSection = _useSectionedTimeFiel.moveSection,
218
+ parsePasted = _useSectionedTimeFiel.parsePasted,
219
+ sections = _useSectionedTimeFiel.sections,
220
+ setActiveSection = _useSectionedTimeFiel.setActiveSection,
221
+ setSectionValue = _useSectionedTimeFiel.setSectionValue,
222
+ pendingDigits = _useSectionedTimeFiel.pendingDigits;
223
+
224
+ // Builds the announcement text for a given section: its current value
225
+ // (e.g. "3 hours") if it has one, or just the section name (e.g. "hours
226
+ // selected") when it doesn't yet. Called explicitly on every navigation
227
+ // and edit interaction so screen readers hear meaningful feedback instead
228
+ // of the raw separator/placeholder characters in the native input value.
229
+ var getSectionValueAnnouncement = (0, _react.useCallback)(function (section) {
230
+ var sectionName = (0, _utils2.getSectionName)(section, format, formatMessage, messages);
231
+ if (section === _utils2.SECTION_PERIOD) {
232
+ if (sections.period === undefined) {
233
+ return formatMessage({
234
+ id: 'timeInput.activeSection',
235
+ messages: messages,
236
+ values: {
237
+ section: sectionName
238
+ }
239
+ });
240
+ }
241
+ return formatMessage({
242
+ id: 'timeInput.activePeriodValue',
243
+ messages: messages,
244
+ values: {
245
+ period: sections.period
246
+ }
247
+ });
248
+ }
249
+ var sectionKey = getSectionKey(section);
250
+ var sectionValue = sections[sectionKey];
251
+ if (sectionValue === undefined) {
252
+ return formatMessage({
253
+ id: 'timeInput.activeSection',
254
+ messages: messages,
255
+ values: {
256
+ section: sectionName
257
+ }
258
+ });
259
+ }
260
+ return formatMessage({
261
+ id: 'timeInput.activeSectionValue',
262
+ messages: messages,
263
+ values: {
264
+ value: sectionValue,
265
+ section: sectionName
266
+ }
267
+ });
268
+ }, [format, formatMessage, messages, sections]);
269
+ var focusSection = (0, _react.useCallback)(function (section) {
270
+ var target = segmentRefs.current[section];
271
+ if (target) {
272
+ target.focus();
273
+ }
274
+ }, []);
275
+ var placeholder = (0, _react.useMemo)(function () {
276
+ return buildPlaceholder(sectionOrder);
277
+ }, [sectionOrder]);
278
+ var inputValue = displayValue || placeholder;
279
+ var hasDisplayValue = !!displayValue;
280
+ var displaySections = (0, _react.useMemo)(function () {
281
+ // Merge sections with pending digits for display
282
+ var displaySectionsData = _extends({}, sections);
283
+ var pendingSection = Object.keys(pendingDigits)[0];
284
+ if (pendingSection && pendingDigits[pendingSection] !== undefined) {
285
+ displaySectionsData[pendingSection] = pendingDigits[pendingSection];
286
+ }
287
+ return sectionOrder.map(function (section, index) {
288
+ var key = getDisplaySectionKey(section);
289
+ return {
290
+ section: section,
291
+ prefix: getDisplaySectionPrefix(section, index),
292
+ text: getDisplaySectionText({
293
+ key: key,
294
+ section: section,
295
+ sections: displaySectionsData
296
+ }),
297
+ filled: displaySectionsData[key] !== undefined
298
+ };
299
+ });
300
+ }, [sectionOrder, sections, pendingDigits]);
301
+ var onDisplaySectionMouseDown = (0, _react.useCallback)(function (section, event) {
302
+ if (readOnly) return;
303
+ if (disabled) return;
304
+ if (event.button !== 0) return;
305
+ if (event.defaultPrevented) return;
306
+ event.preventDefault();
307
+ event.stopPropagation();
308
+ setSegmentFocused(true);
309
+ setActiveSection(section);
310
+ focusSection(section);
311
+ }, [disabled, focusSection, readOnly, setSegmentFocused, setActiveSection]);
312
+ var onDisplayMouseDown = (0, _react.useCallback)(function (event) {
313
+ var _sectionNode$dataset;
314
+ if (readOnly) return;
315
+ if (event.button !== 0) return;
316
+ if (event.defaultPrevented) return;
317
+ var sectionNode = event.target.closest == null ? void 0 : event.target.closest('[data-section]');
318
+ if ((sectionNode == null || (_sectionNode$dataset = sectionNode.dataset) == null ? void 0 : _sectionNode$dataset.section) !== undefined) {
319
+ var section = Number(sectionNode.dataset.section);
320
+ if (!Number.isNaN(section)) {
321
+ onDisplaySectionMouseDown(section, event);
322
+ return;
323
+ }
324
+ }
325
+ var nodes = Array.from(event.currentTarget.querySelectorAll('[data-section]'));
326
+ if (nodes.length) {
327
+ var _sectionFromBounds$no;
328
+ var x = event.clientX;
329
+ var sectionsWithRects = nodes.map(function (node) {
330
+ return {
331
+ node: node,
332
+ rect: node.getBoundingClientRect()
333
+ };
334
+ }).sort(function (a, b) {
335
+ return a.rect.left - b.rect.left;
336
+ });
337
+ var sectionFromBounds = sectionsWithRects.find(function (_ref3) {
338
+ var rect = _ref3.rect;
339
+ return x >= rect.left && x <= rect.right;
340
+ });
341
+ if ((sectionFromBounds == null || (_sectionFromBounds$no = sectionFromBounds.node) == null || (_sectionFromBounds$no = _sectionFromBounds$no.dataset) == null ? void 0 : _sectionFromBounds$no.section) !== undefined) {
342
+ var _section = Number(sectionFromBounds.node.dataset.section);
343
+ if (!Number.isNaN(_section)) {
344
+ onDisplaySectionMouseDown(_section, event);
345
+ return;
346
+ }
347
+ }
348
+ var zones = sectionsWithRects.map(function (_ref4, index) {
349
+ var rect = _ref4.rect;
350
+ var prev = sectionsWithRects[index - 1];
351
+ var next = sectionsWithRects[index + 1];
352
+ var start = prev !== undefined ? (prev.rect.right + rect.left) / 2 : Number.NEGATIVE_INFINITY;
353
+ var end = next !== undefined ? (rect.right + next.rect.left) / 2 : Number.POSITIVE_INFINITY;
354
+ return {
355
+ index: index,
356
+ start: start,
357
+ end: end
358
+ };
359
+ });
360
+ var zone = zones.find(function (_ref5) {
361
+ var start = _ref5.start,
362
+ end = _ref5.end;
363
+ return x >= start && x <= end;
364
+ }) || zones[0] || null;
365
+ if (zone) {
366
+ var _sectionsWithRects$zo, _matched$dataset;
367
+ var matched = (_sectionsWithRects$zo = sectionsWithRects[zone.index]) == null ? void 0 : _sectionsWithRects$zo.node;
368
+ if ((matched == null || (_matched$dataset = matched.dataset) == null ? void 0 : _matched$dataset.section) !== undefined) {
369
+ var _section2 = Number(matched.dataset.section);
370
+ if (!Number.isNaN(_section2)) {
371
+ onDisplaySectionMouseDown(_section2, event);
372
+ return;
373
+ }
374
+ }
375
+ }
376
+ }
377
+ event.preventDefault();
378
+ setSegmentFocused(true);
379
+ setActiveSection(firstSection);
380
+ focusSection(firstSection);
381
+ }, [firstSection, focusSection, onDisplaySectionMouseDown, readOnly, setSegmentFocused, setActiveSection]);
382
+ var openPicker = (0, _react.useCallback)(function () {
383
+ if (disabled || readOnly) return;
384
+ setActiveSection(firstSection);
385
+ setOpen(true);
386
+ }, [disabled, firstSection, readOnly, setActiveSection]);
387
+ var closePicker = (0, _react.useCallback)(function () {
388
+ setOpen(false);
389
+ setTimeout(function () {
390
+ focusSection(activeSection);
391
+ }, 0);
392
+ }, [activeSection, focusSection]);
393
+ var onSegmentFocus = (0, _react.useCallback)(function (section) {
394
+ if (!segmentFocused && !readOnly && !disabled && !open) {
395
+ announce(formatMessage({
396
+ id: 'timeInput.openDrop',
397
+ messages: messages
398
+ }));
399
+ }
400
+ setSegmentFocused(true);
401
+ if (readOnly || disabled) return;
402
+ setActiveSection(section);
403
+ }, [announce, disabled, formatMessage, messages, open, readOnly, segmentFocused, setActiveSection]);
404
+ var onSegmentBlur = (0, _react.useCallback)(function () {
405
+ requestAnimationFrame(function () {
406
+ var _document = document,
407
+ activeElement = _document.activeElement;
408
+ var isSegmentFocused = Object.values(segmentRefs.current).includes(activeElement);
409
+ if (!isSegmentFocused && activeElement === document.body && !readOnly && !disabled) {
410
+ focusSection(activeSection);
411
+ return;
412
+ }
413
+ if (!isSegmentFocused) {
414
+ setSegmentFocused(false);
415
+ }
416
+ });
417
+ }, [activeSection, disabled, focusSection, readOnly]);
418
+ var onSegmentKeyDown = (0, _react.useCallback)(function (section, event) {
419
+ if (readOnly || disabled) return;
420
+ var key = event.key;
421
+ if (activeSection !== section) {
422
+ setActiveSection(section);
423
+ }
424
+ if (key === 'ArrowRight') {
425
+ event.preventDefault();
426
+ var next = moveSection(1);
427
+ setActiveSection(next);
428
+ focusSection(next);
429
+ return;
430
+ }
431
+ if (key === 'ArrowLeft') {
432
+ event.preventDefault();
433
+ var _next = moveSection(-1);
434
+ setActiveSection(_next);
435
+ focusSection(_next);
436
+ return;
437
+ }
438
+ if (key === 'Home') {
439
+ event.preventDefault();
440
+ setActiveSection(firstSection);
441
+ focusSection(firstSection);
442
+ return;
443
+ }
444
+ if (key === 'End') {
445
+ event.preventDefault();
446
+ setActiveSection(lastSection);
447
+ focusSection(lastSection);
448
+ return;
449
+ }
450
+ if (key === 'ArrowUp') {
451
+ event.preventDefault();
452
+ incrementSection(section, open ? -1 : 1);
453
+ return;
454
+ }
455
+ if (key === 'ArrowDown') {
456
+ if (event.altKey) {
457
+ event.preventDefault();
458
+ openPicker();
459
+ return;
460
+ }
461
+ event.preventDefault();
462
+ incrementSection(section, open ? 1 : -1);
463
+ return;
464
+ }
465
+ if (key === 'Delete' || key === 'Backspace') {
466
+ event.preventDefault();
467
+ clearActiveSection();
468
+ return;
469
+ }
470
+ if (key === 'Enter') {
471
+ event.preventDefault();
472
+ if (open) closePicker();
473
+ return;
474
+ }
475
+ if (key === 'Escape' && open) {
476
+ event.preventDefault();
477
+ closePicker();
478
+ return;
479
+ }
480
+ if (key === ' ' || key === 'Spacebar') {
481
+ event.preventDefault();
482
+ openPicker();
483
+ return;
484
+ }
485
+ if (format === '12' && section === _utils2.SECTION_PERIOD) {
486
+ var lower = key.toLowerCase();
487
+ if (lower === 'a') {
488
+ event.preventDefault();
489
+ setSectionValue(_utils2.SECTION_PERIOD, 'AM');
490
+ } else if (lower === 'p') {
491
+ event.preventDefault();
492
+ setSectionValue(_utils2.SECTION_PERIOD, 'PM');
493
+ }
494
+ return;
495
+ }
496
+ if (/^\d$/.test(key)) {
497
+ event.preventDefault();
498
+ var _next2 = applyDigit(Number(key));
499
+ var targetSection = _next2 != null ? _next2 : section;
500
+ setActiveSection(targetSection);
501
+ if (targetSection === section) {
502
+ event.currentTarget.focus();
503
+ } else {
504
+ focusSection(targetSection);
505
+ }
506
+ }
507
+ }, [activeSection, applyDigit, clearActiveSection, closePicker, disabled, firstSection, focusSection, format, incrementSection, lastSection, moveSection, open, openPicker, readOnly, setActiveSection, setSectionValue]);
508
+ (0, _react.useEffect)(function () {
509
+ if (!segmentFocused) return;
510
+ if (readOnly || disabled) return;
511
+ var activeSegment = segmentRefs.current[activeSection];
512
+ if (activeSegment && document.activeElement !== activeSegment) {
513
+ activeSegment.focus();
514
+ }
515
+ }, [activeSection, disabled, readOnly, segmentFocused]);
516
+ var onSegmentPaste = (0, _react.useCallback)(function (event) {
517
+ if (readOnly) {
518
+ event.preventDefault();
519
+ return;
520
+ }
521
+ var pasted = event.clipboardData.getData('text');
522
+ var parsed = parsePasted(pasted);
523
+ if (!parsed) {
524
+ handleInvalid();
525
+ event.preventDefault();
526
+ return;
527
+ }
528
+ commitSections(parsed);
529
+ event.preventDefault();
530
+ }, [commitSections, handleInvalid, parsePasted, readOnly]);
531
+ var hoursOptions = (0, _react.useMemo)(function () {
532
+ return Array.from({
533
+ length: format === '12' ? 12 : 24
534
+ }, function (_, index) {
535
+ return format === '12' ? index + 1 : index;
536
+ });
537
+ }, [format]);
538
+ var minuteOptions = (0, _react.useMemo)(function () {
539
+ return Array.from({
540
+ length: Math.ceil(60 / normalizedMinuteStep)
541
+ }, function (_, index) {
542
+ return index * normalizedMinuteStep;
543
+ }).filter(function (valueAtIndex) {
544
+ return valueAtIndex < 60;
545
+ });
546
+ }, [normalizedMinuteStep]);
547
+ var secondOptions = (0, _react.useMemo)(function () {
548
+ return Array.from({
549
+ length: 60
550
+ }, function (_, index) {
551
+ return index;
552
+ });
553
+ }, []);
554
+ var showActiveSection = (segmentFocused || open) && !readOnly && !disabled;
555
+ return /*#__PURE__*/_react["default"].createElement(_Keyboard.Keyboard, {
556
+ onEsc: open ? closePicker : undefined
557
+ }, /*#__PURE__*/_react["default"].createElement(_Box.Box, null, /*#__PURE__*/_react["default"].createElement(_StyledTimeInput.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["default"].createElement(_StyledTimeInput.StyledTimeInputField, passThemeFlag, /*#__PURE__*/_react["default"].createElement(_StyledTimeInput.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["default"].createElement(_react["default"].Fragment, {
577
+ key: section
578
+ }, !!prefix && /*#__PURE__*/_react["default"].createElement(_StyledTimeInput.StyledTimeInputSeparator, _extends({
579
+ $filled: hasDisplayValue
580
+ }, passThemeFlag), prefix), /*#__PURE__*/_react["default"].createElement(_StyledTimeInput.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": (0, _utils2.getSectionName)(section, format, formatMessage, messages),
600
+ role: "spinbutton",
601
+ "aria-disabled": disabled || undefined,
602
+ "aria-readonly": readOnly || undefined,
603
+ "aria-valuenow": (0, _utils2.getSectionAriaMeta)({
604
+ section: section,
605
+ format: format,
606
+ sections: sections
607
+ }).now,
608
+ "aria-valuemin": (0, _utils2.getSectionAriaMeta)({
609
+ section: section,
610
+ format: format,
611
+ sections: sections
612
+ }).min,
613
+ "aria-valuemax": (0, _utils2.getSectionAriaMeta)({
614
+ section: section,
615
+ format: format,
616
+ sections: sections
617
+ }).max,
618
+ "aria-valuetext": getSectionValueAnnouncement(section)
619
+ }), text));
620
+ })), /*#__PURE__*/_react["default"].createElement(_StyledTimeInput.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["default"].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["default"].createElement(_Button.Button, {
639
+ icon: /*#__PURE__*/_react["default"].createElement(_Clock.Clock, 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["default"].createElement(_TimeInputPopup.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
+ moveSection: moveSection,
678
+ sectionOrder: sectionOrder,
679
+ onClose: closePicker,
680
+ onFocusLeave: closePicker,
681
+ secondOptions: secondOptions,
682
+ sections: sections,
683
+ setActiveSection: setActiveSection,
684
+ setSectionValue: setSectionValue,
685
+ target: containerRef.current
686
+ })));
687
+ });
688
+ TimeInput.displayName = 'TimeInput';
689
+ TimeInput.propTypes = _propTypes.TimeInputPropTypes;