grommet 2.55.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 (109) hide show
  1. package/components/Button/Button.js +7 -4
  2. package/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +86 -0
  3. package/components/FormField/FormField.js +1 -1
  4. package/components/Grommet/index.d.ts +21 -0
  5. package/components/Grommet/propTypes.js +26 -0
  6. package/components/Stepper/StepConnector.js +68 -0
  7. package/components/Stepper/Stepper.js +309 -0
  8. package/components/Stepper/StepperContext.js +43 -0
  9. package/components/Stepper/StepperDescription.js +26 -0
  10. package/components/Stepper/StepperHelperText.js +44 -0
  11. package/components/Stepper/StepperIndicator.js +74 -0
  12. package/components/Stepper/StepperLabel.js +41 -0
  13. package/components/Stepper/StepperStep.js +127 -0
  14. package/components/Stepper/StyledStepper.js +124 -0
  15. package/components/Stepper/index.d.ts +80 -0
  16. package/components/Stepper/index.js +18 -0
  17. package/components/Stepper/propTypes.js +35 -0
  18. package/components/Stepper/stories/DisabledSteps.stories.js +45 -0
  19. package/components/Stepper/stories/ErrorStates.stories.js +45 -0
  20. package/components/Stepper/stories/HorizontalSteps.stories.js +50 -0
  21. package/components/Stepper/stories/Interactive.stories.js +60 -0
  22. package/components/Stepper/stories/KeyboardNavigation.stories.js +64 -0
  23. package/components/Stepper/stories/NestedSubSteps.stories.js +70 -0
  24. package/components/Stepper/stories/ReadOnly.stories.js +43 -0
  25. package/components/Stepper/stories/ThemingLightDark.stories.js +58 -0
  26. package/components/Stepper/stories/VerticalSteps.stories.js +67 -0
  27. package/components/Tab/Tab.js +19 -6
  28. package/components/Tabs/Tabs.js +156 -22
  29. package/components/TimeInput/README.md +2 -0
  30. package/components/TimeInput/StyledTimeInput.js +73 -0
  31. package/components/TimeInput/TimeInput.js +689 -0
  32. package/components/TimeInput/TimeInputPopup.js +393 -0
  33. package/components/TimeInput/index.d.ts +41 -0
  34. package/components/TimeInput/index.js +6 -0
  35. package/components/TimeInput/propTypes.js +35 -0
  36. package/components/TimeInput/stories/Controlled.stories.tsx +29 -0
  37. package/components/TimeInput/stories/Disabled.stories.tsx +13 -0
  38. package/components/TimeInput/stories/Form.stories.tsx +38 -0
  39. package/components/TimeInput/stories/ReadOnly.stories.tsx +13 -0
  40. package/components/TimeInput/stories/Simple.stories.tsx +19 -0
  41. package/components/TimeInput/stories/Step.stories.tsx +14 -0
  42. package/components/TimeInput/stories/ThemingLightDark.stories.tsx +22 -0
  43. package/components/TimeInput/stories/Uncontrolled.stories.tsx +22 -0
  44. package/components/TimeInput/useSectionedTimeField.js +359 -0
  45. package/components/TimeInput/utils.js +187 -0
  46. package/components/index.d.ts +2 -0
  47. package/components/index.js +12 -0
  48. package/es6/components/Button/Button.js +7 -4
  49. package/es6/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +81 -0
  50. package/es6/components/FormField/FormField.js +1 -1
  51. package/es6/components/Grommet/index.d.ts +21 -0
  52. package/es6/components/Grommet/propTypes.js +26 -0
  53. package/es6/components/Stepper/StepConnector.js +63 -0
  54. package/es6/components/Stepper/Stepper.js +306 -0
  55. package/es6/components/Stepper/StepperContext.js +39 -0
  56. package/es6/components/Stepper/StepperDescription.js +21 -0
  57. package/es6/components/Stepper/StepperHelperText.js +39 -0
  58. package/es6/components/Stepper/StepperIndicator.js +69 -0
  59. package/es6/components/Stepper/StepperLabel.js +36 -0
  60. package/es6/components/Stepper/StepperStep.js +122 -0
  61. package/es6/components/Stepper/StyledStepper.js +120 -0
  62. package/es6/components/Stepper/index.d.ts +80 -0
  63. package/es6/components/Stepper/index.js +6 -0
  64. package/es6/components/Stepper/propTypes.js +30 -0
  65. package/es6/components/Stepper/stories/DisabledSteps.stories.js +41 -0
  66. package/es6/components/Stepper/stories/ErrorStates.stories.js +41 -0
  67. package/es6/components/Stepper/stories/HorizontalSteps.stories.js +46 -0
  68. package/es6/components/Stepper/stories/Interactive.stories.js +56 -0
  69. package/es6/components/Stepper/stories/KeyboardNavigation.stories.js +60 -0
  70. package/es6/components/Stepper/stories/NestedSubSteps.stories.js +66 -0
  71. package/es6/components/Stepper/stories/ReadOnly.stories.js +39 -0
  72. package/es6/components/Stepper/stories/ThemingLightDark.stories.js +54 -0
  73. package/es6/components/Stepper/stories/VerticalSteps.stories.js +63 -0
  74. package/es6/components/Tab/Tab.js +19 -6
  75. package/es6/components/Tabs/Tabs.js +157 -23
  76. package/es6/components/TimeInput/README.md +2 -0
  77. package/es6/components/TimeInput/StyledTimeInput.js +68 -0
  78. package/es6/components/TimeInput/TimeInput.js +685 -0
  79. package/es6/components/TimeInput/TimeInputPopup.js +389 -0
  80. package/es6/components/TimeInput/index.d.ts +41 -0
  81. package/es6/components/TimeInput/index.js +1 -0
  82. package/es6/components/TimeInput/propTypes.js +30 -0
  83. package/es6/components/TimeInput/stories/Controlled.stories.tsx +29 -0
  84. package/es6/components/TimeInput/stories/Disabled.stories.tsx +13 -0
  85. package/es6/components/TimeInput/stories/Form.stories.tsx +38 -0
  86. package/es6/components/TimeInput/stories/ReadOnly.stories.tsx +13 -0
  87. package/es6/components/TimeInput/stories/Simple.stories.tsx +19 -0
  88. package/es6/components/TimeInput/stories/Step.stories.tsx +14 -0
  89. package/es6/components/TimeInput/stories/ThemingLightDark.stories.tsx +22 -0
  90. package/es6/components/TimeInput/stories/Uncontrolled.stories.tsx +22 -0
  91. package/es6/components/TimeInput/useSectionedTimeField.js +356 -0
  92. package/es6/components/TimeInput/utils.js +183 -0
  93. package/es6/components/index.d.ts +2 -0
  94. package/es6/components/index.js +2 -0
  95. package/es6/index.d.ts +2 -0
  96. package/es6/languages/default.json +20 -0
  97. package/es6/themes/base.d.ts +108 -0
  98. package/es6/themes/base.js +208 -0
  99. package/grommet.min.js +1 -1
  100. package/grommet.min.js.map +1 -1
  101. package/index.d.ts +2 -0
  102. package/languages/default.json +20 -0
  103. package/package.json +41 -40
  104. package/themes/base.d.ts +108 -0
  105. package/themes/base.js +208 -0
  106. package/components/TextInput/stories/CustomThemed/CustomSuggestions.stories.tsx +0 -180
  107. package/components/TextInput/stories/CustomThemed/Themed.stories.js +0 -79
  108. package/es6/components/TextInput/stories/CustomThemed/CustomSuggestions.stories.tsx +0 -180
  109. package/es6/components/TextInput/stories/CustomThemed/Themed.stories.js +0 -74
@@ -0,0 +1,356 @@
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
+ /* eslint-disable no-nested-ternary */
3
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
+ import { defaultSections, hasAnyValue, isoTimeToSections, normalizeToIsoTime, pad, sectionKey, sectionMax, sectionMin, sectionsToIsoTime, SECTION_HOUR, SECTION_MINUTE, SECTION_PERIOD, SECTION_SECOND } from './utils';
5
+ var separatorBeforeSection = function separatorBeforeSection(section) {
6
+ return section === SECTION_PERIOD ? ' ' : ':';
7
+ };
8
+ var sectionToken = function sectionToken(section) {
9
+ if (section === SECTION_HOUR) return 'hh';
10
+ if (section === SECTION_MINUTE) return 'mm';
11
+ if (section === SECTION_SECOND) return 'ss';
12
+ return 'aa';
13
+ };
14
+ var sectionPattern = function sectionPattern(section) {
15
+ if (section === SECTION_PERIOD) return '(AM|PM)';
16
+ return '(\\d{1,2})';
17
+ };
18
+ var isNumericSection = function isNumericSection(section) {
19
+ return section !== SECTION_PERIOD;
20
+ };
21
+ var parseSectionsValue = function parseSectionsValue(value, format, sectionOrder) {
22
+ if (!value || typeof value !== 'string') return undefined;
23
+ var normalized = value.trim().toUpperCase();
24
+ if (!normalized || !sectionOrder.length) return undefined;
25
+ var pattern = sectionOrder.map(function (section, index) {
26
+ var sectionRegex = sectionPattern(section);
27
+ if (index === 0) return sectionRegex;
28
+ return separatorBeforeSection(section) + "\\s*" + sectionRegex;
29
+ }).join('');
30
+ var regex = new RegExp("^" + pattern + "$");
31
+ var match = normalized.match(regex);
32
+ if (!match) return undefined;
33
+ var parsed = defaultSections(format);
34
+ sectionOrder.forEach(function (section, index) {
35
+ var key = sectionKey(section);
36
+ var captured = match[index + 1];
37
+ if (section === SECTION_PERIOD) {
38
+ parsed[key] = captured;
39
+ } else {
40
+ var next = Number(captured);
41
+ if (!Number.isNaN(next)) parsed[key] = next;
42
+ }
43
+ });
44
+ for (var i = 0; i < sectionOrder.length; i += 1) {
45
+ var section = sectionOrder[i];
46
+ if (isNumericSection(section)) {
47
+ var key = sectionKey(section);
48
+ var next = parsed[key];
49
+ if (next === undefined || next < sectionMin(section, format) || next > sectionMax(section, format)) {
50
+ return undefined;
51
+ }
52
+ }
53
+ }
54
+ return parsed;
55
+ };
56
+ var formatSectionsValue = function formatSectionsValue(_ref) {
57
+ var sections = _ref.sections,
58
+ sectionOrder = _ref.sectionOrder,
59
+ _ref$includeTokens = _ref.includeTokens,
60
+ includeTokens = _ref$includeTokens === void 0 ? false : _ref$includeTokens;
61
+ return sectionOrder.map(function (section, index) {
62
+ var key = sectionKey(section);
63
+ var rawValue = sections[key];
64
+ var rendered = rawValue === undefined ? includeTokens ? sectionToken(section) : '' : section === SECTION_PERIOD ? rawValue : pad(rawValue);
65
+ if (index === 0) return rendered;
66
+ return "" + separatorBeforeSection(section) + rendered;
67
+ }).join('');
68
+ };
69
+ export var useSectionedTimeField = function useSectionedTimeField(_ref2) {
70
+ var format = _ref2.format,
71
+ sectionOrder = _ref2.sectionOrder,
72
+ _ref2$minuteStep = _ref2.minuteStep,
73
+ minuteStep = _ref2$minuteStep === void 0 ? 1 : _ref2$minuteStep,
74
+ value = _ref2.value,
75
+ onCommit = _ref2.onCommit,
76
+ onInvalid = _ref2.onInvalid;
77
+ var editStateRef = useRef({
78
+ section: SECTION_HOUR,
79
+ digits: 0,
80
+ previousValue: undefined,
81
+ firstDigit: undefined
82
+ });
83
+ var preserveIncompleteSectionsRef = useRef(false);
84
+ // Track pending single digit for display without committing
85
+ var _useState = useState({}),
86
+ pendingDigits = _useState[0],
87
+ setPendingDigits = _useState[1];
88
+ var parsedValue = useMemo(function () {
89
+ return isoTimeToSections(normalizeToIsoTime(value), format);
90
+ }, [format, value]);
91
+ var _useState2 = useState(parsedValue || defaultSections(format)),
92
+ sections = _useState2[0],
93
+ setSections = _useState2[1];
94
+ var _useState3 = useState(sectionOrder[0] || SECTION_HOUR),
95
+ activeSection = _useState3[0],
96
+ setActiveSection = _useState3[1];
97
+ useEffect(function () {
98
+ if (!sectionOrder.includes(activeSection)) {
99
+ setActiveSection(sectionOrder[0] || SECTION_HOUR);
100
+ }
101
+ }, [activeSection, sectionOrder]);
102
+ useEffect(function () {
103
+ if (!parsedValue && preserveIncompleteSectionsRef.current) {
104
+ preserveIncompleteSectionsRef.current = false;
105
+ return;
106
+ }
107
+ setSections(parsedValue || defaultSections(format));
108
+ }, [parsedValue, format]);
109
+ var displayValue = useMemo(function () {
110
+ if (!hasAnyValue(sections)) return '';
111
+
112
+ // Create a copy of sections with pending digits overlaid for display
113
+ var displaySections = _extends({}, sections);
114
+ var pendingSection = Object.keys(pendingDigits)[0];
115
+ if (pendingSection && pendingDigits[pendingSection] !== undefined) {
116
+ displaySections[pendingSection] = pendingDigits[pendingSection];
117
+ }
118
+ return formatSectionsValue({
119
+ sections: displaySections,
120
+ sectionOrder: sectionOrder,
121
+ includeTokens: true
122
+ });
123
+ }, [sectionOrder, sections, pendingDigits]);
124
+ var commitSections = useCallback(function (nextSections) {
125
+ var _nextSections$second;
126
+ setSections(nextSections);
127
+ var complete = sectionOrder.every(function (section) {
128
+ return nextSections[sectionKey(section)] !== undefined;
129
+ });
130
+
131
+ // Check if all numeric sections are valid
132
+ var allValid = sectionOrder.every(function (section) {
133
+ if (!isNumericSection(section)) return true; // skip period
134
+ var key = sectionKey(section);
135
+ var sectionValue = nextSections[key];
136
+ var min = sectionMin(section, format);
137
+ var max = sectionMax(section, format);
138
+ return sectionValue >= min && sectionValue <= max;
139
+ });
140
+ var nextValue = complete && sectionOrder.length && allValid ? sectionsToIsoTime(_extends({}, nextSections, {
141
+ second: (_nextSections$second = nextSections.second) != null ? _nextSections$second : 0
142
+ }), format) : undefined;
143
+
144
+ // Mark as incomplete if: sections incomplete OR some invalid
145
+ var hasIncompleteSections = !complete || !allValid;
146
+ preserveIncompleteSectionsRef.current = hasIncompleteSections && hasAnyValue(nextSections);
147
+ onCommit(nextSections, nextValue);
148
+ }, [onCommit, sectionOrder, format]);
149
+ var setSectionValue = useCallback(function (section, rawValue) {
150
+ var _extends2;
151
+ var key = sectionKey(section);
152
+ var next = _extends({}, sections, (_extends2 = {}, _extends2[key] = rawValue, _extends2));
153
+ commitSections(next);
154
+ }, [commitSections, sections]);
155
+ var moveSection = useCallback(function (direction) {
156
+ if (!sectionOrder.length) return activeSection;
157
+ var activeIndex = Math.max(0, sectionOrder.indexOf(activeSection));
158
+ var count = sectionOrder.length;
159
+ var nextIndex = (activeIndex + direction + count) % count;
160
+ var nextSection = sectionOrder[nextIndex];
161
+ setActiveSection(nextSection);
162
+ return nextSection;
163
+ }, [activeSection, sectionOrder]);
164
+ var incrementSection = useCallback(function (section, delta) {
165
+ if (section === SECTION_PERIOD) {
166
+ setSectionValue(section, sections.period === 'AM' ? 'PM' : 'AM');
167
+ return;
168
+ }
169
+ var minValue = sectionMin(section, format);
170
+ var maxValue = sectionMax(section, format);
171
+ var key = sectionKey(section);
172
+ var current = sections[key];
173
+ var step = section === SECTION_MINUTE ? minuteStep : section === SECTION_SECOND ? 1 : 1;
174
+ var next;
175
+ if (step > 1 && (section === SECTION_MINUTE || section === SECTION_SECOND)) {
176
+ var options = Array.from({
177
+ length: Math.ceil((maxValue - minValue + 1) / step)
178
+ }, function (_, index) {
179
+ return minValue + index * step;
180
+ }).filter(function (valueAtIndex) {
181
+ return valueAtIndex <= maxValue;
182
+ });
183
+ var currentIndex = options.indexOf(current);
184
+ if (currentIndex !== -1) {
185
+ var wrappedIndex = ((currentIndex + delta) % options.length + options.length) % options.length;
186
+ next = options[wrappedIndex];
187
+ } else if (delta > 0) {
188
+ var _options$find;
189
+ next = (_options$find = options.find(function (option) {
190
+ return option > (current != null ? current : minValue - 1);
191
+ })) != null ? _options$find : options[0];
192
+ } else {
193
+ var _descending$find;
194
+ var descending = [].concat(options).reverse();
195
+ next = (_descending$find = descending.find(function (option) {
196
+ return option < (current != null ? current : maxValue + 1);
197
+ })) != null ? _descending$find : options[options.length - 1];
198
+ }
199
+ } else {
200
+ var base = current === undefined ? minValue : current;
201
+ next = base + delta;
202
+ if (next > maxValue) next = minValue;
203
+ if (next < minValue) next = maxValue;
204
+ }
205
+ setSectionValue(section, next);
206
+ }, [format, minuteStep, sections, setSectionValue]);
207
+ var applyDigit = useCallback(function (digit) {
208
+ if (activeSection === SECTION_PERIOD) return undefined;
209
+ var minValue = sectionMin(activeSection, format);
210
+ var maxValue = sectionMax(activeSection, format);
211
+ var key = sectionKey(activeSection);
212
+ var isSameSection = editStateRef.current.section === activeSection;
213
+ var isSecondDigit = isSameSection && editStateRef.current.digits === 1;
214
+ var currentRaw = sections[key] === undefined ? 0 : sections[key];
215
+ var nextValue;
216
+ if (isSecondDigit) {
217
+ var _editStateRef$current;
218
+ // Use the stored first digit from editState
219
+ var firstDigit = (_editStateRef$current = editStateRef.current.firstDigit) != null ? _editStateRef$current : currentRaw % 10;
220
+ nextValue = firstDigit * 10 + digit;
221
+ editStateRef.current = {
222
+ section: activeSection,
223
+ digits: 0,
224
+ previousValue: editStateRef.current.previousValue,
225
+ firstDigit: undefined
226
+ };
227
+ // Clear pending digits since we're committing now
228
+ setPendingDigits({});
229
+ } else {
230
+ var _setPendingDigits;
231
+ // First digit: store in pending for display only
232
+ nextValue = digit;
233
+ editStateRef.current = {
234
+ section: activeSection,
235
+ digits: 1,
236
+ previousValue: sections[key],
237
+ firstDigit: digit
238
+ };
239
+ // Show the first digit in pending state
240
+ setPendingDigits((_setPendingDigits = {}, _setPendingDigits[key] = digit, _setPendingDigits));
241
+ }
242
+
243
+ // For 2nd digit: validate combined value, but allow invalid 1st digit
244
+ // (allows "0X" patterns in formats where single "0" is invalid)
245
+ if (isSecondDigit && (nextValue < minValue || nextValue > maxValue)) {
246
+ var _editStateRef$current2;
247
+ // Combined value invalid. Try to use first digit for current section
248
+ // and apply second digit to next section (MUI behavior)
249
+ var _firstDigit = (_editStateRef$current2 = editStateRef.current.firstDigit) != null ? _editStateRef$current2 : currentRaw % 10;
250
+ if (_firstDigit >= minValue && _firstDigit <= maxValue) {
251
+ setSectionValue(activeSection, _firstDigit);
252
+
253
+ // Get next section and check if second digit is valid there
254
+ var currentSectionIndex = sectionOrder.indexOf(activeSection);
255
+ var nextSection = sectionOrder[currentSectionIndex + 1];
256
+ if (nextSection && isNumericSection(nextSection)) {
257
+ var nextMinValue = sectionMin(nextSection, format);
258
+ var nextMaxValue = sectionMax(nextSection, format);
259
+
260
+ // If second digit is valid for next section, apply it there
261
+ if (digit >= nextMinValue && digit <= nextMaxValue) {
262
+ setSectionValue(nextSection, digit);
263
+ // Now move to section after that
264
+ return moveSection(2);
265
+ }
266
+ }
267
+
268
+ // If second digit not valid for next section, just move to next
269
+ return moveSection(1);
270
+ }
271
+
272
+ // If even first digit alone is invalid, reject the entry
273
+ onInvalid == null || onInvalid();
274
+ setPendingDigits({});
275
+ return undefined;
276
+ }
277
+
278
+ // MUI Pattern: Determine if we should commit and move to next section
279
+ // shouldGoToNextSection = nextValue * 10 > max || digitCount === 2
280
+ var shouldMoveToNextSection = nextValue * 10 > maxValue || isSecondDigit;
281
+ setSectionValue(activeSection, nextValue);
282
+ if (shouldMoveToNextSection) {
283
+ // Don't move past the last section during digit entry
284
+ // (Tab navigation can still wrap, but digit entry stops at last
285
+ // section)
286
+ var currentIndex = sectionOrder.indexOf(activeSection);
287
+ var isLastSection = currentIndex === sectionOrder.length - 1;
288
+ if (!isLastSection) {
289
+ return moveSection(1);
290
+ }
291
+ }
292
+ return activeSection;
293
+ }, [activeSection, format, moveSection, onInvalid, sections, setSectionValue, setPendingDigits, sectionOrder]);
294
+ var clearActiveSection = useCallback(function () {
295
+ setSectionValue(activeSection, undefined);
296
+ }, [activeSection, setSectionValue]);
297
+ var parsePasted = useCallback(function (pasted) {
298
+ var parsed = parseSectionsValue(pasted, format, sectionOrder);
299
+ if (parsed) {
300
+ return parsed;
301
+ }
302
+ var digits = pasted.replace(/\D/g, '');
303
+ var numericSections = sectionOrder.filter(function (section) {
304
+ return section !== SECTION_PERIOD;
305
+ });
306
+ var hasExplicitPeriod = /\b(AM|PM)\b/i.test(pasted);
307
+ var shouldInferPeriod = format === '12' && sectionOrder.includes(SECTION_PERIOD) && !hasExplicitPeriod;
308
+ if (digits.length >= numericSections.length * 2 && numericSections.length) {
309
+ var next = _extends({}, sections);
310
+ for (var i = 0; i < numericSections.length; i += 1) {
311
+ var section = numericSections[i];
312
+ var parsedNumber = Number(digits.slice(i * 2, i * 2 + 2));
313
+ var minValue = section === SECTION_HOUR && shouldInferPeriod ? 0 : sectionMin(section, format);
314
+ var maxValue = section === SECTION_HOUR && shouldInferPeriod ? 23 : sectionMax(section, format);
315
+ if (Number.isNaN(parsedNumber) || parsedNumber < minValue || parsedNumber > maxValue) {
316
+ return undefined;
317
+ }
318
+ next[sectionKey(section)] = parsedNumber;
319
+ }
320
+ if (sectionOrder.includes(SECTION_PERIOD)) {
321
+ if (hasExplicitPeriod) {
322
+ next.period = /\bPM\b/i.test(pasted) ? 'PM' : 'AM';
323
+ } else if (shouldInferPeriod) {
324
+ var normalizedHour = next.hour;
325
+ if (normalizedHour === 0) {
326
+ next.hour = 12;
327
+ next.period = 'AM';
328
+ } else if (normalizedHour === 12) {
329
+ next.period = 'PM';
330
+ } else if (normalizedHour > 12) {
331
+ next.hour = normalizedHour - 12;
332
+ next.period = 'PM';
333
+ } else {
334
+ next.period = 'AM';
335
+ }
336
+ }
337
+ }
338
+ return next;
339
+ }
340
+ return undefined;
341
+ }, [format, sectionOrder, sections]);
342
+ return {
343
+ activeSection: activeSection,
344
+ clearActiveSection: clearActiveSection,
345
+ displayValue: displayValue,
346
+ incrementSection: incrementSection,
347
+ moveSection: moveSection,
348
+ parsePasted: parsePasted,
349
+ sections: sections,
350
+ setActiveSection: setActiveSection,
351
+ setSectionValue: setSectionValue,
352
+ applyDigit: applyDigit,
353
+ commitSections: commitSections,
354
+ pendingDigits: pendingDigits
355
+ };
356
+ };
@@ -0,0 +1,183 @@
1
+ export var SECTION_HOUR = 0;
2
+ export var SECTION_MINUTE = 1;
3
+ export var SECTION_SECOND = 2;
4
+ export var SECTION_PERIOD = 3;
5
+ export var pad = function pad(value) {
6
+ return value.toString().padStart(2, '0');
7
+ };
8
+ var sectionMessageId = function sectionMessageId(section) {
9
+ if (section === SECTION_HOUR) return 'timeInput.sectionHours';
10
+ if (section === SECTION_MINUTE) return 'timeInput.sectionMinutes';
11
+ if (section === SECTION_SECOND) return 'timeInput.sectionSeconds';
12
+ return 'timeInput.sectionMeridiem';
13
+ };
14
+ export var getSectionName = function getSectionName(section, format, formatMessage, messages) {
15
+ if (formatMessage) {
16
+ return formatMessage({
17
+ id: sectionMessageId(section),
18
+ messages: messages
19
+ });
20
+ }
21
+ var names = format === '12' ? ['hours', 'minutes', 'seconds', 'meridiem'] : ['hours', 'minutes', 'seconds'];
22
+ return names[section];
23
+ };
24
+ export var getRanges = function getRanges(format) {
25
+ if (format === '12') {
26
+ return [[0, 2], [3, 5], [6, 8], [9, 11]];
27
+ }
28
+ return [[0, 2], [3, 5], [6, 8]];
29
+ };
30
+
31
+ // TimeInput always transacts (value/defaultValue/onChange) in a canonical
32
+ // 24-hour ISO time string ("HH:MM:SS"), regardless of the display `format`
33
+ // prop.
34
+ export var ISO_TIME_REGEX = /^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)$/;
35
+ export var normalizeToIsoTime = function normalizeToIsoTime(value) {
36
+ if (typeof value !== 'string' || !value.trim()) return undefined;
37
+ var trimmed = value.trim();
38
+ if (ISO_TIME_REGEX.test(trimmed)) return trimmed;
39
+ var parsed = new Date(trimmed);
40
+ if (Number.isNaN(parsed.getTime())) return undefined;
41
+ return pad(parsed.getHours()) + ":" + pad(parsed.getMinutes()) + ":" + pad(parsed.getSeconds());
42
+ };
43
+
44
+ // Converts a canonical 24-hour ISO time string into the section shape the
45
+ // sectioned editor uses for display, deriving 12-hour + period fields when
46
+ // needed.
47
+ export var isoTimeToSections = function isoTimeToSections(isoTime, format) {
48
+ if (typeof isoTime !== 'string') return undefined;
49
+ var match = isoTime.match(ISO_TIME_REGEX);
50
+ if (!match) return undefined;
51
+ var hour24 = Number(match[1]);
52
+ var minute = Number(match[2]);
53
+ var second = Number(match[3]);
54
+ if (format === '12') {
55
+ var period = hour24 < 12 ? 'AM' : 'PM';
56
+ var hour = hour24 % 12 || 12;
57
+ return {
58
+ hour: hour,
59
+ minute: minute,
60
+ second: second,
61
+ period: period
62
+ };
63
+ }
64
+ return {
65
+ hour: hour24,
66
+ minute: minute,
67
+ second: second
68
+ };
69
+ };
70
+ export var sectionsToIsoTime = function sectionsToIsoTime(sections, format) {
71
+ if (sections.hour === undefined || sections.minute === undefined || sections.second === undefined) {
72
+ return undefined;
73
+ }
74
+ var hour24 = sections.hour;
75
+ if (format === '12') {
76
+ var period = sections.period || 'AM';
77
+ hour24 = sections.hour % 12;
78
+ if (period === 'PM') hour24 += 12;
79
+ }
80
+ return pad(hour24) + ":" + pad(sections.minute) + ":" + pad(sections.second);
81
+ };
82
+ export var parseTime = function parseTime(value, format) {
83
+ if (!value || typeof value !== 'string') return undefined;
84
+ var trimmed = value.trim().toUpperCase();
85
+ if (format === '12') {
86
+ var _match = trimmed.match(/^(\d{1,2}):(\d{2}):(\d{2})\s*(AM|PM)$/);
87
+ if (!_match) return undefined;
88
+ var _hour = Number(_match[1]);
89
+ var _minute = Number(_match[2]);
90
+ var _second = Number(_match[3]);
91
+ var period = _match[4];
92
+ if (Number.isNaN(_hour) || Number.isNaN(_minute) || Number.isNaN(_second) || _hour < 1 || _hour > 12 || _minute < 0 || _minute > 59 || _second < 0 || _second > 59) {
93
+ return undefined;
94
+ }
95
+ return {
96
+ hour: _hour,
97
+ minute: _minute,
98
+ second: _second,
99
+ period: period
100
+ };
101
+ }
102
+ var match = trimmed.match(/^(\d{1,2}):(\d{2}):(\d{2})$/);
103
+ if (!match) return undefined;
104
+ var hour = Number(match[1]);
105
+ var minute = Number(match[2]);
106
+ var second = Number(match[3]);
107
+ if (Number.isNaN(hour) || Number.isNaN(minute) || Number.isNaN(second) || hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59) {
108
+ return undefined;
109
+ }
110
+ return {
111
+ hour: hour,
112
+ minute: minute,
113
+ second: second
114
+ };
115
+ };
116
+ export var formatTime = function formatTime(time, format) {
117
+ if (!time) return undefined;
118
+ if (format === '12') {
119
+ return pad(time.hour) + ":" + pad(time.minute) + ":" + pad(time.second) + " " + (time.period || 'AM');
120
+ }
121
+ return pad(time.hour) + ":" + pad(time.minute) + ":" + pad(time.second);
122
+ };
123
+ export var defaultSections = function defaultSections(format) {
124
+ return format === '12' ? {
125
+ hour: undefined,
126
+ minute: undefined,
127
+ second: undefined,
128
+ period: undefined
129
+ } : {
130
+ hour: undefined,
131
+ minute: undefined,
132
+ second: undefined
133
+ };
134
+ };
135
+ export var hasAnyValue = function hasAnyValue(sections) {
136
+ return sections.hour !== undefined || sections.minute !== undefined || sections.second !== undefined || sections.period !== undefined;
137
+ };
138
+ export var sectionMax = function sectionMax(section, format) {
139
+ if (section === SECTION_HOUR) return format === '12' ? 12 : 23;
140
+ return 59;
141
+ };
142
+ export var sectionMin = function sectionMin(section, format) {
143
+ if (section === SECTION_HOUR) return format === '12' ? 1 : 0;
144
+ return 0;
145
+ };
146
+ export var sectionKey = function sectionKey(section) {
147
+ if (section === SECTION_HOUR) return 'hour';
148
+ if (section === SECTION_MINUTE) return 'minute';
149
+ if (section === SECTION_SECOND) return 'second';
150
+ return 'period';
151
+ };
152
+ export var getSectionAriaMeta = function getSectionAriaMeta(_ref) {
153
+ var _sections$key;
154
+ var section = _ref.section,
155
+ format = _ref.format,
156
+ sections = _ref.sections;
157
+ if (section === SECTION_PERIOD) {
158
+ return {
159
+ now: sections.period === 'PM' ? 1 : 0,
160
+ min: 0,
161
+ max: 1
162
+ };
163
+ }
164
+ var key = sectionKey(section);
165
+ var min = sectionMin(section, format);
166
+ var max = sectionMax(section, format);
167
+ var now = (_sections$key = sections[key]) != null ? _sections$key : min;
168
+ return {
169
+ now: now,
170
+ min: min,
171
+ max: max
172
+ };
173
+ };
174
+ export var getActiveSectionAriaMeta = function getActiveSectionAriaMeta(_ref2) {
175
+ var activeSection = _ref2.activeSection,
176
+ format = _ref2.format,
177
+ sections = _ref2.sections;
178
+ return getSectionAriaMeta({
179
+ section: activeSection,
180
+ format: format,
181
+ sections: sections
182
+ });
183
+ };
@@ -75,6 +75,7 @@ export * from './SkipLinkTarget';
75
75
  export * from './Spinner';
76
76
  export * from './Stack';
77
77
  export * from './StarRating';
78
+ export * from './Stepper';
78
79
  export * from './Table';
79
80
  export * from './TableBody';
80
81
  export * from './TableCell';
@@ -87,6 +88,7 @@ export * from './Tag';
87
88
  export * from './Text';
88
89
  export * from './TextArea';
89
90
  export * from './TextInput';
91
+ export * from './TimeInput';
90
92
  export * from './ThumbsRating';
91
93
  export * from './Tip';
92
94
  export * from './ToggleGroup';
@@ -76,6 +76,7 @@ export * from './SkipLinkTarget';
76
76
  export * from './Spinner';
77
77
  export * from './Stack';
78
78
  export * from './StarRating';
79
+ export * from './Stepper';
79
80
  export * from './Table';
80
81
  export * from './TableBody';
81
82
  export * from './TableCell';
@@ -88,6 +89,7 @@ export * from './Tag';
88
89
  export * from './Text';
89
90
  export * from './TextArea';
90
91
  export * from './TextInput';
92
+ export * from './TimeInput';
91
93
  export * from './Tip';
92
94
  export * from './Toolbar';
93
95
  export * from './ToggleGroup';
package/es6/index.d.ts CHANGED
@@ -75,6 +75,7 @@ export * from './components/SkipLinkTarget';
75
75
  export * from './components/Spinner';
76
76
  export * from './components/Stack';
77
77
  export * from './components/StarRating';
78
+ export * from './components/Stepper';
78
79
  export * from './components/Table';
79
80
  export * from './components/TableBody';
80
81
  export * from './components/TableCell';
@@ -87,6 +88,7 @@ export * from './components/Tag';
87
88
  export * from './components/Text';
88
89
  export * from './components/TextArea';
89
90
  export * from './components/TextInput';
91
+ export * from './components/TimeInput';
90
92
  export * from './components/ThumbsRating';
91
93
  export * from './components/Tip';
92
94
  export * from './components/ToggleGroup';
@@ -197,7 +197,13 @@
197
197
  "skipLinks": {
198
198
  "skipTo": "Skip To:"
199
199
  },
200
+ "stepper": {
201
+ "progress": "Progress",
202
+ "step": "Step {step} of {total}: {title}"
203
+ },
200
204
  "tabs": {
205
+ "nextTab": "Next Tab",
206
+ "previousTab": "Previous Tab",
201
207
  "tabContents": "Tab Contents"
202
208
  },
203
209
  "tag": {
@@ -212,6 +218,20 @@
212
218
  "suggestionsExist": "This input has suggestions use arrow keys to navigate",
213
219
  "suggestionIsOpen": "Suggestions drop is open, continue to use arrow keys to navigate"
214
220
  },
221
+ "timeInput": {
222
+ "inputLabel": "Time input",
223
+ "chooseTime": "Choose time",
224
+ "currentValue": "Current time {hour}:{minute}:{second}{period}",
225
+ "activeSection": "{section} selected",
226
+ "activeSectionValue": "{value} {section}",
227
+ "activePeriodValue": "{period} period",
228
+ "openDrop": "Press space to open time picker",
229
+ "invalidTime": "Invalid time value",
230
+ "sectionHours": "hours",
231
+ "sectionMinutes": "minutes",
232
+ "sectionSeconds": "seconds",
233
+ "sectionMeridiem": "meridiem"
234
+ },
215
235
  "video": {
216
236
  "audioDescriptions": "video audio description",
217
237
  "captions": "closed captions",