@react-spectrum/datepicker 3.0.0-nightly.2519 → 3.0.0-nightly.2531
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 +312 -244
- package/dist/main.js +310 -242
- package/dist/main.js.map +1 -1
- package/dist/module.js +312 -244
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +25 -24
- package/src/DateField.tsx +10 -3
- package/src/DatePicker.tsx +13 -7
- package/src/DateRangePicker.tsx +13 -7
- package/src/TimeField.tsx +10 -3
- package/src/utils.ts +1 -1
package/src/DatePicker.tsx
CHANGED
|
@@ -33,12 +33,14 @@ import {useDatePicker} from '@react-aria/datepicker';
|
|
|
33
33
|
import {useDatePickerState} from '@react-stately/datepicker';
|
|
34
34
|
import {useFocusManagerRef, useFormatHelpText, useVisibleMonths} from './utils';
|
|
35
35
|
import {useFocusRing} from '@react-aria/focus';
|
|
36
|
+
import {useFormProps} from '@react-spectrum/form';
|
|
36
37
|
import {useHover} from '@react-aria/interactions';
|
|
37
38
|
import {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
38
39
|
import {useProviderProps} from '@react-spectrum/provider';
|
|
39
40
|
|
|
40
41
|
function DatePicker<T extends DateValue>(props: SpectrumDatePickerProps<T>, ref: FocusableRef<HTMLElement>) {
|
|
41
42
|
props = useProviderProps(props);
|
|
43
|
+
props = useFormProps(props);
|
|
42
44
|
let {
|
|
43
45
|
autoFocus,
|
|
44
46
|
isQuiet,
|
|
@@ -54,7 +56,7 @@ function DatePicker<T extends DateValue>(props: SpectrumDatePickerProps<T>, ref:
|
|
|
54
56
|
...props,
|
|
55
57
|
shouldCloseOnSelect: () => !state.hasTime
|
|
56
58
|
});
|
|
57
|
-
let {groupProps, labelProps, fieldProps, descriptionProps, errorMessageProps, buttonProps, dialogProps, calendarProps} = useDatePicker(props, state, targetRef);
|
|
59
|
+
let {groupProps, labelProps, fieldProps, descriptionProps, errorMessageProps, buttonProps, dialogProps, calendarProps, isInvalid, validationErrors, validationDetails} = useDatePicker(props, state, targetRef);
|
|
58
60
|
let {isOpen, setOpen} = state;
|
|
59
61
|
let {direction} = useLocale();
|
|
60
62
|
let domRef = useFocusManagerRef(ref);
|
|
@@ -77,7 +79,7 @@ function DatePicker<T extends DateValue>(props: SpectrumDatePickerProps<T>, ref:
|
|
|
77
79
|
'spectrum-InputGroup',
|
|
78
80
|
{
|
|
79
81
|
'spectrum-InputGroup--quiet': isQuiet,
|
|
80
|
-
'spectrum-InputGroup--invalid':
|
|
82
|
+
'spectrum-InputGroup--invalid': isInvalid && !isDisabled,
|
|
81
83
|
'is-disabled': isDisabled,
|
|
82
84
|
'is-hovered': isHovered,
|
|
83
85
|
'is-focused': isFocused,
|
|
@@ -90,7 +92,7 @@ function DatePicker<T extends DateValue>(props: SpectrumDatePickerProps<T>, ref:
|
|
|
90
92
|
'spectrum-InputGroup-input',
|
|
91
93
|
{
|
|
92
94
|
'is-disabled': isDisabled,
|
|
93
|
-
'is-invalid':
|
|
95
|
+
'is-invalid': isInvalid && !isDisabled
|
|
94
96
|
}
|
|
95
97
|
);
|
|
96
98
|
|
|
@@ -109,6 +111,7 @@ function DatePicker<T extends DateValue>(props: SpectrumDatePickerProps<T>, ref:
|
|
|
109
111
|
let showTimeField = !!timeGranularity;
|
|
110
112
|
|
|
111
113
|
let visibleMonths = useVisibleMonths(maxVisibleMonths);
|
|
114
|
+
let validationState = state.validationState || (isInvalid ? 'invalid' : null);
|
|
112
115
|
|
|
113
116
|
return (
|
|
114
117
|
<Field
|
|
@@ -119,7 +122,10 @@ function DatePicker<T extends DateValue>(props: SpectrumDatePickerProps<T>, ref:
|
|
|
119
122
|
labelProps={labelProps}
|
|
120
123
|
descriptionProps={descriptionProps}
|
|
121
124
|
errorMessageProps={errorMessageProps}
|
|
122
|
-
validationState={
|
|
125
|
+
validationState={validationState}
|
|
126
|
+
isInvalid={isInvalid}
|
|
127
|
+
validationErrors={validationErrors}
|
|
128
|
+
validationDetails={validationDetails}
|
|
123
129
|
wrapperClassName={classNames(datepickerStyles, 'react-spectrum-Datepicker-fieldWrapper')}>
|
|
124
130
|
<div
|
|
125
131
|
{...mergeProps(groupProps, hoverProps, focusProps)}
|
|
@@ -128,7 +134,7 @@ function DatePicker<T extends DateValue>(props: SpectrumDatePickerProps<T>, ref:
|
|
|
128
134
|
<Input
|
|
129
135
|
isDisabled={isDisabled}
|
|
130
136
|
isQuiet={isQuiet}
|
|
131
|
-
validationState={
|
|
137
|
+
validationState={validationState}
|
|
132
138
|
className={classNames(styles, 'spectrum-InputGroup-field')}
|
|
133
139
|
inputClassName={fieldClassName}
|
|
134
140
|
disableFocusRing>
|
|
@@ -150,7 +156,7 @@ function DatePicker<T extends DateValue>(props: SpectrumDatePickerProps<T>, ref:
|
|
|
150
156
|
{...mergeProps(buttonProps, focusPropsButton)}
|
|
151
157
|
UNSAFE_className={classNames(styles, 'spectrum-FieldButton')}
|
|
152
158
|
isQuiet={isQuiet}
|
|
153
|
-
validationState={
|
|
159
|
+
validationState={validationState}
|
|
154
160
|
isDisabled={isDisabled || isReadOnly}>
|
|
155
161
|
<CalendarIcon />
|
|
156
162
|
</FieldButton>
|
|
@@ -161,7 +167,7 @@ function DatePicker<T extends DateValue>(props: SpectrumDatePickerProps<T>, ref:
|
|
|
161
167
|
{...calendarProps}
|
|
162
168
|
visibleMonths={visibleMonths}
|
|
163
169
|
pageBehavior={pageBehavior}
|
|
164
|
-
UNSAFE_className={classNames(datepickerStyles, 'react-spectrum-Datepicker-calendar', {'is-invalid':
|
|
170
|
+
UNSAFE_className={classNames(datepickerStyles, 'react-spectrum-Datepicker-calendar', {'is-invalid': isInvalid})} />
|
|
165
171
|
{showTimeField &&
|
|
166
172
|
<div className={classNames(datepickerStyles, 'react-spectrum-Datepicker-timeFields')}>
|
|
167
173
|
<TimeField
|
package/src/DateRangePicker.tsx
CHANGED
|
@@ -33,12 +33,14 @@ import {useDateRangePicker} from '@react-aria/datepicker';
|
|
|
33
33
|
import {useDateRangePickerState} from '@react-stately/datepicker';
|
|
34
34
|
import {useFocusManagerRef, useFormatHelpText, useVisibleMonths} from './utils';
|
|
35
35
|
import {useFocusRing} from '@react-aria/focus';
|
|
36
|
+
import {useFormProps} from '@react-spectrum/form';
|
|
36
37
|
import {useHover} from '@react-aria/interactions';
|
|
37
38
|
import {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
38
39
|
import {useProviderProps} from '@react-spectrum/provider';
|
|
39
40
|
|
|
40
41
|
function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePickerProps<T>, ref: FocusableRef<HTMLElement>) {
|
|
41
42
|
props = useProviderProps(props);
|
|
43
|
+
props = useFormProps(props);
|
|
42
44
|
let {
|
|
43
45
|
isQuiet,
|
|
44
46
|
isDisabled,
|
|
@@ -54,7 +56,7 @@ function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePickerProp
|
|
|
54
56
|
...props,
|
|
55
57
|
shouldCloseOnSelect: () => !state.hasTime
|
|
56
58
|
});
|
|
57
|
-
let {labelProps, groupProps, buttonProps, dialogProps, startFieldProps, endFieldProps, descriptionProps, errorMessageProps, calendarProps} = useDateRangePicker(props, state, targetRef);
|
|
59
|
+
let {labelProps, groupProps, buttonProps, dialogProps, startFieldProps, endFieldProps, descriptionProps, errorMessageProps, calendarProps, isInvalid, validationErrors, validationDetails} = useDateRangePicker(props, state, targetRef);
|
|
58
60
|
let {isOpen, setOpen} = state;
|
|
59
61
|
let {direction} = useLocale();
|
|
60
62
|
let domRef = useFocusManagerRef(ref);
|
|
@@ -77,7 +79,7 @@ function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePickerProp
|
|
|
77
79
|
'spectrum-InputGroup',
|
|
78
80
|
{
|
|
79
81
|
'spectrum-InputGroup--quiet': isQuiet,
|
|
80
|
-
'spectrum-InputGroup--invalid':
|
|
82
|
+
'spectrum-InputGroup--invalid': isInvalid && !isDisabled,
|
|
81
83
|
'is-disabled': isDisabled,
|
|
82
84
|
'is-hovered': isHovered,
|
|
83
85
|
'is-focused': isFocused,
|
|
@@ -90,7 +92,7 @@ function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePickerProp
|
|
|
90
92
|
'spectrum-InputGroup-input',
|
|
91
93
|
{
|
|
92
94
|
'is-disabled': isDisabled,
|
|
93
|
-
'is-invalid':
|
|
95
|
+
'is-invalid': isInvalid && !isDisabled
|
|
94
96
|
}
|
|
95
97
|
);
|
|
96
98
|
|
|
@@ -109,6 +111,7 @@ function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePickerProp
|
|
|
109
111
|
let showTimeField = !!timeGranularity;
|
|
110
112
|
|
|
111
113
|
let visibleMonths = useVisibleMonths(maxVisibleMonths);
|
|
114
|
+
let validationState = state.validationState || (isInvalid ? 'invalid' : null);
|
|
112
115
|
|
|
113
116
|
return (
|
|
114
117
|
<Field
|
|
@@ -119,7 +122,10 @@ function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePickerProp
|
|
|
119
122
|
labelProps={labelProps}
|
|
120
123
|
descriptionProps={descriptionProps}
|
|
121
124
|
errorMessageProps={errorMessageProps}
|
|
122
|
-
validationState={
|
|
125
|
+
validationState={validationState}
|
|
126
|
+
isInvalid={isInvalid}
|
|
127
|
+
validationErrors={validationErrors}
|
|
128
|
+
validationDetails={validationDetails}
|
|
123
129
|
wrapperClassName={classNames(datepickerStyles, 'react-spectrum-Datepicker-fieldWrapper')}>
|
|
124
130
|
<div
|
|
125
131
|
{...mergeProps(groupProps, hoverProps, focusProps)}
|
|
@@ -128,7 +134,7 @@ function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePickerProp
|
|
|
128
134
|
<Input
|
|
129
135
|
isDisabled={isDisabled}
|
|
130
136
|
isQuiet={isQuiet}
|
|
131
|
-
validationState={
|
|
137
|
+
validationState={validationState}
|
|
132
138
|
className={classNames(styles, 'spectrum-InputGroup-field')}
|
|
133
139
|
inputClassName={fieldClassName}
|
|
134
140
|
disableFocusRing>
|
|
@@ -164,7 +170,7 @@ function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePickerProp
|
|
|
164
170
|
{...mergeProps(buttonProps, focusPropsButton)}
|
|
165
171
|
UNSAFE_className={classNames(styles, 'spectrum-FieldButton')}
|
|
166
172
|
isQuiet={isQuiet}
|
|
167
|
-
validationState={
|
|
173
|
+
validationState={validationState}
|
|
168
174
|
isDisabled={isDisabled || isReadOnly}>
|
|
169
175
|
<CalendarIcon />
|
|
170
176
|
</FieldButton>
|
|
@@ -175,7 +181,7 @@ function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePickerProp
|
|
|
175
181
|
{...calendarProps}
|
|
176
182
|
visibleMonths={visibleMonths}
|
|
177
183
|
pageBehavior={pageBehavior}
|
|
178
|
-
UNSAFE_className={classNames(datepickerStyles, 'react-spectrum-Datepicker-calendar', {'is-invalid':
|
|
184
|
+
UNSAFE_className={classNames(datepickerStyles, 'react-spectrum-Datepicker-calendar', {'is-invalid': validationState === 'invalid'})} />
|
|
179
185
|
{showTimeField &&
|
|
180
186
|
<Flex gap="size-100" marginTop="size-100" UNSAFE_className={classNames(datepickerStyles, 'react-spectrum-Datepicker-timeFields')}>
|
|
181
187
|
<TimeField
|
package/src/TimeField.tsx
CHANGED
|
@@ -19,6 +19,7 @@ import {Input} from './Input';
|
|
|
19
19
|
import React, {ReactElement, useRef} from 'react';
|
|
20
20
|
import {SpectrumTimeFieldProps, TimeValue} from '@react-types/datepicker';
|
|
21
21
|
import {useFocusManagerRef} from './utils';
|
|
22
|
+
import {useFormProps} from '@react-spectrum/form';
|
|
22
23
|
import {useLocale} from '@react-aria/i18n';
|
|
23
24
|
import {useProviderProps} from '@react-spectrum/provider';
|
|
24
25
|
import {useTimeField} from '@react-aria/datepicker';
|
|
@@ -26,6 +27,7 @@ import {useTimeFieldState} from '@react-stately/datepicker';
|
|
|
26
27
|
|
|
27
28
|
function TimeField<T extends TimeValue>(props: SpectrumTimeFieldProps<T>, ref: FocusableRef<HTMLElement>) {
|
|
28
29
|
props = useProviderProps(props);
|
|
30
|
+
props = useFormProps(props);
|
|
29
31
|
let {
|
|
30
32
|
autoFocus,
|
|
31
33
|
isDisabled,
|
|
@@ -43,11 +45,13 @@ function TimeField<T extends TimeValue>(props: SpectrumTimeFieldProps<T>, ref: F
|
|
|
43
45
|
|
|
44
46
|
let fieldRef = useRef(null);
|
|
45
47
|
let inputRef = useRef(null);
|
|
46
|
-
let {labelProps, fieldProps, inputProps, descriptionProps, errorMessageProps} = useTimeField({
|
|
48
|
+
let {labelProps, fieldProps, inputProps, descriptionProps, errorMessageProps, isInvalid, validationErrors, validationDetails} = useTimeField({
|
|
47
49
|
...props,
|
|
48
50
|
inputRef
|
|
49
51
|
}, state, fieldRef);
|
|
50
52
|
|
|
53
|
+
let validationState = state.validationState || (isInvalid ? 'invalid' : null);
|
|
54
|
+
|
|
51
55
|
return (
|
|
52
56
|
<Field
|
|
53
57
|
{...props}
|
|
@@ -56,7 +60,10 @@ function TimeField<T extends TimeValue>(props: SpectrumTimeFieldProps<T>, ref: F
|
|
|
56
60
|
labelProps={labelProps}
|
|
57
61
|
descriptionProps={descriptionProps}
|
|
58
62
|
errorMessageProps={errorMessageProps}
|
|
59
|
-
validationState={
|
|
63
|
+
validationState={validationState}
|
|
64
|
+
isInvalid={isInvalid}
|
|
65
|
+
validationErrors={validationErrors}
|
|
66
|
+
validationDetails={validationDetails}
|
|
60
67
|
wrapperClassName={classNames(datepickerStyles, 'react-spectrum-TimeField-fieldWrapper')}>
|
|
61
68
|
<Input
|
|
62
69
|
ref={fieldRef}
|
|
@@ -64,7 +71,7 @@ function TimeField<T extends TimeValue>(props: SpectrumTimeFieldProps<T>, ref: F
|
|
|
64
71
|
isDisabled={isDisabled}
|
|
65
72
|
isQuiet={isQuiet}
|
|
66
73
|
autoFocus={autoFocus}
|
|
67
|
-
validationState={
|
|
74
|
+
validationState={validationState}
|
|
68
75
|
className={classNames(datepickerStyles, 'react-spectrum-TimeField')}>
|
|
69
76
|
{state.segments.map((segment, i) =>
|
|
70
77
|
(<DatePickerSegment
|
package/src/utils.ts
CHANGED
|
@@ -19,7 +19,7 @@ import {useImperativeHandle, useMemo, useRef, useState} from 'react';
|
|
|
19
19
|
import {useLayoutEffect} from '@react-aria/utils';
|
|
20
20
|
import {useProvider} from '@react-spectrum/provider';
|
|
21
21
|
|
|
22
|
-
export function useFormatHelpText(props: Pick<SpectrumDatePickerBase
|
|
22
|
+
export function useFormatHelpText(props: Pick<SpectrumDatePickerBase<any>, 'description' | 'showFormatHelpText'>) {
|
|
23
23
|
let formatter = useDateFormatter({dateStyle: 'short'});
|
|
24
24
|
let displayNames = useDisplayNames();
|
|
25
25
|
return useMemo(() => {
|