rsuite 5.48.1 → 5.50.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/CHANGELOG.md +27 -0
- package/Cascader/styles/index.less +5 -4
- package/DatePicker/styles/index.less +18 -11
- package/DateRangeInput/package.json +7 -0
- package/DateRangePicker/styles/index.less +20 -0
- package/Dropdown/styles/index.less +5 -4
- package/Dropdown/styles/mixin.less +0 -11
- package/InputGroup/styles/index.less +1 -0
- package/Picker/styles/index.less +51 -24
- package/Picker/styles/mixin.less +17 -13
- package/README.md +34 -24
- package/Sidenav/styles/index.less +2 -0
- package/TagInput/styles/index.less +1 -1
- package/cjs/AutoComplete/AutoComplete.js +25 -26
- package/cjs/Calendar/Calendar.d.ts +5 -1
- package/cjs/Calendar/CalendarContainer.d.ts +7 -1
- package/cjs/Calendar/CalendarContainer.js +11 -4
- package/cjs/Calendar/CalendarHeader.js +2 -0
- package/cjs/Calendar/MonthDropdown.js +7 -2
- package/cjs/Calendar/MonthDropdownItem.js +2 -2
- package/cjs/Calendar/Table.js +6 -1
- package/cjs/Calendar/TimeDropdown.js +17 -10
- package/cjs/Calendar/types.d.ts +1 -0
- package/cjs/Cascader/Cascader.js +46 -48
- package/cjs/CheckPicker/CheckPicker.d.ts +2 -2
- package/cjs/CheckPicker/CheckPicker.js +33 -36
- package/cjs/CheckTreePicker/CheckTreePicker.js +61 -64
- package/cjs/CustomProvider/CustomProvider.d.ts +13 -0
- package/cjs/CustomProvider/CustomProvider.js +2 -2
- package/cjs/DateInput/DateField.d.ts +9 -31
- package/cjs/DateInput/DateField.js +61 -12
- package/cjs/DateInput/DateInput.d.ts +7 -2
- package/cjs/DateInput/DateInput.js +74 -92
- package/cjs/DateInput/index.d.ts +4 -0
- package/cjs/DateInput/index.js +19 -1
- package/cjs/DateInput/useDateInputState.d.ts +7 -31
- package/cjs/DateInput/useDateInputState.js +39 -15
- package/cjs/DateInput/useIsFocused.d.ts +7 -0
- package/cjs/DateInput/useIsFocused.js +28 -0
- package/cjs/DateInput/useKeyboardInputEvent.d.ts +10 -0
- package/cjs/DateInput/useKeyboardInputEvent.js +44 -0
- package/cjs/DateInput/utils.d.ts +23 -1
- package/cjs/DateInput/utils.js +155 -51
- package/cjs/DatePicker/DatePicker.d.ts +25 -8
- package/cjs/DatePicker/DatePicker.js +208 -241
- package/cjs/DatePicker/Toolbar.js +5 -22
- package/cjs/DatePicker/utils.d.ts +5 -1
- package/cjs/DatePicker/utils.js +17 -1
- package/cjs/DateRangeInput/DateRangeInput.d.ts +29 -0
- package/cjs/DateRangeInput/DateRangeInput.js +244 -0
- package/cjs/DateRangeInput/index.d.ts +3 -0
- package/cjs/DateRangeInput/index.js +9 -0
- package/cjs/DateRangeInput/utils.d.ts +61 -0
- package/cjs/DateRangeInput/utils.js +146 -0
- package/cjs/DateRangePicker/Calendar.js +24 -23
- package/cjs/DateRangePicker/DateRangePicker.d.ts +18 -4
- package/cjs/DateRangePicker/DateRangePicker.js +251 -203
- package/cjs/DateRangePicker/types.d.ts +11 -3
- package/cjs/DateRangePicker/utils.d.ts +2 -1
- package/cjs/DateRangePicker/utils.js +7 -5
- package/cjs/FormControl/FormControl.d.ts +11 -1
- package/cjs/FormControl/FormControl.js +6 -5
- package/cjs/Input/Input.d.ts +11 -0
- package/cjs/Input/Input.js +11 -8
- package/cjs/InputPicker/InputPicker.js +62 -63
- package/cjs/MultiCascader/MultiCascader.js +40 -42
- package/cjs/Overlay/OverlayTrigger.d.ts +3 -0
- package/cjs/Overlay/OverlayTrigger.js +5 -0
- package/cjs/Picker/PickerIndicator.d.ts +10 -0
- package/cjs/Picker/PickerIndicator.js +49 -0
- package/cjs/Picker/PickerLabel.d.ts +9 -0
- package/cjs/Picker/PickerLabel.js +23 -0
- package/cjs/Picker/PickerToggle.d.ts +17 -22
- package/cjs/Picker/PickerToggle.js +52 -177
- package/cjs/Picker/index.d.ts +3 -0
- package/cjs/Picker/index.js +10 -1
- package/cjs/Picker/usePickerRef.d.ts +19 -0
- package/cjs/Picker/usePickerRef.js +88 -0
- package/cjs/Picker/utils.d.ts +5 -9
- package/cjs/Picker/utils.js +22 -89
- package/cjs/SelectPicker/SelectPicker.d.ts +2 -2
- package/cjs/SelectPicker/SelectPicker.js +39 -42
- package/cjs/TreePicker/TreePicker.js +72 -75
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +3 -1
- package/cjs/locales/index.d.ts +2 -2
- package/cjs/utils/constants.d.ts +2 -1
- package/cjs/utils/constants.js +1 -0
- package/cjs/utils/dateUtils.d.ts +0 -1
- package/cjs/utils/dateUtils.js +0 -6
- package/cjs/utils/getStringLength.d.ts +2 -0
- package/cjs/utils/getStringLength.js +18 -0
- package/cjs/utils/index.d.ts +3 -0
- package/cjs/utils/index.js +11 -2
- package/cjs/utils/useCustom.js +1 -1
- package/cjs/utils/useIsomorphicLayoutEffect.d.ts +3 -0
- package/cjs/utils/useIsomorphicLayoutEffect.js +9 -0
- package/dist/rsuite-no-reset-rtl.css +140 -207
- package/dist/rsuite-no-reset-rtl.min.css +1 -1
- package/dist/rsuite-no-reset-rtl.min.css.map +1 -1
- package/dist/rsuite-no-reset.css +140 -207
- package/dist/rsuite-no-reset.min.css +1 -1
- package/dist/rsuite-no-reset.min.css.map +1 -1
- package/dist/rsuite-rtl.css +140 -75
- package/dist/rsuite-rtl.min.css +1 -1
- package/dist/rsuite-rtl.min.css.map +1 -1
- package/dist/rsuite.css +140 -75
- package/dist/rsuite.js +4833 -258
- package/dist/rsuite.js.map +1 -1
- package/dist/rsuite.min.css +1 -1
- package/dist/rsuite.min.css.map +1 -1
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/AutoComplete/AutoComplete.js +28 -29
- package/esm/Calendar/Calendar.d.ts +5 -1
- package/esm/Calendar/CalendarContainer.d.ts +7 -1
- package/esm/Calendar/CalendarContainer.js +12 -5
- package/esm/Calendar/CalendarHeader.js +2 -0
- package/esm/Calendar/MonthDropdown.js +7 -2
- package/esm/Calendar/MonthDropdownItem.js +2 -2
- package/esm/Calendar/Table.js +6 -1
- package/esm/Calendar/TimeDropdown.js +17 -10
- package/esm/Calendar/types.d.ts +1 -0
- package/esm/Cascader/Cascader.js +49 -51
- package/esm/CheckPicker/CheckPicker.d.ts +2 -2
- package/esm/CheckPicker/CheckPicker.js +36 -39
- package/esm/CheckTreePicker/CheckTreePicker.js +64 -67
- package/esm/CustomProvider/CustomProvider.d.ts +13 -0
- package/esm/CustomProvider/CustomProvider.js +3 -3
- package/esm/DateInput/DateField.d.ts +9 -31
- package/esm/DateInput/DateField.js +61 -12
- package/esm/DateInput/DateInput.d.ts +7 -2
- package/esm/DateInput/DateInput.js +77 -95
- package/esm/DateInput/index.d.ts +4 -0
- package/esm/DateInput/index.js +4 -0
- package/esm/DateInput/useDateInputState.d.ts +7 -31
- package/esm/DateInput/useDateInputState.js +41 -18
- package/esm/DateInput/useIsFocused.d.ts +7 -0
- package/esm/DateInput/useIsFocused.js +22 -0
- package/esm/DateInput/useKeyboardInputEvent.d.ts +10 -0
- package/esm/DateInput/useKeyboardInputEvent.js +38 -0
- package/esm/DateInput/utils.d.ts +23 -1
- package/esm/DateInput/utils.js +150 -51
- package/esm/DatePicker/DatePicker.d.ts +25 -8
- package/esm/DatePicker/DatePicker.js +211 -244
- package/esm/DatePicker/Toolbar.js +5 -22
- package/esm/DatePicker/utils.d.ts +5 -1
- package/esm/DatePicker/utils.js +16 -1
- package/esm/DateRangeInput/DateRangeInput.d.ts +29 -0
- package/esm/DateRangeInput/DateRangeInput.js +237 -0
- package/esm/DateRangeInput/index.d.ts +3 -0
- package/esm/DateRangeInput/index.js +3 -0
- package/esm/DateRangeInput/utils.d.ts +61 -0
- package/esm/DateRangeInput/utils.js +137 -0
- package/esm/DateRangePicker/Calendar.js +25 -23
- package/esm/DateRangePicker/DateRangePicker.d.ts +18 -4
- package/esm/DateRangePicker/DateRangePicker.js +253 -205
- package/esm/DateRangePicker/types.d.ts +11 -3
- package/esm/DateRangePicker/utils.d.ts +2 -1
- package/esm/DateRangePicker/utils.js +7 -5
- package/esm/FormControl/FormControl.d.ts +11 -1
- package/esm/FormControl/FormControl.js +4 -3
- package/esm/Input/Input.d.ts +11 -0
- package/esm/Input/Input.js +12 -9
- package/esm/InputPicker/InputPicker.js +64 -65
- package/esm/MultiCascader/MultiCascader.js +43 -45
- package/esm/Overlay/OverlayTrigger.d.ts +3 -0
- package/esm/Overlay/OverlayTrigger.js +5 -0
- package/esm/Picker/PickerIndicator.d.ts +10 -0
- package/esm/Picker/PickerIndicator.js +43 -0
- package/esm/Picker/PickerLabel.d.ts +9 -0
- package/esm/Picker/PickerLabel.js +17 -0
- package/esm/Picker/PickerToggle.d.ts +17 -22
- package/esm/Picker/PickerToggle.js +54 -179
- package/esm/Picker/index.d.ts +3 -0
- package/esm/Picker/index.js +3 -0
- package/esm/Picker/usePickerRef.d.ts +19 -0
- package/esm/Picker/usePickerRef.js +82 -0
- package/esm/Picker/utils.d.ts +5 -9
- package/esm/Picker/utils.js +24 -90
- package/esm/SelectPicker/SelectPicker.d.ts +2 -2
- package/esm/SelectPicker/SelectPicker.js +42 -45
- package/esm/TreePicker/TreePicker.js +75 -78
- package/esm/index.d.ts +2 -0
- package/esm/index.js +1 -0
- package/esm/locales/index.d.ts +2 -2
- package/esm/utils/constants.d.ts +2 -1
- package/esm/utils/constants.js +1 -0
- package/esm/utils/dateUtils.d.ts +0 -1
- package/esm/utils/dateUtils.js +0 -5
- package/esm/utils/getStringLength.d.ts +2 -0
- package/esm/utils/getStringLength.js +13 -0
- package/esm/utils/index.d.ts +3 -0
- package/esm/utils/index.js +4 -1
- package/esm/utils/useCustom.js +2 -2
- package/esm/utils/useIsomorphicLayoutEffect.d.ts +3 -0
- package/esm/utils/useIsomorphicLayoutEffect.js +4 -0
- package/package.json +1 -1
- package/styles/color-modes/dark.less +1 -0
- package/styles/color-modes/high-contrast.less +1 -0
- package/styles/color-modes/light.less +1 -0
- package/styles/mixins/combobox.less +10 -0
- package/styles/normalize.less +230 -231
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import _taggedTemplateLiteralLoose from "@babel/runtime/helpers/esm/taggedTemplateLiteralLoose";
|
|
2
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
4
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
4
|
-
|
|
5
|
+
var _templateObject;
|
|
6
|
+
import React, { useMemo, useState } from 'react';
|
|
5
7
|
import PropTypes from 'prop-types';
|
|
6
8
|
import mapValues from 'lodash/mapValues';
|
|
7
9
|
import pick from 'lodash/pick';
|
|
8
|
-
import omit from 'lodash/omit';
|
|
9
10
|
import delay from 'lodash/delay';
|
|
10
|
-
import
|
|
11
|
+
import omit from 'lodash/omit';
|
|
11
12
|
import IconCalendar from '@rsuite/icons/legacy/Calendar';
|
|
12
13
|
import IconClockO from '@rsuite/icons/legacy/ClockO';
|
|
13
14
|
import CalendarContainer from '../Calendar/CalendarContainer';
|
|
@@ -16,18 +17,23 @@ import { isEveryDateInMonth } from '../Calendar/MonthDropdown';
|
|
|
16
17
|
import Toolbar from './Toolbar';
|
|
17
18
|
import Stack from '../Stack';
|
|
18
19
|
import PredefinedRanges from './PredefinedRanges';
|
|
19
|
-
import {
|
|
20
|
-
import { shouldRenderMonth, shouldRenderDate, shouldRenderTime, shouldOnlyRenderTime, setHours, getHours, addMonths, addDays,
|
|
21
|
-
import { PickerOverlay,
|
|
20
|
+
import { createChainedFunction, mergeRefs, useClassNames, useControlled, useCustom, useUniqueId, useEventCallback, partitionHTMLProps } from '../utils';
|
|
21
|
+
import { shouldRenderMonth, shouldRenderDate, shouldRenderTime, shouldOnlyRenderTime, setHours, getHours, addMonths, addDays, isValid, disabledTime, copyTime, calendarOnlyProps } from '../utils/dateUtils';
|
|
22
|
+
import { PickerOverlay, PickerLabel, PickerIndicator, PickerToggleTrigger, pickerPropTypes, pickTriggerPropKeys, omitTriggerPropKeys, usePickerClassName, onMenuKeyDown } from '../Picker';
|
|
23
|
+
import usePickerRef from '../Picker/usePickerRef';
|
|
24
|
+
import DateInput from '../DateInput';
|
|
25
|
+
import InputGroup from '../InputGroup';
|
|
22
26
|
import { OverlayCloseCause } from '../Overlay/OverlayTrigger';
|
|
23
27
|
import { deprecatePropTypeNew } from '../utils/deprecatePropType';
|
|
24
28
|
import { getAriaLabel } from '../Calendar/utils';
|
|
29
|
+
import { splitRanges } from './utils';
|
|
25
30
|
/**
|
|
26
31
|
* A date picker allows users to select a date from a calendar.
|
|
27
32
|
*
|
|
28
33
|
* @see https://rsuitejs.com/components/date-picker
|
|
29
34
|
*/
|
|
30
35
|
var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
36
|
+
var _merge;
|
|
31
37
|
var _props$as = props.as,
|
|
32
38
|
Component = _props$as === void 0 ? 'div' : _props$as,
|
|
33
39
|
className = props.className,
|
|
@@ -40,13 +46,18 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
40
46
|
editable = _props$editable === void 0 ? true : _props$editable,
|
|
41
47
|
defaultValue = props.defaultValue,
|
|
42
48
|
disabled = props.disabled,
|
|
49
|
+
readOnly = props.readOnly,
|
|
50
|
+
plaintext = props.plaintext,
|
|
43
51
|
_props$format = props.format,
|
|
44
52
|
formatStr = _props$format === void 0 ? 'yyyy-MM-dd' : _props$format,
|
|
53
|
+
idProp = props.id,
|
|
45
54
|
isoWeek = props.isoWeek,
|
|
46
55
|
_props$limitEndYear = props.limitEndYear,
|
|
47
56
|
limitEndYear = _props$limitEndYear === void 0 ? 1000 : _props$limitEndYear,
|
|
48
57
|
limitStartYear = props.limitStartYear,
|
|
49
58
|
overrideLocale = props.locale,
|
|
59
|
+
loading = props.loading,
|
|
60
|
+
label = props.label,
|
|
50
61
|
menuClassName = props.menuClassName,
|
|
51
62
|
menuStyle = props.menuStyle,
|
|
52
63
|
_props$appearance = props.appearance,
|
|
@@ -61,7 +72,7 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
61
72
|
showMeridian = props.showMeridian,
|
|
62
73
|
showWeekNumbers = props.showWeekNumbers,
|
|
63
74
|
style = props.style,
|
|
64
|
-
|
|
75
|
+
size = props.size,
|
|
65
76
|
caretAsProp = props.caretAs,
|
|
66
77
|
DEPRECATED_disabledDate = props.disabledDate,
|
|
67
78
|
DEPRECATED_disabledHours = props.disabledHours,
|
|
@@ -71,7 +82,6 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
71
82
|
shouldDisableHour = props.shouldDisableHour,
|
|
72
83
|
shouldDisableMinute = props.shouldDisableMinute,
|
|
73
84
|
shouldDisableSecond = props.shouldDisableSecond,
|
|
74
|
-
renderValue = props.renderValue,
|
|
75
85
|
onChange = props.onChange,
|
|
76
86
|
onChangeCalendarDate = props.onChangeCalendarDate,
|
|
77
87
|
onClean = props.onClean,
|
|
@@ -86,11 +96,16 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
86
96
|
onToggleMonthDropdown = props.onToggleMonthDropdown,
|
|
87
97
|
onToggleTimeDropdown = props.onToggleTimeDropdown,
|
|
88
98
|
onShortcutClick = props.onShortcutClick,
|
|
89
|
-
|
|
99
|
+
restProps = _objectWithoutPropertiesLoose(props, ["as", "className", "classPrefix", "calendarDefaultDate", "cleanable", "editable", "defaultValue", "disabled", "readOnly", "plaintext", "format", "id", "isoWeek", "limitEndYear", "limitStartYear", "locale", "loading", "label", "menuClassName", "menuStyle", "appearance", "placement", "oneTap", "placeholder", "ranges", "value", "showMeridian", "showWeekNumbers", "style", "size", "caretAs", "disabledDate", "disabledHours", "disabledMinutes", "disabledSeconds", "shouldDisableDate", "shouldDisableHour", "shouldDisableMinute", "shouldDisableSecond", "onChange", "onChangeCalendarDate", "onClean", "onClose", "onEntered", "onExited", "onNextMonth", "onOk", "onOpen", "onPrevMonth", "onSelect", "onToggleMonthDropdown", "onToggleTimeDropdown", "onShortcutClick"]);
|
|
100
|
+
var id = useUniqueId(classPrefix + "-", idProp);
|
|
101
|
+
var _usePickerRef = usePickerRef(ref),
|
|
102
|
+
trigger = _usePickerRef.trigger,
|
|
103
|
+
root = _usePickerRef.root,
|
|
104
|
+
target = _usePickerRef.target,
|
|
105
|
+
overlay = _usePickerRef.overlay;
|
|
90
106
|
var _useCustom = useCustom('DatePicker', overrideLocale),
|
|
91
107
|
locale = _useCustom.locale,
|
|
92
|
-
formatDate = _useCustom.formatDate
|
|
93
|
-
parseDate = _useCustom.parseDate;
|
|
108
|
+
formatDate = _useCustom.formatDate;
|
|
94
109
|
var _useClassNames = useClassNames(classPrefix),
|
|
95
110
|
merge = _useClassNames.merge,
|
|
96
111
|
prefix = _useClassNames.prefix;
|
|
@@ -106,71 +121,72 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
106
121
|
setShowMonthDropdown = _useState[1]; // Show only the calendar month panel. formatStr = 'yyyy-MM'
|
|
107
122
|
var onlyShowMonth = shouldRenderMonth(formatStr) && !shouldRenderDate(formatStr);
|
|
108
123
|
var showMonth = onlyShowMonth || showMonthDropdown;
|
|
109
|
-
var
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
var
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
124
|
+
var isDateDisabled = function isDateDisabled(date) {
|
|
125
|
+
if (typeof shouldDisableDate === 'function') {
|
|
126
|
+
return shouldDisableDate(date);
|
|
127
|
+
}
|
|
128
|
+
if (typeof DEPRECATED_disabledDate === 'function') {
|
|
129
|
+
return DEPRECATED_disabledDate(date);
|
|
130
|
+
}
|
|
131
|
+
return false;
|
|
132
|
+
};
|
|
133
|
+
var isErrorValue = function isErrorValue(value) {
|
|
134
|
+
if (!isValid(value)) {
|
|
135
|
+
return true;
|
|
136
|
+
} else if (value && isDateDisabled(value)) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
return false;
|
|
140
|
+
};
|
|
125
141
|
|
|
126
142
|
/**
|
|
127
143
|
* Switch to the callback triggered after the next month.
|
|
128
144
|
*/
|
|
129
|
-
var handleMoveForward =
|
|
145
|
+
var handleMoveForward = useEventCallback(function (nextPageDate) {
|
|
130
146
|
setCalendarDate(nextPageDate);
|
|
131
147
|
onNextMonth === null || onNextMonth === void 0 ? void 0 : onNextMonth(nextPageDate);
|
|
132
148
|
onChangeCalendarDate === null || onChangeCalendarDate === void 0 ? void 0 : onChangeCalendarDate(nextPageDate);
|
|
133
|
-
}
|
|
149
|
+
});
|
|
134
150
|
|
|
135
151
|
/**
|
|
136
152
|
* Switch to the callback triggered after the previous month.
|
|
137
153
|
*/
|
|
138
|
-
var handleMoveBackward =
|
|
154
|
+
var handleMoveBackward = useEventCallback(function (nextPageDate) {
|
|
139
155
|
setCalendarDate(nextPageDate);
|
|
140
156
|
onPrevMonth === null || onPrevMonth === void 0 ? void 0 : onPrevMonth(nextPageDate);
|
|
141
157
|
onChangeCalendarDate === null || onChangeCalendarDate === void 0 ? void 0 : onChangeCalendarDate(nextPageDate);
|
|
142
|
-
}
|
|
158
|
+
});
|
|
143
159
|
|
|
144
160
|
/**
|
|
145
161
|
* The callback triggered when the date changes.
|
|
146
162
|
*/
|
|
147
|
-
var handleDateChange =
|
|
163
|
+
var handleDateChange = useEventCallback(function (nextValue, event) {
|
|
148
164
|
onSelect === null || onSelect === void 0 ? void 0 : onSelect(nextValue, event);
|
|
149
165
|
onChangeCalendarDate === null || onChangeCalendarDate === void 0 ? void 0 : onChangeCalendarDate(nextValue, event);
|
|
150
|
-
}
|
|
166
|
+
});
|
|
151
167
|
|
|
152
168
|
/**
|
|
153
169
|
* A callback triggered when the time on the calendar changes.
|
|
154
170
|
*/
|
|
155
|
-
var handleChangeTime =
|
|
171
|
+
var handleChangeTime = useEventCallback(function (nextPageTime) {
|
|
156
172
|
setCalendarDate(nextPageTime);
|
|
157
173
|
handleDateChange(nextPageTime);
|
|
158
|
-
}
|
|
159
|
-
var handleClose =
|
|
160
|
-
var
|
|
161
|
-
(
|
|
162
|
-
}
|
|
174
|
+
});
|
|
175
|
+
var handleClose = useEventCallback(function () {
|
|
176
|
+
var _trigger$current, _trigger$current$clos;
|
|
177
|
+
(_trigger$current = trigger.current) === null || _trigger$current === void 0 ? void 0 : (_trigger$current$clos = _trigger$current.close) === null || _trigger$current$clos === void 0 ? void 0 : _trigger$current$clos.call(_trigger$current);
|
|
178
|
+
});
|
|
163
179
|
|
|
164
180
|
/**
|
|
165
181
|
* The callback triggered when PM/AM is switched.
|
|
166
182
|
*/
|
|
167
|
-
var handleToggleMeridian =
|
|
183
|
+
var handleToggleMeridian = useEventCallback(function () {
|
|
168
184
|
var hours = getHours(calendarDate);
|
|
169
185
|
var nextHours = hours >= 12 ? hours - 12 : hours + 12;
|
|
170
186
|
var nextDate = setHours(calendarDate, nextHours);
|
|
171
187
|
handleChangeTime(nextDate);
|
|
172
|
-
}
|
|
173
|
-
var updateValue =
|
|
188
|
+
});
|
|
189
|
+
var updateValue = function updateValue(event, nextPageDate, closeOverlay) {
|
|
174
190
|
if (closeOverlay === void 0) {
|
|
175
191
|
closeOverlay = true;
|
|
176
192
|
}
|
|
@@ -185,91 +201,80 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
185
201
|
if (closeOverlay !== false) {
|
|
186
202
|
handleClose();
|
|
187
203
|
}
|
|
188
|
-
}
|
|
204
|
+
};
|
|
189
205
|
|
|
190
206
|
/**
|
|
191
207
|
* The callback triggered after the date in the shortcut area is clicked.
|
|
192
208
|
*/
|
|
193
|
-
var handleShortcutPageDate =
|
|
209
|
+
var handleShortcutPageDate = useEventCallback(function (range, closeOverlay, event) {
|
|
194
210
|
var value = range.value;
|
|
195
211
|
updateValue(event, value, closeOverlay);
|
|
196
212
|
handleDateChange(value, event);
|
|
197
213
|
onShortcutClick === null || onShortcutClick === void 0 ? void 0 : onShortcutClick(range, event);
|
|
198
|
-
}
|
|
214
|
+
});
|
|
199
215
|
|
|
200
216
|
/**
|
|
201
217
|
* Get the corresponding container based on date selection and month selection
|
|
202
218
|
*/
|
|
203
|
-
var getOverlayContainer =
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}, [showMonth]);
|
|
219
|
+
var getOverlayContainer = function getOverlayContainer() {
|
|
220
|
+
return showMonth ? document.getElementById(id + "-calendar-month-dropdown") : document.getElementById(id + "-calendar-table");
|
|
221
|
+
};
|
|
207
222
|
|
|
208
223
|
/**
|
|
209
224
|
* Check whether the date is focusable
|
|
210
225
|
*/
|
|
211
|
-
var checkFocusable =
|
|
226
|
+
var checkFocusable = function checkFocusable(date) {
|
|
212
227
|
var formatStr = showMonth ? locale.formattedMonthPattern : locale.formattedDayPattern;
|
|
213
228
|
var ariaLabel = getAriaLabel(date, formatStr, formatDate);
|
|
214
229
|
var container = getOverlayContainer();
|
|
215
|
-
var dateElement = container.querySelector("[aria-label=\"" + ariaLabel + "\"]");
|
|
216
|
-
if (dateElement
|
|
230
|
+
var dateElement = container === null || container === void 0 ? void 0 : container.querySelector("[aria-label=\"" + ariaLabel + "\"]");
|
|
231
|
+
if ((dateElement === null || dateElement === void 0 ? void 0 : dateElement.getAttribute('aria-disabled')) === 'true') {
|
|
217
232
|
return false;
|
|
218
233
|
}
|
|
219
234
|
return true;
|
|
220
|
-
}
|
|
235
|
+
};
|
|
221
236
|
|
|
222
237
|
/**
|
|
223
238
|
* Focus on the currently selected date element
|
|
224
239
|
*/
|
|
225
|
-
var focusSelectedDate =
|
|
240
|
+
var focusSelectedDate = function focusSelectedDate() {
|
|
226
241
|
delay(function () {
|
|
227
242
|
var container = getOverlayContainer();
|
|
228
243
|
var selectedElement = container === null || container === void 0 ? void 0 : container.querySelector('[aria-selected="true"]');
|
|
229
244
|
selectedElement === null || selectedElement === void 0 ? void 0 : selectedElement.focus();
|
|
230
245
|
}, 1);
|
|
231
|
-
}
|
|
246
|
+
};
|
|
232
247
|
|
|
233
248
|
/**
|
|
234
249
|
* Focus on the input element
|
|
235
250
|
*/
|
|
236
|
-
var
|
|
251
|
+
var focusTargetInput = useEventCallback(function () {
|
|
237
252
|
delay(function () {
|
|
238
|
-
var
|
|
239
|
-
(
|
|
240
|
-
},
|
|
241
|
-
}
|
|
253
|
+
var _target$current;
|
|
254
|
+
return (_target$current = target.current) === null || _target$current === void 0 ? void 0 : _target$current.focus();
|
|
255
|
+
}, 1);
|
|
256
|
+
});
|
|
242
257
|
|
|
243
258
|
/**
|
|
244
259
|
* The callback triggered after clicking the OK button.
|
|
245
260
|
*/
|
|
246
|
-
var handleOK =
|
|
261
|
+
var handleOK = useEventCallback(function (event) {
|
|
247
262
|
updateValue(event);
|
|
248
263
|
onOk === null || onOk === void 0 ? void 0 : onOk(calendarDate, event);
|
|
249
|
-
|
|
250
|
-
}
|
|
264
|
+
focusTargetInput();
|
|
265
|
+
});
|
|
251
266
|
|
|
252
267
|
/**
|
|
253
268
|
* Callback after clicking the clear button.
|
|
254
269
|
*/
|
|
255
|
-
|
|
270
|
+
|
|
271
|
+
var handleClean = useEventCallback(function (event) {
|
|
256
272
|
updateValue(event, null);
|
|
257
273
|
resetCalendarDate(null);
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
if (tagName === 'INPUT') {
|
|
263
|
-
if (event.key === 'ArrowDown') {
|
|
264
|
-
event.preventDefault();
|
|
265
|
-
focusSelectedDate();
|
|
266
|
-
} else if (event.key === 'Enter') {
|
|
267
|
-
var _triggerRef$current2, _triggerRef$current2$;
|
|
268
|
-
(_triggerRef$current2 = triggerRef.current) === null || _triggerRef$current2 === void 0 ? void 0 : (_triggerRef$current2$ = _triggerRef$current2.open) === null || _triggerRef$current2$ === void 0 ? void 0 : _triggerRef$current2$.call(_triggerRef$current2);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}, [focusSelectedDate]);
|
|
272
|
-
var handlePickerOverlayKeyDown = useCallback(function (event) {
|
|
274
|
+
onClean === null || onClean === void 0 ? void 0 : onClean(event);
|
|
275
|
+
event.stopPropagation();
|
|
276
|
+
});
|
|
277
|
+
var handlePickerOverlayKeyDown = useEventCallback(function (event) {
|
|
273
278
|
var delta = 0;
|
|
274
279
|
var step = showMonth ? 6 : 7;
|
|
275
280
|
var changeDateFunc = showMonth ? addMonths : addDays;
|
|
@@ -295,135 +300,91 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
295
300
|
setCalendarDate(nextDate);
|
|
296
301
|
focusSelectedDate();
|
|
297
302
|
}
|
|
298
|
-
}
|
|
303
|
+
});
|
|
299
304
|
|
|
300
305
|
/**
|
|
301
306
|
* The callback triggered after the month selection box is opened or closed.
|
|
302
307
|
*/
|
|
303
|
-
var handleToggleMonthDropdown =
|
|
308
|
+
var handleToggleMonthDropdown = useEventCallback(function (toggle) {
|
|
304
309
|
onToggleMonthDropdown === null || onToggleMonthDropdown === void 0 ? void 0 : onToggleMonthDropdown(toggle);
|
|
305
310
|
setShowMonthDropdown(toggle);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
targetRef: targetRef,
|
|
314
|
-
overlayRef: overlayRef,
|
|
315
|
-
active: active,
|
|
316
|
-
onExit: handleClean,
|
|
317
|
-
onKeyDown: handlePickerToggleKeyDown
|
|
318
|
-
}, rest));
|
|
311
|
+
});
|
|
312
|
+
var handleClick = useEventCallback(function () {
|
|
313
|
+
if (editable) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
focusSelectedDate();
|
|
317
|
+
});
|
|
319
318
|
|
|
320
319
|
/**
|
|
321
320
|
* Callback after the date is selected.
|
|
322
321
|
*/
|
|
323
|
-
var handleSelect =
|
|
322
|
+
var handleSelect = useEventCallback(function (nextValue, event, updatableValue) {
|
|
324
323
|
if (updatableValue === void 0) {
|
|
325
324
|
updatableValue = true;
|
|
326
325
|
}
|
|
327
326
|
setCalendarDate(
|
|
328
327
|
// Determine whether the current value contains time, if not, use calendarDate.
|
|
329
|
-
shouldRenderTime(formatStr) ? nextValue :
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}, function (d) {
|
|
334
|
-
return setSeconds(d, getSeconds(calendarDate));
|
|
335
|
-
})(nextValue));
|
|
328
|
+
shouldRenderTime(formatStr) ? nextValue : copyTime({
|
|
329
|
+
from: calendarDate,
|
|
330
|
+
to: nextValue
|
|
331
|
+
}));
|
|
336
332
|
handleDateChange(nextValue);
|
|
337
333
|
if (oneTap && updatableValue) {
|
|
338
334
|
updateValue(event, nextValue);
|
|
335
|
+
focusTargetInput();
|
|
339
336
|
}
|
|
340
|
-
}
|
|
337
|
+
});
|
|
341
338
|
|
|
342
339
|
/**
|
|
343
340
|
* A callback triggered when the date on the calendar changes.
|
|
344
341
|
*/
|
|
345
|
-
var handleChangeMonth =
|
|
342
|
+
var handleChangeMonth = useEventCallback(function (nextPageDate, event) {
|
|
346
343
|
setCalendarDate(nextPageDate);
|
|
347
344
|
handleDateChange(nextPageDate);
|
|
348
345
|
focusSelectedDate();
|
|
349
346
|
if (oneTap && onlyShowMonth) {
|
|
350
347
|
updateValue(event, nextPageDate);
|
|
348
|
+
focusTargetInput();
|
|
351
349
|
}
|
|
352
|
-
}
|
|
353
|
-
var isDateDisabled = useCallback(function (date) {
|
|
354
|
-
if (typeof shouldDisableDate === 'function') {
|
|
355
|
-
return shouldDisableDate(date);
|
|
356
|
-
}
|
|
357
|
-
if (typeof DEPRECATED_disabledDate === 'function') {
|
|
358
|
-
return DEPRECATED_disabledDate(date);
|
|
359
|
-
}
|
|
360
|
-
return false;
|
|
361
|
-
}, [DEPRECATED_disabledDate, shouldDisableDate]);
|
|
350
|
+
});
|
|
362
351
|
|
|
363
352
|
/**
|
|
364
353
|
* Callback after the input box value is changed.
|
|
365
354
|
*/
|
|
366
|
-
var handleInputChange =
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
// isMatch('01/11/2020', 'MM/dd/yyyy') ==> true
|
|
370
|
-
// isMatch('2020-11-01', 'MM/dd/yyyy') ==> false
|
|
371
|
-
if (!isMatch(value, formatStr, {
|
|
372
|
-
locale: locale.dateLocale
|
|
373
|
-
})) {
|
|
374
|
-
setInputState('Error');
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
var date = parseDate(value, formatStr);
|
|
378
|
-
|
|
379
|
-
// If only the time is included in the characters, it will default to today.
|
|
380
|
-
if (shouldOnlyRenderTime(formatStr)) {
|
|
381
|
-
date = new Date(format(new Date(), 'yyyy-MM-dd') + " " + value);
|
|
382
|
-
}
|
|
383
|
-
if (!isValid(date)) {
|
|
384
|
-
setInputState('Error');
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
if (isDateDisabled(date)) {
|
|
388
|
-
setInputState('Error');
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
handleSelect(date, event, false);
|
|
392
|
-
}, [formatStr, locale, parseDate, isDateDisabled, handleSelect]);
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* The callback after the enter key is triggered on the input
|
|
396
|
-
*/
|
|
397
|
-
var handleInputPressEnd = useCallback(function (event) {
|
|
398
|
-
if (inputState === 'Typing') {
|
|
399
|
-
updateValue(event, calendarDate);
|
|
400
|
-
}
|
|
401
|
-
setInputState('Initial');
|
|
402
|
-
}, [inputState, calendarDate, updateValue]);
|
|
403
|
-
var handleInputBackspace = useCallback(function (event) {
|
|
404
|
-
var value = event.target.value;
|
|
405
|
-
|
|
406
|
-
// When the input box is empty, the date is cleared.
|
|
407
|
-
if (value === '') {
|
|
408
|
-
handleClean(event);
|
|
355
|
+
var handleInputChange = useEventCallback(function (value, event) {
|
|
356
|
+
if (!isErrorValue(value)) {
|
|
357
|
+
handleSelect(value, event);
|
|
409
358
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
359
|
+
updateValue(event, value, false);
|
|
360
|
+
});
|
|
361
|
+
var handleInputKeyDown = useEventCallback(function (event) {
|
|
362
|
+
onMenuKeyDown(event, {
|
|
363
|
+
esc: handleClose,
|
|
364
|
+
enter: function enter() {
|
|
365
|
+
var _trigger$current2;
|
|
366
|
+
var _ref = ((_trigger$current2 = trigger.current) === null || _trigger$current2 === void 0 ? void 0 : _trigger$current2.getState()) || {},
|
|
367
|
+
open = _ref.open;
|
|
368
|
+
if (open) {
|
|
369
|
+
if (isValid(calendarDate) && !isDateDisabled(calendarDate)) {
|
|
370
|
+
updateValue(event);
|
|
371
|
+
focusTargetInput();
|
|
372
|
+
}
|
|
373
|
+
} else {
|
|
374
|
+
var _trigger$current3;
|
|
375
|
+
(_trigger$current3 = trigger.current) === null || _trigger$current3 === void 0 ? void 0 : _trigger$current3.open();
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
});
|
|
419
380
|
|
|
420
381
|
// Check whether the time is within the time range of the shortcut option in the toolbar.
|
|
421
|
-
var disabledToolbarHandle =
|
|
382
|
+
var disabledToolbarHandle = function disabledToolbarHandle(date) {
|
|
422
383
|
var _DEPRECATED_disabledD;
|
|
423
384
|
var allowDate = (_DEPRECATED_disabledD = DEPRECATED_disabledDate === null || DEPRECATED_disabledDate === void 0 ? void 0 : DEPRECATED_disabledDate(date)) !== null && _DEPRECATED_disabledD !== void 0 ? _DEPRECATED_disabledD : false;
|
|
424
385
|
var allowTime = disabledTime(props, date);
|
|
425
386
|
return allowDate || allowTime;
|
|
426
|
-
}
|
|
387
|
+
};
|
|
427
388
|
|
|
428
389
|
/**
|
|
429
390
|
* Whether "OK" button is disabled
|
|
@@ -431,12 +392,12 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
431
392
|
* - If format is date, disable ok button if selected date is disabled
|
|
432
393
|
* - If format is month, disable ok button if all dates in the month of selected date are disabled
|
|
433
394
|
*/
|
|
434
|
-
var isOKButtonDisabled =
|
|
395
|
+
var isOKButtonDisabled = function isOKButtonDisabled(selectedDate) {
|
|
435
396
|
if (shouldRenderMonth(formatStr) && !shouldRenderDate(formatStr)) {
|
|
436
397
|
return isEveryDateInMonth(selectedDate.getFullYear(), selectedDate.getMonth(), disabledToolbarHandle);
|
|
437
398
|
}
|
|
438
399
|
return disabledToolbarHandle(selectedDate);
|
|
439
|
-
}
|
|
400
|
+
};
|
|
440
401
|
var calendarProps = useMemo(function () {
|
|
441
402
|
return mapValues(pick(props, calendarOnlyProps), function (disabledOrHiddenTimeFunc) {
|
|
442
403
|
return function (next, date) {
|
|
@@ -445,53 +406,26 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
445
406
|
};
|
|
446
407
|
});
|
|
447
408
|
}, [props]);
|
|
448
|
-
var
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
showMeridian: showMeridian,
|
|
452
|
-
disabledDate: isDateDisabled,
|
|
453
|
-
disabledHours: shouldDisableHour !== null && shouldDisableHour !== void 0 ? shouldDisableHour : DEPRECATED_disabledHours,
|
|
454
|
-
disabledMinutes: shouldDisableMinute !== null && shouldDisableMinute !== void 0 ? shouldDisableMinute : DEPRECATED_disabledMinutes,
|
|
455
|
-
disabledSeconds: shouldDisableSecond !== null && shouldDisableSecond !== void 0 ? shouldDisableSecond : DEPRECATED_disabledSeconds,
|
|
456
|
-
limitEndYear: limitEndYear,
|
|
457
|
-
limitStartYear: limitStartYear,
|
|
458
|
-
format: formatStr,
|
|
459
|
-
isoWeek: isoWeek,
|
|
460
|
-
calendarDate: calendarDate,
|
|
461
|
-
onMoveForward: handleMoveForward,
|
|
462
|
-
onMoveBackward: handleMoveBackward,
|
|
463
|
-
onSelect: handleSelect,
|
|
464
|
-
onToggleMonthDropdown: handleToggleMonthDropdown,
|
|
465
|
-
onToggleTimeDropdown: onToggleTimeDropdown,
|
|
466
|
-
onChangeMonth: handleChangeMonth,
|
|
467
|
-
onChangeTime: handleChangeTime,
|
|
468
|
-
onToggleMeridian: handleToggleMeridian
|
|
469
|
-
}));
|
|
470
|
-
|
|
471
|
-
// The shortcut option on the left side of the calendar panel
|
|
472
|
-
var sideRanges = (ranges === null || ranges === void 0 ? void 0 : ranges.filter(function (range) {
|
|
473
|
-
return (range === null || range === void 0 ? void 0 : range.placement) === 'left';
|
|
474
|
-
})) || [];
|
|
475
|
-
|
|
476
|
-
// The shortcut option on the bottom of the calendar panel
|
|
477
|
-
var bottomRanges = (ranges === null || ranges === void 0 ? void 0 : ranges.filter(function (range) {
|
|
478
|
-
return (range === null || range === void 0 ? void 0 : range.placement) === 'bottom' || (range === null || range === void 0 ? void 0 : range.placement) === undefined;
|
|
479
|
-
})) || [];
|
|
409
|
+
var _splitRanges = splitRanges(ranges),
|
|
410
|
+
sideRanges = _splitRanges.sideRanges,
|
|
411
|
+
bottomRanges = _splitRanges.bottomRanges;
|
|
480
412
|
var renderCalendarOverlay = function renderCalendarOverlay(positionProps, speakerRef) {
|
|
481
413
|
var left = positionProps.left,
|
|
482
414
|
top = positionProps.top,
|
|
483
415
|
className = positionProps.className;
|
|
484
|
-
var classes = merge(menuClassName, className
|
|
416
|
+
var classes = merge(menuClassName, className);
|
|
485
417
|
var styles = _extends({}, menuStyle, {
|
|
486
418
|
left: left,
|
|
487
419
|
top: top
|
|
488
420
|
});
|
|
489
421
|
return /*#__PURE__*/React.createElement(PickerOverlay, {
|
|
490
422
|
role: "dialog",
|
|
423
|
+
"aria-labelledby": label ? id + "-label" : undefined,
|
|
424
|
+
tabIndex: -1,
|
|
491
425
|
className: classes,
|
|
492
|
-
ref: mergeRefs(
|
|
426
|
+
ref: mergeRefs(overlay, speakerRef),
|
|
493
427
|
style: styles,
|
|
494
|
-
target:
|
|
428
|
+
target: trigger,
|
|
495
429
|
onKeyDown: handlePickerOverlayKeyDown
|
|
496
430
|
}, /*#__PURE__*/React.createElement(Stack, {
|
|
497
431
|
alignItems: "flex-start"
|
|
@@ -504,7 +438,29 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
504
438
|
locale: locale,
|
|
505
439
|
disabledShortcut: disabledToolbarHandle,
|
|
506
440
|
onShortcutClick: handleShortcutPageDate
|
|
507
|
-
}), /*#__PURE__*/React.createElement(React.Fragment, null,
|
|
441
|
+
}), /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CalendarContainer, _extends({}, calendarProps, {
|
|
442
|
+
targetId: id,
|
|
443
|
+
locale: locale,
|
|
444
|
+
showWeekNumbers: showWeekNumbers,
|
|
445
|
+
showMeridian: showMeridian,
|
|
446
|
+
disabledDate: isDateDisabled,
|
|
447
|
+
disabledHours: shouldDisableHour !== null && shouldDisableHour !== void 0 ? shouldDisableHour : DEPRECATED_disabledHours,
|
|
448
|
+
disabledMinutes: shouldDisableMinute !== null && shouldDisableMinute !== void 0 ? shouldDisableMinute : DEPRECATED_disabledMinutes,
|
|
449
|
+
disabledSeconds: shouldDisableSecond !== null && shouldDisableSecond !== void 0 ? shouldDisableSecond : DEPRECATED_disabledSeconds,
|
|
450
|
+
limitEndYear: limitEndYear,
|
|
451
|
+
limitStartYear: limitStartYear,
|
|
452
|
+
format: formatStr,
|
|
453
|
+
isoWeek: isoWeek,
|
|
454
|
+
calendarDate: calendarDate,
|
|
455
|
+
onMoveForward: handleMoveForward,
|
|
456
|
+
onMoveBackward: handleMoveBackward,
|
|
457
|
+
onSelect: handleSelect,
|
|
458
|
+
onToggleMonthDropdown: handleToggleMonthDropdown,
|
|
459
|
+
onToggleTimeDropdown: onToggleTimeDropdown,
|
|
460
|
+
onChangeMonth: handleChangeMonth,
|
|
461
|
+
onChangeTime: handleChangeTime,
|
|
462
|
+
onToggleMeridian: handleToggleMeridian
|
|
463
|
+
})), /*#__PURE__*/React.createElement(Toolbar, {
|
|
508
464
|
locale: locale,
|
|
509
465
|
ranges: bottomRanges,
|
|
510
466
|
calendarDate: calendarDate,
|
|
@@ -515,7 +471,7 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
515
471
|
hideOkBtn: oneTap
|
|
516
472
|
}))));
|
|
517
473
|
};
|
|
518
|
-
var hasValue =
|
|
474
|
+
var hasValue = isValid(value);
|
|
519
475
|
var _usePickerClassName = usePickerClassName(_extends({}, props, {
|
|
520
476
|
classPrefix: classPrefix,
|
|
521
477
|
name: 'date',
|
|
@@ -525,62 +481,73 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
525
481
|
})),
|
|
526
482
|
classes = _usePickerClassName[0],
|
|
527
483
|
usedClassNamePropKeys = _usePickerClassName[1];
|
|
528
|
-
var renderDate = useCallback(function () {
|
|
529
|
-
var _renderValue;
|
|
530
|
-
if (!value) {
|
|
531
|
-
return placeholder || formatStr;
|
|
532
|
-
}
|
|
533
|
-
return (_renderValue = renderValue === null || renderValue === void 0 ? void 0 : renderValue(value, formatStr)) !== null && _renderValue !== void 0 ? _renderValue : formatDate(value, formatStr);
|
|
534
|
-
}, [formatStr, formatDate, placeholder, renderValue, value]);
|
|
535
484
|
var caretAs = useMemo(function () {
|
|
485
|
+
if (caretAsProp === null) {
|
|
486
|
+
return null;
|
|
487
|
+
}
|
|
536
488
|
return caretAsProp || (shouldOnlyRenderTime(formatStr) ? IconClockO : IconCalendar);
|
|
537
489
|
}, [caretAsProp, formatStr]);
|
|
538
|
-
var handleTriggerClose =
|
|
490
|
+
var handleTriggerClose = useEventCallback(function (cause) {
|
|
539
491
|
// Unless overlay is closing on user clicking "OK" button,
|
|
540
492
|
// reset the selected date on calendar panel
|
|
541
493
|
if (cause !== OverlayCloseCause.ImperativeHandle) {
|
|
542
494
|
resetCalendarDate();
|
|
543
495
|
}
|
|
544
496
|
setShowMonthDropdown(false);
|
|
545
|
-
}
|
|
497
|
+
});
|
|
498
|
+
var showCleanButton = cleanable && hasValue && !readOnly;
|
|
499
|
+
var _partitionHTMLProps = partitionHTMLProps(restProps, {
|
|
500
|
+
htmlProps: [],
|
|
501
|
+
includeAria: true
|
|
502
|
+
}),
|
|
503
|
+
ariaProps = _partitionHTMLProps[0],
|
|
504
|
+
rest = _partitionHTMLProps[1];
|
|
505
|
+
var invalidValue = value && isErrorValue(value);
|
|
546
506
|
return /*#__PURE__*/React.createElement(PickerToggleTrigger, {
|
|
547
507
|
trigger: "active",
|
|
548
508
|
pickerProps: pick(props, pickTriggerPropKeys),
|
|
549
|
-
ref:
|
|
509
|
+
ref: trigger,
|
|
550
510
|
placement: placement,
|
|
551
511
|
onClose: handleTriggerClose,
|
|
552
|
-
onEntered: createChainedFunction(
|
|
553
|
-
onExited: createChainedFunction(
|
|
512
|
+
onEntered: createChainedFunction(onOpen, onEntered),
|
|
513
|
+
onExited: createChainedFunction(onClose, onExited),
|
|
554
514
|
speaker: renderCalendarOverlay
|
|
555
515
|
}, /*#__PURE__*/React.createElement(Component, {
|
|
556
|
-
className: merge(className, classes),
|
|
516
|
+
className: merge(className, classes, (_merge = {}, _merge[prefix('error')] = invalidValue, _merge)),
|
|
557
517
|
style: style,
|
|
558
|
-
ref:
|
|
559
|
-
}, /*#__PURE__*/React.createElement(
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
518
|
+
ref: root
|
|
519
|
+
}, plaintext ? /*#__PURE__*/React.createElement(DateInput, {
|
|
520
|
+
value: value,
|
|
521
|
+
format: formatStr,
|
|
522
|
+
plaintext: plaintext
|
|
523
|
+
}) : /*#__PURE__*/React.createElement(InputGroup, _extends({}, omit(rest, [].concat(omitTriggerPropKeys, usedClassNamePropKeys, calendarOnlyProps)), {
|
|
524
|
+
inside: true,
|
|
525
|
+
size: size,
|
|
526
|
+
onClick: handleClick
|
|
527
|
+
}), /*#__PURE__*/React.createElement(PickerLabel, {
|
|
528
|
+
className: prefix(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["label"]))),
|
|
529
|
+
id: id + "-label"
|
|
530
|
+
}, label), /*#__PURE__*/React.createElement(DateInput, _extends({
|
|
531
|
+
"aria-haspopup": "dialog",
|
|
532
|
+
"aria-invalid": invalidValue,
|
|
533
|
+
"aria-labelledby": label ? id + "-label" : undefined
|
|
534
|
+
}, ariaProps, {
|
|
535
|
+
ref: target,
|
|
536
|
+
id: id,
|
|
537
|
+
value: value,
|
|
538
|
+
format: formatStr,
|
|
539
|
+
placeholder: placeholder ? placeholder : formatStr,
|
|
580
540
|
disabled: disabled,
|
|
541
|
+
onChange: handleInputChange,
|
|
542
|
+
readOnly: readOnly || !editable || loading,
|
|
543
|
+
plaintext: plaintext,
|
|
544
|
+
onKeyDown: handleInputKeyDown
|
|
545
|
+
})), /*#__PURE__*/React.createElement(PickerIndicator, {
|
|
546
|
+
loading: loading,
|
|
581
547
|
caretAs: caretAs,
|
|
582
|
-
|
|
583
|
-
|
|
548
|
+
onClose: handleClean,
|
|
549
|
+
showCleanButton: showCleanButton
|
|
550
|
+
}))));
|
|
584
551
|
});
|
|
585
552
|
DatePicker.displayName = 'DatePicker';
|
|
586
553
|
DatePicker.propTypes = _extends({}, pickerPropTypes, {
|