@ringcentral/spring-ui 1.11.2 → 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 +72 -20
- package/Alert.js +120 -28
- package/Animation.js +2 -45
- package/Announcement.js +46 -35
- package/Autocomplete.js +1011 -580
- 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 +55 -11
- 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 -190
- package/DateUtilsContext.js +43 -25
- package/Dialer.js +576 -250
- package/Dialog.js +100 -45
- package/Divider.js +43 -7
- package/DragHandle.js +32 -6
- package/Drawer.js +117 -19
- package/Dropdown.js +154 -74
- package/EmptyState.js +63 -11
- package/FabButton.js +51 -17
- package/FocusTrap.js +109 -12
- package/FormField.js +106 -8
- 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 -16
- 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 -15
- package/MenuItem.js +402 -33
- package/MenuItemText.js +51 -8
- package/MenuList.js +87 -34
- package/Modal.js +345 -16
- package/NestedMenuContext.js +183 -11
- package/Option.js +32 -34
- package/Overlap.js +54 -7
- package/PageHeader.js +62 -24
- package/PickerTextField.js +156 -33
- package/Popover.js +262 -21
- package/Popper.js +130 -77
- 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 -41
- package/SingleFilter.js +148 -77
- package/Skeleton.js +68 -17
- package/Slider.js +168 -69
- package/Snackbar.js +122 -59
- package/SortableList.js +32 -12
- package/SortableListDndContext.js +69 -22
- package/SortableListItem.js +92 -47
- package/SortableVirtualizedList.js +52 -28
- package/SplitButton.js +124 -86
- 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 +68 -25
- package/StepIcon.js +90 -9
- package/StepLabel.js +90 -14
- package/Stepper.js +65 -23
- package/SubMenu.js +203 -99
- 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 -77
- package/TableRow.js +60 -21
- package/Tabs.js +593 -268
- package/Tag.js +51 -16
- package/Text.js +68 -37
- package/TextField.js +209 -29
- package/Textarea.js +51 -40
- package/TimePicker.js +490 -230
- package/Tooltip.js +48 -23
- package/Tray.js +237 -13
- package/TrayMenu.js +62 -41
- package/VirtualizedList.js +208 -109
- 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 +2624 -2416
- package/index.js +245 -193
- package/internal/utils/index.d.ts +1 -0
- package/internal/utils/setRef.d.ts +2 -0
- package/package.json +8 -8
- package/src/Alert/Alert.type.d.ts +2 -1
- package/src/Animation/components/Fade/Fade.d.ts +4 -2
- package/src/Animation/components/Grow/Grow.d.ts +4 -2
- package/src/Animation/components/ShowHideEye/ShowHideEye.d.ts +1 -1
- package/src/Animation/components/SlideIn/SlideIn.d.ts +4 -2
- package/src/Animation/components/SlideIn/getSlideIn.d.ts +1 -1
- package/src/Animation/hooks/useMotionSafeTransition/useMotionSafeTransition.d.ts +2 -0
- package/src/Autocomplete/SuggestionList/SuggestionList.d.ts +1 -1
- package/src/Autocomplete/useAutocomplete.d.ts +18 -18
- package/src/Autocomplete/useAutocompleteTag.d.ts +18 -18
- package/src/Badge/Badge.d.ts +2 -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/DatePickerAriaLabelUtils.d.ts +2 -1
- package/src/DatePicker/utils/DatePickerUtils.d.ts +1 -1
- package/src/Dialer/DialDelete/DialDelete.d.ts +2 -2
- package/src/Dialer/DialPad/DialPad.d.ts +2 -2
- package/src/Dialer/Dialer.d.ts +4 -2
- package/src/Dropdown/Dropdown.type.d.ts +2 -2
- package/src/InlineEditable/InlineEditable.type.d.ts +2 -1
- package/src/ListNavigation/useListNavigation.d.ts +3 -3
- package/src/MenuActions/MenuActions.d.ts +2 -2
- package/src/MenuItem/MenuItem.type.d.ts +1 -0
- package/src/MenuItem/useMenuItem.d.ts +1 -1
- package/src/MenuItem/useVirtualizedMenuItem.d.ts +1 -1
- package/src/MenuList/MenuList.type.d.ts +1 -1
- package/src/MenuList/MenuListContext.d.ts +2 -3
- package/src/Modal/Modal.type.d.ts +1 -0
- package/src/NestedMenuContext/MenuOverlayGroupContext.d.ts +2 -2
- 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/Popper/Popper.type.d.ts +10 -7
- package/src/Rating/utils.d.ts +3 -2
- package/src/Select/Select.type.d.ts +7 -5
- package/src/Slider/Slider.d.ts +2 -2
- package/src/Slider/SliderThumb.d.ts +2 -1
- package/src/Squircle/Squircle.d.ts +1 -1
- package/src/StatusIndicator/StatusIndicator.d.ts +2 -1
- package/src/SubMenu/PopperMenu.type.d.ts +4 -1
- 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 -32
- 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 -17
- package/chunks/MenuList.js +0 -46
- package/chunks/Modal.js +0 -212
- package/chunks/Overlap.js +0 -25
- package/chunks/PickerTextField.js +0 -85
- package/chunks/Popover.js +0 -53
- package/chunks/PopperPaper.js +0 -15
- package/chunks/Select.js +0 -220
- package/chunks/ShowHideEye.js +0 -56
- package/chunks/SlideIn.js +0 -19
- 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 -164
- package/chunks/VisuallyHidden.js +0 -12
- 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 -36
- package/chunks/useHelperTextId.js +0 -22
- package/chunks/useListNavigation.js +0 -199
- package/chunks/useMenuItemSelect.js +0 -273
- 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,79 +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
|
-
const TimePickerClassesContext = createContext(() => '');
|
|
32
|
-
const useTimePickerClasses = () => useContext(TimePickerClassesContext);
|
|
33
|
-
|
|
34
|
-
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)=>{
|
|
35
31
|
const { value, selected, disabled, children, onFocus, onBlur, className, ...rest } = props;
|
|
36
32
|
const cls = useTimePickerClasses();
|
|
37
33
|
const { focusVisible, focusVisibleHandlers, focusVisibleRef } = useFocusVisible();
|
|
38
34
|
const handleRef = useForkRef(ref, focusVisibleRef);
|
|
39
|
-
return
|
|
35
|
+
return /*#__PURE__*/ jsx("button", {
|
|
36
|
+
ref: handleRef,
|
|
37
|
+
className: clsx(className, cls('time-button', {
|
|
40
38
|
selected,
|
|
41
39
|
disabled,
|
|
42
|
-
focusVisible
|
|
43
|
-
})),
|
|
40
|
+
focusVisible
|
|
41
|
+
})),
|
|
42
|
+
...rest,
|
|
43
|
+
...combineProps({
|
|
44
|
+
onBlur,
|
|
45
|
+
onFocus
|
|
46
|
+
}, focusVisibleHandlers),
|
|
47
|
+
type: "button",
|
|
48
|
+
children: children
|
|
49
|
+
});
|
|
44
50
|
});
|
|
45
51
|
TimeButton.displayName = 'SuiTimeButton';
|
|
46
52
|
|
|
53
|
+
|
|
47
54
|
function isClick(event) {
|
|
48
55
|
return event.type === 'click';
|
|
49
56
|
}
|
|
50
57
|
|
|
51
|
-
var TIME_SYSTEM_TEXT
|
|
52
|
-
(function (TIME_SYSTEM_TEXT) {
|
|
58
|
+
var constant_TIME_SYSTEM_TEXT = /*#__PURE__*/ function(TIME_SYSTEM_TEXT) {
|
|
53
59
|
TIME_SYSTEM_TEXT["PM"] = "PM";
|
|
54
60
|
TIME_SYSTEM_TEXT["AM"] = "AM";
|
|
55
|
-
|
|
61
|
+
return TIME_SYSTEM_TEXT;
|
|
62
|
+
}(constant_TIME_SYSTEM_TEXT || {});
|
|
56
63
|
const K_ENTER = 'Enter';
|
|
57
64
|
const K_SPACE = ' ';
|
|
58
65
|
|
|
59
|
-
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
const parseNumber = (value, isTwelveHourSystem)=>{
|
|
60
69
|
const count = isTwelveHourSystem ? value % 12 : value;
|
|
61
|
-
if (isTwelveHourSystem && count === 0)
|
|
62
|
-
return 12;
|
|
70
|
+
if (isTwelveHourSystem && count === 0) return 12;
|
|
63
71
|
return count;
|
|
64
72
|
};
|
|
65
|
-
const parseNumberToString = (value, isTwelveHourSystem)
|
|
73
|
+
const parseNumberToString = (value, isTwelveHourSystem)=>{
|
|
66
74
|
const count = parseNumber(value, isTwelveHourSystem);
|
|
67
75
|
return pad(count);
|
|
68
76
|
};
|
|
69
|
-
const pad = (num, size = 2)
|
|
77
|
+
/** add miss zero */ const pad = (num, size = 2)=>{
|
|
70
78
|
let s = `${num}`;
|
|
71
|
-
while
|
|
79
|
+
while(s.length < size){
|
|
72
80
|
s = `0${s}`;
|
|
73
81
|
}
|
|
74
82
|
return s;
|
|
75
83
|
};
|
|
76
|
-
|
|
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)=>{
|
|
77
90
|
const formattedHour = parseNumberToString(hour, isTwelveHourSystem);
|
|
78
91
|
const formattedMinute = parseNumberToString(minute);
|
|
79
92
|
const periodText = isTwelveHourSystem ? ` ${period}` : '';
|
|
@@ -84,12 +97,11 @@ const HOUR_MINUTES = 60;
|
|
|
84
97
|
const TIME_GAP = 15;
|
|
85
98
|
const ONE_HOUR = HOUR_MINUTES * HOUR_MINUTES * 1000;
|
|
86
99
|
const ONE_MINUTE = HOUR_MINUTES * 1000;
|
|
87
|
-
const buildConsecutiveNumberToArray = (min, max)
|
|
100
|
+
const buildConsecutiveNumberToArray = (min, max)=>{
|
|
88
101
|
const array = [];
|
|
89
|
-
if (min > max)
|
|
90
|
-
return array;
|
|
102
|
+
if (min > max) return array;
|
|
91
103
|
let count = min;
|
|
92
|
-
while
|
|
104
|
+
while(count <= max){
|
|
93
105
|
array.push(count);
|
|
94
106
|
count++;
|
|
95
107
|
}
|
|
@@ -97,69 +109,89 @@ const buildConsecutiveNumberToArray = (min, max) => {
|
|
|
97
109
|
};
|
|
98
110
|
const twelveHourSystemSource = buildConsecutiveNumberToArray(0, 11);
|
|
99
111
|
const twentyFourHourSystemSource = buildConsecutiveNumberToArray(0, 23);
|
|
100
|
-
const minuteSource = [
|
|
112
|
+
const minuteSource = [
|
|
113
|
+
0,
|
|
114
|
+
15,
|
|
115
|
+
30,
|
|
116
|
+
45
|
|
117
|
+
];
|
|
101
118
|
const lastMinute = 45;
|
|
102
|
-
|
|
119
|
+
/**
|
|
120
|
+
* hour and minute timestamp
|
|
121
|
+
*/ const getTimestampFromDate = (date)=>{
|
|
103
122
|
return date.getHours() * ONE_HOUR + date.getMinutes() * ONE_MINUTE;
|
|
104
123
|
};
|
|
105
|
-
|
|
124
|
+
/**
|
|
125
|
+
* hour and minute number
|
|
126
|
+
*/ const getHourAndMinute = (times)=>{
|
|
106
127
|
if (times === null) {
|
|
107
128
|
return {
|
|
108
129
|
hour: 0,
|
|
109
|
-
minute: 0
|
|
130
|
+
minute: 0
|
|
110
131
|
};
|
|
111
132
|
}
|
|
112
133
|
const minute = times % ONE_HOUR;
|
|
113
134
|
const hour = (times - minute) / ONE_HOUR;
|
|
114
135
|
return {
|
|
115
136
|
hour,
|
|
116
|
-
minute: Math.floor(minute / ONE_MINUTE)
|
|
137
|
+
minute: Math.floor(minute / ONE_MINUTE)
|
|
117
138
|
};
|
|
118
139
|
};
|
|
119
|
-
|
|
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) {
|
|
120
145
|
return nowTime instanceof Date ? getTimestampFromDate(nowTime) : nowTime;
|
|
121
146
|
}
|
|
122
|
-
|
|
147
|
+
/**
|
|
148
|
+
* hour and min object to timestamp
|
|
149
|
+
*/ const getTimestampFromHourAndMin = (option)=>{
|
|
123
150
|
return option.hour * ONE_HOUR + option.minute * ONE_MINUTE;
|
|
124
151
|
};
|
|
125
|
-
|
|
126
|
-
|
|
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;
|
|
127
156
|
}
|
|
128
|
-
const getRecoupHour = (currHour, period)
|
|
129
|
-
switch
|
|
130
|
-
case
|
|
157
|
+
const getRecoupHour = (currHour, period)=>{
|
|
158
|
+
switch(period){
|
|
159
|
+
case constant_TIME_SYSTEM_TEXT.PM:
|
|
131
160
|
if (currHour < HALF_DAY_HOURS) {
|
|
132
161
|
return HALF_DAY_HOURS;
|
|
133
162
|
}
|
|
134
163
|
break;
|
|
135
|
-
case
|
|
164
|
+
case constant_TIME_SYSTEM_TEXT.AM:
|
|
165
|
+
// FIXME
|
|
166
|
+
// oxlint-disable-next-line sonarjs/no-collapsible-if
|
|
136
167
|
if (currHour < HALF_DAY_HOURS) {
|
|
137
168
|
if (currHour >= HALF_DAY_HOURS) {
|
|
138
169
|
return -HALF_DAY_HOURS;
|
|
139
170
|
}
|
|
140
171
|
}
|
|
141
172
|
break;
|
|
173
|
+
default:
|
|
174
|
+
break;
|
|
142
175
|
}
|
|
143
176
|
return 0;
|
|
144
177
|
};
|
|
145
178
|
|
|
146
|
-
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
const getDateBeginning = ()=>{
|
|
147
182
|
const date = new Date();
|
|
148
183
|
date.setHours(0, 0, 0, 0);
|
|
149
184
|
return date;
|
|
150
185
|
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
timeGap;
|
|
186
|
+
/**
|
|
187
|
+
* get target time boundary, what time is nearest time with that timeGap
|
|
188
|
+
*/ class TimeBoundary {
|
|
155
189
|
get hour() {
|
|
156
190
|
return this._hour;
|
|
157
191
|
}
|
|
158
|
-
_minute = undefined;
|
|
159
192
|
get minute() {
|
|
160
193
|
return this._minute;
|
|
161
194
|
}
|
|
162
|
-
_date = undefined;
|
|
163
195
|
get date() {
|
|
164
196
|
return this._date;
|
|
165
197
|
}
|
|
@@ -169,15 +201,17 @@ class TimeBoundary {
|
|
|
169
201
|
}
|
|
170
202
|
this._date = value;
|
|
171
203
|
}
|
|
172
|
-
|
|
173
|
-
|
|
204
|
+
constructor(value, direction, timeGap){
|
|
205
|
+
this._hour = undefined;
|
|
206
|
+
this._minute = undefined;
|
|
207
|
+
this._date = undefined;
|
|
208
|
+
this.timestamp = 0;
|
|
174
209
|
this.value = value;
|
|
175
210
|
this.timeGap = timeGap;
|
|
176
211
|
if (value) {
|
|
177
212
|
if (direction === 'after') {
|
|
178
213
|
this.getAfterNearTime();
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
214
|
+
} else {
|
|
181
215
|
this.getBeforeNearTime();
|
|
182
216
|
}
|
|
183
217
|
this.date = new Date(getDateBeginning().setHours(this.hour, this.minute, 0, 0));
|
|
@@ -188,12 +222,13 @@ class TimeBoundary {
|
|
|
188
222
|
let hour = time.getHours();
|
|
189
223
|
let minute = time.getMinutes();
|
|
190
224
|
const partCount = Math.ceil(minute / this.timeGap);
|
|
191
|
-
|
|
225
|
+
// when time is the latest or more, add one hour
|
|
226
|
+
if (partCount >= (/* inlined export .HOUR_MINUTES */60) / this.timeGap) {
|
|
192
227
|
hour++;
|
|
193
228
|
minute = 0;
|
|
194
229
|
}
|
|
195
230
|
this._hour = hour;
|
|
196
|
-
this._minute =
|
|
231
|
+
this._minute = partCount * this.timeGap % (/* inlined export .HOUR_MINUTES */60);
|
|
197
232
|
}
|
|
198
233
|
getBeforeNearTime() {
|
|
199
234
|
const time = this.getDateTime();
|
|
@@ -210,7 +245,7 @@ class TimeBoundary {
|
|
|
210
245
|
return date;
|
|
211
246
|
}
|
|
212
247
|
}
|
|
213
|
-
const getRangeBoundary = ({ min, max, gap = TIME_GAP
|
|
248
|
+
const getRangeBoundary = ({ min, max, gap = (/* inlined export .TIME_GAP */15) })=>{
|
|
214
249
|
if (min !== undefined && max !== undefined) {
|
|
215
250
|
const minTimestamp = getTimestamp(min);
|
|
216
251
|
const maxTimestamp = getTimestamp(max);
|
|
@@ -220,59 +255,76 @@ const getRangeBoundary = ({ min, max, gap = TIME_GAP, }) => {
|
|
|
220
255
|
}
|
|
221
256
|
return {
|
|
222
257
|
min: new TimeBoundary(min, 'after', gap),
|
|
223
|
-
max: new TimeBoundary(max, 'before', gap)
|
|
258
|
+
max: new TimeBoundary(max, 'before', gap)
|
|
224
259
|
};
|
|
225
260
|
};
|
|
226
261
|
|
|
227
|
-
|
|
228
|
-
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* get range from current hour
|
|
265
|
+
*/ function getNumberPickerBoundary(currentHour, { range, isTwelveHourSystem }) {
|
|
266
|
+
const currentIsPM = currentHour >= (/* inlined export .HALF_DAY_HOURS */12);
|
|
229
267
|
let maxHour = range.max.hour ?? 23;
|
|
230
|
-
let maxMinute = range.max.minute ?? lastMinute;
|
|
268
|
+
let maxMinute = range.max.minute ?? (/* inlined export .lastMinute */45);
|
|
231
269
|
let minHour = range.min.hour ?? 0;
|
|
232
270
|
let minMinute = range.min.minute ?? 0;
|
|
233
271
|
if (isTwelveHourSystem) {
|
|
234
272
|
if (currentIsPM) {
|
|
235
|
-
if (minHour < HALF_DAY_HOURS) {
|
|
273
|
+
if (minHour < (/* inlined export .HALF_DAY_HOURS */12)) {
|
|
236
274
|
minHour = 0;
|
|
237
275
|
minMinute = 0;
|
|
238
276
|
}
|
|
239
|
-
}
|
|
240
|
-
else if (maxHour >= HALF_DAY_HOURS) {
|
|
277
|
+
} else if (maxHour >= (/* inlined export .HALF_DAY_HOURS */12)) {
|
|
241
278
|
maxHour = 11;
|
|
242
|
-
maxMinute = lastMinute;
|
|
279
|
+
maxMinute = (/* inlined export .lastMinute */45);
|
|
243
280
|
}
|
|
244
281
|
}
|
|
245
|
-
if (maxMinute !== lastMinute && currentHour < maxHour) {
|
|
246
|
-
maxMinute = lastMinute;
|
|
282
|
+
if (maxMinute !== (/* inlined export .lastMinute */45) && currentHour < maxHour) {
|
|
283
|
+
maxMinute = (/* inlined export .lastMinute */45);
|
|
247
284
|
}
|
|
248
285
|
if (minMinute !== 0 && currentHour > minHour) {
|
|
249
286
|
minMinute = 0;
|
|
250
287
|
}
|
|
251
288
|
if (isTwelveHourSystem) {
|
|
252
|
-
maxHour = maxHour % HALF_DAY_HOURS;
|
|
253
|
-
minHour = minHour % HALF_DAY_HOURS;
|
|
289
|
+
maxHour = maxHour % (/* inlined export .HALF_DAY_HOURS */12);
|
|
290
|
+
minHour = minHour % (/* inlined export .HALF_DAY_HOURS */12);
|
|
254
291
|
}
|
|
255
292
|
return {
|
|
256
293
|
hour: {
|
|
257
294
|
min: minHour,
|
|
258
|
-
max: maxHour
|
|
295
|
+
max: maxHour
|
|
259
296
|
},
|
|
260
297
|
minute: {
|
|
261
298
|
min: minMinute,
|
|
262
|
-
max: maxMinute
|
|
263
|
-
}
|
|
299
|
+
max: maxMinute
|
|
300
|
+
}
|
|
264
301
|
};
|
|
265
302
|
}
|
|
266
303
|
|
|
267
|
-
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
const NumberPicker = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
268
319
|
const { onClick, value, onChange: onUpdate, onKeyDown, source, min, max, step, renderValue, getScreenReaderLabel, autoFocus, ...rest } = props;
|
|
269
320
|
const { focusVisible, focusVisibleHandlers, focusVisibleRef } = useFocusVisible();
|
|
270
321
|
const pickerRef = useRef(null);
|
|
271
322
|
const handlePickerRef = useForkRef(pickerRef, focusVisibleRef);
|
|
272
|
-
useLayoutEffect(()
|
|
323
|
+
useLayoutEffect(()=>{
|
|
273
324
|
if (autoFocus) {
|
|
274
325
|
pickerRef.current?.focus();
|
|
275
326
|
}
|
|
327
|
+
// oxlint-disable-next-line react-hooks/exhaustive-deps
|
|
276
328
|
}, []);
|
|
277
329
|
const index = Math.floor(value / step);
|
|
278
330
|
const isFirst = index === 0;
|
|
@@ -281,179 +333,347 @@ const NumberPicker = forwardRef((props, ref) => {
|
|
|
281
333
|
const latestValue = source[source.length - 1];
|
|
282
334
|
const decreaseValue = isFirst ? latestValue : source[index - 1];
|
|
283
335
|
const increaseValue = isLatest ? firstValue : source[index + 1];
|
|
284
|
-
const decreaseDisabled = isFirst
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const increaseDisabled = isLatest
|
|
288
|
-
? !!(min !== undefined && firstValue < min)
|
|
289
|
-
: !!(max !== undefined && increaseValue > max);
|
|
290
|
-
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 = (()=>{
|
|
291
339
|
if (renderValue) {
|
|
292
340
|
return renderValue(value);
|
|
293
341
|
}
|
|
294
342
|
return pad(value);
|
|
295
343
|
})();
|
|
296
344
|
const label = getScreenReaderLabel?.(showValue);
|
|
297
|
-
const handleKeyDown = (event)
|
|
345
|
+
const handleKeyDown = (event)=>{
|
|
298
346
|
runKeyHandler(event, {
|
|
299
|
-
ArrowUp: ()
|
|
347
|
+
ArrowUp: ()=>{
|
|
300
348
|
if (increaseDisabled) {
|
|
301
349
|
return;
|
|
302
350
|
}
|
|
303
351
|
onUpdate(increaseValue, 'arrowKey');
|
|
304
352
|
},
|
|
305
|
-
ArrowDown: ()
|
|
353
|
+
ArrowDown: ()=>{
|
|
306
354
|
if (decreaseDisabled) {
|
|
307
355
|
return;
|
|
308
356
|
}
|
|
309
357
|
onUpdate(decreaseValue, 'arrowKey');
|
|
310
|
-
}
|
|
358
|
+
}
|
|
311
359
|
});
|
|
312
360
|
onKeyDown?.(event);
|
|
313
361
|
};
|
|
314
362
|
const cls = useTimePickerClasses();
|
|
315
|
-
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: ()=>{
|
|
316
384
|
onUpdate(increaseValue, 'arrowButton');
|
|
317
|
-
},
|
|
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: ()=>{
|
|
318
408
|
onUpdate(decreaseValue, 'arrowButton');
|
|
319
|
-
},
|
|
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
|
+
});
|
|
320
419
|
});
|
|
321
420
|
NumberPicker.displayName = 'SuiNumberPicker';
|
|
322
421
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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;
|
|
331
435
|
const showValue = parseNumberToString(value, isTwelveHourSystem);
|
|
332
436
|
const cls = useTimePickerClasses();
|
|
333
|
-
return
|
|
334
|
-
|
|
335
|
-
|
|
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);
|
|
336
441
|
const itemShowValue = parseNumberToString(v, isTwelveHourSystem);
|
|
337
|
-
const confirm = ()
|
|
338
|
-
if (disabled)
|
|
339
|
-
return;
|
|
442
|
+
const confirm = ()=>{
|
|
443
|
+
if (disabled) return;
|
|
340
444
|
onConfirm(v);
|
|
341
445
|
};
|
|
342
|
-
return
|
|
343
|
-
|
|
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
|
+
});
|
|
344
455
|
};
|
|
345
456
|
SelectionView.displayName = 'SuiSelectionView';
|
|
346
457
|
|
|
347
|
-
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
const ToggleText = /*#__PURE__*/ forwardRef(({ onChange: onUpdate, value, disabled, getScreenReaderLabel, ...rest }, ref)=>{
|
|
348
469
|
const label = getScreenReaderLabel?.(value);
|
|
349
|
-
const nextValue = value ===
|
|
350
|
-
const handleClick = useEventCallback((event)
|
|
351
|
-
if (disabled || !isClick(event))
|
|
352
|
-
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;
|
|
353
473
|
onUpdate(nextValue, 'arrowButton');
|
|
354
474
|
});
|
|
355
|
-
const handleToggleKeyDown = useEventCallback((event)
|
|
475
|
+
const handleToggleKeyDown = useEventCallback((event)=>{
|
|
356
476
|
if (disabled) {
|
|
357
477
|
return;
|
|
358
478
|
}
|
|
359
|
-
const togglePeriod = ()
|
|
479
|
+
const togglePeriod = ()=>{
|
|
360
480
|
onUpdate(nextValue, 'arrowKey');
|
|
361
481
|
};
|
|
362
482
|
runKeyHandler(event, {
|
|
363
483
|
ArrowUp: togglePeriod,
|
|
364
|
-
ArrowDown: togglePeriod
|
|
484
|
+
ArrowDown: togglePeriod
|
|
365
485
|
});
|
|
366
486
|
});
|
|
367
|
-
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
|
+
});
|
|
368
496
|
});
|
|
369
497
|
ToggleText.displayName = 'SuiToggleText';
|
|
370
498
|
|
|
371
|
-
|
|
372
|
-
|
|
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;
|
|
373
511
|
const [value, setValue] = useState(defaultValue);
|
|
374
|
-
const handleChange = (toValue, onlyInnerState)
|
|
512
|
+
const handleChange = (toValue, onlyInnerState)=>{
|
|
375
513
|
const resultValue = {
|
|
376
514
|
hour: toValue.hour ?? value.hour,
|
|
377
515
|
minute: toValue.minute ?? value.minute,
|
|
378
|
-
period: toValue.period ?? value.period
|
|
516
|
+
period: toValue.period ?? value.period
|
|
379
517
|
};
|
|
380
518
|
setValue(resultValue);
|
|
381
519
|
if (!onlyInnerState) {
|
|
382
520
|
onChange(resultValue);
|
|
383
521
|
}
|
|
384
522
|
};
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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);
|
|
388
526
|
return getNumberPickerBoundary(originHour, {
|
|
389
527
|
range,
|
|
390
|
-
isTwelveHourSystem
|
|
528
|
+
isTwelveHourSystem
|
|
391
529
|
});
|
|
392
|
-
}, [
|
|
393
|
-
|
|
530
|
+
}, [
|
|
531
|
+
range,
|
|
532
|
+
value,
|
|
533
|
+
isTwelveHourSystem
|
|
534
|
+
]);
|
|
535
|
+
// reset pickerValue if pickerValue is out of range
|
|
536
|
+
useLayoutEffect(()=>{
|
|
394
537
|
const { hour, minute, period } = value;
|
|
395
538
|
if (hour > boundary.hour.max || minute > boundary.minute.max) {
|
|
396
539
|
handleChange({
|
|
397
540
|
hour: boundary.hour.max,
|
|
398
541
|
minute: boundary.minute.max,
|
|
399
|
-
period
|
|
542
|
+
period
|
|
400
543
|
}, true);
|
|
401
|
-
}
|
|
402
|
-
else if (hour < boundary.hour.min || minute < boundary.minute.min) {
|
|
544
|
+
} else if (hour < boundary.hour.min || minute < boundary.minute.min) {
|
|
403
545
|
handleChange({
|
|
404
546
|
hour: boundary.hour.min,
|
|
405
547
|
minute: boundary.minute.min,
|
|
406
|
-
period
|
|
548
|
+
period
|
|
407
549
|
}, true);
|
|
408
550
|
}
|
|
409
|
-
|
|
551
|
+
// ignore `handleChange`
|
|
552
|
+
// oxlint-disable-next-line react-hooks/exhaustive-deps
|
|
553
|
+
}, [
|
|
554
|
+
boundary,
|
|
555
|
+
value
|
|
556
|
+
]);
|
|
410
557
|
const isHourView = selectionShowType === 'hour';
|
|
411
|
-
const { getHourPickerAriaLabel, getMinutePickerAriaLabel, getPeriodToggleAriaLabel
|
|
412
|
-
const toggleTextDisabled = useMemo(()
|
|
413
|
-
return Boolean(range.min.hour &&
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
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
|
+
]);
|
|
419
567
|
const cls = useTimePickerClasses();
|
|
420
|
-
return selectionShowType === 'none' ?
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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 = ()=>{
|
|
424
574
|
onChange(value);
|
|
425
575
|
afterDraftConfirm();
|
|
426
576
|
};
|
|
427
577
|
runKeyHandler(event, {
|
|
428
578
|
Enter: confirm,
|
|
429
|
-
' ': confirm
|
|
579
|
+
' ': confirm
|
|
430
580
|
});
|
|
431
|
-
},
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
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)=>{
|
|
436
595
|
return parseNumberToString(hourValue, isTwelveHourSystem);
|
|
437
|
-
},
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
:
|
|
441
|
-
|
|
442
|
-
|
|
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);
|
|
443
637
|
onSelectionShowTypeChange('none');
|
|
444
|
-
},
|
|
638
|
+
},
|
|
639
|
+
"data-sui-picker-selection-view": selectionShowType
|
|
640
|
+
});
|
|
445
641
|
};
|
|
446
642
|
|
|
447
|
-
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"};
|
|
448
643
|
|
|
449
|
-
|
|
450
|
-
|
|
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
|
+
});
|
|
451
667
|
const { isTwelveHourSystem = false, value, onChange, disabled, min, max, onKeyDown, onClear, PopoverProps, classes, defaultPickerValue = null, clearBtn = true, dateMode = false, screenReaderProps = {
|
|
452
|
-
getHourPickerAriaLabel: (hour)
|
|
453
|
-
getMinutePickerAriaLabel: (minute)
|
|
454
|
-
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`
|
|
455
671
|
}, className, ...rest } = props;
|
|
456
|
-
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
|
+
]);
|
|
457
677
|
const actionRef = useRef(null);
|
|
458
678
|
const [selectionShowType, setSelectionType] = useState('none');
|
|
459
679
|
const pickerValue = value ?? defaultPickerValue;
|
|
@@ -461,101 +681,141 @@ const TimePicker = forwardRef((inProps, ref) => {
|
|
|
461
681
|
const textFieldTimestamp = getTimestamp(value);
|
|
462
682
|
const { hour: textFieldHour } = getHourAndMinute(textFieldTimestamp);
|
|
463
683
|
const textFieldPeriod = getPeriod(textFieldHour);
|
|
464
|
-
const formattedTime = textFieldTimestamp === null
|
|
465
|
-
|
|
466
|
-
:
|
|
467
|
-
|
|
468
|
-
period: textFieldPeriod,
|
|
469
|
-
}, isTwelveHourSystem);
|
|
684
|
+
const formattedTime = textFieldTimestamp === null ? '' : getFormattedTime({
|
|
685
|
+
...getHourAndMinute(textFieldTimestamp),
|
|
686
|
+
period: textFieldPeriod
|
|
687
|
+
}, isTwelveHourSystem);
|
|
470
688
|
const pickerTimestamp = getTimestamp(pickerValue);
|
|
471
689
|
const { hour: originPickerHour, minute: originPickerMinute } = getHourAndMinute(pickerTimestamp);
|
|
472
690
|
const pickerPeriod = getPeriod(originPickerHour);
|
|
473
|
-
const pickerHour = isTwelveHourSystem
|
|
474
|
-
? originPickerHour % HALF_DAY_HOURS
|
|
475
|
-
: originPickerHour;
|
|
691
|
+
const pickerHour = isTwelveHourSystem ? originPickerHour % (/* inlined export .HALF_DAY_HOURS */12) : originPickerHour;
|
|
476
692
|
const pickerMinute = originPickerMinute;
|
|
477
|
-
const range = useMemo(()
|
|
478
|
-
return getRangeBoundary({
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
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)=>{
|
|
482
704
|
onChange?.(toValue);
|
|
483
705
|
};
|
|
484
706
|
if (isDateMode) {
|
|
485
707
|
update(toValue);
|
|
486
|
-
}
|
|
487
|
-
|
|
708
|
+
} else {
|
|
709
|
+
// * when time is zero emit null
|
|
488
710
|
update(toValue ? getTimestamp(toValue) : null);
|
|
489
711
|
}
|
|
490
712
|
});
|
|
491
|
-
const getInitialDate = useEventCallback(()
|
|
713
|
+
const getInitialDate = useEventCallback(()=>{
|
|
492
714
|
const date = value !== null ? new Date(value) : new Date();
|
|
493
715
|
date.setHours(originPickerHour, originPickerMinute, 0, 0);
|
|
494
716
|
return date;
|
|
495
717
|
});
|
|
496
|
-
const updateTime = (option)
|
|
497
|
-
const { hour = originPickerHour, minute = originPickerMinute, period = pickerPeriod
|
|
498
|
-
const recoupHour = isTwelveHourSystem && pickerPeriod ===
|
|
499
|
-
? HALF_DAY_HOURS
|
|
500
|
-
: 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;
|
|
501
721
|
const time = getInitialDate();
|
|
502
722
|
time.setMinutes(minute);
|
|
503
723
|
time.setHours(hour + recoupHour);
|
|
504
724
|
if (isTwelveHourSystem) {
|
|
505
725
|
const currHour = time.getHours();
|
|
506
|
-
if (period ===
|
|
507
|
-
if (currHour < HALF_DAY_HOURS) {
|
|
508
|
-
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));
|
|
509
729
|
}
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
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));
|
|
513
732
|
}
|
|
514
733
|
}
|
|
515
734
|
const toTimestamp = getTimestamp(time);
|
|
516
735
|
if (range.max.date && toTimestamp > range.max.timestamp) {
|
|
517
736
|
time.setHours(range.max.hour);
|
|
518
737
|
time.setMinutes(range.max.minute);
|
|
519
|
-
}
|
|
520
|
-
else if (range.min.date && toTimestamp < range.min.timestamp) {
|
|
738
|
+
} else if (range.min.date && toTimestamp < range.min.timestamp) {
|
|
521
739
|
time.setHours(range.min.hour);
|
|
522
740
|
time.setMinutes(range.min.minute);
|
|
523
741
|
}
|
|
524
742
|
handleChange(time);
|
|
525
743
|
};
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
744
|
+
// reset value if value is out of range
|
|
745
|
+
useLayoutEffect(()=>{
|
|
746
|
+
if (textFieldTimestamp === null) return;
|
|
529
747
|
const time = getInitialDate();
|
|
530
748
|
if (range.max.date && textFieldTimestamp > range.max.timestamp) {
|
|
531
749
|
time.setHours(range.max.hour);
|
|
532
750
|
time.setMinutes(range.max.minute);
|
|
533
751
|
handleChange(time);
|
|
534
|
-
}
|
|
535
|
-
else if (range.min.date && textFieldTimestamp < range.min.timestamp) {
|
|
752
|
+
} else if (range.min.date && textFieldTimestamp < range.min.timestamp) {
|
|
536
753
|
time.setHours(range.min.hour);
|
|
537
754
|
time.setMinutes(range.min.minute);
|
|
538
755
|
handleChange(time);
|
|
539
756
|
}
|
|
540
|
-
}, [
|
|
541
|
-
|
|
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)=>{
|
|
542
771
|
onClear?.(e);
|
|
543
772
|
handleChange(null);
|
|
544
|
-
},
|
|
545
|
-
|
|
773
|
+
},
|
|
774
|
+
value: formattedTime,
|
|
775
|
+
disabled: disabled,
|
|
776
|
+
PopoverProps: combineProps({
|
|
777
|
+
onExitComplete: ()=>{
|
|
546
778
|
setSelectionType('none');
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
779
|
+
}
|
|
780
|
+
}, PopoverProps),
|
|
781
|
+
endIconSymbol: RecentMd,
|
|
782
|
+
clearBtn: clearBtn,
|
|
783
|
+
...rest,
|
|
784
|
+
children: /*#__PURE__*/ jsx(PickerView, {
|
|
785
|
+
isTwelveHourSystem: isTwelveHourSystem,
|
|
786
|
+
onChange: updateTime,
|
|
787
|
+
afterDraftConfirm: ()=>{
|
|
552
788
|
actionRef.current?.close();
|
|
553
|
-
},
|
|
789
|
+
},
|
|
790
|
+
defaultValue: {
|
|
554
791
|
hour: pickerHour,
|
|
555
792
|
minute: pickerMinute,
|
|
556
|
-
period: pickerPeriod
|
|
557
|
-
},
|
|
793
|
+
period: pickerPeriod
|
|
794
|
+
},
|
|
795
|
+
onSelectionShowTypeChange: setSelectionType,
|
|
796
|
+
range: range,
|
|
797
|
+
screenReaderProps: screenReaderProps,
|
|
798
|
+
selectionShowType: selectionShowType
|
|
799
|
+
})
|
|
800
|
+
})
|
|
801
|
+
});
|
|
558
802
|
});
|
|
559
|
-
|
|
803
|
+
TimePicker_TimePicker.displayName = 'SuiTimePicker';
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
560
820
|
|
|
561
|
-
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 };
|