@react-stately/datepicker 3.0.0-alpha.3 → 3.0.0-alpha.4
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/main.js +137 -116
- package/dist/main.js.map +1 -1
- package/dist/module.js +134 -113
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +159 -33
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +1 -1
- package/src/{useDatePickerFieldState.ts → useDateFieldState.ts} +86 -18
- package/src/useDatePickerState.ts +48 -13
- package/src/useDateRangePickerState.ts +61 -17
- package/src/useTimeFieldState.ts +15 -8
package/dist/module.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {useControlledState as $
|
|
3
|
-
import {useState as $
|
|
1
|
+
import {toCalendarDate as $7UzoM$toCalendarDate, toCalendarDateTime as $7UzoM$toCalendarDateTime, DateFormatter as $7UzoM$DateFormatter, Time as $7UzoM$Time, toCalendar as $7UzoM$toCalendar, now as $7UzoM$now, GregorianCalendar as $7UzoM$GregorianCalendar, getMinimumMonthInYear as $7UzoM$getMinimumMonthInYear, getMinimumDayInMonth as $7UzoM$getMinimumDayInMonth, toTime as $7UzoM$toTime, today as $7UzoM$today, getLocalTimeZone as $7UzoM$getLocalTimeZone} from "@internationalized/date";
|
|
2
|
+
import {useControlledState as $7UzoM$useControlledState} from "@react-stately/utils";
|
|
3
|
+
import {useState as $7UzoM$useState, useRef as $7UzoM$useRef, useMemo as $7UzoM$useMemo, useEffect as $7UzoM$useEffect} from "react";
|
|
4
4
|
|
|
5
5
|
function $parcel$export(e, n, v, s) {
|
|
6
6
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
7
|
}
|
|
8
|
-
var $
|
|
8
|
+
var $ab5bf3f618090389$exports = {};
|
|
9
9
|
|
|
10
|
-
$parcel$export($
|
|
10
|
+
$parcel$export($ab5bf3f618090389$exports, "useDatePickerState", () => $ab5bf3f618090389$export$87194bb378cc3ac2);
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
function $
|
|
14
|
+
function $35a22f14a1f04b11$export$eac50920cf2fd59a(value, minValue, maxValue) {
|
|
15
15
|
return value != null && (minValue != null && value.compare(minValue) < 0 || maxValue != null && value.compare(maxValue) > 0);
|
|
16
16
|
}
|
|
17
|
-
const $
|
|
17
|
+
const $35a22f14a1f04b11$var$DEFAULT_FIELD_OPTIONS = {
|
|
18
18
|
year: 'numeric',
|
|
19
19
|
month: 'numeric',
|
|
20
20
|
day: 'numeric',
|
|
@@ -22,9 +22,9 @@ const $64af0ac69b0f6b87$var$DEFAULT_FIELD_OPTIONS = {
|
|
|
22
22
|
minute: '2-digit',
|
|
23
23
|
second: '2-digit'
|
|
24
24
|
};
|
|
25
|
-
function $
|
|
25
|
+
function $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, options) {
|
|
26
26
|
fieldOptions = {
|
|
27
|
-
...$
|
|
27
|
+
...$35a22f14a1f04b11$var$DEFAULT_FIELD_OPTIONS,
|
|
28
28
|
...fieldOptions
|
|
29
29
|
};
|
|
30
30
|
let granularity = options.granularity || 'minute';
|
|
@@ -46,30 +46,30 @@ function $64af0ac69b0f6b87$export$7e319ea407e63bc0(fieldOptions, options) {
|
|
|
46
46
|
if (hasTime && options.timeZone && !options.hideTimeZone) opts1.timeZoneName = 'short';
|
|
47
47
|
return opts1;
|
|
48
48
|
}
|
|
49
|
-
function $
|
|
49
|
+
function $35a22f14a1f04b11$export$c5221a78ef73c5e9(placeholderValue) {
|
|
50
50
|
if (placeholderValue && 'hour' in placeholderValue) return placeholderValue;
|
|
51
|
-
return new $
|
|
51
|
+
return new $7UzoM$Time();
|
|
52
52
|
}
|
|
53
|
-
function $
|
|
53
|
+
function $35a22f14a1f04b11$export$61a490a80c552550(value, calendar) {
|
|
54
54
|
if (value === null) return null;
|
|
55
55
|
if (!value) return undefined;
|
|
56
|
-
return $
|
|
56
|
+
return $7UzoM$toCalendar(value, calendar);
|
|
57
57
|
}
|
|
58
|
-
function $
|
|
59
|
-
if (placeholderValue) return $
|
|
60
|
-
let date = $
|
|
58
|
+
function $35a22f14a1f04b11$export$66aa2b09de4b1ea5(placeholderValue, granularity, calendar, timeZone) {
|
|
59
|
+
if (placeholderValue) return $35a22f14a1f04b11$export$61a490a80c552550(placeholderValue, calendar);
|
|
60
|
+
let date = $7UzoM$toCalendar($7UzoM$now(timeZone).set({
|
|
61
61
|
hour: 0,
|
|
62
62
|
minute: 0,
|
|
63
63
|
second: 0,
|
|
64
64
|
millisecond: 0
|
|
65
65
|
}), calendar);
|
|
66
|
-
if (granularity === 'year' || granularity === 'month' || granularity === 'day') return $
|
|
67
|
-
if (!timeZone) return $
|
|
66
|
+
if (granularity === 'year' || granularity === 'month' || granularity === 'day') return $7UzoM$toCalendarDate(date);
|
|
67
|
+
if (!timeZone) return $7UzoM$toCalendarDateTime(date);
|
|
68
68
|
return date;
|
|
69
69
|
}
|
|
70
|
-
function $
|
|
70
|
+
function $35a22f14a1f04b11$export$2440da353cedad43(v, granularity) {
|
|
71
71
|
// Compute default granularity and time zone from the value. If the value becomes null, keep the last values.
|
|
72
|
-
let lastValue = $
|
|
72
|
+
let lastValue = $7UzoM$useRef(v);
|
|
73
73
|
if (v) lastValue.current = v;
|
|
74
74
|
v = lastValue.current;
|
|
75
75
|
let defaultTimeZone = v && 'timeZone' in v ? v.timeZone : undefined;
|
|
@@ -86,15 +86,18 @@ function $64af0ac69b0f6b87$export$2440da353cedad43(v, granularity) {
|
|
|
86
86
|
|
|
87
87
|
|
|
88
88
|
|
|
89
|
-
function $
|
|
90
|
-
|
|
91
|
-
let [
|
|
89
|
+
function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
90
|
+
var ref;
|
|
91
|
+
let [isOpen1, setOpen] = $7UzoM$useState(false);
|
|
92
|
+
let [value, setValue] = $7UzoM$useControlledState(props.value, props.defaultValue || null, props.onChange);
|
|
92
93
|
let v = value || props.placeholderValue;
|
|
93
|
-
let [granularity, defaultTimeZone] = $
|
|
94
|
+
let [granularity, defaultTimeZone] = $35a22f14a1f04b11$export$2440da353cedad43(v, props.granularity);
|
|
94
95
|
let dateValue = value != null ? value.toDate(defaultTimeZone !== null && defaultTimeZone !== void 0 ? defaultTimeZone : 'UTC') : null;
|
|
95
96
|
let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second' || granularity === 'millisecond';
|
|
96
|
-
|
|
97
|
-
let
|
|
97
|
+
var _shouldCloseOnSelect;
|
|
98
|
+
let shouldCloseOnSelect = (_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _shouldCloseOnSelect !== void 0 ? _shouldCloseOnSelect : true;
|
|
99
|
+
let [selectedDate, setSelectedDate] = $7UzoM$useState(null);
|
|
100
|
+
let [selectedTime, setSelectedTime] = $7UzoM$useState(null);
|
|
98
101
|
if (value) {
|
|
99
102
|
selectedDate = value;
|
|
100
103
|
if ('hour' in value) selectedTime = value;
|
|
@@ -102,21 +105,22 @@ function $1c592026c7d68d73$export$87194bb378cc3ac2(props) {
|
|
|
102
105
|
// props.granularity must actually exist in the value if one is provided.
|
|
103
106
|
if (v && !(granularity in v)) throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());
|
|
104
107
|
let commitValue = (date, time)=>{
|
|
105
|
-
setValue('timeZone' in time ? time.set($
|
|
108
|
+
setValue('timeZone' in time ? time.set($7UzoM$toCalendarDate(date)) : $7UzoM$toCalendarDateTime(date, time));
|
|
106
109
|
};
|
|
107
110
|
// Intercept setValue to make sure the Time section is not changed by date selection in Calendar
|
|
108
111
|
let selectDate = (newValue)=>{
|
|
112
|
+
let shouldClose = typeof shouldCloseOnSelect === 'function' ? shouldCloseOnSelect() : shouldCloseOnSelect;
|
|
109
113
|
if (hasTime) {
|
|
110
|
-
if (selectedTime) commitValue(newValue, selectedTime);
|
|
114
|
+
if (selectedTime || shouldClose) commitValue(newValue, selectedTime || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue));
|
|
111
115
|
else setSelectedDate(newValue);
|
|
112
116
|
} else setValue(newValue);
|
|
113
|
-
if (
|
|
117
|
+
if (shouldClose) setOpen(false);
|
|
114
118
|
};
|
|
115
119
|
let selectTime = (newValue)=>{
|
|
116
120
|
if (selectedDate) commitValue(selectedDate, newValue);
|
|
117
121
|
else setSelectedTime(newValue);
|
|
118
122
|
};
|
|
119
|
-
let validationState = props.validationState || ($
|
|
123
|
+
let validationState = props.validationState || ($35a22f14a1f04b11$export$eac50920cf2fd59a(value, props.minValue, props.maxValue) ? 'invalid' : null) || (value && ((ref = props.isDateUnavailable) === null || ref === void 0 ? void 0 : ref.call(props, value)) ? 'invalid' : null);
|
|
120
124
|
return {
|
|
121
125
|
value: value,
|
|
122
126
|
setValue: setValue,
|
|
@@ -125,38 +129,39 @@ function $1c592026c7d68d73$export$87194bb378cc3ac2(props) {
|
|
|
125
129
|
setDateValue: selectDate,
|
|
126
130
|
setTimeValue: selectTime,
|
|
127
131
|
granularity: granularity,
|
|
132
|
+
hasTime: hasTime,
|
|
128
133
|
isOpen: isOpen1,
|
|
129
134
|
setOpen (isOpen) {
|
|
130
135
|
// Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
131
136
|
// If only the time was set and not the date, don't commit. The state will be preserved until
|
|
132
137
|
// the user opens the popover again.
|
|
133
|
-
if (!isOpen && !value && selectedDate && hasTime) commitValue(selectedDate, selectedTime || $
|
|
138
|
+
if (!isOpen && !value && selectedDate && hasTime) commitValue(selectedDate, selectedTime || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue));
|
|
134
139
|
setOpen(isOpen);
|
|
135
140
|
},
|
|
136
141
|
validationState: validationState,
|
|
137
142
|
formatValue (locale, fieldOptions) {
|
|
138
143
|
if (!dateValue) return '';
|
|
139
|
-
let formatOptions = $
|
|
144
|
+
let formatOptions = $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, {
|
|
140
145
|
granularity: granularity,
|
|
141
146
|
timeZone: defaultTimeZone,
|
|
142
147
|
hideTimeZone: props.hideTimeZone,
|
|
143
148
|
hourCycle: props.hourCycle
|
|
144
149
|
});
|
|
145
|
-
let formatter = new $
|
|
150
|
+
let formatter = new $7UzoM$DateFormatter(locale, formatOptions);
|
|
146
151
|
return formatter.format(dateValue);
|
|
147
152
|
}
|
|
148
153
|
};
|
|
149
154
|
}
|
|
150
155
|
|
|
151
156
|
|
|
152
|
-
var $
|
|
157
|
+
var $3c0fc76039f1c516$exports = {};
|
|
153
158
|
|
|
154
|
-
$parcel$export($
|
|
159
|
+
$parcel$export($3c0fc76039f1c516$exports, "useDateFieldState", () => $3c0fc76039f1c516$export$60e84778edff6d26);
|
|
155
160
|
|
|
156
161
|
|
|
157
162
|
|
|
158
163
|
|
|
159
|
-
const $
|
|
164
|
+
const $3c0fc76039f1c516$var$EDITABLE_SEGMENTS = {
|
|
160
165
|
year: true,
|
|
161
166
|
month: true,
|
|
162
167
|
day: true,
|
|
@@ -166,7 +171,7 @@ const $a80b84f02ae54764$var$EDITABLE_SEGMENTS = {
|
|
|
166
171
|
dayPeriod: true,
|
|
167
172
|
era: true
|
|
168
173
|
};
|
|
169
|
-
const $
|
|
174
|
+
const $3c0fc76039f1c516$var$PAGE_STEP = {
|
|
170
175
|
year: 5,
|
|
171
176
|
month: 2,
|
|
172
177
|
day: 7,
|
|
@@ -175,18 +180,18 @@ const $a80b84f02ae54764$var$PAGE_STEP = {
|
|
|
175
180
|
second: 15
|
|
176
181
|
};
|
|
177
182
|
// Node seems to convert everything to lowercase...
|
|
178
|
-
const $
|
|
183
|
+
const $3c0fc76039f1c516$var$TYPE_MAPPING = {
|
|
179
184
|
dayperiod: 'dayPeriod'
|
|
180
185
|
};
|
|
181
|
-
function $
|
|
182
|
-
let { locale: locale , createCalendar: createCalendar , hideTimeZone: hideTimeZone } = props;
|
|
186
|
+
function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
|
|
187
|
+
let { locale: locale , createCalendar: createCalendar , hideTimeZone: hideTimeZone , isDisabled: isDisabled , isReadOnly: isReadOnly , isRequired: isRequired } = props;
|
|
183
188
|
let v1 = props.value || props.defaultValue || props.placeholderValue;
|
|
184
|
-
let [granularity, defaultTimeZone] = $
|
|
189
|
+
let [granularity, defaultTimeZone] = $35a22f14a1f04b11$export$2440da353cedad43(v1, props.granularity);
|
|
185
190
|
let timeZone = defaultTimeZone || 'UTC';
|
|
186
191
|
// props.granularity must actually exist in the value if one is provided.
|
|
187
192
|
if (v1 && !(granularity in v1)) throw new Error('Invalid granularity ' + granularity + ' for value ' + v1.toString());
|
|
188
193
|
var _maxGranularity;
|
|
189
|
-
let formatOpts = $
|
|
194
|
+
let formatOpts = $7UzoM$useMemo(()=>({
|
|
190
195
|
granularity: granularity,
|
|
191
196
|
maxGranularity: (_maxGranularity = props.maxGranularity) !== null && _maxGranularity !== void 0 ? _maxGranularity : 'year',
|
|
192
197
|
timeZone: defaultTimeZone,
|
|
@@ -200,35 +205,35 @@ function $a80b84f02ae54764$export$714a241b39a650d6(props) {
|
|
|
200
205
|
defaultTimeZone,
|
|
201
206
|
hideTimeZone
|
|
202
207
|
]);
|
|
203
|
-
let opts = $
|
|
208
|
+
let opts = $7UzoM$useMemo(()=>$35a22f14a1f04b11$export$7e319ea407e63bc0({
|
|
204
209
|
}, formatOpts)
|
|
205
210
|
, [
|
|
206
211
|
formatOpts
|
|
207
212
|
]);
|
|
208
|
-
let dateFormatter = $
|
|
213
|
+
let dateFormatter = $7UzoM$useMemo(()=>new $7UzoM$DateFormatter(locale, opts)
|
|
209
214
|
, [
|
|
210
215
|
locale,
|
|
211
216
|
opts
|
|
212
217
|
]);
|
|
213
|
-
let resolvedOptions = $
|
|
218
|
+
let resolvedOptions = $7UzoM$useMemo(()=>dateFormatter.resolvedOptions()
|
|
214
219
|
, [
|
|
215
220
|
dateFormatter
|
|
216
221
|
]);
|
|
217
|
-
let calendar = $
|
|
222
|
+
let calendar = $7UzoM$useMemo(()=>createCalendar(resolvedOptions.calendar)
|
|
218
223
|
, [
|
|
219
224
|
createCalendar,
|
|
220
225
|
resolvedOptions.calendar
|
|
221
226
|
]);
|
|
222
227
|
// Determine how many editable segments there are for validation purposes.
|
|
223
228
|
// The result is cached for performance.
|
|
224
|
-
let allSegments = $
|
|
229
|
+
let allSegments = $7UzoM$useMemo(()=>dateFormatter.formatToParts(new Date()).filter((seg)=>$3c0fc76039f1c516$var$EDITABLE_SEGMENTS[seg.type]
|
|
225
230
|
).reduce((p, seg)=>(p[seg.type] = true, p)
|
|
226
231
|
, {
|
|
227
232
|
})
|
|
228
233
|
, [
|
|
229
234
|
dateFormatter
|
|
230
235
|
]);
|
|
231
|
-
let [validSegments, setValidSegments] = $
|
|
236
|
+
let [validSegments, setValidSegments] = $7UzoM$useState(()=>props.value || props.defaultValue ? {
|
|
232
237
|
...allSegments
|
|
233
238
|
} : {
|
|
234
239
|
}
|
|
@@ -237,14 +242,14 @@ function $a80b84f02ae54764$export$714a241b39a650d6(props) {
|
|
|
237
242
|
// until all segments are set. If the value === null (not undefined), then assume the component
|
|
238
243
|
// is controlled, so use the placeholder as the value until all segments are entered so it doesn't
|
|
239
244
|
// change from uncontrolled to controlled and emit a warning.
|
|
240
|
-
let [placeholderDate, setPlaceholderDate] = $
|
|
245
|
+
let [placeholderDate, setPlaceholderDate] = $7UzoM$useState(()=>$35a22f14a1f04b11$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone)
|
|
241
246
|
);
|
|
242
247
|
// Reset placeholder when calendar changes
|
|
243
|
-
let lastCalendarIdentifier = $
|
|
244
|
-
$
|
|
248
|
+
let lastCalendarIdentifier = $7UzoM$useRef(calendar.identifier);
|
|
249
|
+
$7UzoM$useEffect(()=>{
|
|
245
250
|
if (calendar.identifier !== lastCalendarIdentifier.current) {
|
|
246
251
|
lastCalendarIdentifier.current = calendar.identifier;
|
|
247
|
-
setPlaceholderDate((placeholder)=>Object.keys(validSegments).length > 0 ? $
|
|
252
|
+
setPlaceholderDate((placeholder)=>Object.keys(validSegments).length > 0 ? $7UzoM$toCalendar(placeholder, calendar) : $35a22f14a1f04b11$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone)
|
|
248
253
|
);
|
|
249
254
|
}
|
|
250
255
|
}, [
|
|
@@ -254,8 +259,8 @@ function $a80b84f02ae54764$export$714a241b39a650d6(props) {
|
|
|
254
259
|
defaultTimeZone,
|
|
255
260
|
props.placeholderValue
|
|
256
261
|
]);
|
|
257
|
-
let [value1, setDate] = $
|
|
258
|
-
let calendarValue = $
|
|
262
|
+
let [value1, setDate] = $7UzoM$useControlledState(props.value, props.defaultValue, props.onChange);
|
|
263
|
+
let calendarValue = $7UzoM$useMemo(()=>$35a22f14a1f04b11$export$61a490a80c552550(value1, calendar)
|
|
259
264
|
, [
|
|
260
265
|
value1,
|
|
261
266
|
calendar
|
|
@@ -272,7 +277,7 @@ function $a80b84f02ae54764$export$714a241b39a650d6(props) {
|
|
|
272
277
|
validSegments = {
|
|
273
278
|
};
|
|
274
279
|
setValidSegments(validSegments);
|
|
275
|
-
setPlaceholderDate($
|
|
280
|
+
setPlaceholderDate($35a22f14a1f04b11$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone));
|
|
276
281
|
}
|
|
277
282
|
// If all segments are valid, use the date from state, otherwise use the placeholder date.
|
|
278
283
|
let displayValue = calendarValue && Object.keys(validSegments).length >= Object.keys(allSegments).length ? calendarValue : placeholderDate;
|
|
@@ -281,23 +286,23 @@ function $a80b84f02ae54764$export$714a241b39a650d6(props) {
|
|
|
281
286
|
if (Object.keys(validSegments).length >= Object.keys(allSegments).length) {
|
|
282
287
|
// The display calendar should not have any effect on the emitted value.
|
|
283
288
|
// Emit dates in the same calendar as the original value, if any, otherwise gregorian.
|
|
284
|
-
newValue = $
|
|
289
|
+
newValue = $7UzoM$toCalendar(newValue, (v1 === null || v1 === void 0 ? void 0 : v1.calendar) || new $7UzoM$GregorianCalendar());
|
|
285
290
|
setDate(newValue);
|
|
286
291
|
} else setPlaceholderDate(newValue);
|
|
287
292
|
};
|
|
288
|
-
let dateValue = $
|
|
293
|
+
let dateValue = $7UzoM$useMemo(()=>displayValue.toDate(timeZone)
|
|
289
294
|
, [
|
|
290
295
|
displayValue,
|
|
291
296
|
timeZone
|
|
292
297
|
]);
|
|
293
|
-
let segments = $
|
|
294
|
-
let isEditable = $
|
|
298
|
+
let segments = $7UzoM$useMemo(()=>dateFormatter.formatToParts(dateValue).map((segment)=>{
|
|
299
|
+
let isEditable = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type];
|
|
295
300
|
if (segment.type === 'era' && calendar.getEras().length === 1) isEditable = false;
|
|
296
301
|
return {
|
|
297
|
-
type: $
|
|
302
|
+
type: $3c0fc76039f1c516$var$TYPE_MAPPING[segment.type] || segment.type,
|
|
298
303
|
text: segment.value,
|
|
299
|
-
...$
|
|
300
|
-
isPlaceholder: $
|
|
304
|
+
...$3c0fc76039f1c516$var$getSegmentLimits(displayValue, segment.type, resolvedOptions),
|
|
305
|
+
isPlaceholder: $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type],
|
|
301
306
|
isEditable: isEditable
|
|
302
307
|
};
|
|
303
308
|
})
|
|
@@ -309,7 +314,7 @@ function $a80b84f02ae54764$export$714a241b39a650d6(props) {
|
|
|
309
314
|
displayValue,
|
|
310
315
|
calendar
|
|
311
316
|
]);
|
|
312
|
-
let hasEra = $
|
|
317
|
+
let hasEra = $7UzoM$useMemo(()=>segments.some((s)=>s.type === 'era'
|
|
313
318
|
)
|
|
314
319
|
, [
|
|
315
320
|
segments
|
|
@@ -323,9 +328,9 @@ function $a80b84f02ae54764$export$714a241b39a650d6(props) {
|
|
|
323
328
|
};
|
|
324
329
|
let adjustSegment = (type, amount)=>{
|
|
325
330
|
markValid(type);
|
|
326
|
-
setValue($
|
|
331
|
+
setValue($3c0fc76039f1c516$var$addSegment(displayValue, type, amount, resolvedOptions));
|
|
327
332
|
};
|
|
328
|
-
let validationState = props.validationState || ($
|
|
333
|
+
let validationState = props.validationState || ($35a22f14a1f04b11$export$eac50920cf2fd59a(calendarValue, props.minValue, props.maxValue) ? 'invalid' : null);
|
|
329
334
|
return {
|
|
330
335
|
value: calendarValue,
|
|
331
336
|
dateValue: dateValue,
|
|
@@ -334,6 +339,9 @@ function $a80b84f02ae54764$export$714a241b39a650d6(props) {
|
|
|
334
339
|
dateFormatter: dateFormatter,
|
|
335
340
|
validationState: validationState,
|
|
336
341
|
granularity: granularity,
|
|
342
|
+
isDisabled: isDisabled,
|
|
343
|
+
isReadOnly: isReadOnly,
|
|
344
|
+
isRequired: isRequired,
|
|
337
345
|
increment (part) {
|
|
338
346
|
adjustSegment(part, 1);
|
|
339
347
|
},
|
|
@@ -341,14 +349,14 @@ function $a80b84f02ae54764$export$714a241b39a650d6(props) {
|
|
|
341
349
|
adjustSegment(part, -1);
|
|
342
350
|
},
|
|
343
351
|
incrementPage (part) {
|
|
344
|
-
adjustSegment(part, $
|
|
352
|
+
adjustSegment(part, $3c0fc76039f1c516$var$PAGE_STEP[part] || 1);
|
|
345
353
|
},
|
|
346
354
|
decrementPage (part) {
|
|
347
|
-
adjustSegment(part, -($
|
|
355
|
+
adjustSegment(part, -($3c0fc76039f1c516$var$PAGE_STEP[part] || 1));
|
|
348
356
|
},
|
|
349
357
|
setSegment (part, v) {
|
|
350
358
|
markValid(part);
|
|
351
|
-
setValue($
|
|
359
|
+
setValue($3c0fc76039f1c516$var$setSegment(displayValue, part, v, resolvedOptions));
|
|
352
360
|
},
|
|
353
361
|
confirmPlaceholder (part) {
|
|
354
362
|
if (props.isDisabled || props.isReadOnly) return;
|
|
@@ -372,7 +380,7 @@ function $a80b84f02ae54764$export$714a241b39a650d6(props) {
|
|
|
372
380
|
setValidSegments({
|
|
373
381
|
...validSegments
|
|
374
382
|
});
|
|
375
|
-
let placeholder = $
|
|
383
|
+
let placeholder = $35a22f14a1f04b11$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone);
|
|
376
384
|
let value = displayValue;
|
|
377
385
|
// Reset day period to default without changing the hour.
|
|
378
386
|
if (part === 'dayPeriod' && 'hour' in displayValue && 'hour' in placeholder) {
|
|
@@ -390,12 +398,15 @@ function $a80b84f02ae54764$export$714a241b39a650d6(props) {
|
|
|
390
398
|
setDate(null);
|
|
391
399
|
setValue(value);
|
|
392
400
|
},
|
|
393
|
-
|
|
394
|
-
|
|
401
|
+
formatValue (fieldOptions) {
|
|
402
|
+
if (!calendarValue) return '';
|
|
403
|
+
let formatOptions = $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, formatOpts);
|
|
404
|
+
let formatter = new $7UzoM$DateFormatter(locale, formatOptions);
|
|
405
|
+
return formatter.format(dateValue);
|
|
395
406
|
}
|
|
396
407
|
};
|
|
397
408
|
}
|
|
398
|
-
function $
|
|
409
|
+
function $3c0fc76039f1c516$var$getSegmentLimits(date, type, options) {
|
|
399
410
|
switch(type){
|
|
400
411
|
case 'era':
|
|
401
412
|
{
|
|
@@ -415,13 +426,13 @@ function $a80b84f02ae54764$var$getSegmentLimits(date, type, options) {
|
|
|
415
426
|
case 'month':
|
|
416
427
|
return {
|
|
417
428
|
value: date.month,
|
|
418
|
-
minValue: $
|
|
429
|
+
minValue: $7UzoM$getMinimumMonthInYear(date),
|
|
419
430
|
maxValue: date.calendar.getMonthsInYear(date)
|
|
420
431
|
};
|
|
421
432
|
case 'day':
|
|
422
433
|
return {
|
|
423
434
|
value: date.day,
|
|
424
|
-
minValue: $
|
|
435
|
+
minValue: $7UzoM$getMinimumDayInMonth(date),
|
|
425
436
|
maxValue: date.calendar.getDaysInMonth(date)
|
|
426
437
|
};
|
|
427
438
|
}
|
|
@@ -462,7 +473,7 @@ function $a80b84f02ae54764$var$getSegmentLimits(date, type, options) {
|
|
|
462
473
|
return {
|
|
463
474
|
};
|
|
464
475
|
}
|
|
465
|
-
function $
|
|
476
|
+
function $3c0fc76039f1c516$var$addSegment(value, part, amount, options) {
|
|
466
477
|
switch(part){
|
|
467
478
|
case 'era':
|
|
468
479
|
case 'year':
|
|
@@ -490,7 +501,7 @@ function $a80b84f02ae54764$var$addSegment(value, part, amount, options) {
|
|
|
490
501
|
});
|
|
491
502
|
}
|
|
492
503
|
}
|
|
493
|
-
function $
|
|
504
|
+
function $3c0fc76039f1c516$var$setSegment(value, part, segmentValue, options) {
|
|
494
505
|
switch(part){
|
|
495
506
|
case 'day':
|
|
496
507
|
case 'month':
|
|
@@ -528,17 +539,18 @@ function $a80b84f02ae54764$var$setSegment(value, part, segmentValue, options) {
|
|
|
528
539
|
}
|
|
529
540
|
|
|
530
541
|
|
|
531
|
-
var $
|
|
542
|
+
var $93c38a5e28be6249$exports = {};
|
|
532
543
|
|
|
533
|
-
$parcel$export($
|
|
544
|
+
$parcel$export($93c38a5e28be6249$exports, "useDateRangePickerState", () => $93c38a5e28be6249$export$e50a61c1de9f574);
|
|
534
545
|
|
|
535
546
|
|
|
536
547
|
|
|
537
548
|
|
|
538
|
-
function $
|
|
539
|
-
|
|
540
|
-
let [
|
|
541
|
-
let [
|
|
549
|
+
function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
550
|
+
var ref, ref1;
|
|
551
|
+
let [isOpen1, setOpen] = $7UzoM$useState(false);
|
|
552
|
+
let [controlledValue, setControlledValue] = $7UzoM$useControlledState(props.value, props.defaultValue || null, props.onChange);
|
|
553
|
+
let [placeholderValue, setPlaceholderValue] = $7UzoM$useState(()=>controlledValue || {
|
|
542
554
|
start: null,
|
|
543
555
|
end: null
|
|
544
556
|
}
|
|
@@ -552,7 +564,7 @@ function $1d5ee7717ccc6781$export$e50a61c1de9f574(props) {
|
|
|
552
564
|
setPlaceholderValue(placeholderValue);
|
|
553
565
|
}
|
|
554
566
|
let value1 = controlledValue || placeholderValue;
|
|
555
|
-
let valueRef = $
|
|
567
|
+
let valueRef = $7UzoM$useRef(value1);
|
|
556
568
|
valueRef.current = value1;
|
|
557
569
|
let setValue = (value)=>{
|
|
558
570
|
valueRef.current = value;
|
|
@@ -561,40 +573,47 @@ function $1d5ee7717ccc6781$export$e50a61c1de9f574(props) {
|
|
|
561
573
|
else setControlledValue(null);
|
|
562
574
|
};
|
|
563
575
|
let v = (value1 === null || value1 === void 0 ? void 0 : value1.start) || (value1 === null || value1 === void 0 ? void 0 : value1.end) || props.placeholderValue;
|
|
564
|
-
let [granularity, defaultTimeZone] = $
|
|
576
|
+
let [granularity, defaultTimeZone] = $35a22f14a1f04b11$export$2440da353cedad43(v, props.granularity);
|
|
565
577
|
let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second' || granularity === 'millisecond';
|
|
566
|
-
|
|
567
|
-
let
|
|
578
|
+
var _shouldCloseOnSelect;
|
|
579
|
+
let shouldCloseOnSelect = (_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _shouldCloseOnSelect !== void 0 ? _shouldCloseOnSelect : true;
|
|
580
|
+
let [dateRange1, setSelectedDateRange] = $7UzoM$useState(null);
|
|
581
|
+
let [timeRange1, setSelectedTimeRange] = $7UzoM$useState(null);
|
|
568
582
|
if (value1 && value1.start && value1.end) {
|
|
569
583
|
dateRange1 = value1;
|
|
570
584
|
if ('hour' in value1.start) timeRange1 = value1;
|
|
571
585
|
}
|
|
572
586
|
let commitValue = (dateRange, timeRange)=>{
|
|
573
587
|
setValue({
|
|
574
|
-
start: 'timeZone' in timeRange.start ? timeRange.start.set($
|
|
575
|
-
end: 'timeZone' in timeRange.end ? timeRange.end.set($
|
|
588
|
+
start: 'timeZone' in timeRange.start ? timeRange.start.set($7UzoM$toCalendarDate(dateRange.start)) : $7UzoM$toCalendarDateTime(dateRange.start, timeRange.start),
|
|
589
|
+
end: 'timeZone' in timeRange.end ? timeRange.end.set($7UzoM$toCalendarDate(dateRange.end)) : $7UzoM$toCalendarDateTime(dateRange.end, timeRange.end)
|
|
576
590
|
});
|
|
577
591
|
};
|
|
578
592
|
// Intercept setValue to make sure the Time section is not changed by date selection in Calendar
|
|
579
593
|
let setDateRange = (range)=>{
|
|
594
|
+
let shouldClose = typeof shouldCloseOnSelect === 'function' ? shouldCloseOnSelect() : shouldCloseOnSelect;
|
|
580
595
|
if (hasTime) {
|
|
581
|
-
if (range.start && range.end && (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.start) && (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.end)) commitValue(range,
|
|
596
|
+
if (shouldClose || range.start && range.end && (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.start) && (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.end)) commitValue(range, {
|
|
597
|
+
start: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.start) || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue),
|
|
598
|
+
end: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.end) || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue)
|
|
599
|
+
});
|
|
582
600
|
else setSelectedDateRange(range);
|
|
583
601
|
} else if (range.start && range.end) setValue(range);
|
|
584
602
|
else setSelectedDateRange(range);
|
|
585
|
-
if (
|
|
603
|
+
if (shouldClose) setOpen(false);
|
|
586
604
|
};
|
|
587
605
|
let setTimeRange = (range)=>{
|
|
588
606
|
if ((dateRange1 === null || dateRange1 === void 0 ? void 0 : dateRange1.start) && (dateRange1 === null || dateRange1 === void 0 ? void 0 : dateRange1.end) && range.start && range.end) commitValue(dateRange1, range);
|
|
589
607
|
else setSelectedTimeRange(range);
|
|
590
608
|
};
|
|
591
|
-
let validationState = props.validationState || (value1 != null && ($
|
|
609
|
+
let validationState = props.validationState || (value1 != null && ($35a22f14a1f04b11$export$eac50920cf2fd59a(value1.start, props.minValue, props.maxValue) || $35a22f14a1f04b11$export$eac50920cf2fd59a(value1.end, props.minValue, props.maxValue) || value1.end != null && value1.start != null && value1.end.compare(value1.start) < 0 || (value1 === null || value1 === void 0 ? void 0 : value1.start) && ((ref = props.isDateUnavailable) === null || ref === void 0 ? void 0 : ref.call(props, value1.start)) || (value1 === null || value1 === void 0 ? void 0 : value1.end) && ((ref1 = props.isDateUnavailable) === null || ref1 === void 0 ? void 0 : ref1.call(props, value1.end))) ? 'invalid' : null);
|
|
592
610
|
return {
|
|
593
611
|
value: value1,
|
|
594
612
|
setValue: setValue,
|
|
595
613
|
dateRange: dateRange1,
|
|
596
614
|
timeRange: timeRange1,
|
|
597
615
|
granularity: granularity,
|
|
616
|
+
hasTime: hasTime,
|
|
598
617
|
setDate (part, date) {
|
|
599
618
|
setDateRange({
|
|
600
619
|
...dateRange1,
|
|
@@ -621,8 +640,8 @@ function $1d5ee7717ccc6781$export$e50a61c1de9f574(props) {
|
|
|
621
640
|
// If only the time range was set and not the date range, don't commit. The state will be preserved until
|
|
622
641
|
// the user opens the popover again.
|
|
623
642
|
if (!isOpen && !((value1 === null || value1 === void 0 ? void 0 : value1.start) && (value1 === null || value1 === void 0 ? void 0 : value1.end)) && (dateRange1 === null || dateRange1 === void 0 ? void 0 : dateRange1.start) && (dateRange1 === null || dateRange1 === void 0 ? void 0 : dateRange1.end) && hasTime) commitValue(dateRange1, {
|
|
624
|
-
start: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.start) || $
|
|
625
|
-
end: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.end) || $
|
|
643
|
+
start: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.start) || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue),
|
|
644
|
+
end: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.end) || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue)
|
|
626
645
|
});
|
|
627
646
|
setOpen(isOpen);
|
|
628
647
|
},
|
|
@@ -633,13 +652,13 @@ function $1d5ee7717ccc6781$export$e50a61c1de9f574(props) {
|
|
|
633
652
|
let startGranularity = props.granularity || (value1.start && 'minute' in value1.start ? 'minute' : 'day');
|
|
634
653
|
let endTimeZone = 'timeZone' in value1.end ? value1.end.timeZone : undefined;
|
|
635
654
|
let endGranularity = props.granularity || (value1.end && 'minute' in value1.end ? 'minute' : 'day');
|
|
636
|
-
let startOptions = $
|
|
655
|
+
let startOptions = $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, {
|
|
637
656
|
granularity: startGranularity,
|
|
638
657
|
timeZone: startTimeZone,
|
|
639
658
|
hideTimeZone: props.hideTimeZone,
|
|
640
659
|
hourCycle: props.hourCycle
|
|
641
660
|
});
|
|
642
|
-
let startFormatter = new $
|
|
661
|
+
let startFormatter = new $7UzoM$DateFormatter(locale, startOptions);
|
|
643
662
|
let endFormatter;
|
|
644
663
|
if (startTimeZone === endTimeZone && startGranularity === endGranularity) {
|
|
645
664
|
// Use formatRange, as it results in shorter output when some of the fields
|
|
@@ -652,13 +671,13 @@ function $1d5ee7717ccc6781$export$e50a61c1de9f574(props) {
|
|
|
652
671
|
}
|
|
653
672
|
endFormatter = startFormatter;
|
|
654
673
|
} else {
|
|
655
|
-
let endOptions = $
|
|
674
|
+
let endOptions = $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, {
|
|
656
675
|
granularity: endGranularity,
|
|
657
676
|
timeZone: endTimeZone,
|
|
658
677
|
hideTimeZone: props.hideTimeZone,
|
|
659
678
|
hourCycle: props.hourCycle
|
|
660
679
|
});
|
|
661
|
-
endFormatter = new $
|
|
680
|
+
endFormatter = new $7UzoM$DateFormatter(locale, endOptions);
|
|
662
681
|
}
|
|
663
682
|
return `${startFormatter.format(value1.start.toDate(startTimeZone))} – ${endFormatter.format(value1.end.toDate(endTimeZone))}`;
|
|
664
683
|
},
|
|
@@ -668,7 +687,7 @@ function $1d5ee7717ccc6781$export$e50a61c1de9f574(props) {
|
|
|
668
687
|
let value = valueRef.current;
|
|
669
688
|
if (value && Boolean(value.start) !== Boolean(value.end)) {
|
|
670
689
|
let calendar = (value.start || value.end).calendar;
|
|
671
|
-
let placeholder = $
|
|
690
|
+
let placeholder = $35a22f14a1f04b11$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone);
|
|
672
691
|
setValue({
|
|
673
692
|
start: value.start || placeholder,
|
|
674
693
|
end: value.end || placeholder
|
|
@@ -679,40 +698,40 @@ function $1d5ee7717ccc6781$export$e50a61c1de9f574(props) {
|
|
|
679
698
|
}
|
|
680
699
|
|
|
681
700
|
|
|
682
|
-
var $
|
|
701
|
+
var $eff5d8ee529ac4bb$exports = {};
|
|
683
702
|
|
|
684
|
-
$parcel$export($
|
|
703
|
+
$parcel$export($eff5d8ee529ac4bb$exports, "useTimeFieldState", () => $eff5d8ee529ac4bb$export$fd53cef0cc796101);
|
|
685
704
|
|
|
686
705
|
|
|
687
706
|
|
|
688
707
|
|
|
689
|
-
function $
|
|
690
|
-
let { placeholderValue: placeholderValue = new $
|
|
691
|
-
let [value, setValue] = $
|
|
708
|
+
function $eff5d8ee529ac4bb$export$fd53cef0cc796101(props) {
|
|
709
|
+
let { placeholderValue: placeholderValue = new $7UzoM$Time() , minValue: minValue , maxValue: maxValue , granularity: granularity } = props;
|
|
710
|
+
let [value, setValue] = $7UzoM$useControlledState(props.value, props.defaultValue, props.onChange);
|
|
692
711
|
let v = value || placeholderValue;
|
|
693
712
|
let day = v && 'day' in v ? v : undefined;
|
|
694
|
-
let placeholderDate = $
|
|
713
|
+
let placeholderDate = $7UzoM$useMemo(()=>$eff5d8ee529ac4bb$var$convertValue(placeholderValue)
|
|
695
714
|
, [
|
|
696
715
|
placeholderValue
|
|
697
716
|
]);
|
|
698
|
-
let minDate = $
|
|
717
|
+
let minDate = $7UzoM$useMemo(()=>$eff5d8ee529ac4bb$var$convertValue(minValue, day)
|
|
699
718
|
, [
|
|
700
719
|
minValue,
|
|
701
720
|
day
|
|
702
721
|
]);
|
|
703
|
-
let maxDate = $
|
|
722
|
+
let maxDate = $7UzoM$useMemo(()=>$eff5d8ee529ac4bb$var$convertValue(maxValue, day)
|
|
704
723
|
, [
|
|
705
724
|
maxValue,
|
|
706
725
|
day
|
|
707
726
|
]);
|
|
708
|
-
let dateTime = $
|
|
727
|
+
let dateTime = $7UzoM$useMemo(()=>value == null ? null : $eff5d8ee529ac4bb$var$convertValue(value)
|
|
709
728
|
, [
|
|
710
729
|
value
|
|
711
730
|
]);
|
|
712
731
|
let onChange = (newValue)=>{
|
|
713
|
-
setValue(v && 'day' in v ? newValue : newValue && $
|
|
732
|
+
setValue(v && 'day' in v ? newValue : newValue && $7UzoM$toTime(newValue));
|
|
714
733
|
};
|
|
715
|
-
return $
|
|
734
|
+
return $3c0fc76039f1c516$export$60e84778edff6d26({
|
|
716
735
|
...props,
|
|
717
736
|
value: dateTime,
|
|
718
737
|
defaultValue: undefined,
|
|
@@ -721,17 +740,19 @@ function $5f733956a51c019d$export$fd53cef0cc796101(props) {
|
|
|
721
740
|
onChange: onChange,
|
|
722
741
|
granularity: granularity || 'minute',
|
|
723
742
|
maxGranularity: 'hour',
|
|
724
|
-
placeholderValue: placeholderDate
|
|
743
|
+
placeholderValue: placeholderDate,
|
|
744
|
+
// Calendar should not matter for time fields.
|
|
745
|
+
createCalendar: ()=>new $7UzoM$GregorianCalendar()
|
|
725
746
|
});
|
|
726
747
|
}
|
|
727
|
-
function $
|
|
748
|
+
function $eff5d8ee529ac4bb$var$convertValue(value, date = $7UzoM$today($7UzoM$getLocalTimeZone())) {
|
|
728
749
|
if (!value) return null;
|
|
729
750
|
if ('day' in value) return value;
|
|
730
|
-
return $
|
|
751
|
+
return $7UzoM$toCalendarDateTime(date, value);
|
|
731
752
|
}
|
|
732
753
|
|
|
733
754
|
|
|
734
755
|
|
|
735
756
|
|
|
736
|
-
export {$
|
|
757
|
+
export {$ab5bf3f618090389$export$87194bb378cc3ac2 as useDatePickerState, $3c0fc76039f1c516$export$60e84778edff6d26 as useDateFieldState, $93c38a5e28be6249$export$e50a61c1de9f574 as useDateRangePickerState, $eff5d8ee529ac4bb$export$fd53cef0cc796101 as useTimeFieldState};
|
|
737
758
|
//# sourceMappingURL=module.js.map
|