@react-spectrum/datepicker 3.14.10 → 3.15.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 +5 -5
- package/dist/main.js +8 -8
- package/dist/main.js.map +1 -1
- package/dist/module.js +5 -5
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +8 -0
- package/package.json +12 -44
- package/src/index.ts +9 -5
- package/dist/DateField.main.js +0 -108
- package/dist/DateField.main.js.map +0 -1
- package/dist/DateField.mjs +0 -103
- package/dist/DateField.module.js +0 -103
- package/dist/DateField.module.js.map +0 -1
- package/dist/DatePicker.main.js +0 -197
- package/dist/DatePicker.main.js.map +0 -1
- package/dist/DatePicker.mjs +0 -192
- package/dist/DatePicker.module.js +0 -192
- package/dist/DatePicker.module.js.map +0 -1
- package/dist/DatePickerField.main.js +0 -72
- package/dist/DatePickerField.main.js.map +0 -1
- package/dist/DatePickerField.mjs +0 -67
- package/dist/DatePickerField.module.js +0 -67
- package/dist/DatePickerField.module.js.map +0 -1
- package/dist/DatePickerSegment.main.js +0 -73
- package/dist/DatePickerSegment.main.js.map +0 -1
- package/dist/DatePickerSegment.mjs +0 -68
- package/dist/DatePickerSegment.module.js +0 -68
- package/dist/DatePickerSegment.module.js.map +0 -1
- package/dist/DateRangePicker.main.js +0 -229
- package/dist/DateRangePicker.main.js.map +0 -1
- package/dist/DateRangePicker.mjs +0 -224
- package/dist/DateRangePicker.module.js +0 -224
- package/dist/DateRangePicker.module.js.map +0 -1
- package/dist/Input.main.js +0 -128
- package/dist/Input.main.js.map +0 -1
- package/dist/Input.mjs +0 -123
- package/dist/Input.module.js +0 -123
- package/dist/Input.module.js.map +0 -1
- package/dist/TimeField.main.js +0 -100
- package/dist/TimeField.main.js.map +0 -1
- package/dist/TimeField.mjs +0 -95
- package/dist/TimeField.module.js +0 -95
- package/dist/TimeField.module.js.map +0 -1
- package/dist/ar-AE.main.js +0 -8
- package/dist/ar-AE.main.js.map +0 -1
- package/dist/ar-AE.mjs +0 -10
- package/dist/ar-AE.module.js +0 -10
- package/dist/ar-AE.module.js.map +0 -1
- package/dist/bg-BG.main.js +0 -8
- package/dist/bg-BG.main.js.map +0 -1
- package/dist/bg-BG.mjs +0 -10
- package/dist/bg-BG.module.js +0 -10
- package/dist/bg-BG.module.js.map +0 -1
- package/dist/cs-CZ.main.js +0 -8
- package/dist/cs-CZ.main.js.map +0 -1
- package/dist/cs-CZ.mjs +0 -10
- package/dist/cs-CZ.module.js +0 -10
- package/dist/cs-CZ.module.js.map +0 -1
- package/dist/da-DK.main.js +0 -8
- package/dist/da-DK.main.js.map +0 -1
- package/dist/da-DK.mjs +0 -10
- package/dist/da-DK.module.js +0 -10
- package/dist/da-DK.module.js.map +0 -1
- package/dist/datepicker.4d1286b0.css +0 -649
- package/dist/datepicker.4d1286b0.css.map +0 -1
- package/dist/datepicker.776a7787.css +0 -550
- package/dist/datepicker.776a7787.css.map +0 -1
- package/dist/datepicker.e85992d8.css +0 -204
- package/dist/datepicker.e85992d8.css.map +0 -1
- package/dist/de-DE.main.js +0 -8
- package/dist/de-DE.main.js.map +0 -1
- package/dist/de-DE.mjs +0 -10
- package/dist/de-DE.module.js +0 -10
- package/dist/de-DE.module.js.map +0 -1
- package/dist/el-GR.main.js +0 -8
- package/dist/el-GR.main.js.map +0 -1
- package/dist/el-GR.mjs +0 -10
- package/dist/el-GR.module.js +0 -10
- package/dist/el-GR.module.js.map +0 -1
- package/dist/en-US.main.js +0 -8
- package/dist/en-US.main.js.map +0 -1
- package/dist/en-US.mjs +0 -10
- package/dist/en-US.module.js +0 -10
- package/dist/en-US.module.js.map +0 -1
- package/dist/es-ES.main.js +0 -8
- package/dist/es-ES.main.js.map +0 -1
- package/dist/es-ES.mjs +0 -10
- package/dist/es-ES.module.js +0 -10
- package/dist/es-ES.module.js.map +0 -1
- package/dist/et-EE.main.js +0 -8
- package/dist/et-EE.main.js.map +0 -1
- package/dist/et-EE.mjs +0 -10
- package/dist/et-EE.module.js +0 -10
- package/dist/et-EE.module.js.map +0 -1
- package/dist/fi-FI.main.js +0 -8
- package/dist/fi-FI.main.js.map +0 -1
- package/dist/fi-FI.mjs +0 -10
- package/dist/fi-FI.module.js +0 -10
- package/dist/fi-FI.module.js.map +0 -1
- package/dist/fr-FR.main.js +0 -8
- package/dist/fr-FR.main.js.map +0 -1
- package/dist/fr-FR.mjs +0 -10
- package/dist/fr-FR.module.js +0 -10
- package/dist/fr-FR.module.js.map +0 -1
- package/dist/he-IL.main.js +0 -8
- package/dist/he-IL.main.js.map +0 -1
- package/dist/he-IL.mjs +0 -10
- package/dist/he-IL.module.js +0 -10
- package/dist/he-IL.module.js.map +0 -1
- package/dist/hr-HR.main.js +0 -8
- package/dist/hr-HR.main.js.map +0 -1
- package/dist/hr-HR.mjs +0 -10
- package/dist/hr-HR.module.js +0 -10
- package/dist/hr-HR.module.js.map +0 -1
- package/dist/hu-HU.main.js +0 -8
- package/dist/hu-HU.main.js.map +0 -1
- package/dist/hu-HU.mjs +0 -10
- package/dist/hu-HU.module.js +0 -10
- package/dist/hu-HU.module.js.map +0 -1
- package/dist/inputgroup_vars_css.main.js +0 -86
- package/dist/inputgroup_vars_css.main.js.map +0 -1
- package/dist/inputgroup_vars_css.mjs +0 -88
- package/dist/inputgroup_vars_css.module.js +0 -88
- package/dist/inputgroup_vars_css.module.js.map +0 -1
- package/dist/intlStrings.main.js +0 -108
- package/dist/intlStrings.main.js.map +0 -1
- package/dist/intlStrings.mjs +0 -110
- package/dist/intlStrings.module.js +0 -110
- package/dist/intlStrings.module.js.map +0 -1
- package/dist/it-IT.main.js +0 -8
- package/dist/it-IT.main.js.map +0 -1
- package/dist/it-IT.mjs +0 -10
- package/dist/it-IT.module.js +0 -10
- package/dist/it-IT.module.js.map +0 -1
- package/dist/ja-JP.main.js +0 -8
- package/dist/ja-JP.main.js.map +0 -1
- package/dist/ja-JP.mjs +0 -10
- package/dist/ja-JP.module.js +0 -10
- package/dist/ja-JP.module.js.map +0 -1
- package/dist/ko-KR.main.js +0 -8
- package/dist/ko-KR.main.js.map +0 -1
- package/dist/ko-KR.mjs +0 -10
- package/dist/ko-KR.module.js +0 -10
- package/dist/ko-KR.module.js.map +0 -1
- package/dist/lt-LT.main.js +0 -8
- package/dist/lt-LT.main.js.map +0 -1
- package/dist/lt-LT.mjs +0 -10
- package/dist/lt-LT.module.js +0 -10
- package/dist/lt-LT.module.js.map +0 -1
- package/dist/lv-LV.main.js +0 -8
- package/dist/lv-LV.main.js.map +0 -1
- package/dist/lv-LV.mjs +0 -10
- package/dist/lv-LV.module.js +0 -10
- package/dist/lv-LV.module.js.map +0 -1
- package/dist/nb-NO.main.js +0 -8
- package/dist/nb-NO.main.js.map +0 -1
- package/dist/nb-NO.mjs +0 -10
- package/dist/nb-NO.module.js +0 -10
- package/dist/nb-NO.module.js.map +0 -1
- package/dist/nl-NL.main.js +0 -8
- package/dist/nl-NL.main.js.map +0 -1
- package/dist/nl-NL.mjs +0 -10
- package/dist/nl-NL.module.js +0 -10
- package/dist/nl-NL.module.js.map +0 -1
- package/dist/pl-PL.main.js +0 -8
- package/dist/pl-PL.main.js.map +0 -1
- package/dist/pl-PL.mjs +0 -10
- package/dist/pl-PL.module.js +0 -10
- package/dist/pl-PL.module.js.map +0 -1
- package/dist/pt-BR.main.js +0 -8
- package/dist/pt-BR.main.js.map +0 -1
- package/dist/pt-BR.mjs +0 -10
- package/dist/pt-BR.module.js +0 -10
- package/dist/pt-BR.module.js.map +0 -1
- package/dist/pt-PT.main.js +0 -8
- package/dist/pt-PT.main.js.map +0 -1
- package/dist/pt-PT.mjs +0 -10
- package/dist/pt-PT.module.js +0 -10
- package/dist/pt-PT.module.js.map +0 -1
- package/dist/ro-RO.main.js +0 -8
- package/dist/ro-RO.main.js.map +0 -1
- package/dist/ro-RO.mjs +0 -10
- package/dist/ro-RO.module.js +0 -10
- package/dist/ro-RO.module.js.map +0 -1
- package/dist/ru-RU.main.js +0 -8
- package/dist/ru-RU.main.js.map +0 -1
- package/dist/ru-RU.mjs +0 -10
- package/dist/ru-RU.module.js +0 -10
- package/dist/ru-RU.module.js.map +0 -1
- package/dist/sk-SK.main.js +0 -8
- package/dist/sk-SK.main.js.map +0 -1
- package/dist/sk-SK.mjs +0 -10
- package/dist/sk-SK.module.js +0 -10
- package/dist/sk-SK.module.js.map +0 -1
- package/dist/sl-SI.main.js +0 -8
- package/dist/sl-SI.main.js.map +0 -1
- package/dist/sl-SI.mjs +0 -10
- package/dist/sl-SI.module.js +0 -10
- package/dist/sl-SI.module.js.map +0 -1
- package/dist/sr-SP.main.js +0 -8
- package/dist/sr-SP.main.js.map +0 -1
- package/dist/sr-SP.mjs +0 -10
- package/dist/sr-SP.module.js +0 -10
- package/dist/sr-SP.module.js.map +0 -1
- package/dist/styles_css.main.js +0 -77
- package/dist/styles_css.main.js.map +0 -1
- package/dist/styles_css.mjs +0 -79
- package/dist/styles_css.module.js +0 -79
- package/dist/styles_css.module.js.map +0 -1
- package/dist/sv-SE.main.js +0 -8
- package/dist/sv-SE.main.js.map +0 -1
- package/dist/sv-SE.mjs +0 -10
- package/dist/sv-SE.module.js +0 -10
- package/dist/sv-SE.module.js.map +0 -1
- package/dist/textfield_vars_css.main.js +0 -74
- package/dist/textfield_vars_css.main.js.map +0 -1
- package/dist/textfield_vars_css.mjs +0 -76
- package/dist/textfield_vars_css.module.js +0 -76
- package/dist/textfield_vars_css.module.js.map +0 -1
- package/dist/tr-TR.main.js +0 -8
- package/dist/tr-TR.main.js.map +0 -1
- package/dist/tr-TR.mjs +0 -10
- package/dist/tr-TR.module.js +0 -10
- package/dist/tr-TR.module.js.map +0 -1
- package/dist/types.d.ts +0 -33
- package/dist/types.d.ts.map +0 -1
- package/dist/uk-UA.main.js +0 -8
- package/dist/uk-UA.main.js.map +0 -1
- package/dist/uk-UA.mjs +0 -10
- package/dist/uk-UA.module.js +0 -10
- package/dist/uk-UA.module.js.map +0 -1
- package/dist/utils.main.js +0 -117
- package/dist/utils.main.js.map +0 -1
- package/dist/utils.mjs +0 -105
- package/dist/utils.module.js +0 -105
- package/dist/utils.module.js.map +0 -1
- package/dist/zh-CN.main.js +0 -8
- package/dist/zh-CN.main.js.map +0 -1
- package/dist/zh-CN.mjs +0 -10
- package/dist/zh-CN.module.js +0 -10
- package/dist/zh-CN.module.js.map +0 -1
- package/dist/zh-TW.main.js +0 -8
- package/dist/zh-TW.main.js.map +0 -1
- package/dist/zh-TW.mjs +0 -10
- package/dist/zh-TW.module.js +0 -10
- package/dist/zh-TW.module.js.map +0 -1
- package/src/DateField.tsx +0 -106
- package/src/DatePicker.tsx +0 -196
- package/src/DatePickerField.tsx +0 -61
- package/src/DatePickerSegment.tsx +0 -69
- package/src/DateRangePicker.tsx +0 -234
- package/src/Input.tsx +0 -142
- package/src/TimeField.tsx +0 -96
- package/src/styles.css +0 -203
- package/src/utils.tsx +0 -96
package/src/DatePicker.tsx
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {Calendar} from '@react-spectrum/calendar';
|
|
14
|
-
import CalendarIcon from '@spectrum-icons/workflow/Calendar';
|
|
15
|
-
import {classNames} from '@react-spectrum/utils';
|
|
16
|
-
import {Content} from '@react-spectrum/view';
|
|
17
|
-
import {DatePickerField} from './DatePickerField';
|
|
18
|
-
import datepickerStyles from './styles.css';
|
|
19
|
-
import {DateValue, SpectrumDatePickerProps} from '@react-types/datepicker';
|
|
20
|
-
import {Dialog, DialogTrigger} from '@react-spectrum/dialog';
|
|
21
|
-
import {Field} from '@react-spectrum/label';
|
|
22
|
-
import {FieldButton} from '@react-spectrum/button';
|
|
23
|
-
import {FocusableRef} from '@react-types/shared';
|
|
24
|
-
import {Input} from './Input';
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
import intlMessages from '../intl/*.json';
|
|
27
|
-
import {mergeProps} from '@react-aria/utils';
|
|
28
|
-
import React, {ReactElement, useRef} from 'react';
|
|
29
|
-
import '@adobe/spectrum-css-temp/components/textfield/vars.css'; // HACK: must be included BEFORE inputgroup
|
|
30
|
-
import styles from '@adobe/spectrum-css-temp/components/inputgroup/vars.css';
|
|
31
|
-
import {TimeField} from './TimeField';
|
|
32
|
-
import {useDatePicker} from '@react-aria/datepicker';
|
|
33
|
-
import {useDatePickerState} from '@react-stately/datepicker';
|
|
34
|
-
import {useFocusManagerRef, useFormatHelpText, useFormattedDateWidth, useVisibleMonths} from './utils';
|
|
35
|
-
import {useFocusRing} from '@react-aria/focus';
|
|
36
|
-
import {useFormProps} from '@react-spectrum/form';
|
|
37
|
-
import {useHover} from '@react-aria/interactions';
|
|
38
|
-
import {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
39
|
-
import {useProviderProps} from '@react-spectrum/provider';
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* DatePickers combine a DateField and a Calendar popover to allow users to enter or select a date and time value.
|
|
43
|
-
*/
|
|
44
|
-
export const DatePicker = React.forwardRef(function DatePicker<T extends DateValue>(props: SpectrumDatePickerProps<T>, ref: FocusableRef<HTMLElement>) {
|
|
45
|
-
props = useProviderProps(props);
|
|
46
|
-
props = useFormProps(props);
|
|
47
|
-
let {
|
|
48
|
-
autoFocus,
|
|
49
|
-
isQuiet,
|
|
50
|
-
isDisabled,
|
|
51
|
-
placeholderValue,
|
|
52
|
-
maxVisibleMonths = 1
|
|
53
|
-
} = props;
|
|
54
|
-
let {hoverProps, isHovered} = useHover({isDisabled});
|
|
55
|
-
let targetRef = useRef<HTMLDivElement | null>(null);
|
|
56
|
-
let state = useDatePickerState({
|
|
57
|
-
...props,
|
|
58
|
-
shouldCloseOnSelect: () => !state.hasTime
|
|
59
|
-
});
|
|
60
|
-
let {groupProps, labelProps, fieldProps, descriptionProps, errorMessageProps, buttonProps, dialogProps, calendarProps, isInvalid, validationErrors, validationDetails} = useDatePicker(props, state, targetRef);
|
|
61
|
-
let {isOpen, setOpen} = state;
|
|
62
|
-
let {direction} = useLocale();
|
|
63
|
-
let domRef = useFocusManagerRef(ref);
|
|
64
|
-
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/datepicker');
|
|
65
|
-
|
|
66
|
-
let {isFocused, isFocusVisible, focusProps} = useFocusRing({
|
|
67
|
-
within: true,
|
|
68
|
-
isTextInput: true,
|
|
69
|
-
autoFocus
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
let {isFocused: isFocusedButton, focusProps: focusPropsButton} = useFocusRing({
|
|
73
|
-
within: false,
|
|
74
|
-
isTextInput: false,
|
|
75
|
-
autoFocus
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
let className = classNames(
|
|
79
|
-
styles,
|
|
80
|
-
'spectrum-InputGroup',
|
|
81
|
-
{
|
|
82
|
-
'spectrum-InputGroup--quiet': isQuiet,
|
|
83
|
-
'spectrum-InputGroup--invalid': isInvalid && !isDisabled,
|
|
84
|
-
'is-disabled': isDisabled,
|
|
85
|
-
'is-hovered': isHovered,
|
|
86
|
-
'is-focused': isFocused,
|
|
87
|
-
'focus-ring': isFocusVisible && !isFocusedButton
|
|
88
|
-
}
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
let fieldClassName = classNames(
|
|
92
|
-
styles,
|
|
93
|
-
'spectrum-InputGroup-input',
|
|
94
|
-
{
|
|
95
|
-
'is-disabled': isDisabled,
|
|
96
|
-
'is-invalid': isInvalid && !isDisabled
|
|
97
|
-
}
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
// Note: this description is intentionally not passed to useDatePicker.
|
|
101
|
-
// The format help text is unnecessary for screen reader users because each segment already has a label.
|
|
102
|
-
let description = useFormatHelpText(props);
|
|
103
|
-
if (description && !props.description) {
|
|
104
|
-
descriptionProps.id = undefined;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
let placeholder: DateValue | null | undefined = placeholderValue;
|
|
108
|
-
let timePlaceholder = placeholder && 'hour' in placeholder ? placeholder : null;
|
|
109
|
-
let timeMinValue = props.minValue && 'hour' in props.minValue ? props.minValue : null;
|
|
110
|
-
let timeMaxValue = props.maxValue && 'hour' in props.maxValue ? props.maxValue : null;
|
|
111
|
-
let timeGranularity = state.granularity === 'hour' || state.granularity === 'minute' || state.granularity === 'second' ? state.granularity : null;
|
|
112
|
-
let showTimeField = !!timeGranularity;
|
|
113
|
-
|
|
114
|
-
let visibleMonths = useVisibleMonths(maxVisibleMonths);
|
|
115
|
-
let validationState = state.validationState || (isInvalid ? 'invalid' : null);
|
|
116
|
-
|
|
117
|
-
let approximateWidth = useFormattedDateWidth(state) + 'ch';
|
|
118
|
-
|
|
119
|
-
return (
|
|
120
|
-
<Field
|
|
121
|
-
{...props}
|
|
122
|
-
ref={domRef}
|
|
123
|
-
elementType="span"
|
|
124
|
-
description={description}
|
|
125
|
-
labelProps={labelProps}
|
|
126
|
-
descriptionProps={descriptionProps}
|
|
127
|
-
errorMessageProps={errorMessageProps}
|
|
128
|
-
validationState={validationState}
|
|
129
|
-
isInvalid={isInvalid}
|
|
130
|
-
validationErrors={validationErrors}
|
|
131
|
-
validationDetails={validationDetails}
|
|
132
|
-
wrapperClassName={classNames(datepickerStyles, 'react-spectrum-Datepicker-fieldWrapper')}>
|
|
133
|
-
<div
|
|
134
|
-
{...mergeProps(groupProps, hoverProps, focusProps)}
|
|
135
|
-
className={className}
|
|
136
|
-
ref={targetRef}>
|
|
137
|
-
<Input
|
|
138
|
-
isDisabled={isDisabled}
|
|
139
|
-
isQuiet={isQuiet}
|
|
140
|
-
validationState={validationState}
|
|
141
|
-
className={classNames(styles, 'spectrum-InputGroup-field')}
|
|
142
|
-
inputClassName={fieldClassName}
|
|
143
|
-
disableFocusRing
|
|
144
|
-
minWidth={approximateWidth}>
|
|
145
|
-
<DatePickerField
|
|
146
|
-
{...fieldProps}
|
|
147
|
-
data-testid="date-field"
|
|
148
|
-
isQuiet={isQuiet} />
|
|
149
|
-
</Input>
|
|
150
|
-
<DialogTrigger
|
|
151
|
-
type="popover"
|
|
152
|
-
mobileType="tray"
|
|
153
|
-
placement={direction === 'rtl' ? 'bottom right' : 'bottom left'}
|
|
154
|
-
targetRef={targetRef}
|
|
155
|
-
hideArrow
|
|
156
|
-
isOpen={isOpen}
|
|
157
|
-
onOpenChange={setOpen}
|
|
158
|
-
shouldFlip={props.shouldFlip}>
|
|
159
|
-
<FieldButton
|
|
160
|
-
{...mergeProps(buttonProps, focusPropsButton)}
|
|
161
|
-
UNSAFE_className={classNames(styles, 'spectrum-FieldButton')}
|
|
162
|
-
isQuiet={isQuiet}
|
|
163
|
-
validationState={validationState}>
|
|
164
|
-
<CalendarIcon />
|
|
165
|
-
</FieldButton>
|
|
166
|
-
<Dialog UNSAFE_className={classNames(datepickerStyles, 'react-spectrum-Datepicker-dialog')} {...dialogProps}>
|
|
167
|
-
<Content>
|
|
168
|
-
<div className={classNames(datepickerStyles, 'react-spectrum-Datepicker-dialogContent')}>
|
|
169
|
-
<Calendar
|
|
170
|
-
{...calendarProps}
|
|
171
|
-
visibleMonths={visibleMonths}
|
|
172
|
-
createCalendar={props.createCalendar}
|
|
173
|
-
UNSAFE_className={classNames(datepickerStyles, 'react-spectrum-Datepicker-calendar', {'is-invalid': isInvalid})} />
|
|
174
|
-
{showTimeField &&
|
|
175
|
-
<div className={classNames(datepickerStyles, 'react-spectrum-Datepicker-timeFields')}>
|
|
176
|
-
<TimeField
|
|
177
|
-
label={stringFormatter.format('time')}
|
|
178
|
-
value={state.timeValue}
|
|
179
|
-
onChange={state.setTimeValue}
|
|
180
|
-
placeholderValue={timePlaceholder}
|
|
181
|
-
granularity={timeGranularity}
|
|
182
|
-
minValue={timeMinValue}
|
|
183
|
-
maxValue={timeMaxValue}
|
|
184
|
-
hourCycle={props.hourCycle}
|
|
185
|
-
hideTimeZone={props.hideTimeZone}
|
|
186
|
-
marginTop="size-100" />
|
|
187
|
-
</div>
|
|
188
|
-
}
|
|
189
|
-
</div>
|
|
190
|
-
</Content>
|
|
191
|
-
</Dialog>
|
|
192
|
-
</DialogTrigger>
|
|
193
|
-
</div>
|
|
194
|
-
</Field>
|
|
195
|
-
);
|
|
196
|
-
}) as <T extends DateValue>(props: SpectrumDatePickerProps<T> & {ref?: FocusableRef<HTMLElement>}) => ReactElement;
|
package/src/DatePickerField.tsx
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {classNames} from '@react-spectrum/utils';
|
|
14
|
-
import {createCalendar} from '@internationalized/date';
|
|
15
|
-
import {DatePickerSegment} from './DatePickerSegment';
|
|
16
|
-
import datepickerStyles from './styles.css';
|
|
17
|
-
import {DateValue, SpectrumDatePickerProps} from '@react-types/datepicker';
|
|
18
|
-
import React, {JSX, useRef} from 'react';
|
|
19
|
-
import {useDateField} from '@react-aria/datepicker';
|
|
20
|
-
import {useDateFieldState} from '@react-stately/datepicker';
|
|
21
|
-
import {useLocale} from '@react-aria/i18n';
|
|
22
|
-
|
|
23
|
-
interface DatePickerFieldProps<T extends DateValue> extends SpectrumDatePickerProps<T> {
|
|
24
|
-
inputClassName?: string,
|
|
25
|
-
hideValidationIcon?: boolean,
|
|
26
|
-
maxGranularity?: SpectrumDatePickerProps<T>['granularity']
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function DatePickerField<T extends DateValue>(props: DatePickerFieldProps<T>): JSX.Element {
|
|
30
|
-
let {
|
|
31
|
-
isDisabled,
|
|
32
|
-
isReadOnly,
|
|
33
|
-
isRequired,
|
|
34
|
-
inputClassName
|
|
35
|
-
} = props;
|
|
36
|
-
let ref = useRef<HTMLDivElement | null>(null);
|
|
37
|
-
let {locale} = useLocale();
|
|
38
|
-
let state = useDateFieldState({
|
|
39
|
-
...props,
|
|
40
|
-
locale,
|
|
41
|
-
createCalendar
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
let inputRef = useRef<HTMLInputElement | null>(null);
|
|
45
|
-
let {fieldProps, inputProps} = useDateField({...props, inputRef}, state, ref);
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
<span {...fieldProps} data-testid={props['data-testid']} className={classNames(datepickerStyles, 'react-spectrum-Datepicker-segments', inputClassName)} ref={ref}>
|
|
49
|
-
{state.segments.map((segment, i) =>
|
|
50
|
-
(<DatePickerSegment
|
|
51
|
-
key={i}
|
|
52
|
-
segment={segment}
|
|
53
|
-
state={state}
|
|
54
|
-
isDisabled={isDisabled}
|
|
55
|
-
isReadOnly={isReadOnly}
|
|
56
|
-
isRequired={isRequired} />)
|
|
57
|
-
)}
|
|
58
|
-
<input {...inputProps} ref={inputRef} />
|
|
59
|
-
</span>
|
|
60
|
-
);
|
|
61
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {classNames} from '@react-spectrum/utils';
|
|
14
|
-
import {DateFieldState, DateSegment} from '@react-stately/datepicker';
|
|
15
|
-
import {DatePickerBase, DateValue} from '@react-types/datepicker';
|
|
16
|
-
import React, {JSX, useRef} from 'react';
|
|
17
|
-
import styles from './styles.css';
|
|
18
|
-
import {useDateSegment} from '@react-aria/datepicker';
|
|
19
|
-
|
|
20
|
-
interface DatePickerSegmentProps extends DatePickerBase<DateValue> {
|
|
21
|
-
segment: DateSegment,
|
|
22
|
-
state: DateFieldState
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface LiteralSegmentProps {
|
|
26
|
-
segment: DateSegment
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function DatePickerSegment({segment, state, ...otherProps}: DatePickerSegmentProps): JSX.Element {
|
|
30
|
-
switch (segment.type) {
|
|
31
|
-
// A separator, e.g. punctuation
|
|
32
|
-
case 'literal':
|
|
33
|
-
return <LiteralSegment segment={segment} />;
|
|
34
|
-
|
|
35
|
-
// Editable segment
|
|
36
|
-
default:
|
|
37
|
-
return <EditableSegment segment={segment} state={state} {...otherProps} />;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function LiteralSegment({segment}: LiteralSegmentProps) {
|
|
42
|
-
return (
|
|
43
|
-
<span
|
|
44
|
-
aria-hidden="true"
|
|
45
|
-
className={classNames(styles, 'react-spectrum-Datepicker-literal')}
|
|
46
|
-
data-testid={segment.type === 'literal' ? undefined : segment.type}>
|
|
47
|
-
{segment.text}
|
|
48
|
-
</span>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function EditableSegment({segment, state}: DatePickerSegmentProps) {
|
|
53
|
-
let ref = useRef<HTMLDivElement | null>(null);
|
|
54
|
-
let {segmentProps} = useDateSegment(segment, state, ref);
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<span
|
|
58
|
-
{...segmentProps}
|
|
59
|
-
ref={ref}
|
|
60
|
-
className={classNames(styles, 'react-spectrum-DatePicker-cell', {
|
|
61
|
-
'is-placeholder': segment.isPlaceholder,
|
|
62
|
-
'is-read-only': !segment.isEditable
|
|
63
|
-
})}
|
|
64
|
-
style={segmentProps.style}
|
|
65
|
-
data-testid={segment.type}>
|
|
66
|
-
{segment.isPlaceholder ? <span aria-hidden="true" className={classNames(styles, 'react-spectrum-DatePicker-placeholder')}>{segment.placeholder}</span> : segment.text}
|
|
67
|
-
</span>
|
|
68
|
-
);
|
|
69
|
-
}
|
package/src/DateRangePicker.tsx
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import CalendarIcon from '@spectrum-icons/workflow/Calendar';
|
|
14
|
-
import {classNames} from '@react-spectrum/utils';
|
|
15
|
-
import {Content} from '@react-spectrum/view';
|
|
16
|
-
import {DatePickerField} from './DatePickerField';
|
|
17
|
-
import datepickerStyles from './styles.css';
|
|
18
|
-
import {DateValue, SpectrumDateRangePickerProps} from '@react-types/datepicker';
|
|
19
|
-
import {Dialog, DialogTrigger} from '@react-spectrum/dialog';
|
|
20
|
-
import {Field} from '@react-spectrum/label';
|
|
21
|
-
import {FieldButton} from '@react-spectrum/button';
|
|
22
|
-
import {Flex} from '@react-spectrum/layout';
|
|
23
|
-
import {FocusableRef} from '@react-types/shared';
|
|
24
|
-
import {Input} from './Input';
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
import intlMessages from '../intl/*.json';
|
|
27
|
-
import {mergeProps} from '@react-aria/utils';
|
|
28
|
-
import {RangeCalendar} from '@react-spectrum/calendar';
|
|
29
|
-
import React, {ReactElement, useRef} from 'react';
|
|
30
|
-
import styles from '@adobe/spectrum-css-temp/components/inputgroup/vars.css';
|
|
31
|
-
import {TimeField} from './TimeField';
|
|
32
|
-
import {useDateRangePicker} from '@react-aria/datepicker';
|
|
33
|
-
import {useDateRangePickerState} from '@react-stately/datepicker';
|
|
34
|
-
import {useFocusManagerRef, useFormatHelpText, useFormattedDateWidth, useVisibleMonths} from './utils';
|
|
35
|
-
import {useFocusRing} from '@react-aria/focus';
|
|
36
|
-
import {useFormProps} from '@react-spectrum/form';
|
|
37
|
-
import {useHover} from '@react-aria/interactions';
|
|
38
|
-
import {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
39
|
-
import {useProviderProps} from '@react-spectrum/provider';
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* DateRangePickers combine two DateFields and a RangeCalendar popover to allow users
|
|
43
|
-
* to enter or select a date and time range.
|
|
44
|
-
*/
|
|
45
|
-
export const DateRangePicker = React.forwardRef(function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePickerProps<T>, ref: FocusableRef<HTMLElement>) {
|
|
46
|
-
props = useProviderProps(props);
|
|
47
|
-
props = useFormProps(props);
|
|
48
|
-
let {
|
|
49
|
-
isQuiet,
|
|
50
|
-
isDisabled,
|
|
51
|
-
autoFocus,
|
|
52
|
-
placeholderValue,
|
|
53
|
-
maxVisibleMonths = 1
|
|
54
|
-
} = props;
|
|
55
|
-
let {hoverProps, isHovered} = useHover({isDisabled});
|
|
56
|
-
let targetRef = useRef<HTMLDivElement | null>(null);
|
|
57
|
-
let state = useDateRangePickerState({
|
|
58
|
-
...props,
|
|
59
|
-
shouldCloseOnSelect: () => !state.hasTime
|
|
60
|
-
});
|
|
61
|
-
let {labelProps, groupProps, buttonProps, dialogProps, startFieldProps, endFieldProps, descriptionProps, errorMessageProps, calendarProps, isInvalid, validationErrors, validationDetails} = useDateRangePicker(props, state, targetRef);
|
|
62
|
-
let {isOpen, setOpen} = state;
|
|
63
|
-
let {direction} = useLocale();
|
|
64
|
-
let domRef = useFocusManagerRef(ref);
|
|
65
|
-
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/datepicker');
|
|
66
|
-
|
|
67
|
-
let {isFocused, isFocusVisible, focusProps} = useFocusRing({
|
|
68
|
-
within: true,
|
|
69
|
-
isTextInput: true,
|
|
70
|
-
autoFocus
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
let {isFocused: isFocusedButton, focusProps: focusPropsButton} = useFocusRing({
|
|
74
|
-
within: false,
|
|
75
|
-
isTextInput: false,
|
|
76
|
-
autoFocus
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
let className = classNames(
|
|
80
|
-
styles,
|
|
81
|
-
'spectrum-InputGroup',
|
|
82
|
-
{
|
|
83
|
-
'spectrum-InputGroup--quiet': isQuiet,
|
|
84
|
-
'spectrum-InputGroup--invalid': isInvalid && !isDisabled,
|
|
85
|
-
'is-disabled': isDisabled,
|
|
86
|
-
'is-hovered': isHovered,
|
|
87
|
-
'is-focused': isFocused,
|
|
88
|
-
'focus-ring': isFocusVisible && !isFocusedButton
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
let fieldClassName = classNames(
|
|
93
|
-
styles,
|
|
94
|
-
'spectrum-InputGroup-input',
|
|
95
|
-
{
|
|
96
|
-
'is-disabled': isDisabled,
|
|
97
|
-
'is-invalid': isInvalid && !isDisabled
|
|
98
|
-
}
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
// Note: this description is intentionally not passed to useDatePicker.
|
|
102
|
-
// The format help text is unnecessary for screen reader users because each segment already has a label.
|
|
103
|
-
let description = useFormatHelpText(props);
|
|
104
|
-
if (description && !props.description) {
|
|
105
|
-
descriptionProps.id = undefined;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
let placeholder: DateValue | null | undefined = placeholderValue;
|
|
109
|
-
let timePlaceholder = placeholder && 'hour' in placeholder ? placeholder : null;
|
|
110
|
-
let timeMinValue = props.minValue && 'hour' in props.minValue ? props.minValue : null;
|
|
111
|
-
let timeMaxValue = props.maxValue && 'hour' in props.maxValue ? props.maxValue : null;
|
|
112
|
-
let timeGranularity = state.granularity === 'hour' || state.granularity === 'minute' || state.granularity === 'second' ? state.granularity : null;
|
|
113
|
-
let showTimeField = !!timeGranularity;
|
|
114
|
-
|
|
115
|
-
let visibleMonths = useVisibleMonths(maxVisibleMonths);
|
|
116
|
-
let validationState = state.validationState || (isInvalid ? 'invalid' : null);
|
|
117
|
-
|
|
118
|
-
// Multiplying by two for the two dates, adding one character for the dash, and then the padding around the dash
|
|
119
|
-
let approximateWidth = `calc(${useFormattedDateWidth(state) * 2 + 1}ch + 2 * var(--spectrum-global-dimension-size-100))`;
|
|
120
|
-
|
|
121
|
-
return (
|
|
122
|
-
<Field
|
|
123
|
-
{...props}
|
|
124
|
-
ref={domRef}
|
|
125
|
-
elementType="span"
|
|
126
|
-
description={description}
|
|
127
|
-
labelProps={labelProps}
|
|
128
|
-
descriptionProps={descriptionProps}
|
|
129
|
-
errorMessageProps={errorMessageProps}
|
|
130
|
-
validationState={validationState}
|
|
131
|
-
isInvalid={isInvalid}
|
|
132
|
-
validationErrors={validationErrors}
|
|
133
|
-
validationDetails={validationDetails}
|
|
134
|
-
wrapperClassName={classNames(datepickerStyles, 'react-spectrum-Datepicker-fieldWrapper')}>
|
|
135
|
-
<div
|
|
136
|
-
{...mergeProps(groupProps, hoverProps, focusProps)}
|
|
137
|
-
className={className}
|
|
138
|
-
ref={targetRef}>
|
|
139
|
-
<div style={{overflow: 'hidden', width: '100%'}}>
|
|
140
|
-
<Input
|
|
141
|
-
isDisabled={isDisabled}
|
|
142
|
-
isQuiet={isQuiet}
|
|
143
|
-
validationState={validationState}
|
|
144
|
-
className={classNames(styles, 'spectrum-InputGroup-field')}
|
|
145
|
-
inputClassName={fieldClassName}
|
|
146
|
-
disableFocusRing
|
|
147
|
-
minWidth={approximateWidth}>
|
|
148
|
-
<DatePickerField
|
|
149
|
-
{...startFieldProps}
|
|
150
|
-
data-testid="start-date"
|
|
151
|
-
isQuiet={props.isQuiet}
|
|
152
|
-
inputClassName={classNames(datepickerStyles, 'react-spectrum-Datepicker-startField')} />
|
|
153
|
-
<DateRangeDash />
|
|
154
|
-
<DatePickerField
|
|
155
|
-
{...endFieldProps}
|
|
156
|
-
data-testid="end-date"
|
|
157
|
-
isQuiet={props.isQuiet}
|
|
158
|
-
inputClassName={classNames(
|
|
159
|
-
styles,
|
|
160
|
-
'spectrum-Datepicker-endField',
|
|
161
|
-
classNames(
|
|
162
|
-
datepickerStyles,
|
|
163
|
-
'react-spectrum-Datepicker-endField'
|
|
164
|
-
)
|
|
165
|
-
)} />
|
|
166
|
-
</Input>
|
|
167
|
-
</div>
|
|
168
|
-
<DialogTrigger
|
|
169
|
-
type="popover"
|
|
170
|
-
mobileType="tray"
|
|
171
|
-
placement={direction === 'rtl' ? 'bottom right' : 'bottom left'}
|
|
172
|
-
targetRef={targetRef}
|
|
173
|
-
hideArrow
|
|
174
|
-
isOpen={isOpen}
|
|
175
|
-
onOpenChange={setOpen}
|
|
176
|
-
shouldFlip={props.shouldFlip}>
|
|
177
|
-
<FieldButton
|
|
178
|
-
{...mergeProps(buttonProps, focusPropsButton)}
|
|
179
|
-
UNSAFE_className={classNames(styles, 'spectrum-FieldButton')}
|
|
180
|
-
isQuiet={isQuiet}
|
|
181
|
-
validationState={validationState}>
|
|
182
|
-
<CalendarIcon />
|
|
183
|
-
</FieldButton>
|
|
184
|
-
<Dialog UNSAFE_className={classNames(datepickerStyles, 'react-spectrum-Datepicker-dialog')} {...dialogProps}>
|
|
185
|
-
<Content>
|
|
186
|
-
<div className={classNames(datepickerStyles, 'react-spectrum-Datepicker-dialogContent')}>
|
|
187
|
-
<RangeCalendar
|
|
188
|
-
{...calendarProps}
|
|
189
|
-
visibleMonths={visibleMonths}
|
|
190
|
-
createCalendar={props.createCalendar}
|
|
191
|
-
UNSAFE_className={classNames(datepickerStyles, 'react-spectrum-Datepicker-calendar', {'is-invalid': validationState === 'invalid'})} />
|
|
192
|
-
{showTimeField &&
|
|
193
|
-
<Flex gap="size-100" marginTop="size-100" UNSAFE_className={classNames(datepickerStyles, 'react-spectrum-Datepicker-timeFields')}>
|
|
194
|
-
<TimeField
|
|
195
|
-
label={stringFormatter.format('startTime')}
|
|
196
|
-
value={state.timeRange?.start || null}
|
|
197
|
-
onChange={v => state.setTime('start', v)}
|
|
198
|
-
placeholderValue={timePlaceholder}
|
|
199
|
-
granularity={timeGranularity}
|
|
200
|
-
minValue={timeMinValue}
|
|
201
|
-
maxValue={timeMaxValue}
|
|
202
|
-
hourCycle={props.hourCycle}
|
|
203
|
-
hideTimeZone={props.hideTimeZone}
|
|
204
|
-
flex />
|
|
205
|
-
<TimeField
|
|
206
|
-
label={stringFormatter.format('endTime')}
|
|
207
|
-
value={state.timeRange?.end || null}
|
|
208
|
-
onChange={v => state.setTime('end', v)}
|
|
209
|
-
placeholderValue={timePlaceholder}
|
|
210
|
-
granularity={timeGranularity}
|
|
211
|
-
minValue={timeMinValue}
|
|
212
|
-
maxValue={timeMaxValue}
|
|
213
|
-
hourCycle={props.hourCycle}
|
|
214
|
-
hideTimeZone={props.hideTimeZone}
|
|
215
|
-
flex />
|
|
216
|
-
</Flex>
|
|
217
|
-
}
|
|
218
|
-
</div>
|
|
219
|
-
</Content>
|
|
220
|
-
</Dialog>
|
|
221
|
-
</DialogTrigger>
|
|
222
|
-
</div>
|
|
223
|
-
</Field>
|
|
224
|
-
);
|
|
225
|
-
}) as <T extends DateValue>(props: SpectrumDateRangePickerProps<T> & {ref?: FocusableRef<HTMLElement>}) => ReactElement;
|
|
226
|
-
|
|
227
|
-
function DateRangeDash() {
|
|
228
|
-
return (
|
|
229
|
-
<span
|
|
230
|
-
aria-hidden="true"
|
|
231
|
-
data-testid="date-range-dash"
|
|
232
|
-
className={classNames(datepickerStyles, 'react-spectrum-Datepicker-rangeDash')} />
|
|
233
|
-
);
|
|
234
|
-
}
|