@react-stately/datepicker 3.6.0 → 3.8.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/dist/import.mjs +15 -6
- package/dist/main.js +15 -6
- package/dist/main.js.map +1 -1
- package/dist/module.js +15 -6
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +24 -9
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/useDateFieldState.ts +10 -3
- package/src/useDatePickerState.ts +13 -6
- package/src/useDateRangePickerState.ts +15 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/datepicker",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@internationalized/date": "^3.
|
|
25
|
+
"@internationalized/date": "^3.5.0",
|
|
26
26
|
"@internationalized/string": "^3.1.1",
|
|
27
|
-
"@react-stately/overlays": "^3.6.
|
|
28
|
-
"@react-stately/utils": "^3.
|
|
29
|
-
"@react-types/datepicker": "^3.
|
|
30
|
-
"@react-types/shared": "^3.
|
|
27
|
+
"@react-stately/overlays": "^3.6.3",
|
|
28
|
+
"@react-stately/utils": "^3.8.0",
|
|
29
|
+
"@react-types/datepicker": "^3.6.1",
|
|
30
|
+
"@react-types/shared": "^3.21.0",
|
|
31
31
|
"@swc/helpers": "^0.5.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "4122e44d1991c90507d630d35ed297f89db435d3"
|
|
40
40
|
}
|
package/src/useDateFieldState.ts
CHANGED
|
@@ -51,8 +51,13 @@ export interface DateFieldState {
|
|
|
51
51
|
segments: DateSegment[],
|
|
52
52
|
/** A date formatter configured for the current locale and format. */
|
|
53
53
|
dateFormatter: DateFormatter,
|
|
54
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* The current validation state of the date field, based on the `validationState`, `minValue`, and `maxValue` props.
|
|
56
|
+
* @deprecated Use `isInvalid` instead.
|
|
57
|
+
*/
|
|
55
58
|
validationState: ValidationState,
|
|
59
|
+
/** Whether the date field is invalid, based on the `isInvalid`, `minValue`, and `maxValue` props. */
|
|
60
|
+
isInvalid: boolean,
|
|
56
61
|
/** The granularity for the field, based on the `granularity` prop and current value. */
|
|
57
62
|
granularity: Granularity,
|
|
58
63
|
/** The maximum date or time unit that is displayed in the field. */
|
|
@@ -309,8 +314,9 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
|
|
|
309
314
|
}
|
|
310
315
|
};
|
|
311
316
|
|
|
312
|
-
let
|
|
313
|
-
|
|
317
|
+
let isValueInvalid = props.isInvalid || props.validationState === 'invalid' ||
|
|
318
|
+
isInvalid(calendarValue, props.minValue, props.maxValue);
|
|
319
|
+
let validationState: ValidationState = props.validationState || (isValueInvalid ? 'invalid' : null);
|
|
314
320
|
|
|
315
321
|
return {
|
|
316
322
|
value: calendarValue,
|
|
@@ -320,6 +326,7 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
|
|
|
320
326
|
segments,
|
|
321
327
|
dateFormatter,
|
|
322
328
|
validationState,
|
|
329
|
+
isInvalid: isValueInvalid,
|
|
323
330
|
granularity,
|
|
324
331
|
maxGranularity: props.maxGranularity ?? 'year',
|
|
325
332
|
isDisabled,
|
|
@@ -28,9 +28,9 @@ export interface DatePickerStateOptions<T extends DateValue> extends DatePickerP
|
|
|
28
28
|
|
|
29
29
|
export interface DatePickerState extends OverlayTriggerState {
|
|
30
30
|
/** The currently selected date. */
|
|
31
|
-
value: DateValue,
|
|
31
|
+
value: DateValue | null,
|
|
32
32
|
/** Sets the selected date. */
|
|
33
|
-
setValue(value: DateValue): void,
|
|
33
|
+
setValue(value: DateValue | null): void,
|
|
34
34
|
/**
|
|
35
35
|
* The date portion of the value. This may be set prior to `value` if the user has
|
|
36
36
|
* selected a date but has not yet selected a time.
|
|
@@ -53,8 +53,13 @@ export interface DatePickerState extends OverlayTriggerState {
|
|
|
53
53
|
isOpen: boolean,
|
|
54
54
|
/** Sets whether the calendar popover is open. */
|
|
55
55
|
setOpen(isOpen: boolean): void,
|
|
56
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* The current validation state of the date picker, based on the `validationState`, `minValue`, and `maxValue` props.
|
|
58
|
+
* @deprecated Use `isInvalid` instead.
|
|
59
|
+
*/
|
|
57
60
|
validationState: ValidationState,
|
|
61
|
+
/** Whether the date picker is invalid, based on the `isInvalid`, `minValue`, and `maxValue` props. */
|
|
62
|
+
isInvalid: boolean,
|
|
58
63
|
/** Formats the selected value using the given options. */
|
|
59
64
|
formatValue(locale: string, fieldOptions: FieldOptions): string
|
|
60
65
|
}
|
|
@@ -120,9 +125,10 @@ export function useDatePickerState<T extends DateValue = DateValue>(props: DateP
|
|
|
120
125
|
}
|
|
121
126
|
};
|
|
122
127
|
|
|
123
|
-
let
|
|
124
|
-
|
|
125
|
-
|
|
128
|
+
let isValueInvalid = props.isInvalid || props.validationState === 'invalid' ||
|
|
129
|
+
isInvalid(value, props.minValue, props.maxValue) ||
|
|
130
|
+
value && props.isDateUnavailable?.(value);
|
|
131
|
+
let validationState: ValidationState = props.validationState || (isValueInvalid ? 'invalid' : null);
|
|
126
132
|
|
|
127
133
|
return {
|
|
128
134
|
value,
|
|
@@ -145,6 +151,7 @@ export function useDatePickerState<T extends DateValue = DateValue>(props: DateP
|
|
|
145
151
|
overlayState.setOpen(isOpen);
|
|
146
152
|
},
|
|
147
153
|
validationState,
|
|
154
|
+
isInvalid: isValueInvalid,
|
|
148
155
|
formatValue(locale, fieldOptions) {
|
|
149
156
|
if (!dateValue) {
|
|
150
157
|
return '';
|
|
@@ -29,21 +29,21 @@ export interface DateRangePickerStateOptions<T extends DateValue = DateValue> ex
|
|
|
29
29
|
type TimeRange = RangeValue<TimeValue>;
|
|
30
30
|
export interface DateRangePickerState extends OverlayTriggerState {
|
|
31
31
|
/** The currently selected date range. */
|
|
32
|
-
value: DateRange,
|
|
32
|
+
value: DateRange | null,
|
|
33
33
|
/** Sets the selected date range. */
|
|
34
|
-
setValue(value: DateRange): void,
|
|
34
|
+
setValue(value: DateRange | null): void,
|
|
35
35
|
/**
|
|
36
36
|
* The date portion of the selected range. This may be set prior to `value` if the user has
|
|
37
37
|
* selected a date range but has not yet selected a time range.
|
|
38
38
|
*/
|
|
39
|
-
dateRange: DateRange,
|
|
39
|
+
dateRange: DateRange | null,
|
|
40
40
|
/** Sets the date portion of the selected range. */
|
|
41
41
|
setDateRange(value: DateRange): void,
|
|
42
42
|
/**
|
|
43
43
|
* The time portion of the selected range. This may be set prior to `value` if the user has
|
|
44
44
|
* selected a time range but has not yet selected a date range.
|
|
45
45
|
*/
|
|
46
|
-
timeRange: TimeRange,
|
|
46
|
+
timeRange: TimeRange | null,
|
|
47
47
|
/** Sets the time portion of the selected range. */
|
|
48
48
|
setTimeRange(value: TimeRange): void,
|
|
49
49
|
/** Sets the date portion of either the start or end of the selected range. */
|
|
@@ -60,8 +60,13 @@ export interface DateRangePickerState extends OverlayTriggerState {
|
|
|
60
60
|
isOpen: boolean,
|
|
61
61
|
/** Sets whether the calendar popover is open. */
|
|
62
62
|
setOpen(isOpen: boolean): void,
|
|
63
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* The current validation state of the date range picker, based on the `validationState`, `minValue`, and `maxValue` props.
|
|
65
|
+
* @deprecated Use `isInvalid` instead.
|
|
66
|
+
*/
|
|
64
67
|
validationState: ValidationState,
|
|
68
|
+
/** Whether the date range picker is invalid, based on the `isInvalid`, `minValue`, and `maxValue` props. */
|
|
69
|
+
isInvalid: boolean,
|
|
65
70
|
/** Formats the selected range using the given options. */
|
|
66
71
|
formatValue(locale: string, fieldOptions: FieldOptions): {start: string, end: string}
|
|
67
72
|
}
|
|
@@ -85,7 +90,7 @@ export function useDateRangePickerState<T extends DateValue = DateValue>(props:
|
|
|
85
90
|
let value = controlledValue || placeholderValue;
|
|
86
91
|
|
|
87
92
|
let setValue = (value: DateRange) => {
|
|
88
|
-
setPlaceholderValue(value);
|
|
93
|
+
setPlaceholderValue(value || {start: null, end: null});
|
|
89
94
|
if (value?.start && value.end) {
|
|
90
95
|
setControlledValue(value);
|
|
91
96
|
} else {
|
|
@@ -148,14 +153,15 @@ export function useDateRangePickerState<T extends DateValue = DateValue>(props:
|
|
|
148
153
|
}
|
|
149
154
|
};
|
|
150
155
|
|
|
151
|
-
let
|
|
156
|
+
let isValueInvalid = props.isInvalid || props.validationState === 'invalid'
|
|
152
157
|
|| (value != null && (
|
|
153
158
|
isInvalid(value.start, props.minValue, props.maxValue) ||
|
|
154
159
|
isInvalid(value.end, props.minValue, props.maxValue) ||
|
|
155
160
|
(value.end != null && value.start != null && value.end.compare(value.start) < 0) ||
|
|
156
161
|
(value?.start && props.isDateUnavailable?.(value.start)) ||
|
|
157
162
|
(value?.end && props.isDateUnavailable?.(value.end))
|
|
158
|
-
)
|
|
163
|
+
));
|
|
164
|
+
let validationState: ValidationState = props.validationState || (isValueInvalid ? 'invalid' : null);
|
|
159
165
|
|
|
160
166
|
return {
|
|
161
167
|
value,
|
|
@@ -190,6 +196,7 @@ export function useDateRangePickerState<T extends DateValue = DateValue>(props:
|
|
|
190
196
|
overlayState.setOpen(isOpen);
|
|
191
197
|
},
|
|
192
198
|
validationState,
|
|
199
|
+
isInvalid: isValueInvalid,
|
|
193
200
|
formatValue(locale, fieldOptions) {
|
|
194
201
|
if (!value || !value.start || !value.end) {
|
|
195
202
|
return null;
|