@ringcentral/spring-ui 1.12.0 → 1.13.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.
- package/Accordion.js +90 -34
- package/AccordionHeader.js +71 -21
- package/Alert.js +120 -28
- package/Animation.js +2 -46
- package/Announcement.js +46 -35
- package/Autocomplete.js +1011 -583
- package/Avatar.js +134 -73
- package/AvatarGroup.js +50 -7
- package/Backdrop.js +45 -7
- package/Badge.js +77 -15
- package/Block.js +34 -12
- package/BlockHeader.js +57 -15
- package/BottomNavigation.js +181 -65
- package/BottomNavigationItem.js +93 -30
- package/Button.js +160 -24
- package/CallButton.js +53 -31
- package/Checkbox.js +88 -26
- package/Chip.js +126 -26
- package/CircularProgressIndicator.js +80 -8
- package/ClickAwayListener.js +4 -1
- package/ComponentsProps.js +1 -0
- package/DatePicker.js +611 -192
- package/DateUtilsContext.js +43 -25
- package/Dialer.js +564 -253
- package/Dialog.js +99 -45
- package/Divider.js +43 -7
- package/DragHandle.js +32 -6
- package/Drawer.js +117 -19
- package/Dropdown.js +154 -77
- package/EmptyState.js +65 -15
- package/FabButton.js +51 -17
- package/FocusTrap.js +109 -12
- package/FormField.js +108 -12
- package/FormLabel.js +81 -7
- package/Icon.js +1 -8
- package/IconButton.js +142 -26
- package/IconButtonGroup.js +35 -12
- package/InlineEditable.js +98 -44
- package/LinearProgressIndicator.js +73 -24
- package/Link.js +40 -11
- package/List.js +54 -9
- package/ListItem.js +152 -23
- package/ListItemText.js +44 -17
- package/ListNavigation.js +272 -20
- package/Menu.js +139 -23
- package/MenuActions.js +37 -12
- package/MenuDivider.js +34 -8
- package/MenuFooter.js +36 -12
- package/MenuHeader.js +54 -16
- package/MenuItem.js +402 -35
- package/MenuItemText.js +51 -9
- package/MenuList.js +87 -36
- package/Modal.js +345 -16
- package/NestedMenuContext.js +183 -11
- package/Option.js +32 -36
- package/Overlap.js +54 -7
- package/PageHeader.js +62 -24
- package/PickerTextField.js +156 -35
- package/Popover.js +262 -21
- package/Popper.js +112 -62
- package/PopperPaper.js +54 -8
- package/Portal.js +6 -1
- package/Radio.js +65 -21
- package/RadioGroup.js +56 -17
- package/Rating.js +223 -87
- package/Select.js +387 -44
- package/SingleFilter.js +148 -79
- package/Skeleton.js +68 -17
- package/Slider.js +167 -69
- package/Snackbar.js +122 -59
- package/SortableList.js +32 -12
- package/SortableListDndContext.js +69 -22
- package/SortableListItem.js +92 -47
- package/SortableVirtualizedList.js +44 -20
- package/SplitButton.js +124 -89
- package/Squircle.js +4 -7
- package/StatusIndicator.js +51 -9
- package/Step.js +63 -38
- package/StepButton.js +51 -23
- package/StepConnector.js +48 -8
- package/StepContent.js +67 -24
- package/StepIcon.js +90 -9
- package/StepLabel.js +90 -14
- package/Stepper.js +65 -23
- package/SubMenu.js +203 -101
- package/SwipeableDrawer.js +439 -194
- package/Switch.js +70 -23
- package/Tab.js +120 -57
- package/TabContext.js +59 -15
- package/TabPanel.js +40 -13
- package/Table.js +60 -17
- package/TableBody.js +42 -12
- package/TableCell.js +84 -50
- package/TableContainer.js +32 -10
- package/TableFooter.js +38 -10
- package/TableHead.js +49 -15
- package/TablePagination.js +153 -79
- package/TableRow.js +60 -21
- package/Tabs.js +592 -271
- package/Tag.js +51 -16
- package/Text.js +68 -37
- package/TextField.js +209 -31
- package/Textarea.js +51 -42
- package/TimePicker.js +490 -232
- package/Tooltip.js +48 -23
- package/Tray.js +237 -13
- package/TrayMenu.js +62 -43
- package/VirtualizedList.js +205 -107
- package/VirtualizedMenu.js +359 -29
- package/VisuallyHidden.js +29 -6
- package/chunks/1250.js +98 -0
- package/chunks/1294.js +126 -0
- package/chunks/2956.js +18 -0
- package/chunks/4476.js +460 -0
- package/chunks/4491.js +10 -0
- package/chunks/4535.js +364 -0
- package/chunks/5047.js +3 -0
- package/chunks/6335.js +24 -0
- package/chunks/7279.js +10 -0
- package/chunks/8011.js +8 -0
- package/chunks/8307.js +56 -0
- package/chunks/8467.js +8 -0
- package/chunks/8809.js +8 -0
- package/chunks/{RadioGroup.context.js → 9551.js} +12 -6
- package/chunks/987.js +8 -0
- package/index.css +2436 -2261
- package/index.js +245 -195
- package/internal/utils/setRef.d.ts +2 -1
- package/package.json +4 -4
- package/src/Animation/hooks/useMotionSafeTransition/useMotionSafeTransition.d.ts +2 -0
- package/src/Autocomplete/SuggestionList/SuggestionList.d.ts +1 -1
- package/src/Button/Button.classes.d.ts +1 -1
- package/src/ComponentsProps.d.ts +111 -110
- package/src/DatePicker/DatePickerDataAttributes.d.ts +11 -0
- package/src/DatePicker/utils/DatePickerUtils.d.ts +1 -1
- package/src/MenuItem/MenuItem.type.d.ts +1 -0
- package/src/MenuList/MenuListContext.d.ts +2 -3
- package/src/Modal/Modal.type.d.ts +1 -0
- package/src/Popover/Popover.classes.d.ts +1 -1
- package/src/Popover/Popover.internal.d.ts +8 -0
- package/src/Popover/Popover.type.d.ts +1 -0
- package/src/Select/Select.type.d.ts +6 -4
- package/src/Table/Table.type.d.ts +3 -0
- package/src/Table/TableContext.d.ts +3 -0
- package/src/Table/TableRowContext.d.ts +7 -0
- package/src/Table/index.d.ts +1 -0
- package/src/TableCell/TableCell.classes.d.ts +1 -1
- package/src/TableFooter/TableFooter.classes.d.ts +1 -1
- package/src/TableFooter/TableFooter.type.d.ts +1 -0
- package/src/TableHead/TableHead.classes.d.ts +1 -1
- package/src/TableHead/TableHead.type.d.ts +1 -0
- package/src/TableRow/TableRow.type.d.ts +2 -0
- package/chunks/AccordionContext.js +0 -6
- package/chunks/Alert.js +0 -48
- package/chunks/AvatarGroup.js +0 -22
- package/chunks/Backdrop.js +0 -18
- package/chunks/Badge.js +0 -32
- package/chunks/BottomNavigationItem.js +0 -36
- package/chunks/Button.js +0 -88
- package/chunks/Chip.js +0 -73
- package/chunks/CircularProgressIndicator.js +0 -36
- package/chunks/Divider.js +0 -19
- package/chunks/DragHandle.js +0 -11
- package/chunks/Drawer.js +0 -33
- package/chunks/ExpandCollapseCaret.js +0 -24
- package/chunks/FormLabel.js +0 -27
- package/chunks/Icon.js +0 -25
- package/chunks/IconButtonLabel.js +0 -68
- package/chunks/List.js +0 -22
- package/chunks/ListItem.js +0 -83
- package/chunks/Menu.js +0 -61
- package/chunks/MenuDivider.js +0 -14
- package/chunks/MenuItemText.js +0 -18
- package/chunks/MenuList.js +0 -47
- package/chunks/Modal.js +0 -211
- package/chunks/Overlap.js +0 -25
- package/chunks/PickerTextField.js +0 -85
- package/chunks/Popover.js +0 -61
- package/chunks/PopperPaper.js +0 -15
- package/chunks/Select.js +0 -225
- package/chunks/ShowHideEye.js +0 -56
- package/chunks/SlideIn.js +0 -20
- package/chunks/SortableArrow.js +0 -73
- package/chunks/Squircle.js +0 -31
- package/chunks/StatusIndicator.js +0 -20
- package/chunks/StepConnector.js +0 -21
- package/chunks/StepIcon.js +0 -43
- package/chunks/StepLabel.js +0 -29
- package/chunks/StepperContext.js +0 -9
- package/chunks/TableContext.js +0 -6
- package/chunks/Tablelvl2Context.js +0 -6
- package/chunks/TabsContext.js +0 -6
- package/chunks/TextField.js +0 -110
- package/chunks/Tooltip.js +0 -217
- package/chunks/VirtualizedMenu.js +0 -162
- package/chunks/VisuallyHidden.js +0 -12
- package/chunks/composeEventHandlers.js +0 -10
- package/chunks/getFade.js +0 -27
- package/chunks/getGrow.js +0 -70
- package/chunks/getSlideIn.js +0 -30
- package/chunks/hasContent.js +0 -3
- package/chunks/useAnimationFrame.js +0 -15
- package/chunks/useFocusTrapStack.js +0 -38
- package/chunks/useHelperTextId.js +0 -24
- package/chunks/useListNavigation.js +0 -199
- package/chunks/useMenuItemSelect.js +0 -282
- package/chunks/useMotionSafeTransition.js +0 -9
- package/chunks/useNestedMenuItem.js +0 -27
- package/chunks/useNestedParentMenu.js +0 -113
- package/chunks/usePrefersReducedMotion.js +0 -36
- package/chunks/useTooltipForceHide.js +0 -27
- package/chunks/useTrayNavigate.js +0 -150
- package/chunks/withTooltip.js +0 -15
package/TimePicker.js
CHANGED
|
@@ -1,81 +1,92 @@
|
|
|
1
|
-
import { jsx, jsxs } from
|
|
2
|
-
import { createContext, useContext,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
import './chunks/VisuallyHidden.js';
|
|
32
|
-
|
|
33
|
-
const TimePickerClassesContext = createContext(() => '');
|
|
34
|
-
const useTimePickerClasses = () => useContext(TimePickerClassesContext);
|
|
35
|
-
|
|
36
|
-
const TimeButton = forwardRef((props, ref) => {
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, forwardRef, useContext, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { combineProps, runKeyHandler, useEventCallback, useFocusVisible, useForkRef } from "@ringcentral/spring-base";
|
|
4
|
+
import { CaretDownMd, CaretUpMd, RecentMd } from "@ringcentral/spring-icon";
|
|
5
|
+
import clsx from "clsx";
|
|
6
|
+
import { useClassesWithMode, useThemeProps } from "@ringcentral/spring-theme";
|
|
7
|
+
import { Icon as Icon_Icon } from "./chunks/8307.js";
|
|
8
|
+
import { IconButton as IconButton_IconButton } from "./IconButton.js";
|
|
9
|
+
import { PickerTextField as PickerTextField_PickerTextField } from "./PickerTextField.js";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const TimePickerClassesContext = createContext(()=>'');
|
|
22
|
+
const useTimePickerClasses = ()=>useContext(TimePickerClassesContext);
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
const TimeButton = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
37
31
|
const { value, selected, disabled, children, onFocus, onBlur, className, ...rest } = props;
|
|
38
32
|
const cls = useTimePickerClasses();
|
|
39
33
|
const { focusVisible, focusVisibleHandlers, focusVisibleRef } = useFocusVisible();
|
|
40
34
|
const handleRef = useForkRef(ref, focusVisibleRef);
|
|
41
|
-
return
|
|
35
|
+
return /*#__PURE__*/ jsx("button", {
|
|
36
|
+
ref: handleRef,
|
|
37
|
+
className: clsx(className, cls('time-button', {
|
|
42
38
|
selected,
|
|
43
39
|
disabled,
|
|
44
|
-
focusVisible
|
|
45
|
-
})),
|
|
40
|
+
focusVisible
|
|
41
|
+
})),
|
|
42
|
+
...rest,
|
|
43
|
+
...combineProps({
|
|
44
|
+
onBlur,
|
|
45
|
+
onFocus
|
|
46
|
+
}, focusVisibleHandlers),
|
|
47
|
+
type: "button",
|
|
48
|
+
children: children
|
|
49
|
+
});
|
|
46
50
|
});
|
|
47
51
|
TimeButton.displayName = 'SuiTimeButton';
|
|
48
52
|
|
|
53
|
+
|
|
49
54
|
function isClick(event) {
|
|
50
55
|
return event.type === 'click';
|
|
51
56
|
}
|
|
52
57
|
|
|
53
|
-
var TIME_SYSTEM_TEXT
|
|
54
|
-
(function (TIME_SYSTEM_TEXT) {
|
|
58
|
+
var constant_TIME_SYSTEM_TEXT = /*#__PURE__*/ function(TIME_SYSTEM_TEXT) {
|
|
55
59
|
TIME_SYSTEM_TEXT["PM"] = "PM";
|
|
56
60
|
TIME_SYSTEM_TEXT["AM"] = "AM";
|
|
57
|
-
|
|
61
|
+
return TIME_SYSTEM_TEXT;
|
|
62
|
+
}(constant_TIME_SYSTEM_TEXT || {});
|
|
58
63
|
const K_ENTER = 'Enter';
|
|
59
64
|
const K_SPACE = ' ';
|
|
60
65
|
|
|
61
|
-
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
const parseNumber = (value, isTwelveHourSystem)=>{
|
|
62
69
|
const count = isTwelveHourSystem ? value % 12 : value;
|
|
63
|
-
if (isTwelveHourSystem && count === 0)
|
|
64
|
-
return 12;
|
|
70
|
+
if (isTwelveHourSystem && count === 0) return 12;
|
|
65
71
|
return count;
|
|
66
72
|
};
|
|
67
|
-
const parseNumberToString = (value, isTwelveHourSystem)
|
|
73
|
+
const parseNumberToString = (value, isTwelveHourSystem)=>{
|
|
68
74
|
const count = parseNumber(value, isTwelveHourSystem);
|
|
69
75
|
return pad(count);
|
|
70
76
|
};
|
|
71
|
-
const pad = (num, size = 2)
|
|
77
|
+
/** add miss zero */ const pad = (num, size = 2)=>{
|
|
72
78
|
let s = `${num}`;
|
|
73
|
-
while
|
|
79
|
+
while(s.length < size){
|
|
74
80
|
s = `0${s}`;
|
|
75
81
|
}
|
|
76
82
|
return s;
|
|
77
83
|
};
|
|
78
|
-
|
|
84
|
+
/**
|
|
85
|
+
* get formatted time hh:mm
|
|
86
|
+
* @param option `{hour, min, period}`
|
|
87
|
+
* @param isTwelveHourSystem boolean
|
|
88
|
+
* @returns `hh:mm AM` or `hh:mm PM` or `hh:mm`
|
|
89
|
+
*/ const getFormattedTime = ({ hour, minute, period }, isTwelveHourSystem)=>{
|
|
79
90
|
const formattedHour = parseNumberToString(hour, isTwelveHourSystem);
|
|
80
91
|
const formattedMinute = parseNumberToString(minute);
|
|
81
92
|
const periodText = isTwelveHourSystem ? ` ${period}` : '';
|
|
@@ -86,12 +97,11 @@ const HOUR_MINUTES = 60;
|
|
|
86
97
|
const TIME_GAP = 15;
|
|
87
98
|
const ONE_HOUR = HOUR_MINUTES * HOUR_MINUTES * 1000;
|
|
88
99
|
const ONE_MINUTE = HOUR_MINUTES * 1000;
|
|
89
|
-
const buildConsecutiveNumberToArray = (min, max)
|
|
100
|
+
const buildConsecutiveNumberToArray = (min, max)=>{
|
|
90
101
|
const array = [];
|
|
91
|
-
if (min > max)
|
|
92
|
-
return array;
|
|
102
|
+
if (min > max) return array;
|
|
93
103
|
let count = min;
|
|
94
|
-
while
|
|
104
|
+
while(count <= max){
|
|
95
105
|
array.push(count);
|
|
96
106
|
count++;
|
|
97
107
|
}
|
|
@@ -99,69 +109,89 @@ const buildConsecutiveNumberToArray = (min, max) => {
|
|
|
99
109
|
};
|
|
100
110
|
const twelveHourSystemSource = buildConsecutiveNumberToArray(0, 11);
|
|
101
111
|
const twentyFourHourSystemSource = buildConsecutiveNumberToArray(0, 23);
|
|
102
|
-
const minuteSource = [
|
|
112
|
+
const minuteSource = [
|
|
113
|
+
0,
|
|
114
|
+
15,
|
|
115
|
+
30,
|
|
116
|
+
45
|
|
117
|
+
];
|
|
103
118
|
const lastMinute = 45;
|
|
104
|
-
|
|
119
|
+
/**
|
|
120
|
+
* hour and minute timestamp
|
|
121
|
+
*/ const getTimestampFromDate = (date)=>{
|
|
105
122
|
return date.getHours() * ONE_HOUR + date.getMinutes() * ONE_MINUTE;
|
|
106
123
|
};
|
|
107
|
-
|
|
124
|
+
/**
|
|
125
|
+
* hour and minute number
|
|
126
|
+
*/ const getHourAndMinute = (times)=>{
|
|
108
127
|
if (times === null) {
|
|
109
128
|
return {
|
|
110
129
|
hour: 0,
|
|
111
|
-
minute: 0
|
|
130
|
+
minute: 0
|
|
112
131
|
};
|
|
113
132
|
}
|
|
114
133
|
const minute = times % ONE_HOUR;
|
|
115
134
|
const hour = (times - minute) / ONE_HOUR;
|
|
116
135
|
return {
|
|
117
136
|
hour,
|
|
118
|
-
minute: Math.floor(minute / ONE_MINUTE)
|
|
137
|
+
minute: Math.floor(minute / ONE_MINUTE)
|
|
119
138
|
};
|
|
120
139
|
};
|
|
121
|
-
|
|
140
|
+
/**
|
|
141
|
+
* get timestamp from date or timestamp
|
|
142
|
+
*
|
|
143
|
+
* if nowTime is number, it must be hour and minute timestamp
|
|
144
|
+
*/ function getTimestamp(nowTime) {
|
|
122
145
|
return nowTime instanceof Date ? getTimestampFromDate(nowTime) : nowTime;
|
|
123
146
|
}
|
|
124
|
-
|
|
147
|
+
/**
|
|
148
|
+
* hour and min object to timestamp
|
|
149
|
+
*/ const getTimestampFromHourAndMin = (option)=>{
|
|
125
150
|
return option.hour * ONE_HOUR + option.minute * ONE_MINUTE;
|
|
126
151
|
};
|
|
127
|
-
|
|
128
|
-
|
|
152
|
+
/**
|
|
153
|
+
* get period, `PM` or `AM`
|
|
154
|
+
*/ function getPeriod(currHour) {
|
|
155
|
+
return currHour >= HALF_DAY_HOURS ? constant_TIME_SYSTEM_TEXT.PM : constant_TIME_SYSTEM_TEXT.AM;
|
|
129
156
|
}
|
|
130
|
-
const getRecoupHour = (currHour, period)
|
|
131
|
-
switch
|
|
132
|
-
case
|
|
157
|
+
const getRecoupHour = (currHour, period)=>{
|
|
158
|
+
switch(period){
|
|
159
|
+
case constant_TIME_SYSTEM_TEXT.PM:
|
|
133
160
|
if (currHour < HALF_DAY_HOURS) {
|
|
134
161
|
return HALF_DAY_HOURS;
|
|
135
162
|
}
|
|
136
163
|
break;
|
|
137
|
-
case
|
|
164
|
+
case constant_TIME_SYSTEM_TEXT.AM:
|
|
165
|
+
// FIXME
|
|
166
|
+
// oxlint-disable-next-line sonarjs/no-collapsible-if
|
|
138
167
|
if (currHour < HALF_DAY_HOURS) {
|
|
139
168
|
if (currHour >= HALF_DAY_HOURS) {
|
|
140
169
|
return -HALF_DAY_HOURS;
|
|
141
170
|
}
|
|
142
171
|
}
|
|
143
172
|
break;
|
|
173
|
+
default:
|
|
174
|
+
break;
|
|
144
175
|
}
|
|
145
176
|
return 0;
|
|
146
177
|
};
|
|
147
178
|
|
|
148
|
-
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
const getDateBeginning = ()=>{
|
|
149
182
|
const date = new Date();
|
|
150
183
|
date.setHours(0, 0, 0, 0);
|
|
151
184
|
return date;
|
|
152
185
|
};
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
timeGap;
|
|
186
|
+
/**
|
|
187
|
+
* get target time boundary, what time is nearest time with that timeGap
|
|
188
|
+
*/ class TimeBoundary {
|
|
157
189
|
get hour() {
|
|
158
190
|
return this._hour;
|
|
159
191
|
}
|
|
160
|
-
_minute = undefined;
|
|
161
192
|
get minute() {
|
|
162
193
|
return this._minute;
|
|
163
194
|
}
|
|
164
|
-
_date = undefined;
|
|
165
195
|
get date() {
|
|
166
196
|
return this._date;
|
|
167
197
|
}
|
|
@@ -171,15 +201,17 @@ class TimeBoundary {
|
|
|
171
201
|
}
|
|
172
202
|
this._date = value;
|
|
173
203
|
}
|
|
174
|
-
|
|
175
|
-
|
|
204
|
+
constructor(value, direction, timeGap){
|
|
205
|
+
this._hour = undefined;
|
|
206
|
+
this._minute = undefined;
|
|
207
|
+
this._date = undefined;
|
|
208
|
+
this.timestamp = 0;
|
|
176
209
|
this.value = value;
|
|
177
210
|
this.timeGap = timeGap;
|
|
178
211
|
if (value) {
|
|
179
212
|
if (direction === 'after') {
|
|
180
213
|
this.getAfterNearTime();
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
214
|
+
} else {
|
|
183
215
|
this.getBeforeNearTime();
|
|
184
216
|
}
|
|
185
217
|
this.date = new Date(getDateBeginning().setHours(this.hour, this.minute, 0, 0));
|
|
@@ -190,12 +222,13 @@ class TimeBoundary {
|
|
|
190
222
|
let hour = time.getHours();
|
|
191
223
|
let minute = time.getMinutes();
|
|
192
224
|
const partCount = Math.ceil(minute / this.timeGap);
|
|
193
|
-
|
|
225
|
+
// when time is the latest or more, add one hour
|
|
226
|
+
if (partCount >= (/* inlined export .HOUR_MINUTES */60) / this.timeGap) {
|
|
194
227
|
hour++;
|
|
195
228
|
minute = 0;
|
|
196
229
|
}
|
|
197
230
|
this._hour = hour;
|
|
198
|
-
this._minute =
|
|
231
|
+
this._minute = partCount * this.timeGap % (/* inlined export .HOUR_MINUTES */60);
|
|
199
232
|
}
|
|
200
233
|
getBeforeNearTime() {
|
|
201
234
|
const time = this.getDateTime();
|
|
@@ -212,7 +245,7 @@ class TimeBoundary {
|
|
|
212
245
|
return date;
|
|
213
246
|
}
|
|
214
247
|
}
|
|
215
|
-
const getRangeBoundary = ({ min, max, gap = TIME_GAP
|
|
248
|
+
const getRangeBoundary = ({ min, max, gap = (/* inlined export .TIME_GAP */15) })=>{
|
|
216
249
|
if (min !== undefined && max !== undefined) {
|
|
217
250
|
const minTimestamp = getTimestamp(min);
|
|
218
251
|
const maxTimestamp = getTimestamp(max);
|
|
@@ -222,59 +255,76 @@ const getRangeBoundary = ({ min, max, gap = TIME_GAP, }) => {
|
|
|
222
255
|
}
|
|
223
256
|
return {
|
|
224
257
|
min: new TimeBoundary(min, 'after', gap),
|
|
225
|
-
max: new TimeBoundary(max, 'before', gap)
|
|
258
|
+
max: new TimeBoundary(max, 'before', gap)
|
|
226
259
|
};
|
|
227
260
|
};
|
|
228
261
|
|
|
229
|
-
|
|
230
|
-
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* get range from current hour
|
|
265
|
+
*/ function getNumberPickerBoundary(currentHour, { range, isTwelveHourSystem }) {
|
|
266
|
+
const currentIsPM = currentHour >= (/* inlined export .HALF_DAY_HOURS */12);
|
|
231
267
|
let maxHour = range.max.hour ?? 23;
|
|
232
|
-
let maxMinute = range.max.minute ?? lastMinute;
|
|
268
|
+
let maxMinute = range.max.minute ?? (/* inlined export .lastMinute */45);
|
|
233
269
|
let minHour = range.min.hour ?? 0;
|
|
234
270
|
let minMinute = range.min.minute ?? 0;
|
|
235
271
|
if (isTwelveHourSystem) {
|
|
236
272
|
if (currentIsPM) {
|
|
237
|
-
if (minHour < HALF_DAY_HOURS) {
|
|
273
|
+
if (minHour < (/* inlined export .HALF_DAY_HOURS */12)) {
|
|
238
274
|
minHour = 0;
|
|
239
275
|
minMinute = 0;
|
|
240
276
|
}
|
|
241
|
-
}
|
|
242
|
-
else if (maxHour >= HALF_DAY_HOURS) {
|
|
277
|
+
} else if (maxHour >= (/* inlined export .HALF_DAY_HOURS */12)) {
|
|
243
278
|
maxHour = 11;
|
|
244
|
-
maxMinute = lastMinute;
|
|
279
|
+
maxMinute = (/* inlined export .lastMinute */45);
|
|
245
280
|
}
|
|
246
281
|
}
|
|
247
|
-
if (maxMinute !== lastMinute && currentHour < maxHour) {
|
|
248
|
-
maxMinute = lastMinute;
|
|
282
|
+
if (maxMinute !== (/* inlined export .lastMinute */45) && currentHour < maxHour) {
|
|
283
|
+
maxMinute = (/* inlined export .lastMinute */45);
|
|
249
284
|
}
|
|
250
285
|
if (minMinute !== 0 && currentHour > minHour) {
|
|
251
286
|
minMinute = 0;
|
|
252
287
|
}
|
|
253
288
|
if (isTwelveHourSystem) {
|
|
254
|
-
maxHour = maxHour % HALF_DAY_HOURS;
|
|
255
|
-
minHour = minHour % HALF_DAY_HOURS;
|
|
289
|
+
maxHour = maxHour % (/* inlined export .HALF_DAY_HOURS */12);
|
|
290
|
+
minHour = minHour % (/* inlined export .HALF_DAY_HOURS */12);
|
|
256
291
|
}
|
|
257
292
|
return {
|
|
258
293
|
hour: {
|
|
259
294
|
min: minHour,
|
|
260
|
-
max: maxHour
|
|
295
|
+
max: maxHour
|
|
261
296
|
},
|
|
262
297
|
minute: {
|
|
263
298
|
min: minMinute,
|
|
264
|
-
max: maxMinute
|
|
265
|
-
}
|
|
299
|
+
max: maxMinute
|
|
300
|
+
}
|
|
266
301
|
};
|
|
267
302
|
}
|
|
268
303
|
|
|
269
|
-
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
const NumberPicker = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
270
319
|
const { onClick, value, onChange: onUpdate, onKeyDown, source, min, max, step, renderValue, getScreenReaderLabel, autoFocus, ...rest } = props;
|
|
271
320
|
const { focusVisible, focusVisibleHandlers, focusVisibleRef } = useFocusVisible();
|
|
272
321
|
const pickerRef = useRef(null);
|
|
273
322
|
const handlePickerRef = useForkRef(pickerRef, focusVisibleRef);
|
|
274
|
-
useLayoutEffect(()
|
|
323
|
+
useLayoutEffect(()=>{
|
|
275
324
|
if (autoFocus) {
|
|
276
325
|
pickerRef.current?.focus();
|
|
277
326
|
}
|
|
327
|
+
// oxlint-disable-next-line react-hooks/exhaustive-deps
|
|
278
328
|
}, []);
|
|
279
329
|
const index = Math.floor(value / step);
|
|
280
330
|
const isFirst = index === 0;
|
|
@@ -283,179 +333,347 @@ const NumberPicker = forwardRef((props, ref) => {
|
|
|
283
333
|
const latestValue = source[source.length - 1];
|
|
284
334
|
const decreaseValue = isFirst ? latestValue : source[index - 1];
|
|
285
335
|
const increaseValue = isLatest ? firstValue : source[index + 1];
|
|
286
|
-
const decreaseDisabled = isFirst
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
const increaseDisabled = isLatest
|
|
290
|
-
? !!(min !== undefined && firstValue < min)
|
|
291
|
-
: !!(max !== undefined && increaseValue > max);
|
|
292
|
-
const showValue = (() => {
|
|
336
|
+
const decreaseDisabled = isFirst ? !!(max !== undefined && latestValue > max) : !!(min !== undefined && decreaseValue < min);
|
|
337
|
+
const increaseDisabled = isLatest ? !!(min !== undefined && firstValue < min) : !!(max !== undefined && increaseValue > max);
|
|
338
|
+
const showValue = (()=>{
|
|
293
339
|
if (renderValue) {
|
|
294
340
|
return renderValue(value);
|
|
295
341
|
}
|
|
296
342
|
return pad(value);
|
|
297
343
|
})();
|
|
298
344
|
const label = getScreenReaderLabel?.(showValue);
|
|
299
|
-
const handleKeyDown = (event)
|
|
345
|
+
const handleKeyDown = (event)=>{
|
|
300
346
|
runKeyHandler(event, {
|
|
301
|
-
ArrowUp: ()
|
|
347
|
+
ArrowUp: ()=>{
|
|
302
348
|
if (increaseDisabled) {
|
|
303
349
|
return;
|
|
304
350
|
}
|
|
305
351
|
onUpdate(increaseValue, 'arrowKey');
|
|
306
352
|
},
|
|
307
|
-
ArrowDown: ()
|
|
353
|
+
ArrowDown: ()=>{
|
|
308
354
|
if (decreaseDisabled) {
|
|
309
355
|
return;
|
|
310
356
|
}
|
|
311
357
|
onUpdate(decreaseValue, 'arrowKey');
|
|
312
|
-
}
|
|
358
|
+
}
|
|
313
359
|
});
|
|
314
360
|
onKeyDown?.(event);
|
|
315
361
|
};
|
|
316
362
|
const cls = useTimePickerClasses();
|
|
317
|
-
return
|
|
363
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
364
|
+
tabIndex: 0,
|
|
365
|
+
className: cls('number-picker', {
|
|
366
|
+
focusVisible
|
|
367
|
+
}),
|
|
368
|
+
onKeyDown: handleKeyDown,
|
|
369
|
+
"aria-live": "assertive",
|
|
370
|
+
"aria-label": label,
|
|
371
|
+
ref: handlePickerRef,
|
|
372
|
+
...focusVisibleHandlers,
|
|
373
|
+
...rest,
|
|
374
|
+
children: [
|
|
375
|
+
/*#__PURE__*/ jsx(IconButton_IconButton, {
|
|
376
|
+
shape: 'squircle',
|
|
377
|
+
variant: 'contained',
|
|
378
|
+
background: false,
|
|
379
|
+
color: 'secondary',
|
|
380
|
+
size: "small",
|
|
381
|
+
tabIndex: -1,
|
|
382
|
+
disabled: increaseDisabled,
|
|
383
|
+
onClick: ()=>{
|
|
318
384
|
onUpdate(increaseValue, 'arrowButton');
|
|
319
|
-
},
|
|
385
|
+
},
|
|
386
|
+
"data-sui-number-picker-previous": true,
|
|
387
|
+
"aria-label": "Arrow Up",
|
|
388
|
+
children: /*#__PURE__*/ jsx(Icon_Icon, {
|
|
389
|
+
size: "medium",
|
|
390
|
+
symbol: CaretUpMd
|
|
391
|
+
})
|
|
392
|
+
}),
|
|
393
|
+
/*#__PURE__*/ jsx(TimeButton, {
|
|
394
|
+
tabIndex: -1,
|
|
395
|
+
onClick: onClick,
|
|
396
|
+
"data-sui-number-picker-text": true,
|
|
397
|
+
children: showValue
|
|
398
|
+
}),
|
|
399
|
+
/*#__PURE__*/ jsx(IconButton_IconButton, {
|
|
400
|
+
shape: 'squircle',
|
|
401
|
+
variant: 'contained',
|
|
402
|
+
background: false,
|
|
403
|
+
color: 'secondary',
|
|
404
|
+
size: "small",
|
|
405
|
+
tabIndex: -1,
|
|
406
|
+
disabled: decreaseDisabled,
|
|
407
|
+
onClick: ()=>{
|
|
320
408
|
onUpdate(decreaseValue, 'arrowButton');
|
|
321
|
-
},
|
|
409
|
+
},
|
|
410
|
+
"data-sui-number-picker-next": true,
|
|
411
|
+
"aria-label": "Arrow Down",
|
|
412
|
+
children: /*#__PURE__*/ jsx(Icon_Icon, {
|
|
413
|
+
size: "medium",
|
|
414
|
+
symbol: CaretDownMd
|
|
415
|
+
})
|
|
416
|
+
})
|
|
417
|
+
]
|
|
418
|
+
});
|
|
322
419
|
});
|
|
323
420
|
NumberPicker.displayName = 'SuiNumberPicker';
|
|
324
421
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
const SelectionView = (props)=>{
|
|
432
|
+
const { source, onConfirm, value, min: minProp, max: maxProp, isTwelveHourSystem, viewType } = props;
|
|
433
|
+
const min = minProp !== undefined && isTwelveHourSystem ? minProp % (/* inlined export .HALF_DAY_HOURS */12) : minProp;
|
|
434
|
+
const max = maxProp !== undefined && isTwelveHourSystem ? maxProp % (/* inlined export .HALF_DAY_HOURS */12) : maxProp;
|
|
333
435
|
const showValue = parseNumberToString(value, isTwelveHourSystem);
|
|
334
436
|
const cls = useTimePickerClasses();
|
|
335
|
-
return
|
|
336
|
-
|
|
337
|
-
|
|
437
|
+
return /*#__PURE__*/ jsx("div", {
|
|
438
|
+
className: cls(`${viewType}-selection-view`, 'picker-view'),
|
|
439
|
+
children: source.map((v)=>{
|
|
440
|
+
const disabled = !!(max !== undefined && v > max || min !== undefined && v < min);
|
|
338
441
|
const itemShowValue = parseNumberToString(v, isTwelveHourSystem);
|
|
339
|
-
const confirm = ()
|
|
340
|
-
if (disabled)
|
|
341
|
-
return;
|
|
442
|
+
const confirm = ()=>{
|
|
443
|
+
if (disabled) return;
|
|
342
444
|
onConfirm(v);
|
|
343
445
|
};
|
|
344
|
-
return
|
|
345
|
-
|
|
446
|
+
return /*#__PURE__*/ jsx(TimeButton, {
|
|
447
|
+
disabled: disabled,
|
|
448
|
+
onClick: confirm,
|
|
449
|
+
selected: itemShowValue === showValue,
|
|
450
|
+
"data-sui-time-button": itemShowValue,
|
|
451
|
+
children: itemShowValue
|
|
452
|
+
}, v);
|
|
453
|
+
})
|
|
454
|
+
});
|
|
346
455
|
};
|
|
347
456
|
SelectionView.displayName = 'SuiSelectionView';
|
|
348
457
|
|
|
349
|
-
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
const ToggleText = /*#__PURE__*/ forwardRef(({ onChange: onUpdate, value, disabled, getScreenReaderLabel, ...rest }, ref)=>{
|
|
350
469
|
const label = getScreenReaderLabel?.(value);
|
|
351
|
-
const nextValue = value ===
|
|
352
|
-
const handleClick = useEventCallback((event)
|
|
353
|
-
if (disabled || !isClick(event))
|
|
354
|
-
return;
|
|
470
|
+
const nextValue = value === constant_TIME_SYSTEM_TEXT.AM ? constant_TIME_SYSTEM_TEXT.PM : constant_TIME_SYSTEM_TEXT.AM;
|
|
471
|
+
const handleClick = useEventCallback((event)=>{
|
|
472
|
+
if (disabled || !isClick(event)) return;
|
|
355
473
|
onUpdate(nextValue, 'arrowButton');
|
|
356
474
|
});
|
|
357
|
-
const handleToggleKeyDown = useEventCallback((event)
|
|
475
|
+
const handleToggleKeyDown = useEventCallback((event)=>{
|
|
358
476
|
if (disabled) {
|
|
359
477
|
return;
|
|
360
478
|
}
|
|
361
|
-
const togglePeriod = ()
|
|
479
|
+
const togglePeriod = ()=>{
|
|
362
480
|
onUpdate(nextValue, 'arrowKey');
|
|
363
481
|
};
|
|
364
482
|
runKeyHandler(event, {
|
|
365
483
|
ArrowUp: togglePeriod,
|
|
366
|
-
ArrowDown: togglePeriod
|
|
484
|
+
ArrowDown: togglePeriod
|
|
367
485
|
});
|
|
368
486
|
});
|
|
369
|
-
return
|
|
487
|
+
return /*#__PURE__*/ jsx(TimeButton, {
|
|
488
|
+
onClick: handleClick,
|
|
489
|
+
onKeyDown: handleToggleKeyDown,
|
|
490
|
+
disabled: disabled,
|
|
491
|
+
"aria-live": "assertive",
|
|
492
|
+
"aria-label": label,
|
|
493
|
+
...rest,
|
|
494
|
+
children: value
|
|
495
|
+
});
|
|
370
496
|
});
|
|
371
497
|
ToggleText.displayName = 'SuiToggleText';
|
|
372
498
|
|
|
373
|
-
|
|
374
|
-
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
const PickerView = (props)=>{
|
|
510
|
+
const { isTwelveHourSystem, selectionShowType, onSelectionShowTypeChange, screenReaderProps, defaultValue, onChange, range, afterDraftConfirm } = props;
|
|
375
511
|
const [value, setValue] = useState(defaultValue);
|
|
376
|
-
const handleChange = (toValue, onlyInnerState)
|
|
512
|
+
const handleChange = (toValue, onlyInnerState)=>{
|
|
377
513
|
const resultValue = {
|
|
378
514
|
hour: toValue.hour ?? value.hour,
|
|
379
515
|
minute: toValue.minute ?? value.minute,
|
|
380
|
-
period: toValue.period ?? value.period
|
|
516
|
+
period: toValue.period ?? value.period
|
|
381
517
|
};
|
|
382
518
|
setValue(resultValue);
|
|
383
519
|
if (!onlyInnerState) {
|
|
384
520
|
onChange(resultValue);
|
|
385
521
|
}
|
|
386
522
|
};
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
523
|
+
// get boundary must use current show value
|
|
524
|
+
const boundary = useMemo(()=>{
|
|
525
|
+
const originHour = value.hour + (isTwelveHourSystem && value.period === constant_TIME_SYSTEM_TEXT.PM ? 12 : 0);
|
|
390
526
|
return getNumberPickerBoundary(originHour, {
|
|
391
527
|
range,
|
|
392
|
-
isTwelveHourSystem
|
|
528
|
+
isTwelveHourSystem
|
|
393
529
|
});
|
|
394
|
-
}, [
|
|
395
|
-
|
|
530
|
+
}, [
|
|
531
|
+
range,
|
|
532
|
+
value,
|
|
533
|
+
isTwelveHourSystem
|
|
534
|
+
]);
|
|
535
|
+
// reset pickerValue if pickerValue is out of range
|
|
536
|
+
useLayoutEffect(()=>{
|
|
396
537
|
const { hour, minute, period } = value;
|
|
397
538
|
if (hour > boundary.hour.max || minute > boundary.minute.max) {
|
|
398
539
|
handleChange({
|
|
399
540
|
hour: boundary.hour.max,
|
|
400
541
|
minute: boundary.minute.max,
|
|
401
|
-
period
|
|
542
|
+
period
|
|
402
543
|
}, true);
|
|
403
|
-
}
|
|
404
|
-
else if (hour < boundary.hour.min || minute < boundary.minute.min) {
|
|
544
|
+
} else if (hour < boundary.hour.min || minute < boundary.minute.min) {
|
|
405
545
|
handleChange({
|
|
406
546
|
hour: boundary.hour.min,
|
|
407
547
|
minute: boundary.minute.min,
|
|
408
|
-
period
|
|
548
|
+
period
|
|
409
549
|
}, true);
|
|
410
550
|
}
|
|
411
|
-
|
|
551
|
+
// ignore `handleChange`
|
|
552
|
+
// oxlint-disable-next-line react-hooks/exhaustive-deps
|
|
553
|
+
}, [
|
|
554
|
+
boundary,
|
|
555
|
+
value
|
|
556
|
+
]);
|
|
412
557
|
const isHourView = selectionShowType === 'hour';
|
|
413
|
-
const { getHourPickerAriaLabel, getMinutePickerAriaLabel, getPeriodToggleAriaLabel
|
|
414
|
-
const toggleTextDisabled = useMemo(()
|
|
415
|
-
return Boolean(range.min.hour &&
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
558
|
+
const { getHourPickerAriaLabel, getMinutePickerAriaLabel, getPeriodToggleAriaLabel } = screenReaderProps;
|
|
559
|
+
const toggleTextDisabled = useMemo(()=>{
|
|
560
|
+
return Boolean(range.min.hour && // * min is pm time
|
|
561
|
+
(range.min.hour >= (/* inlined export .HALF_DAY_HOURS */12) || range.max.hour && // * min and max in same AM period
|
|
562
|
+
range.min.hour < (/* inlined export .HALF_DAY_HOURS */12) && range.max.hour < (/* inlined export .HALF_DAY_HOURS */12)));
|
|
563
|
+
}, [
|
|
564
|
+
range.max.hour,
|
|
565
|
+
range.min.hour
|
|
566
|
+
]);
|
|
421
567
|
const cls = useTimePickerClasses();
|
|
422
|
-
return selectionShowType === 'none' ?
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
568
|
+
return selectionShowType === 'none' ? /*#__PURE__*/ jsxs("div", {
|
|
569
|
+
className: cls('main-view', 'picker-view', {
|
|
570
|
+
'twelve-hour': isTwelveHourSystem
|
|
571
|
+
}),
|
|
572
|
+
onKeyDown: (event)=>{
|
|
573
|
+
const confirm = ()=>{
|
|
426
574
|
onChange(value);
|
|
427
575
|
afterDraftConfirm();
|
|
428
576
|
};
|
|
429
577
|
runKeyHandler(event, {
|
|
430
578
|
Enter: confirm,
|
|
431
|
-
' ': confirm
|
|
579
|
+
' ': confirm
|
|
432
580
|
});
|
|
433
|
-
},
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
581
|
+
},
|
|
582
|
+
children: [
|
|
583
|
+
/*#__PURE__*/ jsx(NumberPicker, {
|
|
584
|
+
onClick: ()=>onSelectionShowTypeChange('hour'),
|
|
585
|
+
value: value.hour,
|
|
586
|
+
...boundary.hour,
|
|
587
|
+
onChange: (hour, reason)=>{
|
|
588
|
+
handleChange({
|
|
589
|
+
hour
|
|
590
|
+
}, reason === 'arrowKey');
|
|
591
|
+
},
|
|
592
|
+
step: 1,
|
|
593
|
+
source: isTwelveHourSystem ? twelveHourSystemSource : twentyFourHourSystemSource,
|
|
594
|
+
renderValue: (hourValue)=>{
|
|
438
595
|
return parseNumberToString(hourValue, isTwelveHourSystem);
|
|
439
|
-
},
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
:
|
|
443
|
-
|
|
444
|
-
|
|
596
|
+
},
|
|
597
|
+
"data-sui-picker-hour": true,
|
|
598
|
+
autoFocus: true,
|
|
599
|
+
getScreenReaderLabel: getHourPickerAriaLabel
|
|
600
|
+
}),
|
|
601
|
+
/*#__PURE__*/ jsx("div", {
|
|
602
|
+
children: ":"
|
|
603
|
+
}),
|
|
604
|
+
/*#__PURE__*/ jsx(NumberPicker, {
|
|
605
|
+
...boundary.minute,
|
|
606
|
+
onChange: (minute, reason)=>handleChange({
|
|
607
|
+
minute
|
|
608
|
+
}, reason === 'arrowKey'),
|
|
609
|
+
onClick: ()=>onSelectionShowTypeChange('minute'),
|
|
610
|
+
value: value.minute,
|
|
611
|
+
source: minuteSource,
|
|
612
|
+
step: (/* inlined export .TIME_GAP */15),
|
|
613
|
+
"data-sui-picker-minute": true,
|
|
614
|
+
getScreenReaderLabel: getMinutePickerAriaLabel
|
|
615
|
+
}),
|
|
616
|
+
isTwelveHourSystem && /*#__PURE__*/ jsx(ToggleText, {
|
|
617
|
+
disabled: toggleTextDisabled,
|
|
618
|
+
onChange: (period, reason)=>handleChange({
|
|
619
|
+
period
|
|
620
|
+
}, reason === 'arrowKey'),
|
|
621
|
+
value: value.period,
|
|
622
|
+
getScreenReaderLabel: getPeriodToggleAriaLabel
|
|
623
|
+
})
|
|
624
|
+
]
|
|
625
|
+
}) : /*#__PURE__*/ jsx(SelectionView, {
|
|
626
|
+
...isHourView ? boundary.hour : boundary.minute,
|
|
627
|
+
viewType: selectionShowType,
|
|
628
|
+
source: isHourView ? isTwelveHourSystem ? twelveHourSystemSource : twentyFourHourSystemSource : minuteSource,
|
|
629
|
+
isTwelveHourSystem: isHourView && isTwelveHourSystem,
|
|
630
|
+
value: isHourView ? value.hour : value.minute,
|
|
631
|
+
onConfirm: (toValue)=>{
|
|
632
|
+
handleChange(isHourView ? {
|
|
633
|
+
hour: toValue
|
|
634
|
+
} : {
|
|
635
|
+
minute: toValue
|
|
636
|
+
}, false);
|
|
445
637
|
onSelectionShowTypeChange('none');
|
|
446
|
-
},
|
|
638
|
+
},
|
|
639
|
+
"data-sui-picker-selection-view": selectionShowType
|
|
640
|
+
});
|
|
447
641
|
};
|
|
448
642
|
|
|
449
|
-
var TimePicker$1 = {"sui-time-picker-picker-root":"sui-time-picker-picker-root","sui-time-picker-time-button":"sui-time-picker-time-button","sui-focus-visible":"sui-focus-visible","sui-selected":"sui-selected","sui-disabled":"sui-disabled","sui-time-picker-number-picker":"sui-time-picker-number-picker","sui-time-picker-picker-view":"sui-time-picker-picker-view","sui-time-picker-main-view":"sui-time-picker-main-view","sui-time-picker-twelve-hour":"sui-time-picker-twelve-hour","sui-time-picker-minute-selection-view":"sui-time-picker-minute-selection-view","sui-time-picker-hour-selection-view":"sui-time-picker-hour-selection-view","sui-compact":"sui-compact"};
|
|
450
643
|
|
|
451
|
-
|
|
452
|
-
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
// extracted by css-extract-rspack-plugin
|
|
650
|
+
/* export default */ var TimePicker = ({"sui-time-picker-picker-root":"sui-time-picker-picker-root","sui-time-picker-time-button":"sui-time-picker-time-button","sui-focus-visible":"sui-focus-visible","sui-selected":"sui-selected","sui-disabled":"sui-disabled","sui-time-picker-number-picker":"sui-time-picker-number-picker","sui-time-picker-picker-view":"sui-time-picker-picker-view","sui-time-picker-main-view":"sui-time-picker-main-view","sui-time-picker-twelve-hour":"sui-time-picker-twelve-hour","sui-time-picker-minute-selection-view":"sui-time-picker-minute-selection-view","sui-time-picker-hour-selection-view":"sui-time-picker-hour-selection-view","sui-compact":"sui-compact"});
|
|
651
|
+
|
|
652
|
+
/* oxlint-disable @typescript-eslint/no-non-null-assertion */
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
const TimePicker_TimePicker = /*#__PURE__*/ forwardRef((inProps, ref)=>{
|
|
663
|
+
const props = useThemeProps({
|
|
664
|
+
props: inProps,
|
|
665
|
+
name: 'TimePicker'
|
|
666
|
+
});
|
|
453
667
|
const { isTwelveHourSystem = false, value, onChange, disabled, min, max, onKeyDown, onClear, PopoverProps, classes, defaultPickerValue = null, clearBtn = true, dateMode = false, screenReaderProps = {
|
|
454
|
-
getHourPickerAriaLabel: (hour)
|
|
455
|
-
getMinutePickerAriaLabel: (minute)
|
|
456
|
-
getPeriodToggleAriaLabel: (period)
|
|
668
|
+
getHourPickerAriaLabel: (hour)=>`Hour: ${hour}, use up and down arrow keys to change hour time by 1`,
|
|
669
|
+
getMinutePickerAriaLabel: (minute)=>`Minute: ${minute}, use up and down arrow keys to change minutes time by 15 minutes`,
|
|
670
|
+
getPeriodToggleAriaLabel: (period)=>`${period}, use up or down arrow keys to switch between AM or PM`
|
|
457
671
|
}, className, ...rest } = props;
|
|
458
|
-
const cls = useClassesWithMode('time-picker', classes, className, [
|
|
672
|
+
const cls = useClassesWithMode('time-picker', classes, className, [
|
|
673
|
+
'main-view',
|
|
674
|
+
'hour-selection-view',
|
|
675
|
+
'minute-selection-view'
|
|
676
|
+
]);
|
|
459
677
|
const actionRef = useRef(null);
|
|
460
678
|
const [selectionShowType, setSelectionType] = useState('none');
|
|
461
679
|
const pickerValue = value ?? defaultPickerValue;
|
|
@@ -463,101 +681,141 @@ const TimePicker = forwardRef((inProps, ref) => {
|
|
|
463
681
|
const textFieldTimestamp = getTimestamp(value);
|
|
464
682
|
const { hour: textFieldHour } = getHourAndMinute(textFieldTimestamp);
|
|
465
683
|
const textFieldPeriod = getPeriod(textFieldHour);
|
|
466
|
-
const formattedTime = textFieldTimestamp === null
|
|
467
|
-
|
|
468
|
-
:
|
|
469
|
-
|
|
470
|
-
period: textFieldPeriod,
|
|
471
|
-
}, isTwelveHourSystem);
|
|
684
|
+
const formattedTime = textFieldTimestamp === null ? '' : getFormattedTime({
|
|
685
|
+
...getHourAndMinute(textFieldTimestamp),
|
|
686
|
+
period: textFieldPeriod
|
|
687
|
+
}, isTwelveHourSystem);
|
|
472
688
|
const pickerTimestamp = getTimestamp(pickerValue);
|
|
473
689
|
const { hour: originPickerHour, minute: originPickerMinute } = getHourAndMinute(pickerTimestamp);
|
|
474
690
|
const pickerPeriod = getPeriod(originPickerHour);
|
|
475
|
-
const pickerHour = isTwelveHourSystem
|
|
476
|
-
? originPickerHour % HALF_DAY_HOURS
|
|
477
|
-
: originPickerHour;
|
|
691
|
+
const pickerHour = isTwelveHourSystem ? originPickerHour % (/* inlined export .HALF_DAY_HOURS */12) : originPickerHour;
|
|
478
692
|
const pickerMinute = originPickerMinute;
|
|
479
|
-
const range = useMemo(()
|
|
480
|
-
return getRangeBoundary({
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
693
|
+
const range = useMemo(()=>{
|
|
694
|
+
return getRangeBoundary({
|
|
695
|
+
min,
|
|
696
|
+
max
|
|
697
|
+
});
|
|
698
|
+
}, [
|
|
699
|
+
max,
|
|
700
|
+
min
|
|
701
|
+
]);
|
|
702
|
+
const handleChange = useEventCallback((toValue)=>{
|
|
703
|
+
const update = (toValue)=>{
|
|
484
704
|
onChange?.(toValue);
|
|
485
705
|
};
|
|
486
706
|
if (isDateMode) {
|
|
487
707
|
update(toValue);
|
|
488
|
-
}
|
|
489
|
-
|
|
708
|
+
} else {
|
|
709
|
+
// * when time is zero emit null
|
|
490
710
|
update(toValue ? getTimestamp(toValue) : null);
|
|
491
711
|
}
|
|
492
712
|
});
|
|
493
|
-
const getInitialDate = useEventCallback(()
|
|
713
|
+
const getInitialDate = useEventCallback(()=>{
|
|
494
714
|
const date = value !== null ? new Date(value) : new Date();
|
|
495
715
|
date.setHours(originPickerHour, originPickerMinute, 0, 0);
|
|
496
716
|
return date;
|
|
497
717
|
});
|
|
498
|
-
const updateTime = (option)
|
|
499
|
-
const { hour = originPickerHour, minute = originPickerMinute, period = pickerPeriod
|
|
500
|
-
const recoupHour = isTwelveHourSystem && pickerPeriod ===
|
|
501
|
-
? HALF_DAY_HOURS
|
|
502
|
-
: 0;
|
|
718
|
+
const updateTime = (option)=>{
|
|
719
|
+
const { hour = originPickerHour, minute = originPickerMinute, period = pickerPeriod } = option;
|
|
720
|
+
const recoupHour = isTwelveHourSystem && pickerPeriod === constant_TIME_SYSTEM_TEXT.PM ? (/* inlined export .HALF_DAY_HOURS */12) : 0;
|
|
503
721
|
const time = getInitialDate();
|
|
504
722
|
time.setMinutes(minute);
|
|
505
723
|
time.setHours(hour + recoupHour);
|
|
506
724
|
if (isTwelveHourSystem) {
|
|
507
725
|
const currHour = time.getHours();
|
|
508
|
-
if (period ===
|
|
509
|
-
if (currHour < HALF_DAY_HOURS) {
|
|
510
|
-
time.setHours(currHour + HALF_DAY_HOURS);
|
|
726
|
+
if (period === constant_TIME_SYSTEM_TEXT.PM) {
|
|
727
|
+
if (currHour < (/* inlined export .HALF_DAY_HOURS */12)) {
|
|
728
|
+
time.setHours(currHour + (/* inlined export .HALF_DAY_HOURS */12));
|
|
511
729
|
}
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
time.setHours(currHour - HALF_DAY_HOURS);
|
|
730
|
+
} else if (currHour >= (/* inlined export .HALF_DAY_HOURS */12)) {
|
|
731
|
+
time.setHours(currHour - (/* inlined export .HALF_DAY_HOURS */12));
|
|
515
732
|
}
|
|
516
733
|
}
|
|
517
734
|
const toTimestamp = getTimestamp(time);
|
|
518
735
|
if (range.max.date && toTimestamp > range.max.timestamp) {
|
|
519
736
|
time.setHours(range.max.hour);
|
|
520
737
|
time.setMinutes(range.max.minute);
|
|
521
|
-
}
|
|
522
|
-
else if (range.min.date && toTimestamp < range.min.timestamp) {
|
|
738
|
+
} else if (range.min.date && toTimestamp < range.min.timestamp) {
|
|
523
739
|
time.setHours(range.min.hour);
|
|
524
740
|
time.setMinutes(range.min.minute);
|
|
525
741
|
}
|
|
526
742
|
handleChange(time);
|
|
527
743
|
};
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
744
|
+
// reset value if value is out of range
|
|
745
|
+
useLayoutEffect(()=>{
|
|
746
|
+
if (textFieldTimestamp === null) return;
|
|
531
747
|
const time = getInitialDate();
|
|
532
748
|
if (range.max.date && textFieldTimestamp > range.max.timestamp) {
|
|
533
749
|
time.setHours(range.max.hour);
|
|
534
750
|
time.setMinutes(range.max.minute);
|
|
535
751
|
handleChange(time);
|
|
536
|
-
}
|
|
537
|
-
else if (range.min.date && textFieldTimestamp < range.min.timestamp) {
|
|
752
|
+
} else if (range.min.date && textFieldTimestamp < range.min.timestamp) {
|
|
538
753
|
time.setHours(range.min.hour);
|
|
539
754
|
time.setMinutes(range.min.minute);
|
|
540
755
|
handleChange(time);
|
|
541
756
|
}
|
|
542
|
-
}, [
|
|
543
|
-
|
|
757
|
+
}, [
|
|
758
|
+
range,
|
|
759
|
+
handleChange,
|
|
760
|
+
getInitialDate,
|
|
761
|
+
textFieldTimestamp
|
|
762
|
+
]);
|
|
763
|
+
return /*#__PURE__*/ jsx(TimePickerClassesContext.Provider, {
|
|
764
|
+
value: cls,
|
|
765
|
+
children: /*#__PURE__*/ jsx(PickerTextField_PickerTextField, {
|
|
766
|
+
ref: ref,
|
|
767
|
+
variant: "standard",
|
|
768
|
+
className: cls('root'),
|
|
769
|
+
action: actionRef,
|
|
770
|
+
onClear: (e)=>{
|
|
544
771
|
onClear?.(e);
|
|
545
772
|
handleChange(null);
|
|
546
|
-
},
|
|
547
|
-
|
|
773
|
+
},
|
|
774
|
+
value: formattedTime,
|
|
775
|
+
disabled: disabled,
|
|
776
|
+
PopoverProps: combineProps({
|
|
777
|
+
onExitComplete: ()=>{
|
|
548
778
|
setSelectionType('none');
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
779
|
+
}
|
|
780
|
+
}, PopoverProps),
|
|
781
|
+
endIconSymbol: RecentMd,
|
|
782
|
+
clearBtn: clearBtn,
|
|
783
|
+
...rest,
|
|
784
|
+
children: /*#__PURE__*/ jsx(PickerView, {
|
|
785
|
+
isTwelveHourSystem: isTwelveHourSystem,
|
|
786
|
+
onChange: updateTime,
|
|
787
|
+
afterDraftConfirm: ()=>{
|
|
554
788
|
actionRef.current?.close();
|
|
555
|
-
},
|
|
789
|
+
},
|
|
790
|
+
defaultValue: {
|
|
556
791
|
hour: pickerHour,
|
|
557
792
|
minute: pickerMinute,
|
|
558
|
-
period: pickerPeriod
|
|
559
|
-
},
|
|
793
|
+
period: pickerPeriod
|
|
794
|
+
},
|
|
795
|
+
onSelectionShowTypeChange: setSelectionType,
|
|
796
|
+
range: range,
|
|
797
|
+
screenReaderProps: screenReaderProps,
|
|
798
|
+
selectionShowType: selectionShowType
|
|
799
|
+
})
|
|
800
|
+
})
|
|
801
|
+
});
|
|
560
802
|
});
|
|
561
|
-
|
|
803
|
+
TimePicker_TimePicker.displayName = 'SuiTimePicker';
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
562
820
|
|
|
563
|
-
export { HALF_DAY_HOURS, HOUR_MINUTES, K_ENTER, K_SPACE, NumberPicker, ONE_HOUR, PickerView, SelectionView, TIME_GAP,
|
|
821
|
+
export { HALF_DAY_HOURS, HOUR_MINUTES, K_ENTER, K_SPACE, NumberPicker, ONE_HOUR, PickerView, SelectionView, TIME_GAP, TimeBoundary, TimeButton, TimePicker as timePickerStyle, TimePickerClassesContext, TimePicker_TimePicker as TimePicker, ToggleText, constant_TIME_SYSTEM_TEXT as TIME_SYSTEM_TEXT, getFormattedTime, getHourAndMinute, getNumberPickerBoundary, getPeriod, getRangeBoundary, getRecoupHour, getTimestamp, getTimestampFromDate, getTimestampFromHourAndMin, isClick, lastMinute, minuteSource, pad, parseNumber, parseNumberToString, twelveHourSystemSource, twentyFourHourSystemSource, useTimePickerClasses };
|