@react-spectrum/datepicker 3.0.0-alpha.4 → 3.0.0-alpha.5
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.css +1 -1
- package/dist/main.js +412 -461
- package/dist/main.js.map +1 -1
- package/dist/module.js +409 -458
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/DateField.tsx +3 -2
- package/src/DatePicker.tsx +10 -22
- package/src/DatePickerField.tsx +3 -3
- package/src/DatePickerSegment.tsx +7 -21
- package/src/DateRangePicker.tsx +13 -34
- package/src/Input.tsx +4 -7
- package/src/TimeField.tsx +4 -5
- package/src/index.css +9 -15
package/src/DateRangePicker.tsx
CHANGED
|
@@ -35,7 +35,8 @@ import {useLocale} from '@react-aria/i18n';
|
|
|
35
35
|
import {useProviderProps} from '@react-spectrum/provider';
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* DateRangePickers combine two DateFields and a RangeCalendar popover to allow users
|
|
39
|
+
* to enter or select a date and time range.
|
|
39
40
|
*/
|
|
40
41
|
export function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePickerProps<T>) {
|
|
41
42
|
props = useProviderProps(props);
|
|
@@ -43,7 +44,6 @@ export function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePic
|
|
|
43
44
|
isQuiet,
|
|
44
45
|
isDisabled,
|
|
45
46
|
isReadOnly,
|
|
46
|
-
isRequired,
|
|
47
47
|
autoFocus,
|
|
48
48
|
placeholderValue,
|
|
49
49
|
maxVisibleMonths = 1,
|
|
@@ -52,9 +52,12 @@ export function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePic
|
|
|
52
52
|
let {styleProps} = useStyleProps(otherProps);
|
|
53
53
|
let {hoverProps, isHovered} = useHover({isDisabled});
|
|
54
54
|
let targetRef = useRef<HTMLDivElement>();
|
|
55
|
-
let state = useDateRangePickerState(
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
let state = useDateRangePickerState({
|
|
56
|
+
...props,
|
|
57
|
+
shouldCloseOnSelect: () => !state.hasTime
|
|
58
|
+
});
|
|
59
|
+
let {labelProps, groupProps, buttonProps, dialogProps, startFieldProps, endFieldProps, descriptionProps, errorMessageProps, calendarProps} = useDateRangePicker(props, state, targetRef);
|
|
60
|
+
let {isOpen, setOpen} = state;
|
|
58
61
|
let {direction} = useLocale();
|
|
59
62
|
|
|
60
63
|
let {isFocused, isFocusVisible, focusProps} = useFocusRing({
|
|
@@ -105,6 +108,7 @@ export function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePic
|
|
|
105
108
|
return (
|
|
106
109
|
<Field
|
|
107
110
|
{...props}
|
|
111
|
+
elementType="span"
|
|
108
112
|
ref={targetRef}
|
|
109
113
|
description={description}
|
|
110
114
|
labelProps={labelProps}
|
|
@@ -120,39 +124,18 @@ export function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePic
|
|
|
120
124
|
isDisabled={isDisabled}
|
|
121
125
|
isQuiet={isQuiet}
|
|
122
126
|
validationState={state.validationState}
|
|
123
|
-
autoFocus={autoFocus}
|
|
124
127
|
className={classNames(styles, 'spectrum-InputGroup-field')}
|
|
125
128
|
inputClassName={fieldClassName}>
|
|
126
129
|
<DatePickerField
|
|
127
130
|
{...startFieldProps}
|
|
131
|
+
data-testid="start-date"
|
|
128
132
|
isQuiet={props.isQuiet}
|
|
129
|
-
isDisabled={isDisabled}
|
|
130
|
-
isReadOnly={isReadOnly}
|
|
131
|
-
isRequired={isRequired}
|
|
132
|
-
validationState={state.validationState}
|
|
133
|
-
placeholderValue={placeholderValue}
|
|
134
|
-
value={value?.start || null}
|
|
135
|
-
defaultValue={null}
|
|
136
|
-
onChange={start => state.setDateTime('start', start)}
|
|
137
|
-
granularity={props.granularity}
|
|
138
|
-
hourCycle={props.hourCycle}
|
|
139
|
-
hideTimeZone={props.hideTimeZone}
|
|
140
133
|
inputClassName={classNames(datepickerStyles, 'react-spectrum-Datepicker-startField')} />
|
|
141
134
|
<DateRangeDash />
|
|
142
135
|
<DatePickerField
|
|
143
136
|
{...endFieldProps}
|
|
137
|
+
data-testid="end-date"
|
|
144
138
|
isQuiet={props.isQuiet}
|
|
145
|
-
isDisabled={isDisabled}
|
|
146
|
-
isReadOnly={isReadOnly}
|
|
147
|
-
isRequired={isRequired}
|
|
148
|
-
validationState={state.validationState}
|
|
149
|
-
placeholderValue={placeholderValue}
|
|
150
|
-
value={value?.end || null}
|
|
151
|
-
defaultValue={null}
|
|
152
|
-
onChange={end => state.setDateTime('end', end)}
|
|
153
|
-
granularity={props.granularity}
|
|
154
|
-
hourCycle={props.hourCycle}
|
|
155
|
-
hideTimeZone={props.hideTimeZone}
|
|
156
139
|
inputClassName={classNames(
|
|
157
140
|
styles,
|
|
158
141
|
'spectrum-Datepicker-endField',
|
|
@@ -181,12 +164,8 @@ export function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePic
|
|
|
181
164
|
<Dialog UNSAFE_className={classNames(datepickerStyles, 'react-spectrum-Datepicker-dialog')} {...dialogProps}>
|
|
182
165
|
<Content UNSAFE_className={classNames(datepickerStyles, 'react-spectrum-Datepicker-dialogContent')}>
|
|
183
166
|
<RangeCalendar
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
onChange={state.setDateRange}
|
|
187
|
-
visibleMonths={visibleMonths}
|
|
188
|
-
minValue={props.minValue}
|
|
189
|
-
maxValue={props.maxValue} />
|
|
167
|
+
{...calendarProps}
|
|
168
|
+
visibleMonths={visibleMonths} />
|
|
190
169
|
{showTimeField &&
|
|
191
170
|
<Flex gap="size-100" marginTop="size-100" UNSAFE_className={classNames(datepickerStyles, 'react-spectrum-Datepicker-timeFields')}>
|
|
192
171
|
<TimeField
|
package/src/Input.tsx
CHANGED
|
@@ -14,10 +14,10 @@ import Alert from '@spectrum-icons/ui/AlertMedium';
|
|
|
14
14
|
import Checkmark from '@spectrum-icons/ui/CheckmarkMedium';
|
|
15
15
|
import {classNames, useValueEffect} from '@react-spectrum/utils';
|
|
16
16
|
import datepickerStyles from './index.css';
|
|
17
|
-
import {FocusRing
|
|
18
|
-
import {mergeProps, useEvent, useLayoutEffect, useResizeObserver} from '@react-aria/utils';
|
|
17
|
+
import {FocusRing} from '@react-aria/focus';
|
|
19
18
|
import React, {useCallback, useRef} from 'react';
|
|
20
19
|
import textfieldStyles from '@adobe/spectrum-css-temp/components/textfield/vars.css';
|
|
20
|
+
import {useEvent, useLayoutEffect, useResizeObserver} from '@react-aria/utils';
|
|
21
21
|
|
|
22
22
|
export function Input(props) {
|
|
23
23
|
let defaultRef = useRef();
|
|
@@ -30,7 +30,6 @@ export function Input(props) {
|
|
|
30
30
|
fieldProps,
|
|
31
31
|
inputRef = defaultRef,
|
|
32
32
|
className,
|
|
33
|
-
autoFocus,
|
|
34
33
|
style
|
|
35
34
|
} = props;
|
|
36
35
|
|
|
@@ -113,13 +112,11 @@ export function Input(props) {
|
|
|
113
112
|
}
|
|
114
113
|
|
|
115
114
|
return (
|
|
116
|
-
<div {...
|
|
115
|
+
<div role="presentation" {...fieldProps} className={textfieldClass} style={style}>
|
|
117
116
|
<FocusRing focusClass={classNames(textfieldStyles, 'is-focused')} focusRingClass={classNames(textfieldStyles, 'focus-ring')} isTextInput within>
|
|
118
117
|
<div role="presentation" className={inputClass}>
|
|
119
118
|
<div role="presentation" className={classNames(datepickerStyles, 'react-spectrum-Datepicker-inputContents')} ref={inputRef}>
|
|
120
|
-
|
|
121
|
-
{children}
|
|
122
|
-
</FocusScope>
|
|
119
|
+
{children}
|
|
123
120
|
</div>
|
|
124
121
|
</div>
|
|
125
122
|
</FocusRing>
|
package/src/TimeField.tsx
CHANGED
|
@@ -11,16 +11,15 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {classNames} from '@react-spectrum/utils';
|
|
14
|
-
import {createCalendar} from '@internationalized/date';
|
|
15
14
|
import {DatePickerSegment} from './DatePickerSegment';
|
|
16
15
|
import datepickerStyles from './index.css';
|
|
17
16
|
import {Field} from '@react-spectrum/label';
|
|
18
17
|
import {Input} from './Input';
|
|
19
18
|
import React, {useRef} from 'react';
|
|
20
19
|
import {SpectrumTimePickerProps, TimeValue} from '@react-types/datepicker';
|
|
21
|
-
import {useDateField} from '@react-aria/datepicker';
|
|
22
20
|
import {useLocale} from '@react-aria/i18n';
|
|
23
21
|
import {useProviderProps} from '@react-spectrum/provider';
|
|
22
|
+
import {useTimeField} from '@react-aria/datepicker';
|
|
24
23
|
import {useTimeFieldState} from '@react-stately/datepicker';
|
|
25
24
|
|
|
26
25
|
/**
|
|
@@ -41,15 +40,15 @@ export function TimeField<T extends TimeValue>(props: SpectrumTimePickerProps<T>
|
|
|
41
40
|
let {locale} = useLocale();
|
|
42
41
|
let state = useTimeFieldState({
|
|
43
42
|
...props,
|
|
44
|
-
locale
|
|
45
|
-
createCalendar
|
|
43
|
+
locale
|
|
46
44
|
});
|
|
47
45
|
|
|
48
|
-
let {labelProps, fieldProps, descriptionProps, errorMessageProps} =
|
|
46
|
+
let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useTimeField(props, state, ref);
|
|
49
47
|
|
|
50
48
|
return (
|
|
51
49
|
<Field
|
|
52
50
|
{...props}
|
|
51
|
+
elementType="span"
|
|
53
52
|
labelProps={labelProps}
|
|
54
53
|
descriptionProps={descriptionProps}
|
|
55
54
|
errorMessageProps={errorMessageProps}
|
package/src/index.css
CHANGED
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
.react-spectrum-Datepicker-input.react-spectrum-Datepicker-input {
|
|
55
55
|
/* always reserve space for the validation icon */
|
|
56
56
|
padding-inline-end: calc(var(--spectrum-textfield-padding-x) + var(--spectrum-icon-alert-medium-width) + var(--spectrum-textfield-icon-margin-left));
|
|
57
|
+
cursor: text;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
.react-spectrum-Datepicker-inputContents {
|
|
@@ -106,15 +107,8 @@
|
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
.react-spectrum-DatePicker-cell:focus {
|
|
110
|
-
background-color: var(--spectrum-global-color-static-blue);
|
|
111
|
-
color: white;
|
|
112
|
-
caret-color: transparent;
|
|
113
|
-
outline: none;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
110
|
.react-spectrum-DatePicker-cell.is-placeholder {
|
|
117
|
-
color: var(--spectrum-
|
|
111
|
+
color: var(--react-spectrum-datepicker-placeholder-color);
|
|
118
112
|
|
|
119
113
|
&:before {
|
|
120
114
|
content: attr(aria-placeholder);
|
|
@@ -125,15 +119,15 @@
|
|
|
125
119
|
color: var(--spectrum-textfield-placeholder-text-color, var(--spectrum-global-color-gray-600));
|
|
126
120
|
}
|
|
127
121
|
|
|
128
|
-
.react-spectrum-DatePicker-cell.is-placeholder:focus {
|
|
129
|
-
color: var(--spectrum-global-color-static-gray-400);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
122
|
.react-spectrum-DatePicker-cell.is-read-only {
|
|
133
123
|
color: var(--spectrum-global-color-gray-700);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.react-spectrum-DatePicker-cell:focus {
|
|
127
|
+
background-color: var(--spectrum-global-color-static-blue);
|
|
128
|
+
color: white;
|
|
129
|
+
caret-color: transparent;
|
|
130
|
+
outline: none;
|
|
137
131
|
}
|
|
138
132
|
|
|
139
133
|
.react-spectrum-Datepicker-dialog.react-spectrum-Datepicker-dialog {
|