@react-stately/datepicker 3.9.2 → 3.9.3
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/dist/ar-AE.mjs +1 -1
- package/dist/bg-BG.mjs +1 -1
- package/dist/cs-CZ.mjs +1 -1
- package/dist/da-DK.mjs +1 -1
- package/dist/de-DE.mjs +1 -1
- package/dist/el-GR.mjs +1 -1
- package/dist/en-US.mjs +1 -1
- package/dist/es-ES.mjs +1 -1
- package/dist/et-EE.mjs +1 -1
- package/dist/fi-FI.mjs +1 -1
- package/dist/fr-FR.mjs +1 -1
- package/dist/he-IL.mjs +1 -1
- package/dist/hr-HR.mjs +1 -1
- package/dist/hu-HU.mjs +1 -1
- package/dist/import.mjs +4 -1514
- package/dist/intlStrings.main.js +108 -0
- package/dist/intlStrings.main.js.map +1 -0
- package/dist/intlStrings.mjs +110 -0
- package/dist/intlStrings.module.js +110 -0
- package/dist/intlStrings.module.js.map +1 -0
- package/dist/it-IT.mjs +1 -1
- package/dist/ja-JP.mjs +1 -1
- package/dist/ko-KR.mjs +1 -1
- package/dist/lt-LT.mjs +1 -1
- package/dist/lv-LV.mjs +1 -1
- package/dist/main.js +8 -1518
- package/dist/main.js.map +1 -1
- package/dist/module.js +4 -1514
- package/dist/module.js.map +1 -1
- package/dist/nb-NO.mjs +1 -1
- package/dist/nl-NL.mjs +1 -1
- package/dist/pl-PL.mjs +1 -1
- package/dist/placeholders.main.js +409 -0
- package/dist/placeholders.main.js.map +1 -0
- package/dist/placeholders.mjs +404 -0
- package/dist/placeholders.module.js +404 -0
- package/dist/placeholders.module.js.map +1 -0
- package/dist/pt-BR.mjs +1 -1
- package/dist/pt-PT.mjs +1 -1
- package/dist/ro-RO.mjs +1 -1
- package/dist/ru-RU.mjs +1 -1
- package/dist/sk-SK.mjs +1 -1
- package/dist/sl-SI.mjs +1 -1
- package/dist/sr-SP.mjs +1 -1
- package/dist/sv-SE.mjs +1 -1
- package/dist/tr-TR.mjs +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/uk-UA.mjs +1 -1
- package/dist/useDateFieldState.main.js +441 -0
- package/dist/useDateFieldState.main.js.map +1 -0
- package/dist/useDateFieldState.mjs +436 -0
- package/dist/useDateFieldState.module.js +436 -0
- package/dist/useDateFieldState.module.js.map +1 -0
- package/dist/useDatePickerState.main.js +130 -0
- package/dist/useDatePickerState.main.js.map +1 -0
- package/dist/useDatePickerState.mjs +125 -0
- package/dist/useDatePickerState.module.js +125 -0
- package/dist/useDatePickerState.module.js.map +1 -0
- package/dist/useDateRangePickerState.main.js +237 -0
- package/dist/useDateRangePickerState.main.js.map +1 -0
- package/dist/useDateRangePickerState.mjs +232 -0
- package/dist/useDateRangePickerState.module.js +232 -0
- package/dist/useDateRangePickerState.module.js.map +1 -0
- package/dist/useTimeFieldState.main.js +86 -0
- package/dist/useTimeFieldState.main.js.map +1 -0
- package/dist/useTimeFieldState.mjs +81 -0
- package/dist/useTimeFieldState.module.js +81 -0
- package/dist/useTimeFieldState.module.js.map +1 -0
- package/dist/utils.main.js +190 -0
- package/dist/utils.main.js.map +1 -0
- package/dist/utils.mjs +179 -0
- package/dist/utils.module.js +179 -0
- package/dist/utils.module.js.map +1 -0
- package/dist/zh-CN.mjs +1 -1
- package/dist/zh-TW.mjs +1 -1
- package/package.json +9 -9
- package/src/utils.ts +2 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {getFormatOptions as $35a22f14a1f04b11$export$7e319ea407e63bc0, getPlaceholderTime as $35a22f14a1f04b11$export$c5221a78ef73c5e9, getValidationResult as $35a22f14a1f04b11$export$f18627323ab57ac0, useDefaultProps as $35a22f14a1f04b11$export$2440da353cedad43} from "./utils.mjs";
|
|
2
|
+
import {toCalendarDate as $goopS$toCalendarDate, toCalendarDateTime as $goopS$toCalendarDateTime, DateFormatter as $goopS$DateFormatter} from "@internationalized/date";
|
|
3
|
+
import {useFormValidationState as $goopS$useFormValidationState} from "@react-stately/form";
|
|
4
|
+
import {useOverlayTriggerState as $goopS$useOverlayTriggerState} from "@react-stately/overlays";
|
|
5
|
+
import {useControlledState as $goopS$useControlledState} from "@react-stately/utils";
|
|
6
|
+
import {useState as $goopS$useState, useMemo as $goopS$useMemo} from "react";
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
10
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
12
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
15
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
16
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
17
|
+
* governing permissions and limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
25
|
+
let overlayState = (0, $goopS$useOverlayTriggerState)(props);
|
|
26
|
+
let [value, setValue] = (0, $goopS$useControlledState)(props.value, props.defaultValue || null, props.onChange);
|
|
27
|
+
let v = value || props.placeholderValue;
|
|
28
|
+
let [granularity, defaultTimeZone] = (0, $35a22f14a1f04b11$export$2440da353cedad43)(v, props.granularity);
|
|
29
|
+
let dateValue = value != null ? value.toDate(defaultTimeZone !== null && defaultTimeZone !== void 0 ? defaultTimeZone : "UTC") : null;
|
|
30
|
+
let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
|
|
31
|
+
var _props_shouldCloseOnSelect;
|
|
32
|
+
let shouldCloseOnSelect = (_props_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _props_shouldCloseOnSelect !== void 0 ? _props_shouldCloseOnSelect : true;
|
|
33
|
+
let [selectedDate, setSelectedDate] = (0, $goopS$useState)(null);
|
|
34
|
+
let [selectedTime, setSelectedTime] = (0, $goopS$useState)(null);
|
|
35
|
+
if (value) {
|
|
36
|
+
selectedDate = value;
|
|
37
|
+
if ("hour" in value) selectedTime = value;
|
|
38
|
+
}
|
|
39
|
+
// props.granularity must actually exist in the value if one is provided.
|
|
40
|
+
if (v && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
|
|
41
|
+
let showEra = (value === null || value === void 0 ? void 0 : value.calendar.identifier) === "gregory" && value.era === "BC";
|
|
42
|
+
let formatOpts = (0, $goopS$useMemo)(()=>({
|
|
43
|
+
granularity: granularity,
|
|
44
|
+
timeZone: defaultTimeZone,
|
|
45
|
+
hideTimeZone: props.hideTimeZone,
|
|
46
|
+
hourCycle: props.hourCycle,
|
|
47
|
+
shouldForceLeadingZeros: props.shouldForceLeadingZeros,
|
|
48
|
+
showEra: showEra
|
|
49
|
+
}), [
|
|
50
|
+
granularity,
|
|
51
|
+
props.hourCycle,
|
|
52
|
+
props.shouldForceLeadingZeros,
|
|
53
|
+
defaultTimeZone,
|
|
54
|
+
props.hideTimeZone,
|
|
55
|
+
showEra
|
|
56
|
+
]);
|
|
57
|
+
let { minValue: minValue, maxValue: maxValue, isDateUnavailable: isDateUnavailable } = props;
|
|
58
|
+
let builtinValidation = (0, $goopS$useMemo)(()=>(0, $35a22f14a1f04b11$export$f18627323ab57ac0)(value, minValue, maxValue, isDateUnavailable, formatOpts), [
|
|
59
|
+
value,
|
|
60
|
+
minValue,
|
|
61
|
+
maxValue,
|
|
62
|
+
isDateUnavailable,
|
|
63
|
+
formatOpts
|
|
64
|
+
]);
|
|
65
|
+
let validation = (0, $goopS$useFormValidationState)({
|
|
66
|
+
...props,
|
|
67
|
+
value: value,
|
|
68
|
+
builtinValidation: builtinValidation
|
|
69
|
+
});
|
|
70
|
+
let isValueInvalid = validation.displayValidation.isInvalid;
|
|
71
|
+
let validationState = props.validationState || (isValueInvalid ? "invalid" : null);
|
|
72
|
+
let commitValue = (date, time)=>{
|
|
73
|
+
setValue("timeZone" in time ? time.set((0, $goopS$toCalendarDate)(date)) : (0, $goopS$toCalendarDateTime)(date, time));
|
|
74
|
+
setSelectedDate(null);
|
|
75
|
+
setSelectedTime(null);
|
|
76
|
+
validation.commitValidation();
|
|
77
|
+
};
|
|
78
|
+
// Intercept setValue to make sure the Time section is not changed by date selection in Calendar
|
|
79
|
+
let selectDate = (newValue)=>{
|
|
80
|
+
let shouldClose = typeof shouldCloseOnSelect === "function" ? shouldCloseOnSelect() : shouldCloseOnSelect;
|
|
81
|
+
if (hasTime) {
|
|
82
|
+
if (selectedTime || shouldClose) commitValue(newValue, selectedTime || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue));
|
|
83
|
+
else setSelectedDate(newValue);
|
|
84
|
+
} else {
|
|
85
|
+
setValue(newValue);
|
|
86
|
+
validation.commitValidation();
|
|
87
|
+
}
|
|
88
|
+
if (shouldClose) overlayState.setOpen(false);
|
|
89
|
+
};
|
|
90
|
+
let selectTime = (newValue)=>{
|
|
91
|
+
if (selectedDate && newValue) commitValue(selectedDate, newValue);
|
|
92
|
+
else setSelectedTime(newValue);
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
...validation,
|
|
96
|
+
value: value,
|
|
97
|
+
setValue: setValue,
|
|
98
|
+
dateValue: selectedDate,
|
|
99
|
+
timeValue: selectedTime,
|
|
100
|
+
setDateValue: selectDate,
|
|
101
|
+
setTimeValue: selectTime,
|
|
102
|
+
granularity: granularity,
|
|
103
|
+
hasTime: hasTime,
|
|
104
|
+
...overlayState,
|
|
105
|
+
setOpen (isOpen) {
|
|
106
|
+
// Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
107
|
+
// If only the time was set and not the date, don't commit. The state will be preserved until
|
|
108
|
+
// the user opens the popover again.
|
|
109
|
+
if (!isOpen && !value && selectedDate && hasTime) commitValue(selectedDate, selectedTime || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue));
|
|
110
|
+
overlayState.setOpen(isOpen);
|
|
111
|
+
},
|
|
112
|
+
validationState: validationState,
|
|
113
|
+
isInvalid: isValueInvalid,
|
|
114
|
+
formatValue (locale, fieldOptions) {
|
|
115
|
+
if (!dateValue) return "";
|
|
116
|
+
let formatOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)(fieldOptions, formatOpts);
|
|
117
|
+
let formatter = new (0, $goopS$DateFormatter)(locale, formatOptions);
|
|
118
|
+
return formatter.format(dateValue);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
export {$ab5bf3f618090389$export$87194bb378cc3ac2 as useDatePickerState};
|
|
125
|
+
//# sourceMappingURL=useDatePickerState.mjs.map
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {getFormatOptions as $35a22f14a1f04b11$export$7e319ea407e63bc0, getPlaceholderTime as $35a22f14a1f04b11$export$c5221a78ef73c5e9, getValidationResult as $35a22f14a1f04b11$export$f18627323ab57ac0, useDefaultProps as $35a22f14a1f04b11$export$2440da353cedad43} from "./utils.module.js";
|
|
2
|
+
import {toCalendarDate as $goopS$toCalendarDate, toCalendarDateTime as $goopS$toCalendarDateTime, DateFormatter as $goopS$DateFormatter} from "@internationalized/date";
|
|
3
|
+
import {useFormValidationState as $goopS$useFormValidationState} from "@react-stately/form";
|
|
4
|
+
import {useOverlayTriggerState as $goopS$useOverlayTriggerState} from "@react-stately/overlays";
|
|
5
|
+
import {useControlledState as $goopS$useControlledState} from "@react-stately/utils";
|
|
6
|
+
import {useState as $goopS$useState, useMemo as $goopS$useMemo} from "react";
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
10
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
12
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
15
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
16
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
17
|
+
* governing permissions and limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
25
|
+
let overlayState = (0, $goopS$useOverlayTriggerState)(props);
|
|
26
|
+
let [value, setValue] = (0, $goopS$useControlledState)(props.value, props.defaultValue || null, props.onChange);
|
|
27
|
+
let v = value || props.placeholderValue;
|
|
28
|
+
let [granularity, defaultTimeZone] = (0, $35a22f14a1f04b11$export$2440da353cedad43)(v, props.granularity);
|
|
29
|
+
let dateValue = value != null ? value.toDate(defaultTimeZone !== null && defaultTimeZone !== void 0 ? defaultTimeZone : "UTC") : null;
|
|
30
|
+
let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
|
|
31
|
+
var _props_shouldCloseOnSelect;
|
|
32
|
+
let shouldCloseOnSelect = (_props_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _props_shouldCloseOnSelect !== void 0 ? _props_shouldCloseOnSelect : true;
|
|
33
|
+
let [selectedDate, setSelectedDate] = (0, $goopS$useState)(null);
|
|
34
|
+
let [selectedTime, setSelectedTime] = (0, $goopS$useState)(null);
|
|
35
|
+
if (value) {
|
|
36
|
+
selectedDate = value;
|
|
37
|
+
if ("hour" in value) selectedTime = value;
|
|
38
|
+
}
|
|
39
|
+
// props.granularity must actually exist in the value if one is provided.
|
|
40
|
+
if (v && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
|
|
41
|
+
let showEra = (value === null || value === void 0 ? void 0 : value.calendar.identifier) === "gregory" && value.era === "BC";
|
|
42
|
+
let formatOpts = (0, $goopS$useMemo)(()=>({
|
|
43
|
+
granularity: granularity,
|
|
44
|
+
timeZone: defaultTimeZone,
|
|
45
|
+
hideTimeZone: props.hideTimeZone,
|
|
46
|
+
hourCycle: props.hourCycle,
|
|
47
|
+
shouldForceLeadingZeros: props.shouldForceLeadingZeros,
|
|
48
|
+
showEra: showEra
|
|
49
|
+
}), [
|
|
50
|
+
granularity,
|
|
51
|
+
props.hourCycle,
|
|
52
|
+
props.shouldForceLeadingZeros,
|
|
53
|
+
defaultTimeZone,
|
|
54
|
+
props.hideTimeZone,
|
|
55
|
+
showEra
|
|
56
|
+
]);
|
|
57
|
+
let { minValue: minValue, maxValue: maxValue, isDateUnavailable: isDateUnavailable } = props;
|
|
58
|
+
let builtinValidation = (0, $goopS$useMemo)(()=>(0, $35a22f14a1f04b11$export$f18627323ab57ac0)(value, minValue, maxValue, isDateUnavailable, formatOpts), [
|
|
59
|
+
value,
|
|
60
|
+
minValue,
|
|
61
|
+
maxValue,
|
|
62
|
+
isDateUnavailable,
|
|
63
|
+
formatOpts
|
|
64
|
+
]);
|
|
65
|
+
let validation = (0, $goopS$useFormValidationState)({
|
|
66
|
+
...props,
|
|
67
|
+
value: value,
|
|
68
|
+
builtinValidation: builtinValidation
|
|
69
|
+
});
|
|
70
|
+
let isValueInvalid = validation.displayValidation.isInvalid;
|
|
71
|
+
let validationState = props.validationState || (isValueInvalid ? "invalid" : null);
|
|
72
|
+
let commitValue = (date, time)=>{
|
|
73
|
+
setValue("timeZone" in time ? time.set((0, $goopS$toCalendarDate)(date)) : (0, $goopS$toCalendarDateTime)(date, time));
|
|
74
|
+
setSelectedDate(null);
|
|
75
|
+
setSelectedTime(null);
|
|
76
|
+
validation.commitValidation();
|
|
77
|
+
};
|
|
78
|
+
// Intercept setValue to make sure the Time section is not changed by date selection in Calendar
|
|
79
|
+
let selectDate = (newValue)=>{
|
|
80
|
+
let shouldClose = typeof shouldCloseOnSelect === "function" ? shouldCloseOnSelect() : shouldCloseOnSelect;
|
|
81
|
+
if (hasTime) {
|
|
82
|
+
if (selectedTime || shouldClose) commitValue(newValue, selectedTime || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue));
|
|
83
|
+
else setSelectedDate(newValue);
|
|
84
|
+
} else {
|
|
85
|
+
setValue(newValue);
|
|
86
|
+
validation.commitValidation();
|
|
87
|
+
}
|
|
88
|
+
if (shouldClose) overlayState.setOpen(false);
|
|
89
|
+
};
|
|
90
|
+
let selectTime = (newValue)=>{
|
|
91
|
+
if (selectedDate && newValue) commitValue(selectedDate, newValue);
|
|
92
|
+
else setSelectedTime(newValue);
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
...validation,
|
|
96
|
+
value: value,
|
|
97
|
+
setValue: setValue,
|
|
98
|
+
dateValue: selectedDate,
|
|
99
|
+
timeValue: selectedTime,
|
|
100
|
+
setDateValue: selectDate,
|
|
101
|
+
setTimeValue: selectTime,
|
|
102
|
+
granularity: granularity,
|
|
103
|
+
hasTime: hasTime,
|
|
104
|
+
...overlayState,
|
|
105
|
+
setOpen (isOpen) {
|
|
106
|
+
// Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
107
|
+
// If only the time was set and not the date, don't commit. The state will be preserved until
|
|
108
|
+
// the user opens the popover again.
|
|
109
|
+
if (!isOpen && !value && selectedDate && hasTime) commitValue(selectedDate, selectedTime || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue));
|
|
110
|
+
overlayState.setOpen(isOpen);
|
|
111
|
+
},
|
|
112
|
+
validationState: validationState,
|
|
113
|
+
isInvalid: isValueInvalid,
|
|
114
|
+
formatValue (locale, fieldOptions) {
|
|
115
|
+
if (!dateValue) return "";
|
|
116
|
+
let formatOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)(fieldOptions, formatOpts);
|
|
117
|
+
let formatter = new (0, $goopS$DateFormatter)(locale, formatOptions);
|
|
118
|
+
return formatter.format(dateValue);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121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QACA,GAAG,YAAY;QACf,SAAQ,MAAM;YACZ,kGAAkG;YAClG,6FAA6F;YAC7F,oCAAoC;YACpC,IAAI,CAAC,UAAU,CAAC,SAAS,gBAAgB,SACvC,YAAY,cAAc,gBAAgB,CAAA,GAAA,yCAAiB,EAAE,MAAM,gBAAgB;YAGrF,aAAa,OAAO,CAAC;QACvB;yBACA;QACA,WAAW;QACX,aAAY,MAAM,EAAE,YAAY;YAC9B,IAAI,CAAC,WACH,OAAO;YAGT,IAAI,gBAAgB,CAAA,GAAA,yCAAe,EAAE,cAAc;YACnD,IAAI,YAAY,IAAI,CAAA,GAAA,oBAAY,EAAE,QAAQ;YAC1C,OAAO,UAAU,MAAM,CAAC;QAC1B;IACF;AACF","sources":["packages/@react-stately/datepicker/src/useDatePickerState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CalendarDate, DateFormatter, toCalendarDate, toCalendarDateTime} from '@internationalized/date';\nimport {DatePickerProps, DateValue, Granularity, TimeValue} from '@react-types/datepicker';\nimport {FieldOptions, getFormatOptions, getPlaceholderTime, getValidationResult, useDefaultProps} from './utils';\nimport {FormValidationState, useFormValidationState} from '@react-stately/form';\nimport {OverlayTriggerState, useOverlayTriggerState} from '@react-stately/overlays';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\nimport {ValidationState} from '@react-types/shared';\n\nexport interface DatePickerStateOptions<T extends DateValue> extends DatePickerProps<T> {\n /**\n * Determines whether the date picker popover should close automatically when a date is selected.\n * @default true\n */\n shouldCloseOnSelect?: boolean | (() => boolean)\n}\n\nexport interface DatePickerState extends OverlayTriggerState, FormValidationState {\n /** The currently selected date. */\n value: DateValue | null,\n /** Sets the selected date. */\n setValue(value: DateValue | null): void,\n /**\n * The date portion of the value. This may be set prior to `value` if the user has\n * selected a date but has not yet selected a time.\n */\n dateValue: DateValue,\n /** Sets the date portion of the value. */\n setDateValue(value: CalendarDate): void,\n /**\n * The time portion of the value. This may be set prior to `value` if the user has\n * selected a time but has not yet selected a date.\n */\n timeValue: TimeValue,\n /** Sets the time portion of the value. */\n setTimeValue(value: TimeValue): void,\n /** The granularity for the field, based on the `granularity` prop and current value. */\n granularity: Granularity,\n /** Whether the date picker supports selecting a time, according to the `granularity` prop and current value. */\n hasTime: boolean,\n /** Whether the calendar popover is currently open. */\n isOpen: boolean,\n /** Sets whether the calendar popover is open. */\n setOpen(isOpen: boolean): void,\n /**\n * The current validation state of the date picker, based on the `validationState`, `minValue`, and `maxValue` props.\n * @deprecated Use `isInvalid` instead.\n */\n validationState: ValidationState,\n /** Whether the date picker is invalid, based on the `isInvalid`, `minValue`, and `maxValue` props. */\n isInvalid: boolean,\n /** Formats the selected value using the given options. */\n formatValue(locale: string, fieldOptions: FieldOptions): string\n}\n\n/**\n * Provides state management for a date picker component.\n * A date picker combines a DateField and a Calendar popover to allow users to enter or select a date and time value.\n */\nexport function useDatePickerState<T extends DateValue = DateValue>(props: DatePickerStateOptions<T>): DatePickerState {\n let overlayState = useOverlayTriggerState(props);\n let [value, setValue] = useControlledState<DateValue>(props.value, props.defaultValue || null, props.onChange);\n\n let v = (value || props.placeholderValue);\n let [granularity, defaultTimeZone] = useDefaultProps(v, props.granularity);\n let dateValue = value != null ? value.toDate(defaultTimeZone ?? 'UTC') : null;\n let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second';\n let shouldCloseOnSelect = props.shouldCloseOnSelect ?? true;\n\n let [selectedDate, setSelectedDate] = useState<DateValue>(null);\n let [selectedTime, setSelectedTime] = useState<TimeValue>(null);\n\n if (value) {\n selectedDate = value;\n if ('hour' in value) {\n selectedTime = value;\n }\n }\n\n // props.granularity must actually exist in the value if one is provided.\n if (v && !(granularity in v)) {\n throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());\n }\n\n let showEra = value?.calendar.identifier === 'gregory' && value.era === 'BC';\n let formatOpts = useMemo(() => ({\n granularity,\n timeZone: defaultTimeZone,\n hideTimeZone: props.hideTimeZone,\n hourCycle: props.hourCycle,\n shouldForceLeadingZeros: props.shouldForceLeadingZeros,\n showEra\n }), [granularity, props.hourCycle, props.shouldForceLeadingZeros, defaultTimeZone, props.hideTimeZone, showEra]);\n\n let {minValue, maxValue, isDateUnavailable} = props;\n let builtinValidation = useMemo(() => getValidationResult(\n value,\n minValue,\n maxValue,\n isDateUnavailable,\n formatOpts\n ), [value, minValue, maxValue, isDateUnavailable, formatOpts]);\n\n let validation = useFormValidationState({\n ...props,\n value,\n builtinValidation\n });\n\n let isValueInvalid = validation.displayValidation.isInvalid;\n let validationState: ValidationState = props.validationState || (isValueInvalid ? 'invalid' : null);\n\n let commitValue = (date: DateValue, time: TimeValue) => {\n setValue('timeZone' in time ? time.set(toCalendarDate(date)) : toCalendarDateTime(date, time));\n setSelectedDate(null);\n setSelectedTime(null);\n validation.commitValidation();\n };\n\n // Intercept setValue to make sure the Time section is not changed by date selection in Calendar\n let selectDate = (newValue: CalendarDate) => {\n let shouldClose = typeof shouldCloseOnSelect === 'function' ? shouldCloseOnSelect() : shouldCloseOnSelect;\n if (hasTime) {\n if (selectedTime || shouldClose) {\n commitValue(newValue, selectedTime || getPlaceholderTime(props.placeholderValue));\n } else {\n setSelectedDate(newValue);\n }\n } else {\n setValue(newValue);\n validation.commitValidation();\n }\n\n if (shouldClose) {\n overlayState.setOpen(false);\n }\n };\n\n let selectTime = (newValue: TimeValue) => {\n if (selectedDate && newValue) {\n commitValue(selectedDate, newValue);\n } else {\n setSelectedTime(newValue);\n }\n };\n\n return {\n ...validation,\n value,\n setValue,\n dateValue: selectedDate,\n timeValue: selectedTime,\n setDateValue: selectDate,\n setTimeValue: selectTime,\n granularity,\n hasTime,\n ...overlayState,\n setOpen(isOpen) {\n // Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.\n // If only the time was set and not the date, don't commit. The state will be preserved until\n // the user opens the popover again.\n if (!isOpen && !value && selectedDate && hasTime) {\n commitValue(selectedDate, selectedTime || getPlaceholderTime(props.placeholderValue));\n }\n\n overlayState.setOpen(isOpen);\n },\n validationState,\n isInvalid: isValueInvalid,\n formatValue(locale, fieldOptions) {\n if (!dateValue) {\n return '';\n }\n\n let formatOptions = getFormatOptions(fieldOptions, formatOpts);\n let formatter = new DateFormatter(locale, formatOptions);\n return formatter.format(dateValue);\n }\n };\n}\n"],"names":[],"version":3,"file":"useDatePickerState.module.js.map"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
var $50d5d6a623389320$exports = require("./utils.main.js");
|
|
2
|
+
var $9LYIl$internationalizeddate = require("@internationalized/date");
|
|
3
|
+
var $9LYIl$reactstatelyform = require("@react-stately/form");
|
|
4
|
+
var $9LYIl$reactstatelyoverlays = require("@react-stately/overlays");
|
|
5
|
+
var $9LYIl$reactstatelyutils = require("@react-stately/utils");
|
|
6
|
+
var $9LYIl$react = require("react");
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function $parcel$export(e, n, v, s) {
|
|
10
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
$parcel$export(module.exports, "useDateRangePickerState", () => $7072d26f58deb33b$export$e50a61c1de9f574);
|
|
14
|
+
/*
|
|
15
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
16
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
17
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
18
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
19
|
+
*
|
|
20
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
21
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
22
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
23
|
+
* governing permissions and limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
function $7072d26f58deb33b$export$e50a61c1de9f574(props) {
|
|
31
|
+
var _value_start, _value_end;
|
|
32
|
+
let overlayState = (0, $9LYIl$reactstatelyoverlays.useOverlayTriggerState)(props);
|
|
33
|
+
let [controlledValue, setControlledValue] = (0, $9LYIl$reactstatelyutils.useControlledState)(props.value, props.defaultValue || null, props.onChange);
|
|
34
|
+
let [placeholderValue, setPlaceholderValue] = (0, $9LYIl$react.useState)(()=>controlledValue || {
|
|
35
|
+
start: null,
|
|
36
|
+
end: null
|
|
37
|
+
});
|
|
38
|
+
// Reset the placeholder if the value prop is set to null.
|
|
39
|
+
if (controlledValue == null && placeholderValue.start && placeholderValue.end) {
|
|
40
|
+
placeholderValue = {
|
|
41
|
+
start: null,
|
|
42
|
+
end: null
|
|
43
|
+
};
|
|
44
|
+
setPlaceholderValue(placeholderValue);
|
|
45
|
+
}
|
|
46
|
+
let value = controlledValue || placeholderValue;
|
|
47
|
+
let setValue = (value)=>{
|
|
48
|
+
setPlaceholderValue(value || {
|
|
49
|
+
start: null,
|
|
50
|
+
end: null
|
|
51
|
+
});
|
|
52
|
+
if ((value === null || value === void 0 ? void 0 : value.start) && value.end) setControlledValue(value);
|
|
53
|
+
else setControlledValue(null);
|
|
54
|
+
};
|
|
55
|
+
let v = (value === null || value === void 0 ? void 0 : value.start) || (value === null || value === void 0 ? void 0 : value.end) || props.placeholderValue;
|
|
56
|
+
let [granularity, defaultTimeZone] = (0, $50d5d6a623389320$exports.useDefaultProps)(v, props.granularity);
|
|
57
|
+
let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
|
|
58
|
+
var _props_shouldCloseOnSelect;
|
|
59
|
+
let shouldCloseOnSelect = (_props_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _props_shouldCloseOnSelect !== void 0 ? _props_shouldCloseOnSelect : true;
|
|
60
|
+
let [dateRange, setSelectedDateRange] = (0, $9LYIl$react.useState)(null);
|
|
61
|
+
let [timeRange, setSelectedTimeRange] = (0, $9LYIl$react.useState)(null);
|
|
62
|
+
if (value && value.start && value.end) {
|
|
63
|
+
dateRange = value;
|
|
64
|
+
if ("hour" in value.start) timeRange = value;
|
|
65
|
+
}
|
|
66
|
+
let commitValue = (dateRange, timeRange)=>{
|
|
67
|
+
setValue({
|
|
68
|
+
start: "timeZone" in timeRange.start ? timeRange.start.set((0, $9LYIl$internationalizeddate.toCalendarDate)(dateRange.start)) : (0, $9LYIl$internationalizeddate.toCalendarDateTime)(dateRange.start, timeRange.start),
|
|
69
|
+
end: "timeZone" in timeRange.end ? timeRange.end.set((0, $9LYIl$internationalizeddate.toCalendarDate)(dateRange.end)) : (0, $9LYIl$internationalizeddate.toCalendarDateTime)(dateRange.end, timeRange.end)
|
|
70
|
+
});
|
|
71
|
+
setSelectedDateRange(null);
|
|
72
|
+
setSelectedTimeRange(null);
|
|
73
|
+
validation.commitValidation();
|
|
74
|
+
};
|
|
75
|
+
// Intercept setValue to make sure the Time section is not changed by date selection in Calendar
|
|
76
|
+
let setDateRange = (range)=>{
|
|
77
|
+
let shouldClose = typeof shouldCloseOnSelect === "function" ? shouldCloseOnSelect() : shouldCloseOnSelect;
|
|
78
|
+
if (hasTime) {
|
|
79
|
+
if (shouldClose || range.start && range.end && (timeRange === null || timeRange === void 0 ? void 0 : timeRange.start) && (timeRange === null || timeRange === void 0 ? void 0 : timeRange.end)) commitValue(range, {
|
|
80
|
+
start: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.start) || (0, $50d5d6a623389320$exports.getPlaceholderTime)(props.placeholderValue),
|
|
81
|
+
end: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.end) || (0, $50d5d6a623389320$exports.getPlaceholderTime)(props.placeholderValue)
|
|
82
|
+
});
|
|
83
|
+
else setSelectedDateRange(range);
|
|
84
|
+
} else if (range.start && range.end) {
|
|
85
|
+
setValue(range);
|
|
86
|
+
validation.commitValidation();
|
|
87
|
+
} else setSelectedDateRange(range);
|
|
88
|
+
if (shouldClose) overlayState.setOpen(false);
|
|
89
|
+
};
|
|
90
|
+
let setTimeRange = (range)=>{
|
|
91
|
+
if ((dateRange === null || dateRange === void 0 ? void 0 : dateRange.start) && (dateRange === null || dateRange === void 0 ? void 0 : dateRange.end) && range.start && range.end) commitValue(dateRange, range);
|
|
92
|
+
else setSelectedTimeRange(range);
|
|
93
|
+
};
|
|
94
|
+
let showEra = (value === null || value === void 0 ? void 0 : (_value_start = value.start) === null || _value_start === void 0 ? void 0 : _value_start.calendar.identifier) === "gregory" && value.start.era === "BC" || (value === null || value === void 0 ? void 0 : (_value_end = value.end) === null || _value_end === void 0 ? void 0 : _value_end.calendar.identifier) === "gregory" && value.end.era === "BC";
|
|
95
|
+
let formatOpts = (0, $9LYIl$react.useMemo)(()=>({
|
|
96
|
+
granularity: granularity,
|
|
97
|
+
timeZone: defaultTimeZone,
|
|
98
|
+
hideTimeZone: props.hideTimeZone,
|
|
99
|
+
hourCycle: props.hourCycle,
|
|
100
|
+
shouldForceLeadingZeros: props.shouldForceLeadingZeros,
|
|
101
|
+
showEra: showEra
|
|
102
|
+
}), [
|
|
103
|
+
granularity,
|
|
104
|
+
props.hourCycle,
|
|
105
|
+
props.shouldForceLeadingZeros,
|
|
106
|
+
defaultTimeZone,
|
|
107
|
+
props.hideTimeZone,
|
|
108
|
+
showEra
|
|
109
|
+
]);
|
|
110
|
+
let { minValue: minValue, maxValue: maxValue, isDateUnavailable: isDateUnavailable } = props;
|
|
111
|
+
let builtinValidation = (0, $9LYIl$react.useMemo)(()=>(0, $50d5d6a623389320$exports.getRangeValidationResult)(value, minValue, maxValue, isDateUnavailable, formatOpts), [
|
|
112
|
+
value,
|
|
113
|
+
minValue,
|
|
114
|
+
maxValue,
|
|
115
|
+
isDateUnavailable,
|
|
116
|
+
formatOpts
|
|
117
|
+
]);
|
|
118
|
+
let validation = (0, $9LYIl$reactstatelyform.useFormValidationState)({
|
|
119
|
+
...props,
|
|
120
|
+
value: controlledValue,
|
|
121
|
+
name: (0, $9LYIl$react.useMemo)(()=>[
|
|
122
|
+
props.startName,
|
|
123
|
+
props.endName
|
|
124
|
+
], [
|
|
125
|
+
props.startName,
|
|
126
|
+
props.endName
|
|
127
|
+
]),
|
|
128
|
+
builtinValidation: builtinValidation
|
|
129
|
+
});
|
|
130
|
+
let isValueInvalid = validation.displayValidation.isInvalid;
|
|
131
|
+
let validationState = props.validationState || (isValueInvalid ? "invalid" : null);
|
|
132
|
+
return {
|
|
133
|
+
...validation,
|
|
134
|
+
value: value,
|
|
135
|
+
setValue: setValue,
|
|
136
|
+
dateRange: dateRange,
|
|
137
|
+
timeRange: timeRange,
|
|
138
|
+
granularity: granularity,
|
|
139
|
+
hasTime: hasTime,
|
|
140
|
+
setDate (part, date) {
|
|
141
|
+
setDateRange({
|
|
142
|
+
...dateRange,
|
|
143
|
+
[part]: date
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
setTime (part, time) {
|
|
147
|
+
setTimeRange({
|
|
148
|
+
...timeRange,
|
|
149
|
+
[part]: time
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
setDateTime (part, dateTime) {
|
|
153
|
+
setValue({
|
|
154
|
+
...value,
|
|
155
|
+
[part]: dateTime
|
|
156
|
+
});
|
|
157
|
+
},
|
|
158
|
+
setDateRange: setDateRange,
|
|
159
|
+
setTimeRange: setTimeRange,
|
|
160
|
+
...overlayState,
|
|
161
|
+
setOpen (isOpen) {
|
|
162
|
+
// Commit the selected date range when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
163
|
+
// If only the time range was set and not the date range, don't commit. The state will be preserved until
|
|
164
|
+
// the user opens the popover again.
|
|
165
|
+
if (!isOpen && !((value === null || value === void 0 ? void 0 : value.start) && (value === null || value === void 0 ? void 0 : value.end)) && (dateRange === null || dateRange === void 0 ? void 0 : dateRange.start) && (dateRange === null || dateRange === void 0 ? void 0 : dateRange.end) && hasTime) commitValue(dateRange, {
|
|
166
|
+
start: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.start) || (0, $50d5d6a623389320$exports.getPlaceholderTime)(props.placeholderValue),
|
|
167
|
+
end: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.end) || (0, $50d5d6a623389320$exports.getPlaceholderTime)(props.placeholderValue)
|
|
168
|
+
});
|
|
169
|
+
overlayState.setOpen(isOpen);
|
|
170
|
+
},
|
|
171
|
+
validationState: validationState,
|
|
172
|
+
isInvalid: isValueInvalid,
|
|
173
|
+
formatValue (locale, fieldOptions) {
|
|
174
|
+
if (!value || !value.start || !value.end) return null;
|
|
175
|
+
let startTimeZone = "timeZone" in value.start ? value.start.timeZone : undefined;
|
|
176
|
+
let startGranularity = props.granularity || (value.start && "minute" in value.start ? "minute" : "day");
|
|
177
|
+
let endTimeZone = "timeZone" in value.end ? value.end.timeZone : undefined;
|
|
178
|
+
let endGranularity = props.granularity || (value.end && "minute" in value.end ? "minute" : "day");
|
|
179
|
+
let startOptions = (0, $50d5d6a623389320$exports.getFormatOptions)(fieldOptions, {
|
|
180
|
+
granularity: startGranularity,
|
|
181
|
+
timeZone: startTimeZone,
|
|
182
|
+
hideTimeZone: props.hideTimeZone,
|
|
183
|
+
hourCycle: props.hourCycle,
|
|
184
|
+
showEra: value.start.calendar.identifier === "gregory" && value.start.era === "BC" || value.end.calendar.identifier === "gregory" && value.end.era === "BC"
|
|
185
|
+
});
|
|
186
|
+
let startDate = value.start.toDate(startTimeZone || "UTC");
|
|
187
|
+
let endDate = value.end.toDate(endTimeZone || "UTC");
|
|
188
|
+
let startFormatter = new (0, $9LYIl$internationalizeddate.DateFormatter)(locale, startOptions);
|
|
189
|
+
let endFormatter;
|
|
190
|
+
if (startTimeZone === endTimeZone && startGranularity === endGranularity && value.start.compare(value.end) !== 0) {
|
|
191
|
+
// Use formatRange, as it results in shorter output when some of the fields
|
|
192
|
+
// are shared between the start and end dates (e.g. the same month).
|
|
193
|
+
// Formatting will fail if the end date is before the start date. Fall back below when that happens.
|
|
194
|
+
try {
|
|
195
|
+
let parts = startFormatter.formatRangeToParts(startDate, endDate);
|
|
196
|
+
// Find the separator between the start and end date. This is determined
|
|
197
|
+
// by finding the last shared literal before the end range.
|
|
198
|
+
let separatorIndex = -1;
|
|
199
|
+
for(let i = 0; i < parts.length; i++){
|
|
200
|
+
let part = parts[i];
|
|
201
|
+
if (part.source === "shared" && part.type === "literal") separatorIndex = i;
|
|
202
|
+
else if (part.source === "endRange") break;
|
|
203
|
+
}
|
|
204
|
+
// Now we can combine the parts into start and end strings.
|
|
205
|
+
let start = "";
|
|
206
|
+
let end = "";
|
|
207
|
+
for(let i = 0; i < parts.length; i++){
|
|
208
|
+
if (i < separatorIndex) start += parts[i].value;
|
|
209
|
+
else if (i > separatorIndex) end += parts[i].value;
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
start: start,
|
|
213
|
+
end: end
|
|
214
|
+
};
|
|
215
|
+
} catch (e) {
|
|
216
|
+
// ignore
|
|
217
|
+
}
|
|
218
|
+
endFormatter = startFormatter;
|
|
219
|
+
} else {
|
|
220
|
+
let endOptions = (0, $50d5d6a623389320$exports.getFormatOptions)(fieldOptions, {
|
|
221
|
+
granularity: endGranularity,
|
|
222
|
+
timeZone: endTimeZone,
|
|
223
|
+
hideTimeZone: props.hideTimeZone,
|
|
224
|
+
hourCycle: props.hourCycle
|
|
225
|
+
});
|
|
226
|
+
endFormatter = new (0, $9LYIl$internationalizeddate.DateFormatter)(locale, endOptions);
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
start: startFormatter.format(startDate),
|
|
230
|
+
end: endFormatter.format(endDate)
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+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AC,KAAK;6BAClB,IAAI,IAAI,gBACb,OAAO,KAAK,CAAC,EAAE,CAAC,KAAK;oBAEzB;oBAEA,OAAO;+BAAC;6BAAO;oBAAG;gBACpB,EAAE,OAAO,GAAG;gBACV,SAAS;gBACX;gBAEA,eAAe;YACjB,OAAO;gBACL,IAAI,aAAa,CAAA,GAAA,0CAAe,EAAE,cAAc;oBAC9C,aAAa;oBACb,UAAU;oBACV,cAAc,MAAM,YAAY;oBAChC,WAAW,MAAM,SAAS;gBAC5B;gBAEA,eAAe,IAAI,CAAA,GAAA,0CAAY,EAAE,QAAQ;YAC3C;YAEA,OAAO;gBACL,OAAO,eAAe,MAAM,CAAC;gBAC7B,KAAK,aAAa,MAAM,CAAC;YAC3B;QACF;IACF;AACF","sources":["packages/@react-stately/datepicker/src/useDateRangePickerState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DateFormatter, toCalendarDate, toCalendarDateTime} from '@internationalized/date';\nimport {DateRange, DateRangePickerProps, DateValue, Granularity, TimeValue} from '@react-types/datepicker';\nimport {FieldOptions, getFormatOptions, getPlaceholderTime, getRangeValidationResult, useDefaultProps} from './utils';\nimport {FormValidationState, useFormValidationState} from '@react-stately/form';\nimport {OverlayTriggerState, useOverlayTriggerState} from '@react-stately/overlays';\nimport {RangeValue, ValidationState} from '@react-types/shared';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\n\nexport interface DateRangePickerStateOptions<T extends DateValue = DateValue> extends DateRangePickerProps<T> {\n /**\n * Determines whether the date picker popover should close automatically when a date is selected.\n * @default true\n */\n shouldCloseOnSelect?: boolean | (() => boolean)\n}\n\ntype TimeRange = RangeValue<TimeValue>;\nexport interface DateRangePickerState extends OverlayTriggerState, FormValidationState {\n /** The currently selected date range. */\n value: DateRange | null,\n /** Sets the selected date range. */\n setValue(value: DateRange | null): void,\n /**\n * The date portion of the selected range. This may be set prior to `value` if the user has\n * selected a date range but has not yet selected a time range.\n */\n dateRange: DateRange | null,\n /** Sets the date portion of the selected range. */\n setDateRange(value: DateRange): void,\n /**\n * The time portion of the selected range. This may be set prior to `value` if the user has\n * selected a time range but has not yet selected a date range.\n */\n timeRange: TimeRange | null,\n /** Sets the time portion of the selected range. */\n setTimeRange(value: TimeRange): void,\n /** Sets the date portion of either the start or end of the selected range. */\n setDate(part: 'start' | 'end', value: DateValue): void,\n /** Sets the time portion of either the start or end of the selected range. */\n setTime(part: 'start' | 'end', value: TimeValue): void,\n /** Sets the date and time of either the start or end of the selected range. */\n setDateTime(part: 'start' | 'end', value: DateValue): void,\n /** The granularity for the field, based on the `granularity` prop and current value. */\n granularity: Granularity,\n /** Whether the date range picker supports selecting times, according to the `granularity` prop and current value. */\n hasTime: boolean,\n /** Whether the calendar popover is currently open. */\n isOpen: boolean,\n /** Sets whether the calendar popover is open. */\n setOpen(isOpen: boolean): void,\n /**\n * The current validation state of the date range picker, based on the `validationState`, `minValue`, and `maxValue` props.\n * @deprecated Use `isInvalid` instead.\n */\n validationState: ValidationState,\n /** Whether the date range picker is invalid, based on the `isInvalid`, `minValue`, and `maxValue` props. */\n isInvalid: boolean,\n /** Formats the selected range using the given options. */\n formatValue(locale: string, fieldOptions: FieldOptions): {start: string, end: string}\n}\n\n/**\n * Provides state management for a date range picker component.\n * A date range picker combines two DateFields and a RangeCalendar popover to allow\n * users to enter or select a date and time range.\n */\nexport function useDateRangePickerState<T extends DateValue = DateValue>(props: DateRangePickerStateOptions<T>): DateRangePickerState {\n let overlayState = useOverlayTriggerState(props);\n let [controlledValue, setControlledValue] = useControlledState<DateRange>(props.value, props.defaultValue || null, props.onChange);\n let [placeholderValue, setPlaceholderValue] = useState(() => controlledValue || {start: null, end: null});\n\n // Reset the placeholder if the value prop is set to null.\n if (controlledValue == null && placeholderValue.start && placeholderValue.end) {\n placeholderValue = {start: null, end: null};\n setPlaceholderValue(placeholderValue);\n }\n\n let value = controlledValue || placeholderValue;\n\n let setValue = (value: DateRange) => {\n setPlaceholderValue(value || {start: null, end: null});\n if (value?.start && value.end) {\n setControlledValue(value);\n } else {\n setControlledValue(null);\n }\n };\n\n let v = (value?.start || value?.end || props.placeholderValue);\n let [granularity, defaultTimeZone] = useDefaultProps(v, props.granularity);\n let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second';\n let shouldCloseOnSelect = props.shouldCloseOnSelect ?? true;\n\n let [dateRange, setSelectedDateRange] = useState<DateRange>(null);\n let [timeRange, setSelectedTimeRange] = useState<TimeRange>(null);\n\n if (value && value.start && value.end) {\n dateRange = value;\n if ('hour' in value.start) {\n timeRange = value as TimeRange;\n }\n }\n\n let commitValue = (dateRange: DateRange, timeRange: TimeRange) => {\n setValue({\n start: 'timeZone' in timeRange.start ? timeRange.start.set(toCalendarDate(dateRange.start)) : toCalendarDateTime(dateRange.start, timeRange.start),\n end: 'timeZone' in timeRange.end ? timeRange.end.set(toCalendarDate(dateRange.end)) : toCalendarDateTime(dateRange.end, timeRange.end)\n });\n setSelectedDateRange(null);\n setSelectedTimeRange(null);\n validation.commitValidation();\n };\n\n // Intercept setValue to make sure the Time section is not changed by date selection in Calendar\n let setDateRange = (range: DateRange) => {\n let shouldClose = typeof shouldCloseOnSelect === 'function' ? shouldCloseOnSelect() : shouldCloseOnSelect;\n if (hasTime) {\n if (shouldClose || (range.start && range.end && timeRange?.start && timeRange?.end)) {\n commitValue(range, {\n start: timeRange?.start || getPlaceholderTime(props.placeholderValue),\n end: timeRange?.end || getPlaceholderTime(props.placeholderValue)\n });\n } else {\n setSelectedDateRange(range);\n }\n } else if (range.start && range.end) {\n setValue(range);\n validation.commitValidation();\n } else {\n setSelectedDateRange(range);\n }\n\n if (shouldClose) {\n overlayState.setOpen(false);\n }\n };\n\n let setTimeRange = (range: TimeRange) => {\n if (dateRange?.start && dateRange?.end && range.start && range.end) {\n commitValue(dateRange, range);\n } else {\n setSelectedTimeRange(range);\n }\n };\n\n let showEra = (value?.start?.calendar.identifier === 'gregory' && value.start.era === 'BC') || (value?.end?.calendar.identifier === 'gregory' && value.end.era === 'BC');\n let formatOpts = useMemo(() => ({\n granularity,\n timeZone: defaultTimeZone,\n hideTimeZone: props.hideTimeZone,\n hourCycle: props.hourCycle,\n shouldForceLeadingZeros: props.shouldForceLeadingZeros,\n showEra\n }), [granularity, props.hourCycle, props.shouldForceLeadingZeros, defaultTimeZone, props.hideTimeZone, showEra]);\n\n let {minValue, maxValue, isDateUnavailable} = props;\n let builtinValidation = useMemo(() => getRangeValidationResult(\n value,\n minValue,\n maxValue,\n isDateUnavailable,\n formatOpts\n ), [value, minValue, maxValue, isDateUnavailable, formatOpts]);\n\n let validation = useFormValidationState({\n ...props,\n value: controlledValue,\n name: useMemo(() => [props.startName, props.endName], [props.startName, props.endName]),\n builtinValidation\n });\n\n let isValueInvalid = validation.displayValidation.isInvalid;\n let validationState: ValidationState = props.validationState || (isValueInvalid ? 'invalid' : null);\n\n return {\n ...validation,\n value,\n setValue,\n dateRange,\n timeRange,\n granularity,\n hasTime,\n setDate(part, date) {\n setDateRange({...dateRange, [part]: date});\n },\n setTime(part, time) {\n setTimeRange({...timeRange, [part]: time});\n },\n setDateTime(part, dateTime) {\n setValue({...value, [part]: dateTime});\n },\n setDateRange,\n setTimeRange,\n ...overlayState,\n setOpen(isOpen) {\n // Commit the selected date range when the calendar is closed. Use a placeholder time if one wasn't set.\n // If only the time range was set and not the date range, don't commit. The state will be preserved until\n // the user opens the popover again.\n if (!isOpen && !(value?.start && value?.end) && dateRange?.start && dateRange?.end && hasTime) {\n commitValue(dateRange, {\n start: timeRange?.start || getPlaceholderTime(props.placeholderValue),\n end: timeRange?.end || getPlaceholderTime(props.placeholderValue)\n });\n }\n\n overlayState.setOpen(isOpen);\n },\n validationState,\n isInvalid: isValueInvalid,\n formatValue(locale, fieldOptions) {\n if (!value || !value.start || !value.end) {\n return null;\n }\n\n let startTimeZone = 'timeZone' in value.start ? value.start.timeZone : undefined;\n let startGranularity = props.granularity || (value.start && 'minute' in value.start ? 'minute' : 'day');\n let endTimeZone = 'timeZone' in value.end ? value.end.timeZone : undefined;\n let endGranularity = props.granularity || (value.end && 'minute' in value.end ? 'minute' : 'day');\n\n let startOptions = getFormatOptions(fieldOptions, {\n granularity: startGranularity,\n timeZone: startTimeZone,\n hideTimeZone: props.hideTimeZone,\n hourCycle: props.hourCycle,\n showEra: (value.start.calendar.identifier === 'gregory' && value.start.era === 'BC') ||\n (value.end.calendar.identifier === 'gregory' && value.end.era === 'BC')\n });\n\n let startDate = value.start.toDate(startTimeZone || 'UTC');\n let endDate = value.end.toDate(endTimeZone || 'UTC');\n\n let startFormatter = new DateFormatter(locale, startOptions);\n let endFormatter: Intl.DateTimeFormat;\n if (startTimeZone === endTimeZone && startGranularity === endGranularity && value.start.compare(value.end) !== 0) {\n // Use formatRange, as it results in shorter output when some of the fields\n // are shared between the start and end dates (e.g. the same month).\n // Formatting will fail if the end date is before the start date. Fall back below when that happens.\n try {\n let parts = startFormatter.formatRangeToParts(startDate, endDate);\n\n // Find the separator between the start and end date. This is determined\n // by finding the last shared literal before the end range.\n let separatorIndex = -1;\n for (let i = 0; i < parts.length; i++) {\n let part = parts[i];\n if (part.source === 'shared' && part.type === 'literal') {\n separatorIndex = i;\n } else if (part.source === 'endRange') {\n break;\n }\n }\n\n // Now we can combine the parts into start and end strings.\n let start = '';\n let end = '';\n for (let i = 0; i < parts.length; i++) {\n if (i < separatorIndex) {\n start += parts[i].value;\n } else if (i > separatorIndex) {\n end += parts[i].value;\n }\n }\n\n return {start, end};\n } catch (e) {\n // ignore\n }\n\n endFormatter = startFormatter;\n } else {\n let endOptions = getFormatOptions(fieldOptions, {\n granularity: endGranularity,\n timeZone: endTimeZone,\n hideTimeZone: props.hideTimeZone,\n hourCycle: props.hourCycle\n });\n\n endFormatter = new DateFormatter(locale, endOptions);\n }\n\n return {\n start: startFormatter.format(startDate),\n end: endFormatter.format(endDate)\n };\n }\n };\n}\n"],"names":[],"version":3,"file":"useDateRangePickerState.main.js.map"}
|