@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/DatePicker.js
CHANGED
|
@@ -1,70 +1,93 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { createContext,
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { combineProps, runKeyHandler, useControlled, useEventCallback, useFocusVisible, useForkRef, useId, useKeyboardMoveFocus, useOnlyOneFocusable, usePrevious } from "@ringcentral/spring-base";
|
|
3
|
+
import { createContext, createElement, forwardRef, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { CalendarMd, CaretLeftMd, CaretRightMd } from "@ringcentral/spring-icon";
|
|
5
|
+
import clsx from "clsx";
|
|
6
|
+
import dayjs from "dayjs";
|
|
7
|
+
import { useClassesWithMode, useThemeProps } from "@ringcentral/spring-theme";
|
|
8
|
+
import "./chunks/4476.js";
|
|
9
|
+
import { DateUtilsProvider, useDateUtilsContext } from "./DateUtilsContext.js";
|
|
10
|
+
import { IconButton as IconButton_IconButton } from "./IconButton.js";
|
|
11
|
+
import { Button as Button_Button } from "./Button.js";
|
|
12
|
+
import { CircularProgressIndicator as CircularProgressIndicator_CircularProgressIndicator } from "./CircularProgressIndicator.js";
|
|
13
|
+
import { PickerTextField as PickerTextField_PickerTextField } from "./PickerTextField.js";
|
|
14
|
+
import { ExpandCollapseCaret as ExpandCollapseCaret_ExpandCollapseCaret } from "./chunks/1294.js";
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const DatePickerClassesContext = createContext(()=>'');
|
|
22
|
+
const useDatePickerClasses = ()=>useContext(DatePickerClassesContext);
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
const DATE_PICKER_HEADER_DATA_ATTRIBUTES = {
|
|
26
|
+
previousMonth: 'data-sui-picker-previous-month',
|
|
27
|
+
nextMonth: 'data-sui-picker-next-month',
|
|
28
|
+
switchYearAction: 'data-sui-picker-switch-year-action'
|
|
29
|
+
};
|
|
30
|
+
const DATE_PICKER_HEADER_SELECTORS = {
|
|
31
|
+
previousMonth: `[${DATE_PICKER_HEADER_DATA_ATTRIBUTES.previousMonth}]`,
|
|
32
|
+
nextMonth: `[${DATE_PICKER_HEADER_DATA_ATTRIBUTES.nextMonth}]`,
|
|
33
|
+
switchYearAction: `[${DATE_PICKER_HEADER_DATA_ATTRIBUTES.switchYearAction}]`
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const HeaderAction = (props)=>{
|
|
43
47
|
const { className, disabled, ...rest } = props;
|
|
44
48
|
const cls = useDatePickerClasses();
|
|
45
49
|
const { focusVisible, focusVisibleRef, focusVisibleHandlers } = useFocusVisible();
|
|
46
|
-
return
|
|
50
|
+
return /*#__PURE__*/ jsx("button", {
|
|
51
|
+
className: clsx(className, cls('header-action', {
|
|
52
|
+
focusVisible,
|
|
53
|
+
disabled
|
|
54
|
+
})),
|
|
55
|
+
ref: focusVisibleRef,
|
|
56
|
+
...rest,
|
|
57
|
+
...focusVisibleHandlers,
|
|
58
|
+
type: "button"
|
|
59
|
+
});
|
|
47
60
|
};
|
|
48
61
|
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
49
67
|
const defaultScreenReaderProps = {
|
|
50
|
-
getMonthYearAriaLabel: (monthLabel, expanded)
|
|
51
|
-
getSwitchMonthAriaLabel: (isNext, currentMonth)
|
|
52
|
-
getBackToTodayAriaLabel: ()
|
|
53
|
-
getLoadingAriaLabel: ()
|
|
54
|
-
getDayAriaLabel: (day, selected)
|
|
55
|
-
getYearAriaLabel: (year, selected)
|
|
68
|
+
getMonthYearAriaLabel: (monthLabel, expanded)=>`${monthLabel}${expanded ? ', year selection expanded' : ''}`,
|
|
69
|
+
getSwitchMonthAriaLabel: (isNext, currentMonth)=>`${isNext ? 'Next' : 'Previous'} month, currently viewing ${currentMonth}`,
|
|
70
|
+
getBackToTodayAriaLabel: ()=>'Go back to today',
|
|
71
|
+
getLoadingAriaLabel: ()=>'Loading dates',
|
|
72
|
+
getDayAriaLabel: (day, selected)=>`${day}${selected ? ', selected' : ''}`,
|
|
73
|
+
getYearAriaLabel: (year, selected)=>`${year}${selected ? ', selected' : ''}`
|
|
56
74
|
};
|
|
57
|
-
const ScreenReaderContext = createContext(defaultScreenReaderProps);
|
|
58
|
-
const useScreenReaderContext = ()
|
|
59
|
-
const ScreenReaderProvider = ({ screenReaderProps, children
|
|
60
|
-
return
|
|
75
|
+
const ScreenReaderContext = /*#__PURE__*/ createContext(defaultScreenReaderProps);
|
|
76
|
+
const useScreenReaderContext = ()=>useContext(ScreenReaderContext);
|
|
77
|
+
const ScreenReaderProvider = ({ screenReaderProps, children })=>{
|
|
78
|
+
return /*#__PURE__*/ jsx(ScreenReaderContext.Provider, {
|
|
79
|
+
value: screenReaderProps || defaultScreenReaderProps,
|
|
80
|
+
children: children
|
|
81
|
+
});
|
|
61
82
|
};
|
|
62
83
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
84
|
+
|
|
85
|
+
const focusDayElement = (root = document)=>{
|
|
86
|
+
const focusedDayElement = root?.querySelector('[data-sui-picker-focused]');
|
|
87
|
+
focusedDayElement?.focus();
|
|
88
|
+
return focusedDayElement;
|
|
66
89
|
};
|
|
67
|
-
const isSameYearAndMonth = ({ source, comparing }, utils)
|
|
90
|
+
const isSameYearAndMonth = ({ source, comparing }, utils)=>{
|
|
68
91
|
if (!source || !comparing) {
|
|
69
92
|
return false;
|
|
70
93
|
}
|
|
@@ -74,7 +97,7 @@ const isSameYearAndMonth = ({ source, comparing }, utils) => {
|
|
|
74
97
|
const comparingYear = utils.getYear(comparing);
|
|
75
98
|
return thisMonth === comparingMonth && thisYear === comparingYear;
|
|
76
99
|
};
|
|
77
|
-
const invalidateDateInRange = (day, { dateRange: { min, max }, disableFuture, disablePast, now
|
|
100
|
+
const invalidateDateInRange = (day, { dateRange: { min, max }, disableFuture, disablePast, now }, utils)=>{
|
|
78
101
|
if (disableFuture && utils.isAfterDay(day, now)) {
|
|
79
102
|
return now;
|
|
80
103
|
}
|
|
@@ -90,7 +113,7 @@ const invalidateDateInRange = (day, { dateRange: { min, max }, disableFuture, di
|
|
|
90
113
|
return false;
|
|
91
114
|
};
|
|
92
115
|
|
|
93
|
-
const findClosestEnabledDate = ({ date, utils, minDate, maxDate, disableFuture, disablePast, shouldDisableDate
|
|
116
|
+
const findClosestEnabledDate = ({ date, utils, minDate, maxDate, disableFuture, disablePast, shouldDisableDate })=>{
|
|
94
117
|
const today = utils.startOfDay(utils.date());
|
|
95
118
|
if (disablePast && utils.isBefore(minDate, today)) {
|
|
96
119
|
minDate = today;
|
|
@@ -110,7 +133,7 @@ const findClosestEnabledDate = ({ date, utils, minDate, maxDate, disableFuture,
|
|
|
110
133
|
}
|
|
111
134
|
forward = null;
|
|
112
135
|
}
|
|
113
|
-
while
|
|
136
|
+
while(forward || backward){
|
|
114
137
|
if (forward && utils.isAfter(forward, maxDate)) {
|
|
115
138
|
forward = null;
|
|
116
139
|
}
|
|
@@ -130,20 +153,34 @@ const findClosestEnabledDate = ({ date, utils, minDate, maxDate, disableFuture,
|
|
|
130
153
|
backward = utils.addDays(backward, -1);
|
|
131
154
|
}
|
|
132
155
|
}
|
|
156
|
+
// fallback to today if no enabled days
|
|
133
157
|
return utils.date();
|
|
134
158
|
};
|
|
135
159
|
|
|
136
|
-
|
|
137
|
-
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
const DatePickerHeader = (props)=>{
|
|
174
|
+
const { focusedDate, onMonthChange, disablePrevMonth = false, disableNextMonth = false, onViewChange, view, gridLabelId } = props;
|
|
138
175
|
const utils = useDateUtilsContext();
|
|
139
176
|
const cls = useDatePickerClasses();
|
|
140
177
|
const preMonth = utils.getPreviousMonth(focusedDate);
|
|
141
178
|
const nextMonth = utils.getNextMonth(focusedDate);
|
|
142
179
|
const monthLabel = utils.getCalendarHeaderText(focusedDate);
|
|
143
|
-
const selectNextMonth = ()
|
|
180
|
+
const selectNextMonth = ()=>{
|
|
144
181
|
onMonthChange(nextMonth, 'left');
|
|
145
182
|
};
|
|
146
|
-
const selectPreviousMonth = ()
|
|
183
|
+
const selectPreviousMonth = ()=>{
|
|
147
184
|
onMonthChange(preMonth, 'right');
|
|
148
185
|
};
|
|
149
186
|
const isYearView = view === 'year';
|
|
@@ -152,11 +189,78 @@ const DatePickerHeader = (props) => {
|
|
|
152
189
|
const monthYearAriaLabel = getMonthYearAriaLabel?.(`${monthLabel}`, isExpanded);
|
|
153
190
|
const nextMonthAriaLabel = getSwitchMonthAriaLabel?.(true, utils.getMonthText(focusedDate));
|
|
154
191
|
const previousMonthAriaLabel = getSwitchMonthAriaLabel?.(false, utils.getMonthText(focusedDate));
|
|
155
|
-
return
|
|
192
|
+
return /*#__PURE__*/ jsx(Fragment, {
|
|
193
|
+
children: /*#__PURE__*/ jsxs("div", {
|
|
194
|
+
className: cls('header'),
|
|
195
|
+
children: [
|
|
196
|
+
/*#__PURE__*/ jsxs(HeaderAction, {
|
|
197
|
+
onClick: onViewChange,
|
|
198
|
+
"aria-label": monthYearAriaLabel,
|
|
199
|
+
"aria-expanded": isExpanded,
|
|
200
|
+
[DATE_PICKER_HEADER_DATA_ATTRIBUTES.switchYearAction]: '',
|
|
201
|
+
className: cls('switch-year-action'),
|
|
202
|
+
children: [
|
|
203
|
+
/*#__PURE__*/ jsx("span", {
|
|
204
|
+
id: gridLabelId,
|
|
205
|
+
"aria-live": "polite",
|
|
206
|
+
"aria-atomic": "true",
|
|
207
|
+
children: monthLabel
|
|
208
|
+
}),
|
|
209
|
+
/*#__PURE__*/ jsx(ExpandCollapseCaret_ExpandCollapseCaret, {
|
|
210
|
+
className: cls('switch-year-action-caret'),
|
|
211
|
+
size: "small",
|
|
212
|
+
expanded: isExpanded
|
|
213
|
+
})
|
|
214
|
+
]
|
|
215
|
+
}),
|
|
216
|
+
!isYearView && /*#__PURE__*/ jsxs("div", {
|
|
217
|
+
className: cls('switch-month-actions-group'),
|
|
218
|
+
children: [
|
|
219
|
+
/*#__PURE__*/ jsx(IconButton_IconButton, {
|
|
220
|
+
shape: "squircle",
|
|
221
|
+
variant: "contained",
|
|
222
|
+
color: "secondary",
|
|
223
|
+
size: "small",
|
|
224
|
+
background: false,
|
|
225
|
+
symbol: CaretLeftMd,
|
|
226
|
+
className: cls('switch-month-action'),
|
|
227
|
+
disabled: disablePrevMonth,
|
|
228
|
+
onClick: selectPreviousMonth,
|
|
229
|
+
"aria-label": previousMonthAriaLabel,
|
|
230
|
+
[DATE_PICKER_HEADER_DATA_ATTRIBUTES.previousMonth]: ''
|
|
231
|
+
}),
|
|
232
|
+
/*#__PURE__*/ jsx(IconButton_IconButton, {
|
|
233
|
+
shape: "squircle",
|
|
234
|
+
variant: "contained",
|
|
235
|
+
color: "secondary",
|
|
236
|
+
size: "small",
|
|
237
|
+
background: false,
|
|
238
|
+
symbol: CaretRightMd,
|
|
239
|
+
className: cls('switch-month-action'),
|
|
240
|
+
disabled: disableNextMonth,
|
|
241
|
+
onClick: selectNextMonth,
|
|
242
|
+
"aria-label": nextMonthAriaLabel,
|
|
243
|
+
[DATE_PICKER_HEADER_DATA_ATTRIBUTES.nextMonth]: ''
|
|
244
|
+
})
|
|
245
|
+
]
|
|
246
|
+
})
|
|
247
|
+
]
|
|
248
|
+
})
|
|
249
|
+
});
|
|
156
250
|
};
|
|
157
251
|
DatePickerHeader.displayName = 'RcDatePickerHeader';
|
|
158
252
|
|
|
159
|
-
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
const Day = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
160
264
|
const { onSelect, value, selected, disabled, focused, children, current, date, onFocus, onBlur, ...rest } = props;
|
|
161
265
|
const { getDayAriaLabel } = useScreenReaderContext() ?? {};
|
|
162
266
|
const cls = useDatePickerClasses();
|
|
@@ -164,95 +268,204 @@ const Day = forwardRef((props, ref) => {
|
|
|
164
268
|
const utils = useDateUtilsContext();
|
|
165
269
|
const handleRef = useForkRef(ref, focusVisibleRef);
|
|
166
270
|
const dayLabel = `${utils.getDatePickerHeaderText(date)} ${utils.getYearText(date)}`;
|
|
167
|
-
return
|
|
271
|
+
return /*#__PURE__*/ jsx("button", {
|
|
272
|
+
onClick: ()=>onSelect(value),
|
|
273
|
+
ref: handleRef,
|
|
274
|
+
className: cls('date-button', 'day', {
|
|
168
275
|
'current-date': current,
|
|
169
276
|
selected,
|
|
170
277
|
disabled,
|
|
171
|
-
focusVisible
|
|
172
|
-
}),
|
|
278
|
+
focusVisible
|
|
279
|
+
}),
|
|
280
|
+
"data-sui-picker-focused": focused ? '' : undefined,
|
|
281
|
+
"data-sui-picker-day": value,
|
|
282
|
+
"aria-label": getDayAriaLabel?.(dayLabel, selected, {
|
|
173
283
|
date,
|
|
174
284
|
disabled,
|
|
175
285
|
today: current,
|
|
176
|
-
focused
|
|
177
|
-
}),
|
|
286
|
+
focused
|
|
287
|
+
}),
|
|
288
|
+
...rest,
|
|
289
|
+
...combineProps({
|
|
290
|
+
onBlur,
|
|
291
|
+
onFocus
|
|
292
|
+
}, focusVisibleHandlers),
|
|
293
|
+
type: "button",
|
|
294
|
+
children: children
|
|
295
|
+
});
|
|
178
296
|
});
|
|
179
297
|
Day.displayName = 'SuiDay';
|
|
180
298
|
|
|
181
|
-
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
const Year = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
182
312
|
const { onSelect, value, selected, disabled, children, current, onFocus, onBlur, date, ...rest } = props;
|
|
183
313
|
const { getYearAriaLabel } = useScreenReaderContext() ?? {};
|
|
184
314
|
const cls = useDatePickerClasses();
|
|
185
315
|
const { focusVisible, focusVisibleHandlers, focusVisibleRef } = useFocusVisible();
|
|
186
316
|
const handleRef = useForkRef(ref, focusVisibleRef);
|
|
187
|
-
return
|
|
317
|
+
return /*#__PURE__*/ jsx("button", {
|
|
318
|
+
onClick: ()=>onSelect(value),
|
|
319
|
+
ref: handleRef,
|
|
320
|
+
className: cls('date-button', 'year', {
|
|
188
321
|
'current-date': current,
|
|
189
322
|
selected,
|
|
190
323
|
disabled,
|
|
191
|
-
focusVisible
|
|
192
|
-
}),
|
|
324
|
+
focusVisible
|
|
325
|
+
}),
|
|
326
|
+
"data-sui-picker-year": value,
|
|
327
|
+
"aria-label": getYearAriaLabel?.(value, selected),
|
|
328
|
+
...rest,
|
|
329
|
+
...combineProps({
|
|
330
|
+
onBlur,
|
|
331
|
+
onFocus
|
|
332
|
+
}, focusVisibleHandlers),
|
|
333
|
+
type: "button",
|
|
334
|
+
children: children
|
|
335
|
+
});
|
|
193
336
|
});
|
|
194
337
|
Year.displayName = 'SuiYear';
|
|
195
338
|
|
|
196
|
-
|
|
197
|
-
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
const Years = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
348
|
+
const { date, onYearChange, minDate, maxDate, disablePast, disableFuture, now } = props;
|
|
198
349
|
const utils = useDateUtilsContext();
|
|
199
350
|
const containerRef = useRef(null);
|
|
200
351
|
const combineRef = useForkRef(containerRef, ref);
|
|
201
352
|
const selectedYearRef = useRef(null);
|
|
202
353
|
const currentYear = utils.getYearText(date || now);
|
|
203
|
-
const years = useMemo(()
|
|
354
|
+
const years = useMemo(()=>utils.getYearRange(minDate, maxDate), [
|
|
355
|
+
maxDate,
|
|
356
|
+
minDate,
|
|
357
|
+
utils
|
|
358
|
+
]);
|
|
204
359
|
const focusedIndexRef = useRef(0);
|
|
205
360
|
const focusedYear = utils.getYearText(years[focusedIndexRef.current]);
|
|
206
361
|
const { focusIndex, getItemProps } = useOnlyOneFocusable({
|
|
207
362
|
focusedIndexRef,
|
|
208
|
-
containerRef
|
|
363
|
+
containerRef
|
|
209
364
|
});
|
|
210
|
-
const getOptionDisabled = (year)
|
|
211
|
-
(disableFuture && utils.isAfterYear(year, now)));
|
|
365
|
+
const getOptionDisabled = (year)=>Boolean(disablePast && utils.isBeforeYear(year, now) || disableFuture && utils.isAfterYear(year, now));
|
|
212
366
|
const { onKeyFocusedIndexHandle: handleKeyDown } = useKeyboardMoveFocus({
|
|
213
367
|
options: years,
|
|
214
368
|
focusedIndexRef,
|
|
215
369
|
columns: 4,
|
|
216
370
|
infinite: 'order',
|
|
217
|
-
onFocusedIndexChange: (event, toIndex)
|
|
371
|
+
onFocusedIndexChange: (event, toIndex)=>{
|
|
218
372
|
focusIndex(toIndex);
|
|
219
373
|
event?.preventDefault();
|
|
220
374
|
},
|
|
221
|
-
getOptionDisabled
|
|
375
|
+
getOptionDisabled
|
|
222
376
|
});
|
|
223
|
-
useLayoutEffect(()
|
|
224
|
-
const index = years.findIndex((x)
|
|
377
|
+
useLayoutEffect(()=>{
|
|
378
|
+
const index = years.findIndex((x)=>utils.getYearText(x) === currentYear);
|
|
225
379
|
focusIndex(index);
|
|
380
|
+
// oxlint-disable-next-line react-hooks/exhaustive-deps
|
|
226
381
|
}, []);
|
|
227
382
|
const cls = useDatePickerClasses();
|
|
228
|
-
return
|
|
383
|
+
return /*#__PURE__*/ jsx("div", {
|
|
384
|
+
role: "presentation",
|
|
385
|
+
className: cls('years-panel'),
|
|
386
|
+
ref: combineRef,
|
|
387
|
+
onKeyDown: handleKeyDown,
|
|
388
|
+
children: years.map((year, index)=>{
|
|
229
389
|
const yearText = utils.getYearText(year);
|
|
230
390
|
const selected = yearText === currentYear;
|
|
231
391
|
const focused = yearText === focusedYear;
|
|
232
392
|
const disabled = getOptionDisabled(year);
|
|
233
|
-
return
|
|
393
|
+
return /*#__PURE__*/ createElement(Year, {
|
|
394
|
+
...getItemProps(index),
|
|
395
|
+
current: utils.isSameYear(year, now),
|
|
396
|
+
ref: focused ? selectedYearRef : undefined,
|
|
397
|
+
key: utils.getYearText(year),
|
|
398
|
+
selected: selected,
|
|
399
|
+
date: year,
|
|
400
|
+
value: yearText,
|
|
401
|
+
onSelect: (year)=>{
|
|
234
402
|
const newDate = utils.setYear(date, Number(year));
|
|
235
403
|
onYearChange(newDate);
|
|
236
|
-
},
|
|
237
|
-
|
|
404
|
+
},
|
|
405
|
+
disabled: disabled
|
|
406
|
+
}, utils.getYearText(year));
|
|
407
|
+
})
|
|
408
|
+
});
|
|
238
409
|
});
|
|
239
410
|
Years.displayName = 'SuiYears';
|
|
240
411
|
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
241
425
|
const DATE_PICKER_CALENDAR_GRID_LABEL_ID_PREFIX = 'DatePickerCalendarGridLabel';
|
|
242
|
-
const
|
|
426
|
+
const getFallbackHeaderFocusTarget = (target)=>{
|
|
427
|
+
switch(target){
|
|
428
|
+
case 'previousMonth':
|
|
429
|
+
return 'nextMonth';
|
|
430
|
+
case 'nextMonth':
|
|
431
|
+
return 'previousMonth';
|
|
432
|
+
default:
|
|
433
|
+
return 'switchYearAction';
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
const getHeaderButton = (root, target)=>root?.querySelector(DATE_PICKER_HEADER_SELECTORS[target]) ?? null;
|
|
437
|
+
const getRestorableHeaderFocusElement = (root, target)=>{
|
|
438
|
+
const headerElement = getHeaderButton(root, target);
|
|
439
|
+
if (headerElement && !headerElement.disabled) {
|
|
440
|
+
return headerElement;
|
|
441
|
+
}
|
|
442
|
+
const fallbackElement = getHeaderButton(root, getFallbackHeaderFocusTarget(target));
|
|
443
|
+
if (fallbackElement && !fallbackElement.disabled) {
|
|
444
|
+
return fallbackElement;
|
|
445
|
+
}
|
|
446
|
+
return getHeaderButton(root, 'switchYearAction');
|
|
447
|
+
};
|
|
448
|
+
const Calendar = /*#__PURE__*/ forwardRef(({ onMonthChange, date, shouldDisableDate, dateRange, todayButtonText, loadingIndicator, disablePast, disableFuture, renderDay, onSelectDay, getInvalidateDateInRange }, ref)=>{
|
|
243
449
|
const cls = useDatePickerClasses();
|
|
244
450
|
const utils = useDateUtilsContext();
|
|
245
|
-
const previousFocusDate = usePrevious(()
|
|
246
|
-
const previousView = usePrevious(() => view);
|
|
451
|
+
const previousFocusDate = usePrevious(()=>focusedDate);
|
|
247
452
|
const weeks = useRef([]);
|
|
248
|
-
const
|
|
249
|
-
const
|
|
453
|
+
const calendarRef = useRef(null);
|
|
454
|
+
const handleCalendarRef = useForkRef(calendarRef, ref);
|
|
455
|
+
const focusIntentRef = useRef('day');
|
|
456
|
+
const weekdayLabels = useMemo(()=>utils.getWeekdayLabels(), [
|
|
457
|
+
utils
|
|
458
|
+
]);
|
|
459
|
+
const { now, isTodayDisabled } = useMemo(()=>{
|
|
250
460
|
const nowDate = utils.date();
|
|
251
461
|
return {
|
|
252
462
|
now: nowDate,
|
|
253
|
-
isTodayDisabled: shouldDisableDate(nowDate)
|
|
463
|
+
isTodayDisabled: shouldDisableDate(nowDate)
|
|
254
464
|
};
|
|
255
|
-
}, [
|
|
465
|
+
}, [
|
|
466
|
+
shouldDisableDate,
|
|
467
|
+
utils
|
|
468
|
+
]);
|
|
256
469
|
const [focusedDate, setFocusedDate] = useState(date);
|
|
257
470
|
const [view, setView] = useState('day');
|
|
258
471
|
const [slideDirection, setSlideDirection] = useState('left');
|
|
@@ -260,170 +473,312 @@ const Calendar = forwardRef(({ onMonthChange, date, shouldDisableDate, dateRange
|
|
|
260
473
|
const gridLabelId = useId(DATE_PICKER_CALENDAR_GRID_LABEL_ID_PREFIX, true);
|
|
261
474
|
const { min, max } = dateRange;
|
|
262
475
|
const currentMonthNumber = utils.getMonth(focusedDate);
|
|
263
|
-
const sameMonthDate = previousFocusDate
|
|
264
|
-
|
|
265
|
-
:
|
|
476
|
+
const sameMonthDate = previousFocusDate ? isSameYearAndMonth({
|
|
477
|
+
source: focusedDate,
|
|
478
|
+
comparing: previousFocusDate
|
|
479
|
+
}, utils) : false;
|
|
266
480
|
if (!sameMonthDate) {
|
|
267
481
|
weeks.current = utils.getWeekArray(focusedDate);
|
|
268
482
|
}
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
setLoadingQueue(loadingQueue + 1);
|
|
483
|
+
const pushToLoadingQueue = ()=>{
|
|
484
|
+
setLoadingQueue((queue)=>queue + 1);
|
|
272
485
|
};
|
|
273
|
-
const popFromLoadingQueue = ()
|
|
274
|
-
setLoadingQueue(
|
|
486
|
+
const popFromLoadingQueue = ()=>{
|
|
487
|
+
setLoadingQueue((queue)=>queue <= 0 ? 0 : queue - 1);
|
|
275
488
|
};
|
|
276
|
-
const handleMonthChange = useEventCallback((newMonth, direction)
|
|
489
|
+
const handleMonthChange = useEventCallback((newMonth, direction, shouldFocusDay = false)=>{
|
|
490
|
+
if (shouldFocusDay) {
|
|
491
|
+
focusIntentRef.current = 'day';
|
|
492
|
+
} else {
|
|
493
|
+
focusIntentRef.current = direction === 'left' ? 'nextMonth' : 'previousMonth';
|
|
494
|
+
}
|
|
277
495
|
setSlideDirection(direction);
|
|
278
496
|
setFocusedDate(getInvalidateDateInRange(newMonth) || newMonth);
|
|
279
497
|
if (onMonthChange) {
|
|
280
498
|
const returnVal = onMonthChange(newMonth);
|
|
281
499
|
if (returnVal) {
|
|
282
500
|
pushToLoadingQueue();
|
|
283
|
-
returnVal.then(()
|
|
501
|
+
returnVal.then(()=>{
|
|
284
502
|
popFromLoadingQueue();
|
|
285
503
|
});
|
|
286
504
|
}
|
|
287
505
|
}
|
|
288
506
|
});
|
|
289
|
-
const handleChangeView = useEventCallback(()
|
|
507
|
+
const handleChangeView = useEventCallback(()=>{
|
|
508
|
+
focusIntentRef.current = null;
|
|
290
509
|
setView(view === 'day' ? 'year' : 'day');
|
|
291
510
|
});
|
|
292
|
-
const disableNextMonth = useMemo(()
|
|
511
|
+
const disableNextMonth = useMemo(()=>{
|
|
293
512
|
const nextStartDay = utils.startOfMonth(utils.getNextMonth(focusedDate));
|
|
294
513
|
return !!getInvalidateDateInRange(nextStartDay);
|
|
295
|
-
}, [
|
|
296
|
-
|
|
514
|
+
}, [
|
|
515
|
+
focusedDate,
|
|
516
|
+
getInvalidateDateInRange,
|
|
517
|
+
utils
|
|
518
|
+
]);
|
|
519
|
+
const disablePrevMonth = useMemo(()=>{
|
|
297
520
|
const prevLatestDay = utils.endOfMonth(utils.getPreviousMonth(focusedDate));
|
|
298
521
|
return !!getInvalidateDateInRange(prevLatestDay);
|
|
299
|
-
}, [
|
|
300
|
-
|
|
301
|
-
|
|
522
|
+
}, [
|
|
523
|
+
focusedDate,
|
|
524
|
+
getInvalidateDateInRange,
|
|
525
|
+
utils
|
|
526
|
+
]);
|
|
527
|
+
const handleKeyDown = (event)=>{
|
|
528
|
+
const moveDay = (value)=>{
|
|
302
529
|
const day = utils.addDays(focusedDate, value);
|
|
303
530
|
if (day && !shouldDisableDate(day)) {
|
|
304
531
|
const newMonthNumber = utils.getMonth(day);
|
|
305
532
|
if (newMonthNumber !== currentMonthNumber) {
|
|
306
|
-
return handleMonthChange(day, newMonthNumber > currentMonthNumber ? 'left' : 'right');
|
|
533
|
+
return handleMonthChange(day, newMonthNumber > currentMonthNumber ? 'left' : 'right', true);
|
|
307
534
|
}
|
|
535
|
+
focusIntentRef.current = 'day';
|
|
308
536
|
setFocusedDate(day);
|
|
309
537
|
}
|
|
310
538
|
};
|
|
311
|
-
const goToDate = (day)
|
|
539
|
+
const goToDate = (day)=>{
|
|
540
|
+
focusIntentRef.current = 'day';
|
|
312
541
|
setFocusedDate(getInvalidateDateInRange(day) || day);
|
|
313
542
|
};
|
|
314
|
-
const confirmDate = ()
|
|
543
|
+
const confirmDate = ()=>{
|
|
315
544
|
event.stopPropagation();
|
|
316
545
|
onSelectDay(focusedDate);
|
|
317
546
|
};
|
|
318
547
|
runKeyHandler(event, {
|
|
319
|
-
ArrowUp: ()
|
|
320
|
-
ArrowDown: ()
|
|
321
|
-
ArrowLeft: ()
|
|
322
|
-
ArrowRight: ()
|
|
323
|
-
Home: ()
|
|
324
|
-
End: ()
|
|
548
|
+
ArrowUp: ()=>moveDay(-7),
|
|
549
|
+
ArrowDown: ()=>moveDay(7),
|
|
550
|
+
ArrowLeft: ()=>moveDay(-1),
|
|
551
|
+
ArrowRight: ()=>moveDay(1),
|
|
552
|
+
Home: ()=>goToDate(utils.startOfMonth(focusedDate)),
|
|
553
|
+
End: ()=>goToDate(utils.endOfMonth(focusedDate)),
|
|
325
554
|
Enter: confirmDate,
|
|
326
|
-
' ': confirmDate
|
|
555
|
+
' ': confirmDate
|
|
327
556
|
});
|
|
328
557
|
};
|
|
329
558
|
const { getBackToTodayAriaLabel, getLoadingAriaLabel } = useScreenReaderContext() ?? {};
|
|
330
559
|
const backToTodayAriaLabel = getBackToTodayAriaLabel?.();
|
|
331
560
|
const loadingAriaLabel = getLoadingAriaLabel?.();
|
|
332
|
-
const renderDays = (week)
|
|
561
|
+
const renderDays = (week)=>{
|
|
333
562
|
const selectedDate = date;
|
|
334
|
-
return week.map((day)
|
|
563
|
+
return week.map((day)=>{
|
|
335
564
|
const disabled = shouldDisableDate(day);
|
|
336
565
|
const isDayInCurrentMonth = utils.getMonth(day) === currentMonthNumber;
|
|
337
566
|
const dayText = utils.getDayText(day);
|
|
338
567
|
const key = utils.formatByString(day, 'YYYY-MM-DD');
|
|
339
568
|
const selected = utils.isSameDay(day, selectedDate);
|
|
340
569
|
const focused = utils.isSameDay(focusedDate, day);
|
|
341
|
-
const dayComponent = isDayInCurrentMonth ?
|
|
570
|
+
const dayComponent = isDayInCurrentMonth ? /*#__PURE__*/ jsx(Day, {
|
|
571
|
+
disabled: disabled,
|
|
572
|
+
current: utils.isSameDay(day, now),
|
|
573
|
+
selected: selected,
|
|
574
|
+
tabIndex: focused ? 0 : -1,
|
|
575
|
+
focused: focused,
|
|
576
|
+
date: day,
|
|
577
|
+
value: dayText,
|
|
578
|
+
onSelect: ()=>{
|
|
342
579
|
isDayInCurrentMonth && onSelectDay(day);
|
|
343
|
-
},
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
:
|
|
347
|
-
|
|
580
|
+
},
|
|
581
|
+
children: dayText
|
|
582
|
+
}, key) : /*#__PURE__*/ jsx("div", {
|
|
583
|
+
"aria-hidden": true
|
|
584
|
+
}, key);
|
|
585
|
+
const renderedDay = renderDay ? renderDay(day, focusedDate, isDayInCurrentMonth, dayComponent) : dayComponent;
|
|
586
|
+
return /*#__PURE__*/ jsx("td", {
|
|
587
|
+
className: cls('day-cell'),
|
|
588
|
+
"aria-selected": selected && isDayInCurrentMonth ? true : undefined,
|
|
589
|
+
children: renderedDay
|
|
590
|
+
}, key);
|
|
348
591
|
});
|
|
349
592
|
};
|
|
350
|
-
const renderBody = ()
|
|
351
|
-
const loadingElement = loadingIndicator ?
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
593
|
+
const renderBody = ()=>{
|
|
594
|
+
const loadingElement = loadingIndicator ? loadingIndicator : /*#__PURE__*/ jsx("div", {
|
|
595
|
+
className: cls('loading-container'),
|
|
596
|
+
children: /*#__PURE__*/ jsx(CircularProgressIndicator_CircularProgressIndicator, {
|
|
597
|
+
progressBarProps: {
|
|
598
|
+
'aria-label': loadingAriaLabel
|
|
599
|
+
}
|
|
600
|
+
})
|
|
601
|
+
});
|
|
602
|
+
switch(view){
|
|
355
603
|
case 'day':
|
|
356
|
-
return
|
|
604
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
605
|
+
children: [
|
|
606
|
+
/*#__PURE__*/ jsx("div", {
|
|
607
|
+
className: cls('days-panel'),
|
|
608
|
+
children: /*#__PURE__*/ jsxs("table", {
|
|
609
|
+
className: cls('days-grid'),
|
|
610
|
+
role: "grid",
|
|
611
|
+
"aria-labelledby": gridLabelId,
|
|
612
|
+
"aria-busy": loadingQueue > 0 ? true : undefined,
|
|
613
|
+
onKeyDown: handleKeyDown,
|
|
614
|
+
children: [
|
|
615
|
+
/*#__PURE__*/ jsx("thead", {
|
|
616
|
+
children: /*#__PURE__*/ jsx("tr", {
|
|
617
|
+
className: cls('weekdays'),
|
|
618
|
+
children: weekdayLabels.map(({ full, min })=>/*#__PURE__*/ jsx("th", {
|
|
619
|
+
className: cls('weekday'),
|
|
620
|
+
scope: "col",
|
|
621
|
+
abbr: full,
|
|
622
|
+
"aria-label": full,
|
|
623
|
+
children: min
|
|
624
|
+
}, full))
|
|
625
|
+
})
|
|
626
|
+
}),
|
|
627
|
+
loadingQueue > 0 ? /*#__PURE__*/ jsx("tbody", {
|
|
628
|
+
"data-sui-picker-loading": "",
|
|
629
|
+
children: /*#__PURE__*/ jsx("tr", {
|
|
630
|
+
children: /*#__PURE__*/ jsx("td", {
|
|
631
|
+
colSpan: 7,
|
|
632
|
+
children: loadingElement
|
|
633
|
+
})
|
|
634
|
+
})
|
|
635
|
+
}) : /*#__PURE__*/ jsx("tbody", {
|
|
636
|
+
children: weeks.current.map((week)=>/*#__PURE__*/ jsx("tr", {
|
|
637
|
+
className: cls('week'),
|
|
638
|
+
children: renderDays(week)
|
|
639
|
+
}, utils.formatByString(week[0], 'YYYY-MM-DD')))
|
|
640
|
+
})
|
|
641
|
+
]
|
|
642
|
+
})
|
|
643
|
+
}),
|
|
644
|
+
/*#__PURE__*/ jsx("div", {
|
|
645
|
+
children: /*#__PURE__*/ jsx(Button_Button, {
|
|
646
|
+
className: cls('today-button'),
|
|
647
|
+
variant: "outlined",
|
|
648
|
+
size: "small",
|
|
649
|
+
color: "secondary",
|
|
650
|
+
onClick: ()=>{
|
|
357
651
|
onSelectDay(now);
|
|
358
|
-
},
|
|
652
|
+
},
|
|
653
|
+
disabled: isTodayDisabled,
|
|
654
|
+
"aria-label": backToTodayAriaLabel,
|
|
655
|
+
"data-sui-picker-today": "",
|
|
656
|
+
children: todayButtonText
|
|
657
|
+
})
|
|
658
|
+
})
|
|
659
|
+
]
|
|
660
|
+
});
|
|
359
661
|
case 'year':
|
|
360
|
-
return
|
|
662
|
+
return /*#__PURE__*/ jsx(Years, {
|
|
663
|
+
date: focusedDate,
|
|
664
|
+
minDate: min,
|
|
665
|
+
maxDate: max,
|
|
666
|
+
onYearChange: (day)=>{
|
|
667
|
+
focusIntentRef.current = 'switchYearAction';
|
|
361
668
|
setView('day');
|
|
362
669
|
const validateDate = getInvalidateDateInRange(day) || day;
|
|
363
670
|
setFocusedDate(validateDate);
|
|
364
|
-
},
|
|
671
|
+
},
|
|
672
|
+
disablePast: disablePast,
|
|
673
|
+
disableFuture: disableFuture,
|
|
674
|
+
now: now
|
|
675
|
+
});
|
|
365
676
|
default:
|
|
366
677
|
return null;
|
|
367
678
|
}
|
|
368
679
|
};
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
if (
|
|
680
|
+
useLayoutEffect(()=>{
|
|
681
|
+
const focusIntent = focusIntentRef.current;
|
|
682
|
+
if (!focusIntent) {
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
if (focusIntent !== 'day') {
|
|
686
|
+
const focusTarget = getRestorableHeaderFocusElement(calendarRef.current, focusIntent);
|
|
687
|
+
if (focusTarget) {
|
|
688
|
+
focusTarget.focus();
|
|
689
|
+
focusIntentRef.current = null;
|
|
690
|
+
}
|
|
372
691
|
return;
|
|
373
|
-
|
|
374
|
-
|
|
692
|
+
}
|
|
693
|
+
if (loadingQueue > 0) {
|
|
375
694
|
return;
|
|
376
695
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
!activeEl.hasAttribute('data-sui-picker-next-month') &&
|
|
380
|
-
!activeEl.hasAttribute('data-sui-picker-previous-month')) {
|
|
381
|
-
const timer = setTimeout(() => {
|
|
382
|
-
focusDayElement();
|
|
383
|
-
});
|
|
384
|
-
return () => {
|
|
385
|
-
clearTimeout(timer);
|
|
386
|
-
};
|
|
696
|
+
if (focusDayElement(calendarRef.current)) {
|
|
697
|
+
focusIntentRef.current = null;
|
|
387
698
|
}
|
|
388
|
-
return undefined;
|
|
389
699
|
});
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
700
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
701
|
+
className: cls('calendar'),
|
|
702
|
+
ref: handleCalendarRef,
|
|
703
|
+
children: [
|
|
704
|
+
/*#__PURE__*/ jsx(DatePickerHeader, {
|
|
705
|
+
focusedDate: focusedDate,
|
|
706
|
+
slideDirection: slideDirection,
|
|
707
|
+
view: view,
|
|
708
|
+
onMonthChange: handleMonthChange,
|
|
709
|
+
onViewChange: handleChangeView,
|
|
710
|
+
disablePrevMonth: disablePrevMonth,
|
|
711
|
+
disableNextMonth: disableNextMonth,
|
|
712
|
+
gridLabelId: gridLabelId
|
|
713
|
+
}),
|
|
714
|
+
renderBody()
|
|
715
|
+
]
|
|
716
|
+
});
|
|
399
717
|
});
|
|
400
718
|
Calendar.displayName = 'RcCalendar';
|
|
401
719
|
|
|
402
|
-
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
// extracted by css-extract-rspack-plugin
|
|
728
|
+
/* export default */ var DatePicker = ({"sui-date-picker-calendar":"sui-date-picker-calendar","sui-date-picker-header":"sui-date-picker-header","sui-date-picker-header-action":"sui-date-picker-header-action","sui-focus-visible":"sui-focus-visible","sui-disabled":"sui-disabled","sui-date-picker-switch-year-action":"sui-date-picker-switch-year-action","sui-date-picker-switch-year-action-caret":"sui-date-picker-switch-year-action-caret","sui-date-picker-switch-month-actions-group":"sui-date-picker-switch-month-actions-group","sui-date-picker-switch-month-action":"sui-date-picker-switch-month-action","sui-date-picker-date-button":"sui-date-picker-date-button","sui-selected":"sui-selected","sui-date-picker-current-date":"sui-date-picker-current-date","sui-date-picker-day":"sui-date-picker-day","sui-date-picker-year":"sui-date-picker-year","sui-date-picker-years-panel":"sui-date-picker-years-panel","sui-date-picker-days-panel":"sui-date-picker-days-panel","sui-date-picker-days-grid":"sui-date-picker-days-grid","sui-date-picker-week":"sui-date-picker-week","sui-date-picker-weekdays":"sui-date-picker-weekdays","sui-date-picker-day-cell":"sui-date-picker-day-cell","sui-date-picker-weekday":"sui-date-picker-weekday","sui-date-picker-loading-container":"sui-date-picker-loading-container","sui-date-picker-today-button":"sui-date-picker-today-button","sui-compact":"sui-compact"});
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
403
741
|
|
|
404
742
|
const defaultMinDate = new Date('1900-01-01');
|
|
405
743
|
const defaultMaxDate = new Date('2100-01-01');
|
|
406
744
|
const DEFAULT_FORMAT = 'MM/DD/YYYY';
|
|
407
|
-
const InnerDatePicker = (props)
|
|
745
|
+
const InnerDatePicker = (props)=>{
|
|
408
746
|
const { innerRef, value, onChange, formatString = DEFAULT_FORMAT, todayButtonText = 'Today', min: minDate = null, max: maxDate = null, disableFuture, disablePast, loadingIndicator, onMonthChange, renderDay, disabled, shouldDisableDate: shouldDisableDateProp, onClose, onClear, classes, PopoverProps, screenReaderProps, clearBtn = true, label = 'Date', className, ...rest } = props;
|
|
409
|
-
const cls = useClassesWithMode('date-picker', classes, className, [
|
|
747
|
+
const cls = useClassesWithMode('date-picker', classes, className, [
|
|
748
|
+
'calendar'
|
|
749
|
+
]);
|
|
410
750
|
const utils = useDateUtilsContext();
|
|
411
751
|
const [controlledValue, setControlledValue] = useControlled({
|
|
412
752
|
controlled: value,
|
|
413
753
|
default: null,
|
|
414
|
-
name: 'DatePicker'
|
|
754
|
+
name: 'DatePicker'
|
|
415
755
|
});
|
|
416
756
|
const actionRef = useRef(null);
|
|
417
757
|
const minDateValue = minDate?.valueOf() ?? defaultMinDate.valueOf();
|
|
418
758
|
const maxDateValue = maxDate?.valueOf() ?? defaultMaxDate.valueOf();
|
|
419
|
-
const dateRange = useMemo(()
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
const
|
|
759
|
+
const dateRange = useMemo(()=>({
|
|
760
|
+
min: dayjs(minDateValue),
|
|
761
|
+
max: dayjs(maxDateValue)
|
|
762
|
+
}), [
|
|
763
|
+
minDateValue,
|
|
764
|
+
maxDateValue
|
|
765
|
+
]);
|
|
766
|
+
const getInvalidateDateInRange = useCallback((day)=>invalidateDateInRange(day, {
|
|
767
|
+
dateRange,
|
|
768
|
+
now: utils.date(),
|
|
769
|
+
disableFuture,
|
|
770
|
+
disablePast
|
|
771
|
+
}, utils), [
|
|
772
|
+
dateRange,
|
|
773
|
+
disableFuture,
|
|
774
|
+
disablePast,
|
|
775
|
+
utils
|
|
776
|
+
]);
|
|
777
|
+
const shouldDisableDate = useCallback((day)=>Boolean(getInvalidateDateInRange(day)) || Boolean(shouldDisableDateProp?.(day)), [
|
|
778
|
+
getInvalidateDateInRange,
|
|
779
|
+
shouldDisableDateProp
|
|
780
|
+
]);
|
|
781
|
+
const getClosestEnabledDate = useCallback((currDate)=>{
|
|
427
782
|
return findClosestEnabledDate({
|
|
428
783
|
date: currDate,
|
|
429
784
|
utils,
|
|
@@ -431,7 +786,7 @@ const InnerDatePicker = (props) => {
|
|
|
431
786
|
maxDate: utils.date(dateRange.max),
|
|
432
787
|
disablePast: Boolean(disablePast),
|
|
433
788
|
disableFuture: Boolean(disableFuture),
|
|
434
|
-
shouldDisableDate
|
|
789
|
+
shouldDisableDate
|
|
435
790
|
});
|
|
436
791
|
}, [
|
|
437
792
|
dateRange.max,
|
|
@@ -439,22 +794,32 @@ const InnerDatePicker = (props) => {
|
|
|
439
794
|
disableFuture,
|
|
440
795
|
disablePast,
|
|
441
796
|
shouldDisableDate,
|
|
797
|
+
utils
|
|
798
|
+
]);
|
|
799
|
+
const initialDate = useMemo(()=>getClosestEnabledDate(utils.date()), [
|
|
442
800
|
utils,
|
|
801
|
+
getClosestEnabledDate
|
|
802
|
+
]);
|
|
803
|
+
const dayjsValue = useMemo(()=>controlledValue ? dayjs(controlledValue) : null, [
|
|
804
|
+
controlledValue
|
|
443
805
|
]);
|
|
444
|
-
const initialDate = useMemo(() => getClosestEnabledDate(utils.date()), [utils, getClosestEnabledDate]);
|
|
445
|
-
const dayjsValue = useMemo(() => (controlledValue ? dayjs(controlledValue) : null), [controlledValue]);
|
|
446
806
|
const nowDate = dayjsValue || initialDate;
|
|
447
|
-
const textFiledValue = useMemo(()
|
|
448
|
-
|
|
807
|
+
const textFiledValue = useMemo(()=>dayjsValue ? utils.formatByString(dayjsValue, formatString) : '', [
|
|
808
|
+
dayjsValue,
|
|
809
|
+
utils,
|
|
810
|
+
formatString
|
|
811
|
+
]);
|
|
812
|
+
const handleChange = (toDate, fromUserSelect)=>{
|
|
449
813
|
actionRef.current?.close();
|
|
450
814
|
setControlledValue(toDate);
|
|
451
815
|
onChange?.(toDate, fromUserSelect);
|
|
452
816
|
};
|
|
453
|
-
const handleDaySelect = useEventCallback((day, fromUserSelect = true)
|
|
817
|
+
const handleDaySelect = useEventCallback((day, fromUserSelect = true)=>{
|
|
454
818
|
const newDay = day ? utils.startOfDay(day).toDate() : null;
|
|
455
819
|
handleChange(newDay, fromUserSelect);
|
|
456
820
|
});
|
|
457
|
-
|
|
821
|
+
// Revalidate controlled values when disabled-date rules change.
|
|
822
|
+
useEffect(()=>{
|
|
458
823
|
if (!dayjsValue || !shouldDisableDate(dayjsValue)) {
|
|
459
824
|
return;
|
|
460
825
|
}
|
|
@@ -467,20 +832,74 @@ const InnerDatePicker = (props) => {
|
|
|
467
832
|
getClosestEnabledDate,
|
|
468
833
|
handleDaySelect,
|
|
469
834
|
shouldDisableDate,
|
|
470
|
-
utils
|
|
835
|
+
utils
|
|
471
836
|
]);
|
|
472
|
-
return
|
|
837
|
+
return /*#__PURE__*/ jsx(DatePickerClassesContext.Provider, {
|
|
838
|
+
value: cls,
|
|
839
|
+
children: /*#__PURE__*/ jsx(PickerTextField_PickerTextField, {
|
|
840
|
+
className: cls('root'),
|
|
841
|
+
variant: "standard",
|
|
842
|
+
label: label,
|
|
843
|
+
ref: innerRef,
|
|
844
|
+
action: actionRef,
|
|
845
|
+
onClear: (e)=>{
|
|
473
846
|
onClear?.(e);
|
|
474
847
|
handleChange(null);
|
|
475
|
-
},
|
|
848
|
+
},
|
|
849
|
+
PopoverProps: PopoverProps,
|
|
850
|
+
value: textFiledValue,
|
|
851
|
+
disabled: disabled,
|
|
852
|
+
endIconSymbol: CalendarMd,
|
|
853
|
+
onClose: onClose,
|
|
854
|
+
clearBtn: clearBtn,
|
|
855
|
+
...rest,
|
|
856
|
+
children: /*#__PURE__*/ jsx(ScreenReaderProvider, {
|
|
857
|
+
screenReaderProps: screenReaderProps,
|
|
858
|
+
children: /*#__PURE__*/ jsx(Calendar, {
|
|
859
|
+
date: nowDate,
|
|
860
|
+
dateRange: dateRange,
|
|
861
|
+
onSelectDay: handleDaySelect,
|
|
862
|
+
disableFuture: disableFuture,
|
|
863
|
+
disablePast: disablePast,
|
|
864
|
+
loadingIndicator: loadingIndicator,
|
|
865
|
+
onMonthChange: onMonthChange,
|
|
866
|
+
renderDay: renderDay,
|
|
867
|
+
shouldDisableDate: shouldDisableDate,
|
|
868
|
+
getInvalidateDateInRange: getInvalidateDateInRange,
|
|
869
|
+
todayButtonText: todayButtonText,
|
|
870
|
+
formatString: formatString
|
|
871
|
+
})
|
|
872
|
+
})
|
|
873
|
+
})
|
|
874
|
+
});
|
|
476
875
|
};
|
|
477
|
-
const
|
|
876
|
+
const DatePicker_DatePicker = /*#__PURE__*/ forwardRef((inProps, ref)=>{
|
|
478
877
|
const { locale = 'en', ...rest } = useThemeProps({
|
|
479
878
|
props: inProps,
|
|
480
|
-
name: 'DatePicker'
|
|
879
|
+
name: 'DatePicker'
|
|
880
|
+
});
|
|
881
|
+
return /*#__PURE__*/ jsx(DateUtilsProvider, {
|
|
882
|
+
locale: locale,
|
|
883
|
+
children: /*#__PURE__*/ jsx(InnerDatePicker, {
|
|
884
|
+
innerRef: ref,
|
|
885
|
+
...rest
|
|
886
|
+
})
|
|
481
887
|
});
|
|
482
|
-
return (jsx(DateUtilsProvider, { locale: locale, children: jsx(InnerDatePicker, { innerRef: ref, ...rest }) }));
|
|
483
888
|
});
|
|
484
|
-
|
|
889
|
+
DatePicker_DatePicker.displayName = 'SuiDatePicker';
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
485
904
|
|
|
486
|
-
export { Calendar, DEFAULT_FORMAT, DatePicker, DatePickerClassesContext, DatePickerHeader, Day, HeaderAction, ScreenReaderContext, ScreenReaderProvider, Year, Years,
|
|
905
|
+
export { Calendar, DEFAULT_FORMAT, DatePicker as datePickerStyle, DatePickerClassesContext, DatePickerHeader, DatePicker_DatePicker as DatePicker, Day, HeaderAction, ScreenReaderContext, ScreenReaderProvider, Year, Years, findClosestEnabledDate, focusDayElement, invalidateDateInRange, isSameYearAndMonth, useDatePickerClasses, useScreenReaderContext };
|