@qualtrics/ui-react 2.11.0 → 2.12.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 (77) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/__shared/cjs/index-1a8585e7.js +13058 -0
  3. package/dist/__shared/cjs/{index-30148ada.js → index-def941fc.js} +3 -3
  4. package/dist/components/Accordion/Accordion2.js +3 -3
  5. package/dist/components/Button/Button2.js +3 -3
  6. package/dist/components/ButtonGroup/ButtonGroup2.js +3 -3
  7. package/dist/components/Checkbox/Checkbox2.js +3 -3
  8. package/dist/components/Checkbox/VisualCheckbox2.js +3 -3
  9. package/dist/components/ColorPicker/ColorPicker2.js +3 -3
  10. package/dist/components/Combobox/Combobox2.js +3 -3
  11. package/dist/components/ConfigPane/ConfigPane2.js +3 -3
  12. package/dist/components/Divider/Divider2.js +3 -3
  13. package/dist/components/Dropdown/Dropdown2.js +3 -3
  14. package/dist/components/FilePicker/FilePicker2.js +3 -3
  15. package/dist/components/FormField/Caption.js +3 -3
  16. package/dist/components/FormField/FormField2.js +3 -3
  17. package/dist/components/FullScreenTakeover/FullScreenTakeover2.js +3 -3
  18. package/dist/components/IconButton/IconButton2.js +3 -3
  19. package/dist/components/InlineInput/InlineInput2.js +3 -3
  20. package/dist/components/Input/Input2.js +3 -3
  21. package/dist/components/InputGroup/InputGroup2.js +3 -3
  22. package/dist/components/Label/Label2.js +3 -3
  23. package/dist/components/Link/Link2.js +3 -3
  24. package/dist/components/LoadingSpinner/LoadingSpinner2.js +3 -3
  25. package/dist/components/LogicEditor/LogicEditor2.js +3 -3
  26. package/dist/components/Modal/Modal2.js +3 -3
  27. package/dist/components/NewMenu/BaseMenu.js +0 -1
  28. package/dist/components/NewMenu/NewMenu.js +3 -3
  29. package/dist/components/NewMenu/parts/ArrowNav/ArrowNav.js +5 -9
  30. package/dist/components/NumberStepper/NumberStepper2.js +3 -3
  31. package/dist/components/PageLayout/PageLayout.js +3 -3
  32. package/dist/components/Pagination/Pagination2.js +3 -3
  33. package/dist/components/Popover/Popover2.js +3 -3
  34. package/dist/components/QuickSearch/QuickSearch2.js +3 -3
  35. package/dist/components/Radio/Radio2.js +3 -3
  36. package/dist/components/SearchInput/SearchInput2.js +3 -3
  37. package/dist/components/SidebarNav/SidebarNav2.js +3 -3
  38. package/dist/components/Slider/Slider2.js +3 -3
  39. package/dist/components/Switch/Switch2.js +3 -3
  40. package/dist/components/Table/Table2.js +3 -3
  41. package/dist/components/Tabs/Tabs2.js +3 -3
  42. package/dist/components/Tooltip/Tooltip2.js +3 -3
  43. package/dist/components/deprecated_ColorPicker/ColorPicker2.js +3 -3
  44. package/dist/components/deprecated_NumberStepper/NumberStepper2.js +3 -3
  45. package/dist/components/deprecated_Tabs/Tabs2.js +3 -3
  46. package/dist/components/deprecated_Toolbar/Toolbar2.js +3 -3
  47. package/dist/hooks/useOverlay/useOverlay2.js +3 -3
  48. package/dist/hooks/useScreenReaderAnnouncement/useScreenReaderAnnouncement2.js +3 -3
  49. package/dist/icons/Icon.js +3 -3
  50. package/dist/icons/index.js +1 -1
  51. package/dist/index.es.js +1 -1
  52. package/dist/index.js +83 -8442
  53. package/dist/next/AdvancedTable/AdvancedTable2.js +3 -3
  54. package/dist/next/CollapsibleSearchInput/CollapsibleSearchInput2.js +3 -3
  55. package/dist/next/Combobox/Combobox2.js +3 -3
  56. package/dist/next/Combobox/ComboboxInput.js +3 -1
  57. package/dist/next/Combobox/ComboboxOption.js +1 -0
  58. package/dist/next/Drawer/Drawer2.js +3 -3
  59. package/dist/next/FilterAnchor/FilterAnchor2.js +3 -3
  60. package/dist/next/Input/Input2.js +3 -3
  61. package/dist/next/Menu/Menu2.js +3 -3
  62. package/dist/next/PhoneNumberInput/PhoneNumberInput2.js +3 -3
  63. package/dist/next/SplitButton/SplitButton2.js +3 -3
  64. package/dist/next/TimePicker/TimeDropdown.js +78 -0
  65. package/dist/next/TimePicker/TimeInput.js +87 -0
  66. package/dist/next/TimePicker/TimePicker.js +247 -0
  67. package/dist/next/TimePicker/TimePicker2.js +8 -0
  68. package/dist/next/TimePicker/TimePickerIcon.js +36 -0
  69. package/dist/next/TimePicker/index.js +1 -0
  70. package/dist/next/TimePicker/utils.js +229 -0
  71. package/dist/next/index.d.ts +20 -0
  72. package/dist/next/index.es.js +2 -0
  73. package/dist/next/index.js +807 -163
  74. package/dist/utils/Flyout/Flyout2.js +3 -3
  75. package/dist/utils/keyboardUser/keyboardUser.js +1 -1
  76. package/package.json +2 -2
  77. package/dist/__shared/cjs/index-bb7befc3.js +0 -4656
@@ -0,0 +1,247 @@
1
+ import React__default, { useState, useMemo, useCallback, useEffect, useRef } from 'react';
2
+ import { TimeDropdown } from './TimeDropdown.js';
3
+ import { TimeInput } from './TimeInput.js';
4
+ import TimePickerIcon from './TimePickerIcon.js';
5
+ import { convertTimeObjectToTimeString, generateTimes, correctTime, convertTimeStringToTimeObject } from './utils.js';
6
+ import '../../hooks/index.js';
7
+ import '../../utils/index.js';
8
+ import styles from './TimePicker2.js';
9
+ import useId from '../../hooks/useId/useId.js';
10
+ import useControllableState from '../../hooks/useControllableState/useControllableState.js';
11
+ import useClickOutside from '../../hooks/useClickOutside/useClickOutside.js';
12
+ import mergeRefs from '../../utils/mergeRefs/mergeRefs.js';
13
+
14
+ const DEFAULT_TIME = (() => {
15
+ const now = new Date();
16
+ const hour = now.getHours();
17
+ const minute = now.getMinutes();
18
+ return {
19
+ hour,
20
+ minute
21
+ };
22
+ })();
23
+
24
+ const TimePicker = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
25
+ let {
26
+ value: externalValue,
27
+ onChange: externalOnChange,
28
+ is24HourClock = false,
29
+ isDisabled = false,
30
+ isInvalid = false,
31
+ id: externalId,
32
+ 'data-testid': dataTestId,
33
+ 'aria-label': ariaLabel,
34
+ 'aria-labelledby': ariaLabelledBy,
35
+ 'aria-describedby': ariaDescribedBy
36
+ } = _ref;
37
+ const timePickerId = useId(externalId);
38
+ const inputId = "".concat(timePickerId, "-input");
39
+ const dropdownId = "".concat(timePickerId, "-dropdown");
40
+ const [isOptionHovered, setIsOptionHovered] = useState(false);
41
+ const [timeObject, setTimeObject] = useControllableState(DEFAULT_TIME, externalOnChange, externalValue);
42
+ const defaultTimeString = convertTimeObjectToTimeString(timeObject, is24HourClock); // timeString needs its own state instead of always being derived from timeObject, since typing doesn't "commit" a new time.
43
+
44
+ const [timeString, setTimeString] = useState(defaultTimeString);
45
+ const [isTimeStringDirty, setIsTimeStringDirty] = useState(false);
46
+ const step = 60 * 30;
47
+ const dropdownItems = useMemo(() => generateTimes(step, is24HourClock), [is24HourClock, step]);
48
+ const getScrolledToItemFromTimeString = useCallback(typedTime => {
49
+ const {
50
+ correctedTime
51
+ } = correctTime(typedTime, is24HourClock, true);
52
+ const correctedTimeObject = convertTimeStringToTimeObject(correctedTime);
53
+ const correctedTimeValue = correctedTimeObject.hour * 60 * 60 + correctedTimeObject.minute * 60;
54
+ let minDistance = correctedTimeValue - dropdownItems[0].value; // Substring search up to first empty spot
55
+
56
+ for (let i = 1; i < dropdownItems.length; i += 1) {
57
+ const distance = correctedTimeValue - dropdownItems[i].value;
58
+
59
+ if (distance > minDistance || distance < 0) {
60
+ return {
61
+ index: i - 1,
62
+ isFocused: false,
63
+ isExactMatch: minDistance === 0
64
+ };
65
+ }
66
+
67
+ minDistance = distance;
68
+ }
69
+
70
+ return {
71
+ index: dropdownItems.length - 1,
72
+ isFocused: false,
73
+ isExactMatch: minDistance === 0
74
+ };
75
+ }, [is24HourClock, dropdownItems]);
76
+ const [scrolledToItem, setScrolledToItem] = useState(() => getScrolledToItemFromTimeString(timeString));
77
+ const [shouldMoveSelectionToEnd, setShouldMoveSelectionToEnd] = useState(true); // timeObject may be controlled and may change at any time, so we need to update timeString and the focused item whenever it changes.
78
+
79
+ useEffect(() => {
80
+ const newTimeString = convertTimeObjectToTimeString(timeObject, is24HourClock);
81
+ setTimeString(newTimeString);
82
+ setIsTimeStringDirty(false);
83
+ setShouldMoveSelectionToEnd(true);
84
+ setScrolledToItem(getScrolledToItemFromTimeString(newTimeString));
85
+ }, [timeObject, is24HourClock, getScrolledToItemFromTimeString]);
86
+ const [isFlyoutOpen, setIsFlyoutOpen] = useState(false); // Sets the actual time object and updates the flyout and focus state
87
+
88
+ const commitTimeString = function () {
89
+ let newTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : timeString;
90
+ const {
91
+ correctedTime
92
+ } = correctTime(newTime, is24HourClock, true);
93
+ const newTimeObject = convertTimeStringToTimeObject(correctedTime);
94
+ setTimeObject(newTimeObject);
95
+ setIsFlyoutOpen(false);
96
+ };
97
+
98
+ const inputRef = useRef(null);
99
+ const dropdownRef = useRef(null);
100
+ const iconRef = useRef(null);
101
+ useClickOutside([inputRef, dropdownRef, iconRef], () => isTimeStringDirty ? commitTimeString() : setIsFlyoutOpen(false));
102
+
103
+ const focusNext = () => {
104
+ setScrolledToItem(f => {
105
+ if (!f.isFocused) {
106
+ // Focus just moved from input to listbox.
107
+ // Move to item that was highlighted based on user input
108
+ return {
109
+ index: f.index,
110
+ isFocused: true,
111
+ isExactMatch: false
112
+ };
113
+ }
114
+
115
+ if (f.index === dropdownItems.length - 1) {
116
+ return f;
117
+ }
118
+
119
+ return {
120
+ index: f.index + 1,
121
+ isFocused: true,
122
+ isExactMatch: false
123
+ };
124
+ });
125
+ };
126
+
127
+ const focusPrevious = () => {
128
+ setScrolledToItem(f => {
129
+ if (!f.isFocused) {
130
+ // Focus just moved from input to listbox
131
+ // Move to last item on arrowUp.
132
+ return {
133
+ index: dropdownItems.length - 1,
134
+ isFocused: true,
135
+ isExactMatch: false
136
+ };
137
+ }
138
+
139
+ if (f.index === 0) {
140
+ return f;
141
+ }
142
+
143
+ return {
144
+ index: f.index - 1,
145
+ isFocused: true,
146
+ isExactMatch: false
147
+ };
148
+ });
149
+ };
150
+
151
+ const handleType = typedTime => {
152
+ setIsFlyoutOpen(true);
153
+ setTimeString(typedTime);
154
+ setIsTimeStringDirty(true);
155
+ setScrolledToItem(getScrolledToItemFromTimeString(typedTime));
156
+ };
157
+
158
+ const handleSelectTime = selectedIndex => {
159
+ const timeLabel = dropdownItems[selectedIndex].label;
160
+ setIsOptionHovered(false);
161
+ commitTimeString(timeLabel);
162
+ };
163
+
164
+ const handleKeyDown = e => {
165
+ switch (e.key) {
166
+ case 'ArrowUp':
167
+ e.preventDefault();
168
+ setIsFlyoutOpen(true);
169
+ focusPrevious();
170
+ break;
171
+
172
+ case 'ArrowDown':
173
+ e.preventDefault();
174
+ setIsFlyoutOpen(true);
175
+ focusNext();
176
+ break;
177
+
178
+ case 'Enter':
179
+ e.preventDefault();
180
+
181
+ if (scrolledToItem !== null && scrolledToItem !== void 0 && scrolledToItem.isFocused) {
182
+ // "focus" is on the listbox
183
+ handleSelectTime(scrolledToItem.index);
184
+ } else {
185
+ // "focus" is on the input
186
+ commitTimeString();
187
+ }
188
+
189
+ break;
190
+
191
+ case 'Escape':
192
+ case 'Tab':
193
+ // use whatever time is closest to what's in the input
194
+ commitTimeString();
195
+ break;
196
+
197
+ default:
198
+ break;
199
+ }
200
+ };
201
+
202
+ return /*#__PURE__*/React__default.createElement("div", {
203
+ id: timePickerId,
204
+ className: styles.container
205
+ }, /*#__PURE__*/React__default.createElement(TimeInput, {
206
+ id: inputId,
207
+ dataTestId: dataTestId,
208
+ ariaActiveDescendant: isFlyoutOpen && scrolledToItem !== null && scrolledToItem !== void 0 && scrolledToItem.isFocused ? dropdownItems[scrolledToItem.index].id : undefined,
209
+ ariaControls: dropdownId,
210
+ ariaExpanded: isFlyoutOpen,
211
+ onChange: handleType,
212
+ userInput: timeString,
213
+ handleKeyDown: handleKeyDown,
214
+ setIsFlyoutOpen: setIsFlyoutOpen,
215
+ isDisabled: isDisabled,
216
+ is24HourClock: is24HourClock,
217
+ isInvalid: isInvalid,
218
+ ariaLabel: ariaLabel,
219
+ ariaLabelledBy: ariaLabelledBy,
220
+ ariaDescribedBy: ariaDescribedBy,
221
+ isOptionHovered: isOptionHovered,
222
+ setShouldMoveSelectionToEnd: setShouldMoveSelectionToEnd,
223
+ shouldMoveSelectionToEnd: shouldMoveSelectionToEnd,
224
+ ref: mergeRefs(ref, inputRef)
225
+ }), /*#__PURE__*/React__default.createElement(TimePickerIcon, {
226
+ isOpen: isFlyoutOpen,
227
+ isDisabled: isDisabled,
228
+ setIsFlyoutOpen: setIsFlyoutOpen,
229
+ iconRef: iconRef,
230
+ inputRef: inputRef
231
+ }), isFlyoutOpen && /*#__PURE__*/React__default.createElement(TimeDropdown, {
232
+ id: dropdownId,
233
+ inputRef: inputRef,
234
+ dropdownRef: dropdownRef,
235
+ onClick: handleSelectTime,
236
+ scrolledToItem: scrolledToItem,
237
+ items: dropdownItems,
238
+ dataTestId: dataTestId,
239
+ ariaLabel: ariaLabel,
240
+ ariaLabelledBy: ariaLabelledBy,
241
+ ariaDescribedBy: ariaDescribedBy,
242
+ setIsOptionHovered: setIsOptionHovered,
243
+ isOptionHovered: isOptionHovered
244
+ }));
245
+ });
246
+
247
+ export { TimePicker };
@@ -0,0 +1,8 @@
1
+ import styleInject from './../../__node_modules/style-inject/dist/style-inject.es.js';
2
+
3
+ var css_248z = "._1GejC{display:inline-block;position:relative}._3Dr_r{width:120px}._3Dr_r ._2XocA._1jj-a{transform:rotate(-180deg)}._3Dr_r ._2XocA._1Mz35{fill:#9d9fa1;opacity:.4}._1_Dli>input:focus{box-shadow:none!important;border:1px solid #898989!important}._2BBzB{width:120px}._2BBzB ._2d0wd._2e9oo{background-color:#efefef;border-radius:6px}._2XocA{position:absolute;right:4px;bottom:4px;height:28px;width:28px}._2XocA._1jj-a{transform:rotate(-180deg)}";
4
+ var styles = {"container":"_1GejC","input":"_3Dr_r","icon":"_2XocA","open":"_1jj-a","disabled":"_1Mz35","ignoreFocusStyle":"_1_Dli","flyout":"_2BBzB","option":"_2d0wd","exactMatch":"_2e9oo"};
5
+ var stylesheet="._1GejC{display:inline-block;position:relative}._3Dr_r{width:120px}._3Dr_r ._2XocA._1jj-a{transform:rotate(-180deg)}._3Dr_r ._2XocA._1Mz35{fill:#9d9fa1;opacity:.4}._1_Dli>input:focus{box-shadow:none!important;border:1px solid #898989!important}._2BBzB{width:120px}._2BBzB ._2d0wd._2e9oo{background-color:#efefef;border-radius:6px}._2XocA{position:absolute;right:4px;bottom:4px;height:28px;width:28px}._2XocA._1jj-a{transform:rotate(-180deg)}";
6
+ styleInject(css_248z);
7
+
8
+ export { styles as default, stylesheet };
@@ -0,0 +1,36 @@
1
+ import React__default from 'react';
2
+ import classNames from 'classnames';
3
+ import styles from './TimePicker2.js';
4
+ import '../../icons/index.es.js';
5
+ import '../../components/index.js';
6
+ import IconButton from '../../components/IconButton/IconButton.js';
7
+ import ChevronDownIcon from '../../icons/components/ChevronDownIcon.js';
8
+
9
+ const TimePickerIcon = _ref => {
10
+ let {
11
+ isOpen,
12
+ isDisabled,
13
+ setIsFlyoutOpen,
14
+ iconRef,
15
+ inputRef
16
+ } = _ref;
17
+ return /*#__PURE__*/React__default.createElement(IconButton, {
18
+ "aria-hidden": "true",
19
+ tabIndex: -1,
20
+ disabled: isDisabled,
21
+ className: classNames(styles.icon, {
22
+ [styles.open]: isOpen
23
+ })
24
+ }, /*#__PURE__*/React__default.createElement(ChevronDownIcon, {
25
+ onClick: !isDisabled ? () => {
26
+ var _inputRef$current;
27
+
28
+ setIsFlyoutOpen(i => !i);
29
+ (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
30
+ } : undefined,
31
+ onMouseDown: e => e.preventDefault(),
32
+ ref: iconRef
33
+ }));
34
+ };
35
+
36
+ export { TimePickerIcon as default };
@@ -0,0 +1 @@
1
+ export { TimePicker } from './TimePicker.js';
@@ -0,0 +1,229 @@
1
+ import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
2
+
3
+ const formatUtcDate = (utcDate, is24HourClock) => {
4
+ const {
5
+ format
6
+ } = Intl.DateTimeFormat(undefined, {
7
+ timeStyle: 'short',
8
+ timeZone: 'UTC',
9
+ hourCycle: is24HourClock ? 'h23' : 'h12'
10
+ });
11
+ const dateWithoutLeadingZeros = format(utcDate);
12
+ let dateWithLeadingZeros = dateWithoutLeadingZeros;
13
+
14
+ if (dateWithLeadingZeros.split(':')[0].length === 1) {
15
+ dateWithLeadingZeros = "0".concat(dateWithLeadingZeros);
16
+ }
17
+
18
+ return dateWithLeadingZeros.toLowerCase();
19
+ };
20
+ const convertTimeObjectToTimeString = (time, is24HourClock) => {
21
+ const date = Date.UTC(2000, 0, 0, time.hour, time.minute);
22
+ return formatUtcDate(date, is24HourClock);
23
+ };
24
+ const convertTimeStringToTimeObject = completeTimeString => {
25
+ const [hourPart, minutePart, amPmPart] = completeTimeString.split(/:| /);
26
+ let hour = +hourPart;
27
+ const minute = +minutePart;
28
+
29
+ if (amPmPart === 'am' && hour === 12) {
30
+ hour = 0;
31
+ } else if (amPmPart === 'pm' && hour < 12) {
32
+ hour += 12;
33
+ }
34
+
35
+ return {
36
+ hour,
37
+ minute
38
+ };
39
+ };
40
+ const generateTimes = (step, is24HourClock) => {
41
+ const secondsInDay = 60 * 60 * 24;
42
+ return Array.from(Array(secondsInDay / step)).map((_, i) => {
43
+ const labelWithLeadingZeros = formatUtcDate(Date.UTC(2000, 0, 1, 0, 0, i * step, 0), is24HourClock);
44
+ return {
45
+ label: labelWithLeadingZeros,
46
+ value: i * step,
47
+ id: "time-option-".concat(i)
48
+ };
49
+ });
50
+ };
51
+
52
+ function getTimeStringCorrector(str, is24HourClock) {
53
+ var _letterString;
54
+
55
+ let [numberString, letterString] = str.replace(':', '').split(' ');
56
+ letterString = (_letterString = letterString) === null || _letterString === void 0 ? void 0 : _letterString.toLowerCase();
57
+ let selectionModifier = 0;
58
+
59
+ const getTimeString = () => {
60
+ const finalNumberString = "".concat(numberString.slice(0, 2), ":").concat(numberString.slice(2, 4));
61
+ return is24HourClock ? finalNumberString : "".concat(finalNumberString, " ").concat(letterString);
62
+ };
63
+
64
+ const getSelectionModifier = () => selectionModifier;
65
+
66
+ const replaceDashes = () => {
67
+ numberString = numberString.replace(/-/g, '0');
68
+
69
+ if (letterString) {
70
+ if (letterString[0] === '-' || letterString[0] === 'a') {
71
+ // Arbitrarily choose AM if user hasn't typed 'a' or 'p'
72
+ letterString = 'am';
73
+ } else {
74
+ letterString = 'pm';
75
+ }
76
+ }
77
+ };
78
+
79
+ const shiftMinutesRight = () => {
80
+ numberString = "".concat(numberString.slice(0, 2), "0").concat(numberString[2]);
81
+ selectionModifier += 1;
82
+ };
83
+
84
+ const prependCharacter = character => {
85
+ numberString = "".concat(character).concat(numberString);
86
+ selectionModifier += 1;
87
+ };
88
+
89
+ const setHoursTo12 = () => {
90
+ numberString = "12".concat(numberString.slice(2));
91
+ };
92
+
93
+ const clearSecondHoursDigit = () => {
94
+ numberString = "".concat(numberString.slice(0, 1), "0").concat(numberString.slice(2));
95
+ };
96
+
97
+ const hoursAre00 = () => numberString[0] === '0' && numberString[1] === '0';
98
+
99
+ const firstHourGreaterThan1 = () => {
100
+ var _context;
101
+
102
+ return !_includesInstanceProperty(_context = '01-').call(_context, numberString[0]);
103
+ };
104
+
105
+ const firstHourGreaterThan2 = () => {
106
+ var _context2;
107
+
108
+ return !_includesInstanceProperty(_context2 = '012-').call(_context2, numberString[0]);
109
+ };
110
+
111
+ const hoursGreaterThan12 = () => {
112
+ var _context3;
113
+
114
+ return numberString[0] === '1' && !_includesInstanceProperty(_context3 = '012-').call(_context3, numberString[1]);
115
+ };
116
+
117
+ const hoursGreaterThan23 = () => {
118
+ var _context4;
119
+
120
+ return numberString[0] === '2' && !_includesInstanceProperty(_context4 = '0123-').call(_context4, numberString[1]);
121
+ };
122
+
123
+ const firstMinuteGreaterThan5 = () => numberString[2] !== '-' && +numberString[2] > 5;
124
+
125
+ const hasTypedMinutes = () => numberString[2] !== '-' && numberString[3] !== '-';
126
+
127
+ return {
128
+ getTimeString,
129
+ getSelectionModifier,
130
+ replaceDashes,
131
+ setHoursTo12,
132
+ clearSecondHoursDigit,
133
+ shiftMinutesRight,
134
+ prependCharacter,
135
+ hoursAre00,
136
+ firstHourGreaterThan1,
137
+ firstHourGreaterThan2,
138
+ hoursGreaterThan12,
139
+ hoursGreaterThan23,
140
+ firstMinuteGreaterThan5,
141
+ hasTypedMinutes
142
+ };
143
+ }
144
+
145
+ const correct12HourTime = (time, mustCompleteTime) => {
146
+ const timeStringCorrector = getTimeStringCorrector(time, false);
147
+
148
+ if (mustCompleteTime) {
149
+ timeStringCorrector.replaceDashes();
150
+ }
151
+
152
+ if (timeStringCorrector.firstHourGreaterThan1()) {
153
+ timeStringCorrector.prependCharacter('0');
154
+ }
155
+
156
+ if (timeStringCorrector.hoursGreaterThan12()) {
157
+ if (timeStringCorrector.hasTypedMinutes()) {
158
+ // User likely just edited the first digit and that made the
159
+ // second digit invalid, e.g., changed '08:' to '18:'. They
160
+ // probably are about to fix up the second digit. We'll set it to 0
161
+ timeStringCorrector.clearSecondHoursDigit();
162
+ } else {
163
+ // Assume the user forgot a leading 0
164
+ // Example: we are changing '13:--' to '01:3-'
165
+ timeStringCorrector.prependCharacter('0');
166
+ }
167
+ }
168
+
169
+ if (timeStringCorrector.hoursAre00()) {
170
+ timeStringCorrector.setHoursTo12();
171
+ }
172
+
173
+ if (timeStringCorrector.firstMinuteGreaterThan5()) {
174
+ // Assume the user forgot a 0
175
+ // Example: we are changing 12:6- to 12:06
176
+ timeStringCorrector.shiftMinutesRight();
177
+ }
178
+
179
+ return {
180
+ correctedTime: timeStringCorrector.getTimeString(),
181
+ selectionModifier: timeStringCorrector.getSelectionModifier()
182
+ };
183
+ };
184
+
185
+ const correct24HourTime = (time, mustCompleteTime) => {
186
+ const timeStringCorrector = getTimeStringCorrector(time, true);
187
+
188
+ if (mustCompleteTime) {
189
+ timeStringCorrector.replaceDashes();
190
+ }
191
+
192
+ if (timeStringCorrector.hoursGreaterThan23()) {
193
+ // User likely just edited the first digit and that made the second
194
+ // digit invalid, e.g., changed '15:' to '25:'. They probably
195
+ // are about to fix up the second digit. We'll set it to 0
196
+ if (timeStringCorrector.hasTypedMinutes()) {
197
+ timeStringCorrector.clearSecondHoursDigit();
198
+ } else {
199
+ // Assume the user forgot a leading 0
200
+ // Example: we are changing '25:--' to '02:5-'
201
+ timeStringCorrector.prependCharacter('0');
202
+ }
203
+ }
204
+
205
+ if (timeStringCorrector.firstHourGreaterThan2()) {
206
+ // Assume the user forgot a leading 0
207
+ // Example: we are changing '3-:--' to '03:--'
208
+ timeStringCorrector.prependCharacter('0');
209
+ }
210
+
211
+ if (timeStringCorrector.firstMinuteGreaterThan5()) {
212
+ // Assume the user forgot a 0
213
+ // Example: we are changing 12:6- to 12:06
214
+ timeStringCorrector.shiftMinutesRight();
215
+ }
216
+
217
+ return {
218
+ correctedTime: timeStringCorrector.getTimeString(),
219
+ selectionModifier: timeStringCorrector.getSelectionModifier()
220
+ };
221
+ }; // We will follow the same process to correct the time regardless
222
+ // of what specific character changed.
223
+ // This simplifies logic for when multiple chars are pasted in
224
+ // and for when the input has to be shifted due to invalid entries.
225
+
226
+
227
+ const correctTime = (time, is24HourClock, mustCompleteTime) => is24HourClock ? correct24HourTime(time, mustCompleteTime) : correct12HourTime(time, mustCompleteTime);
228
+
229
+ export { convertTimeObjectToTimeString, convertTimeStringToTimeObject, correctTime, formatUtcDate, generateTimes };
@@ -341,4 +341,24 @@ export declare interface SubMenuProps extends Omit<AllHTMLAttributes<HTMLDivElem
341
341
  isSearchFilteringDisabled?: boolean;
342
342
  }
343
343
 
344
+ declare interface Time {
345
+ hour: number;
346
+ minute: number;
347
+ }
348
+
349
+ export declare const TimePicker: React_2.ForwardRefExoticComponent<TimePickerProps & React_2.RefAttributes<HTMLInputElement>>;
350
+
351
+ export declare interface TimePickerProps {
352
+ value?: Time;
353
+ onChange?: (value: Time) => void;
354
+ is24HourClock?: boolean;
355
+ isDisabled?: boolean;
356
+ isInvalid?: boolean;
357
+ id?: string;
358
+ 'data-testid'?: string;
359
+ 'aria-label'?: string;
360
+ 'aria-labelledby'?: string;
361
+ 'aria-describedby'?: string;
362
+ }
363
+
344
364
  export { }
@@ -7,6 +7,7 @@ import './SplitButton/index.js';
7
7
  import './FilterAnchor/index.js';
8
8
  import './Menu/index.js';
9
9
  import './Drawer/index.js';
10
+ import './TimePicker/index.js';
10
11
  export { AdvancedTable } from './AdvancedTable/AdvancedTable.js';
11
12
  export { default as CollapsibleSearchInput } from './CollapsibleSearchInput/CollapsibleSearchInput.js';
12
13
  export { default as Input } from './Input/Input.js';
@@ -25,5 +26,6 @@ export { MenuPane } from './Menu/MenuPane.js';
25
26
  export { MenuItem } from './Menu/MenuItem.js';
26
27
  export { SubMenu } from './Menu/SubMenu.js';
27
28
  export { default as Drawer } from './Drawer/Drawer.js';
29
+ export { TimePicker } from './TimePicker/TimePicker.js';
28
30
 
29
31
  /* eslint-disable camelcase */