@react-spectrum/datepicker 3.14.11 → 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.
Files changed (255) hide show
  1. package/dist/import.mjs +5 -5
  2. package/dist/main.js +8 -8
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +5 -5
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +8 -0
  7. package/package.json +12 -44
  8. package/src/index.ts +9 -5
  9. package/dist/DateField.main.js +0 -108
  10. package/dist/DateField.main.js.map +0 -1
  11. package/dist/DateField.mjs +0 -103
  12. package/dist/DateField.module.js +0 -103
  13. package/dist/DateField.module.js.map +0 -1
  14. package/dist/DatePicker.main.js +0 -197
  15. package/dist/DatePicker.main.js.map +0 -1
  16. package/dist/DatePicker.mjs +0 -192
  17. package/dist/DatePicker.module.js +0 -192
  18. package/dist/DatePicker.module.js.map +0 -1
  19. package/dist/DatePickerField.main.js +0 -72
  20. package/dist/DatePickerField.main.js.map +0 -1
  21. package/dist/DatePickerField.mjs +0 -67
  22. package/dist/DatePickerField.module.js +0 -67
  23. package/dist/DatePickerField.module.js.map +0 -1
  24. package/dist/DatePickerSegment.main.js +0 -73
  25. package/dist/DatePickerSegment.main.js.map +0 -1
  26. package/dist/DatePickerSegment.mjs +0 -68
  27. package/dist/DatePickerSegment.module.js +0 -68
  28. package/dist/DatePickerSegment.module.js.map +0 -1
  29. package/dist/DateRangePicker.main.js +0 -229
  30. package/dist/DateRangePicker.main.js.map +0 -1
  31. package/dist/DateRangePicker.mjs +0 -224
  32. package/dist/DateRangePicker.module.js +0 -224
  33. package/dist/DateRangePicker.module.js.map +0 -1
  34. package/dist/Input.main.js +0 -128
  35. package/dist/Input.main.js.map +0 -1
  36. package/dist/Input.mjs +0 -123
  37. package/dist/Input.module.js +0 -123
  38. package/dist/Input.module.js.map +0 -1
  39. package/dist/TimeField.main.js +0 -100
  40. package/dist/TimeField.main.js.map +0 -1
  41. package/dist/TimeField.mjs +0 -95
  42. package/dist/TimeField.module.js +0 -95
  43. package/dist/TimeField.module.js.map +0 -1
  44. package/dist/ar-AE.main.js +0 -8
  45. package/dist/ar-AE.main.js.map +0 -1
  46. package/dist/ar-AE.mjs +0 -10
  47. package/dist/ar-AE.module.js +0 -10
  48. package/dist/ar-AE.module.js.map +0 -1
  49. package/dist/bg-BG.main.js +0 -8
  50. package/dist/bg-BG.main.js.map +0 -1
  51. package/dist/bg-BG.mjs +0 -10
  52. package/dist/bg-BG.module.js +0 -10
  53. package/dist/bg-BG.module.js.map +0 -1
  54. package/dist/cs-CZ.main.js +0 -8
  55. package/dist/cs-CZ.main.js.map +0 -1
  56. package/dist/cs-CZ.mjs +0 -10
  57. package/dist/cs-CZ.module.js +0 -10
  58. package/dist/cs-CZ.module.js.map +0 -1
  59. package/dist/da-DK.main.js +0 -8
  60. package/dist/da-DK.main.js.map +0 -1
  61. package/dist/da-DK.mjs +0 -10
  62. package/dist/da-DK.module.js +0 -10
  63. package/dist/da-DK.module.js.map +0 -1
  64. package/dist/datepicker.4d1286b0.css +0 -649
  65. package/dist/datepicker.4d1286b0.css.map +0 -1
  66. package/dist/datepicker.776a7787.css +0 -550
  67. package/dist/datepicker.776a7787.css.map +0 -1
  68. package/dist/datepicker.e85992d8.css +0 -204
  69. package/dist/datepicker.e85992d8.css.map +0 -1
  70. package/dist/de-DE.main.js +0 -8
  71. package/dist/de-DE.main.js.map +0 -1
  72. package/dist/de-DE.mjs +0 -10
  73. package/dist/de-DE.module.js +0 -10
  74. package/dist/de-DE.module.js.map +0 -1
  75. package/dist/el-GR.main.js +0 -8
  76. package/dist/el-GR.main.js.map +0 -1
  77. package/dist/el-GR.mjs +0 -10
  78. package/dist/el-GR.module.js +0 -10
  79. package/dist/el-GR.module.js.map +0 -1
  80. package/dist/en-US.main.js +0 -8
  81. package/dist/en-US.main.js.map +0 -1
  82. package/dist/en-US.mjs +0 -10
  83. package/dist/en-US.module.js +0 -10
  84. package/dist/en-US.module.js.map +0 -1
  85. package/dist/es-ES.main.js +0 -8
  86. package/dist/es-ES.main.js.map +0 -1
  87. package/dist/es-ES.mjs +0 -10
  88. package/dist/es-ES.module.js +0 -10
  89. package/dist/es-ES.module.js.map +0 -1
  90. package/dist/et-EE.main.js +0 -8
  91. package/dist/et-EE.main.js.map +0 -1
  92. package/dist/et-EE.mjs +0 -10
  93. package/dist/et-EE.module.js +0 -10
  94. package/dist/et-EE.module.js.map +0 -1
  95. package/dist/fi-FI.main.js +0 -8
  96. package/dist/fi-FI.main.js.map +0 -1
  97. package/dist/fi-FI.mjs +0 -10
  98. package/dist/fi-FI.module.js +0 -10
  99. package/dist/fi-FI.module.js.map +0 -1
  100. package/dist/fr-FR.main.js +0 -8
  101. package/dist/fr-FR.main.js.map +0 -1
  102. package/dist/fr-FR.mjs +0 -10
  103. package/dist/fr-FR.module.js +0 -10
  104. package/dist/fr-FR.module.js.map +0 -1
  105. package/dist/he-IL.main.js +0 -8
  106. package/dist/he-IL.main.js.map +0 -1
  107. package/dist/he-IL.mjs +0 -10
  108. package/dist/he-IL.module.js +0 -10
  109. package/dist/he-IL.module.js.map +0 -1
  110. package/dist/hr-HR.main.js +0 -8
  111. package/dist/hr-HR.main.js.map +0 -1
  112. package/dist/hr-HR.mjs +0 -10
  113. package/dist/hr-HR.module.js +0 -10
  114. package/dist/hr-HR.module.js.map +0 -1
  115. package/dist/hu-HU.main.js +0 -8
  116. package/dist/hu-HU.main.js.map +0 -1
  117. package/dist/hu-HU.mjs +0 -10
  118. package/dist/hu-HU.module.js +0 -10
  119. package/dist/hu-HU.module.js.map +0 -1
  120. package/dist/inputgroup_vars_css.main.js +0 -86
  121. package/dist/inputgroup_vars_css.main.js.map +0 -1
  122. package/dist/inputgroup_vars_css.mjs +0 -88
  123. package/dist/inputgroup_vars_css.module.js +0 -88
  124. package/dist/inputgroup_vars_css.module.js.map +0 -1
  125. package/dist/intlStrings.main.js +0 -108
  126. package/dist/intlStrings.main.js.map +0 -1
  127. package/dist/intlStrings.mjs +0 -110
  128. package/dist/intlStrings.module.js +0 -110
  129. package/dist/intlStrings.module.js.map +0 -1
  130. package/dist/it-IT.main.js +0 -8
  131. package/dist/it-IT.main.js.map +0 -1
  132. package/dist/it-IT.mjs +0 -10
  133. package/dist/it-IT.module.js +0 -10
  134. package/dist/it-IT.module.js.map +0 -1
  135. package/dist/ja-JP.main.js +0 -8
  136. package/dist/ja-JP.main.js.map +0 -1
  137. package/dist/ja-JP.mjs +0 -10
  138. package/dist/ja-JP.module.js +0 -10
  139. package/dist/ja-JP.module.js.map +0 -1
  140. package/dist/ko-KR.main.js +0 -8
  141. package/dist/ko-KR.main.js.map +0 -1
  142. package/dist/ko-KR.mjs +0 -10
  143. package/dist/ko-KR.module.js +0 -10
  144. package/dist/ko-KR.module.js.map +0 -1
  145. package/dist/lt-LT.main.js +0 -8
  146. package/dist/lt-LT.main.js.map +0 -1
  147. package/dist/lt-LT.mjs +0 -10
  148. package/dist/lt-LT.module.js +0 -10
  149. package/dist/lt-LT.module.js.map +0 -1
  150. package/dist/lv-LV.main.js +0 -8
  151. package/dist/lv-LV.main.js.map +0 -1
  152. package/dist/lv-LV.mjs +0 -10
  153. package/dist/lv-LV.module.js +0 -10
  154. package/dist/lv-LV.module.js.map +0 -1
  155. package/dist/nb-NO.main.js +0 -8
  156. package/dist/nb-NO.main.js.map +0 -1
  157. package/dist/nb-NO.mjs +0 -10
  158. package/dist/nb-NO.module.js +0 -10
  159. package/dist/nb-NO.module.js.map +0 -1
  160. package/dist/nl-NL.main.js +0 -8
  161. package/dist/nl-NL.main.js.map +0 -1
  162. package/dist/nl-NL.mjs +0 -10
  163. package/dist/nl-NL.module.js +0 -10
  164. package/dist/nl-NL.module.js.map +0 -1
  165. package/dist/pl-PL.main.js +0 -8
  166. package/dist/pl-PL.main.js.map +0 -1
  167. package/dist/pl-PL.mjs +0 -10
  168. package/dist/pl-PL.module.js +0 -10
  169. package/dist/pl-PL.module.js.map +0 -1
  170. package/dist/pt-BR.main.js +0 -8
  171. package/dist/pt-BR.main.js.map +0 -1
  172. package/dist/pt-BR.mjs +0 -10
  173. package/dist/pt-BR.module.js +0 -10
  174. package/dist/pt-BR.module.js.map +0 -1
  175. package/dist/pt-PT.main.js +0 -8
  176. package/dist/pt-PT.main.js.map +0 -1
  177. package/dist/pt-PT.mjs +0 -10
  178. package/dist/pt-PT.module.js +0 -10
  179. package/dist/pt-PT.module.js.map +0 -1
  180. package/dist/ro-RO.main.js +0 -8
  181. package/dist/ro-RO.main.js.map +0 -1
  182. package/dist/ro-RO.mjs +0 -10
  183. package/dist/ro-RO.module.js +0 -10
  184. package/dist/ro-RO.module.js.map +0 -1
  185. package/dist/ru-RU.main.js +0 -8
  186. package/dist/ru-RU.main.js.map +0 -1
  187. package/dist/ru-RU.mjs +0 -10
  188. package/dist/ru-RU.module.js +0 -10
  189. package/dist/ru-RU.module.js.map +0 -1
  190. package/dist/sk-SK.main.js +0 -8
  191. package/dist/sk-SK.main.js.map +0 -1
  192. package/dist/sk-SK.mjs +0 -10
  193. package/dist/sk-SK.module.js +0 -10
  194. package/dist/sk-SK.module.js.map +0 -1
  195. package/dist/sl-SI.main.js +0 -8
  196. package/dist/sl-SI.main.js.map +0 -1
  197. package/dist/sl-SI.mjs +0 -10
  198. package/dist/sl-SI.module.js +0 -10
  199. package/dist/sl-SI.module.js.map +0 -1
  200. package/dist/sr-SP.main.js +0 -8
  201. package/dist/sr-SP.main.js.map +0 -1
  202. package/dist/sr-SP.mjs +0 -10
  203. package/dist/sr-SP.module.js +0 -10
  204. package/dist/sr-SP.module.js.map +0 -1
  205. package/dist/styles_css.main.js +0 -77
  206. package/dist/styles_css.main.js.map +0 -1
  207. package/dist/styles_css.mjs +0 -79
  208. package/dist/styles_css.module.js +0 -79
  209. package/dist/styles_css.module.js.map +0 -1
  210. package/dist/sv-SE.main.js +0 -8
  211. package/dist/sv-SE.main.js.map +0 -1
  212. package/dist/sv-SE.mjs +0 -10
  213. package/dist/sv-SE.module.js +0 -10
  214. package/dist/sv-SE.module.js.map +0 -1
  215. package/dist/textfield_vars_css.main.js +0 -74
  216. package/dist/textfield_vars_css.main.js.map +0 -1
  217. package/dist/textfield_vars_css.mjs +0 -76
  218. package/dist/textfield_vars_css.module.js +0 -76
  219. package/dist/textfield_vars_css.module.js.map +0 -1
  220. package/dist/tr-TR.main.js +0 -8
  221. package/dist/tr-TR.main.js.map +0 -1
  222. package/dist/tr-TR.mjs +0 -10
  223. package/dist/tr-TR.module.js +0 -10
  224. package/dist/tr-TR.module.js.map +0 -1
  225. package/dist/types.d.ts +0 -33
  226. package/dist/types.d.ts.map +0 -1
  227. package/dist/uk-UA.main.js +0 -8
  228. package/dist/uk-UA.main.js.map +0 -1
  229. package/dist/uk-UA.mjs +0 -10
  230. package/dist/uk-UA.module.js +0 -10
  231. package/dist/uk-UA.module.js.map +0 -1
  232. package/dist/utils.main.js +0 -117
  233. package/dist/utils.main.js.map +0 -1
  234. package/dist/utils.mjs +0 -105
  235. package/dist/utils.module.js +0 -105
  236. package/dist/utils.module.js.map +0 -1
  237. package/dist/zh-CN.main.js +0 -8
  238. package/dist/zh-CN.main.js.map +0 -1
  239. package/dist/zh-CN.mjs +0 -10
  240. package/dist/zh-CN.module.js +0 -10
  241. package/dist/zh-CN.module.js.map +0 -1
  242. package/dist/zh-TW.main.js +0 -8
  243. package/dist/zh-TW.main.js.map +0 -1
  244. package/dist/zh-TW.mjs +0 -10
  245. package/dist/zh-TW.module.js +0 -10
  246. package/dist/zh-TW.module.js.map +0 -1
  247. package/src/DateField.tsx +0 -106
  248. package/src/DatePicker.tsx +0 -196
  249. package/src/DatePickerField.tsx +0 -61
  250. package/src/DatePickerSegment.tsx +0 -69
  251. package/src/DateRangePicker.tsx +0 -234
  252. package/src/Input.tsx +0 -142
  253. package/src/TimeField.tsx +0 -96
  254. package/src/styles.css +0 -203
  255. package/src/utils.tsx +0 -96
@@ -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;
@@ -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
- }
@@ -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
- }