@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/DatePicker.js
CHANGED
|
@@ -1,68 +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
|
-
|
|
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)=>{
|
|
41
47
|
const { className, disabled, ...rest } = props;
|
|
42
48
|
const cls = useDatePickerClasses();
|
|
43
49
|
const { focusVisible, focusVisibleRef, focusVisibleHandlers } = useFocusVisible();
|
|
44
|
-
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
|
+
});
|
|
45
60
|
};
|
|
46
61
|
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
47
67
|
const defaultScreenReaderProps = {
|
|
48
|
-
getMonthYearAriaLabel: (monthLabel, expanded)
|
|
49
|
-
getSwitchMonthAriaLabel: (isNext, currentMonth)
|
|
50
|
-
getBackToTodayAriaLabel: ()
|
|
51
|
-
getLoadingAriaLabel: ()
|
|
52
|
-
getDayAriaLabel: (day, selected)
|
|
53
|
-
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' : ''}`
|
|
54
74
|
};
|
|
55
|
-
const ScreenReaderContext = createContext(defaultScreenReaderProps);
|
|
56
|
-
const useScreenReaderContext = ()
|
|
57
|
-
const ScreenReaderProvider = ({ screenReaderProps, children
|
|
58
|
-
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
|
+
});
|
|
59
82
|
};
|
|
60
83
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
84
|
+
|
|
85
|
+
const focusDayElement = (root = document)=>{
|
|
86
|
+
const focusedDayElement = root?.querySelector('[data-sui-picker-focused]');
|
|
87
|
+
focusedDayElement?.focus();
|
|
88
|
+
return focusedDayElement;
|
|
64
89
|
};
|
|
65
|
-
const isSameYearAndMonth = ({ source, comparing }, utils)
|
|
90
|
+
const isSameYearAndMonth = ({ source, comparing }, utils)=>{
|
|
66
91
|
if (!source || !comparing) {
|
|
67
92
|
return false;
|
|
68
93
|
}
|
|
@@ -72,7 +97,7 @@ const isSameYearAndMonth = ({ source, comparing }, utils) => {
|
|
|
72
97
|
const comparingYear = utils.getYear(comparing);
|
|
73
98
|
return thisMonth === comparingMonth && thisYear === comparingYear;
|
|
74
99
|
};
|
|
75
|
-
const invalidateDateInRange = (day, { dateRange: { min, max }, disableFuture, disablePast, now
|
|
100
|
+
const invalidateDateInRange = (day, { dateRange: { min, max }, disableFuture, disablePast, now }, utils)=>{
|
|
76
101
|
if (disableFuture && utils.isAfterDay(day, now)) {
|
|
77
102
|
return now;
|
|
78
103
|
}
|
|
@@ -88,7 +113,7 @@ const invalidateDateInRange = (day, { dateRange: { min, max }, disableFuture, di
|
|
|
88
113
|
return false;
|
|
89
114
|
};
|
|
90
115
|
|
|
91
|
-
const findClosestEnabledDate = ({ date, utils, minDate, maxDate, disableFuture, disablePast, shouldDisableDate
|
|
116
|
+
const findClosestEnabledDate = ({ date, utils, minDate, maxDate, disableFuture, disablePast, shouldDisableDate })=>{
|
|
92
117
|
const today = utils.startOfDay(utils.date());
|
|
93
118
|
if (disablePast && utils.isBefore(minDate, today)) {
|
|
94
119
|
minDate = today;
|
|
@@ -108,7 +133,7 @@ const findClosestEnabledDate = ({ date, utils, minDate, maxDate, disableFuture,
|
|
|
108
133
|
}
|
|
109
134
|
forward = null;
|
|
110
135
|
}
|
|
111
|
-
while
|
|
136
|
+
while(forward || backward){
|
|
112
137
|
if (forward && utils.isAfter(forward, maxDate)) {
|
|
113
138
|
forward = null;
|
|
114
139
|
}
|
|
@@ -128,20 +153,34 @@ const findClosestEnabledDate = ({ date, utils, minDate, maxDate, disableFuture,
|
|
|
128
153
|
backward = utils.addDays(backward, -1);
|
|
129
154
|
}
|
|
130
155
|
}
|
|
156
|
+
// fallback to today if no enabled days
|
|
131
157
|
return utils.date();
|
|
132
158
|
};
|
|
133
159
|
|
|
134
|
-
|
|
135
|
-
|
|
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;
|
|
136
175
|
const utils = useDateUtilsContext();
|
|
137
176
|
const cls = useDatePickerClasses();
|
|
138
177
|
const preMonth = utils.getPreviousMonth(focusedDate);
|
|
139
178
|
const nextMonth = utils.getNextMonth(focusedDate);
|
|
140
179
|
const monthLabel = utils.getCalendarHeaderText(focusedDate);
|
|
141
|
-
const selectNextMonth = ()
|
|
180
|
+
const selectNextMonth = ()=>{
|
|
142
181
|
onMonthChange(nextMonth, 'left');
|
|
143
182
|
};
|
|
144
|
-
const selectPreviousMonth = ()
|
|
183
|
+
const selectPreviousMonth = ()=>{
|
|
145
184
|
onMonthChange(preMonth, 'right');
|
|
146
185
|
};
|
|
147
186
|
const isYearView = view === 'year';
|
|
@@ -150,11 +189,78 @@ const DatePickerHeader = (props) => {
|
|
|
150
189
|
const monthYearAriaLabel = getMonthYearAriaLabel?.(`${monthLabel}`, isExpanded);
|
|
151
190
|
const nextMonthAriaLabel = getSwitchMonthAriaLabel?.(true, utils.getMonthText(focusedDate));
|
|
152
191
|
const previousMonthAriaLabel = getSwitchMonthAriaLabel?.(false, utils.getMonthText(focusedDate));
|
|
153
|
-
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
|
+
});
|
|
154
250
|
};
|
|
155
251
|
DatePickerHeader.displayName = 'RcDatePickerHeader';
|
|
156
252
|
|
|
157
|
-
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
const Day = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
158
264
|
const { onSelect, value, selected, disabled, focused, children, current, date, onFocus, onBlur, ...rest } = props;
|
|
159
265
|
const { getDayAriaLabel } = useScreenReaderContext() ?? {};
|
|
160
266
|
const cls = useDatePickerClasses();
|
|
@@ -162,95 +268,204 @@ const Day = forwardRef((props, ref) => {
|
|
|
162
268
|
const utils = useDateUtilsContext();
|
|
163
269
|
const handleRef = useForkRef(ref, focusVisibleRef);
|
|
164
270
|
const dayLabel = `${utils.getDatePickerHeaderText(date)} ${utils.getYearText(date)}`;
|
|
165
|
-
return
|
|
271
|
+
return /*#__PURE__*/ jsx("button", {
|
|
272
|
+
onClick: ()=>onSelect(value),
|
|
273
|
+
ref: handleRef,
|
|
274
|
+
className: cls('date-button', 'day', {
|
|
166
275
|
'current-date': current,
|
|
167
276
|
selected,
|
|
168
277
|
disabled,
|
|
169
|
-
focusVisible
|
|
170
|
-
}),
|
|
278
|
+
focusVisible
|
|
279
|
+
}),
|
|
280
|
+
"data-sui-picker-focused": focused ? '' : undefined,
|
|
281
|
+
"data-sui-picker-day": value,
|
|
282
|
+
"aria-label": getDayAriaLabel?.(dayLabel, selected, {
|
|
171
283
|
date,
|
|
172
284
|
disabled,
|
|
173
285
|
today: current,
|
|
174
|
-
focused
|
|
175
|
-
}),
|
|
286
|
+
focused
|
|
287
|
+
}),
|
|
288
|
+
...rest,
|
|
289
|
+
...combineProps({
|
|
290
|
+
onBlur,
|
|
291
|
+
onFocus
|
|
292
|
+
}, focusVisibleHandlers),
|
|
293
|
+
type: "button",
|
|
294
|
+
children: children
|
|
295
|
+
});
|
|
176
296
|
});
|
|
177
297
|
Day.displayName = 'SuiDay';
|
|
178
298
|
|
|
179
|
-
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
const Year = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
180
312
|
const { onSelect, value, selected, disabled, children, current, onFocus, onBlur, date, ...rest } = props;
|
|
181
313
|
const { getYearAriaLabel } = useScreenReaderContext() ?? {};
|
|
182
314
|
const cls = useDatePickerClasses();
|
|
183
315
|
const { focusVisible, focusVisibleHandlers, focusVisibleRef } = useFocusVisible();
|
|
184
316
|
const handleRef = useForkRef(ref, focusVisibleRef);
|
|
185
|
-
return
|
|
317
|
+
return /*#__PURE__*/ jsx("button", {
|
|
318
|
+
onClick: ()=>onSelect(value),
|
|
319
|
+
ref: handleRef,
|
|
320
|
+
className: cls('date-button', 'year', {
|
|
186
321
|
'current-date': current,
|
|
187
322
|
selected,
|
|
188
323
|
disabled,
|
|
189
|
-
focusVisible
|
|
190
|
-
}),
|
|
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
|
+
});
|
|
191
336
|
});
|
|
192
337
|
Year.displayName = 'SuiYear';
|
|
193
338
|
|
|
194
|
-
|
|
195
|
-
|
|
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;
|
|
196
349
|
const utils = useDateUtilsContext();
|
|
197
350
|
const containerRef = useRef(null);
|
|
198
351
|
const combineRef = useForkRef(containerRef, ref);
|
|
199
352
|
const selectedYearRef = useRef(null);
|
|
200
353
|
const currentYear = utils.getYearText(date || now);
|
|
201
|
-
const years = useMemo(()
|
|
354
|
+
const years = useMemo(()=>utils.getYearRange(minDate, maxDate), [
|
|
355
|
+
maxDate,
|
|
356
|
+
minDate,
|
|
357
|
+
utils
|
|
358
|
+
]);
|
|
202
359
|
const focusedIndexRef = useRef(0);
|
|
203
360
|
const focusedYear = utils.getYearText(years[focusedIndexRef.current]);
|
|
204
361
|
const { focusIndex, getItemProps } = useOnlyOneFocusable({
|
|
205
362
|
focusedIndexRef,
|
|
206
|
-
containerRef
|
|
363
|
+
containerRef
|
|
207
364
|
});
|
|
208
|
-
const getOptionDisabled = (year)
|
|
209
|
-
(disableFuture && utils.isAfterYear(year, now)));
|
|
365
|
+
const getOptionDisabled = (year)=>Boolean(disablePast && utils.isBeforeYear(year, now) || disableFuture && utils.isAfterYear(year, now));
|
|
210
366
|
const { onKeyFocusedIndexHandle: handleKeyDown } = useKeyboardMoveFocus({
|
|
211
367
|
options: years,
|
|
212
368
|
focusedIndexRef,
|
|
213
369
|
columns: 4,
|
|
214
370
|
infinite: 'order',
|
|
215
|
-
onFocusedIndexChange: (event, toIndex)
|
|
371
|
+
onFocusedIndexChange: (event, toIndex)=>{
|
|
216
372
|
focusIndex(toIndex);
|
|
217
373
|
event?.preventDefault();
|
|
218
374
|
},
|
|
219
|
-
getOptionDisabled
|
|
375
|
+
getOptionDisabled
|
|
220
376
|
});
|
|
221
|
-
useLayoutEffect(()
|
|
222
|
-
const index = years.findIndex((x)
|
|
377
|
+
useLayoutEffect(()=>{
|
|
378
|
+
const index = years.findIndex((x)=>utils.getYearText(x) === currentYear);
|
|
223
379
|
focusIndex(index);
|
|
380
|
+
// oxlint-disable-next-line react-hooks/exhaustive-deps
|
|
224
381
|
}, []);
|
|
225
382
|
const cls = useDatePickerClasses();
|
|
226
|
-
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)=>{
|
|
227
389
|
const yearText = utils.getYearText(year);
|
|
228
390
|
const selected = yearText === currentYear;
|
|
229
391
|
const focused = yearText === focusedYear;
|
|
230
392
|
const disabled = getOptionDisabled(year);
|
|
231
|
-
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)=>{
|
|
232
402
|
const newDate = utils.setYear(date, Number(year));
|
|
233
403
|
onYearChange(newDate);
|
|
234
|
-
},
|
|
235
|
-
|
|
404
|
+
},
|
|
405
|
+
disabled: disabled
|
|
406
|
+
}, utils.getYearText(year));
|
|
407
|
+
})
|
|
408
|
+
});
|
|
236
409
|
});
|
|
237
410
|
Years.displayName = 'SuiYears';
|
|
238
411
|
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
239
425
|
const DATE_PICKER_CALENDAR_GRID_LABEL_ID_PREFIX = 'DatePickerCalendarGridLabel';
|
|
240
|
-
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)=>{
|
|
241
449
|
const cls = useDatePickerClasses();
|
|
242
450
|
const utils = useDateUtilsContext();
|
|
243
|
-
const previousFocusDate = usePrevious(()
|
|
244
|
-
const previousView = usePrevious(() => view);
|
|
451
|
+
const previousFocusDate = usePrevious(()=>focusedDate);
|
|
245
452
|
const weeks = useRef([]);
|
|
246
|
-
const
|
|
247
|
-
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(()=>{
|
|
248
460
|
const nowDate = utils.date();
|
|
249
461
|
return {
|
|
250
462
|
now: nowDate,
|
|
251
|
-
isTodayDisabled: shouldDisableDate(nowDate)
|
|
463
|
+
isTodayDisabled: shouldDisableDate(nowDate)
|
|
252
464
|
};
|
|
253
|
-
}, [
|
|
465
|
+
}, [
|
|
466
|
+
shouldDisableDate,
|
|
467
|
+
utils
|
|
468
|
+
]);
|
|
254
469
|
const [focusedDate, setFocusedDate] = useState(date);
|
|
255
470
|
const [view, setView] = useState('day');
|
|
256
471
|
const [slideDirection, setSlideDirection] = useState('left');
|
|
@@ -258,170 +473,312 @@ const Calendar = forwardRef(({ onMonthChange, date, shouldDisableDate, dateRange
|
|
|
258
473
|
const gridLabelId = useId(DATE_PICKER_CALENDAR_GRID_LABEL_ID_PREFIX, true);
|
|
259
474
|
const { min, max } = dateRange;
|
|
260
475
|
const currentMonthNumber = utils.getMonth(focusedDate);
|
|
261
|
-
const sameMonthDate = previousFocusDate
|
|
262
|
-
|
|
263
|
-
:
|
|
476
|
+
const sameMonthDate = previousFocusDate ? isSameYearAndMonth({
|
|
477
|
+
source: focusedDate,
|
|
478
|
+
comparing: previousFocusDate
|
|
479
|
+
}, utils) : false;
|
|
264
480
|
if (!sameMonthDate) {
|
|
265
481
|
weeks.current = utils.getWeekArray(focusedDate);
|
|
266
482
|
}
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
setLoadingQueue(loadingQueue + 1);
|
|
483
|
+
const pushToLoadingQueue = ()=>{
|
|
484
|
+
setLoadingQueue((queue)=>queue + 1);
|
|
270
485
|
};
|
|
271
|
-
const popFromLoadingQueue = ()
|
|
272
|
-
setLoadingQueue(
|
|
486
|
+
const popFromLoadingQueue = ()=>{
|
|
487
|
+
setLoadingQueue((queue)=>queue <= 0 ? 0 : queue - 1);
|
|
273
488
|
};
|
|
274
|
-
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
|
+
}
|
|
275
495
|
setSlideDirection(direction);
|
|
276
496
|
setFocusedDate(getInvalidateDateInRange(newMonth) || newMonth);
|
|
277
497
|
if (onMonthChange) {
|
|
278
498
|
const returnVal = onMonthChange(newMonth);
|
|
279
499
|
if (returnVal) {
|
|
280
500
|
pushToLoadingQueue();
|
|
281
|
-
returnVal.then(()
|
|
501
|
+
returnVal.then(()=>{
|
|
282
502
|
popFromLoadingQueue();
|
|
283
503
|
});
|
|
284
504
|
}
|
|
285
505
|
}
|
|
286
506
|
});
|
|
287
|
-
const handleChangeView = useEventCallback(()
|
|
507
|
+
const handleChangeView = useEventCallback(()=>{
|
|
508
|
+
focusIntentRef.current = null;
|
|
288
509
|
setView(view === 'day' ? 'year' : 'day');
|
|
289
510
|
});
|
|
290
|
-
const disableNextMonth = useMemo(()
|
|
511
|
+
const disableNextMonth = useMemo(()=>{
|
|
291
512
|
const nextStartDay = utils.startOfMonth(utils.getNextMonth(focusedDate));
|
|
292
513
|
return !!getInvalidateDateInRange(nextStartDay);
|
|
293
|
-
}, [
|
|
294
|
-
|
|
514
|
+
}, [
|
|
515
|
+
focusedDate,
|
|
516
|
+
getInvalidateDateInRange,
|
|
517
|
+
utils
|
|
518
|
+
]);
|
|
519
|
+
const disablePrevMonth = useMemo(()=>{
|
|
295
520
|
const prevLatestDay = utils.endOfMonth(utils.getPreviousMonth(focusedDate));
|
|
296
521
|
return !!getInvalidateDateInRange(prevLatestDay);
|
|
297
|
-
}, [
|
|
298
|
-
|
|
299
|
-
|
|
522
|
+
}, [
|
|
523
|
+
focusedDate,
|
|
524
|
+
getInvalidateDateInRange,
|
|
525
|
+
utils
|
|
526
|
+
]);
|
|
527
|
+
const handleKeyDown = (event)=>{
|
|
528
|
+
const moveDay = (value)=>{
|
|
300
529
|
const day = utils.addDays(focusedDate, value);
|
|
301
530
|
if (day && !shouldDisableDate(day)) {
|
|
302
531
|
const newMonthNumber = utils.getMonth(day);
|
|
303
532
|
if (newMonthNumber !== currentMonthNumber) {
|
|
304
|
-
return handleMonthChange(day, newMonthNumber > currentMonthNumber ? 'left' : 'right');
|
|
533
|
+
return handleMonthChange(day, newMonthNumber > currentMonthNumber ? 'left' : 'right', true);
|
|
305
534
|
}
|
|
535
|
+
focusIntentRef.current = 'day';
|
|
306
536
|
setFocusedDate(day);
|
|
307
537
|
}
|
|
308
538
|
};
|
|
309
|
-
const goToDate = (day)
|
|
539
|
+
const goToDate = (day)=>{
|
|
540
|
+
focusIntentRef.current = 'day';
|
|
310
541
|
setFocusedDate(getInvalidateDateInRange(day) || day);
|
|
311
542
|
};
|
|
312
|
-
const confirmDate = ()
|
|
543
|
+
const confirmDate = ()=>{
|
|
313
544
|
event.stopPropagation();
|
|
314
545
|
onSelectDay(focusedDate);
|
|
315
546
|
};
|
|
316
547
|
runKeyHandler(event, {
|
|
317
|
-
ArrowUp: ()
|
|
318
|
-
ArrowDown: ()
|
|
319
|
-
ArrowLeft: ()
|
|
320
|
-
ArrowRight: ()
|
|
321
|
-
Home: ()
|
|
322
|
-
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)),
|
|
323
554
|
Enter: confirmDate,
|
|
324
|
-
' ': confirmDate
|
|
555
|
+
' ': confirmDate
|
|
325
556
|
});
|
|
326
557
|
};
|
|
327
558
|
const { getBackToTodayAriaLabel, getLoadingAriaLabel } = useScreenReaderContext() ?? {};
|
|
328
559
|
const backToTodayAriaLabel = getBackToTodayAriaLabel?.();
|
|
329
560
|
const loadingAriaLabel = getLoadingAriaLabel?.();
|
|
330
|
-
const renderDays = (week)
|
|
561
|
+
const renderDays = (week)=>{
|
|
331
562
|
const selectedDate = date;
|
|
332
|
-
return week.map((day)
|
|
563
|
+
return week.map((day)=>{
|
|
333
564
|
const disabled = shouldDisableDate(day);
|
|
334
565
|
const isDayInCurrentMonth = utils.getMonth(day) === currentMonthNumber;
|
|
335
566
|
const dayText = utils.getDayText(day);
|
|
336
567
|
const key = utils.formatByString(day, 'YYYY-MM-DD');
|
|
337
568
|
const selected = utils.isSameDay(day, selectedDate);
|
|
338
569
|
const focused = utils.isSameDay(focusedDate, day);
|
|
339
|
-
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: ()=>{
|
|
340
579
|
isDayInCurrentMonth && onSelectDay(day);
|
|
341
|
-
},
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
:
|
|
345
|
-
|
|
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);
|
|
346
591
|
});
|
|
347
592
|
};
|
|
348
|
-
const renderBody = ()
|
|
349
|
-
const loadingElement = loadingIndicator ?
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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){
|
|
353
603
|
case 'day':
|
|
354
|
-
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: ()=>{
|
|
355
651
|
onSelectDay(now);
|
|
356
|
-
},
|
|
652
|
+
},
|
|
653
|
+
disabled: isTodayDisabled,
|
|
654
|
+
"aria-label": backToTodayAriaLabel,
|
|
655
|
+
"data-sui-picker-today": "",
|
|
656
|
+
children: todayButtonText
|
|
657
|
+
})
|
|
658
|
+
})
|
|
659
|
+
]
|
|
660
|
+
});
|
|
357
661
|
case 'year':
|
|
358
|
-
return
|
|
662
|
+
return /*#__PURE__*/ jsx(Years, {
|
|
663
|
+
date: focusedDate,
|
|
664
|
+
minDate: min,
|
|
665
|
+
maxDate: max,
|
|
666
|
+
onYearChange: (day)=>{
|
|
667
|
+
focusIntentRef.current = 'switchYearAction';
|
|
359
668
|
setView('day');
|
|
360
669
|
const validateDate = getInvalidateDateInRange(day) || day;
|
|
361
670
|
setFocusedDate(validateDate);
|
|
362
|
-
},
|
|
671
|
+
},
|
|
672
|
+
disablePast: disablePast,
|
|
673
|
+
disableFuture: disableFuture,
|
|
674
|
+
now: now
|
|
675
|
+
});
|
|
363
676
|
default:
|
|
364
677
|
return null;
|
|
365
678
|
}
|
|
366
679
|
};
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
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
|
+
}
|
|
370
691
|
return;
|
|
371
|
-
|
|
372
|
-
|
|
692
|
+
}
|
|
693
|
+
if (loadingQueue > 0) {
|
|
373
694
|
return;
|
|
374
695
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
!activeEl.hasAttribute('data-sui-picker-next-month') &&
|
|
378
|
-
!activeEl.hasAttribute('data-sui-picker-previous-month')) {
|
|
379
|
-
const timer = setTimeout(() => {
|
|
380
|
-
focusDayElement();
|
|
381
|
-
});
|
|
382
|
-
return () => {
|
|
383
|
-
clearTimeout(timer);
|
|
384
|
-
};
|
|
696
|
+
if (focusDayElement(calendarRef.current)) {
|
|
697
|
+
focusIntentRef.current = null;
|
|
385
698
|
}
|
|
386
|
-
return undefined;
|
|
387
699
|
});
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
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
|
+
});
|
|
397
717
|
});
|
|
398
718
|
Calendar.displayName = 'RcCalendar';
|
|
399
719
|
|
|
400
|
-
|
|
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
|
+
|
|
401
741
|
|
|
402
742
|
const defaultMinDate = new Date('1900-01-01');
|
|
403
743
|
const defaultMaxDate = new Date('2100-01-01');
|
|
404
744
|
const DEFAULT_FORMAT = 'MM/DD/YYYY';
|
|
405
|
-
const InnerDatePicker = (props)
|
|
745
|
+
const InnerDatePicker = (props)=>{
|
|
406
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;
|
|
407
|
-
const cls = useClassesWithMode('date-picker', classes, className, [
|
|
747
|
+
const cls = useClassesWithMode('date-picker', classes, className, [
|
|
748
|
+
'calendar'
|
|
749
|
+
]);
|
|
408
750
|
const utils = useDateUtilsContext();
|
|
409
751
|
const [controlledValue, setControlledValue] = useControlled({
|
|
410
752
|
controlled: value,
|
|
411
753
|
default: null,
|
|
412
|
-
name: 'DatePicker'
|
|
754
|
+
name: 'DatePicker'
|
|
413
755
|
});
|
|
414
756
|
const actionRef = useRef(null);
|
|
415
757
|
const minDateValue = minDate?.valueOf() ?? defaultMinDate.valueOf();
|
|
416
758
|
const maxDateValue = maxDate?.valueOf() ?? defaultMaxDate.valueOf();
|
|
417
|
-
const dateRange = useMemo(()
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
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)=>{
|
|
425
782
|
return findClosestEnabledDate({
|
|
426
783
|
date: currDate,
|
|
427
784
|
utils,
|
|
@@ -429,7 +786,7 @@ const InnerDatePicker = (props) => {
|
|
|
429
786
|
maxDate: utils.date(dateRange.max),
|
|
430
787
|
disablePast: Boolean(disablePast),
|
|
431
788
|
disableFuture: Boolean(disableFuture),
|
|
432
|
-
shouldDisableDate
|
|
789
|
+
shouldDisableDate
|
|
433
790
|
});
|
|
434
791
|
}, [
|
|
435
792
|
dateRange.max,
|
|
@@ -437,22 +794,32 @@ const InnerDatePicker = (props) => {
|
|
|
437
794
|
disableFuture,
|
|
438
795
|
disablePast,
|
|
439
796
|
shouldDisableDate,
|
|
797
|
+
utils
|
|
798
|
+
]);
|
|
799
|
+
const initialDate = useMemo(()=>getClosestEnabledDate(utils.date()), [
|
|
440
800
|
utils,
|
|
801
|
+
getClosestEnabledDate
|
|
802
|
+
]);
|
|
803
|
+
const dayjsValue = useMemo(()=>controlledValue ? dayjs(controlledValue) : null, [
|
|
804
|
+
controlledValue
|
|
441
805
|
]);
|
|
442
|
-
const initialDate = useMemo(() => getClosestEnabledDate(utils.date()), [utils, getClosestEnabledDate]);
|
|
443
|
-
const dayjsValue = useMemo(() => (controlledValue ? dayjs(controlledValue) : null), [controlledValue]);
|
|
444
806
|
const nowDate = dayjsValue || initialDate;
|
|
445
|
-
const textFiledValue = useMemo(()
|
|
446
|
-
|
|
807
|
+
const textFiledValue = useMemo(()=>dayjsValue ? utils.formatByString(dayjsValue, formatString) : '', [
|
|
808
|
+
dayjsValue,
|
|
809
|
+
utils,
|
|
810
|
+
formatString
|
|
811
|
+
]);
|
|
812
|
+
const handleChange = (toDate, fromUserSelect)=>{
|
|
447
813
|
actionRef.current?.close();
|
|
448
814
|
setControlledValue(toDate);
|
|
449
815
|
onChange?.(toDate, fromUserSelect);
|
|
450
816
|
};
|
|
451
|
-
const handleDaySelect = useEventCallback((day, fromUserSelect = true)
|
|
817
|
+
const handleDaySelect = useEventCallback((day, fromUserSelect = true)=>{
|
|
452
818
|
const newDay = day ? utils.startOfDay(day).toDate() : null;
|
|
453
819
|
handleChange(newDay, fromUserSelect);
|
|
454
820
|
});
|
|
455
|
-
|
|
821
|
+
// Revalidate controlled values when disabled-date rules change.
|
|
822
|
+
useEffect(()=>{
|
|
456
823
|
if (!dayjsValue || !shouldDisableDate(dayjsValue)) {
|
|
457
824
|
return;
|
|
458
825
|
}
|
|
@@ -465,20 +832,74 @@ const InnerDatePicker = (props) => {
|
|
|
465
832
|
getClosestEnabledDate,
|
|
466
833
|
handleDaySelect,
|
|
467
834
|
shouldDisableDate,
|
|
468
|
-
utils
|
|
835
|
+
utils
|
|
469
836
|
]);
|
|
470
|
-
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)=>{
|
|
471
846
|
onClear?.(e);
|
|
472
847
|
handleChange(null);
|
|
473
|
-
},
|
|
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
|
+
});
|
|
474
875
|
};
|
|
475
|
-
const
|
|
876
|
+
const DatePicker_DatePicker = /*#__PURE__*/ forwardRef((inProps, ref)=>{
|
|
476
877
|
const { locale = 'en', ...rest } = useThemeProps({
|
|
477
878
|
props: inProps,
|
|
478
|
-
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
|
+
})
|
|
479
887
|
});
|
|
480
|
-
return (jsx(DateUtilsProvider, { locale: locale, children: jsx(InnerDatePicker, { innerRef: ref, ...rest }) }));
|
|
481
888
|
});
|
|
482
|
-
|
|
889
|
+
DatePicker_DatePicker.displayName = 'SuiDatePicker';
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
483
904
|
|
|
484
|
-
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 };
|