@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.
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
package/src/Input.tsx DELETED
@@ -1,142 +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 Alert from '@spectrum-icons/ui/AlertMedium';
14
- import Checkmark from '@spectrum-icons/ui/CheckmarkMedium';
15
- import {classNames, useValueEffect} from '@react-spectrum/utils';
16
- import datepickerStyles from './styles.css';
17
- import {mergeProps, mergeRefs, useEvent, useLayoutEffect, useResizeObserver} from '@react-aria/utils';
18
- import React, {ReactElement, useCallback, useRef} from 'react';
19
- import textfieldStyles from '@adobe/spectrum-css-temp/components/textfield/vars.css';
20
- import {useFocusRing} from '@react-aria/focus';
21
-
22
- export const Input = React.forwardRef(function Input(props: any, ref: any) {
23
- let inputRef = useRef<HTMLInputElement | null>(null);
24
- let {
25
- isDisabled,
26
- isQuiet,
27
- inputClassName,
28
- validationState,
29
- children,
30
- fieldProps,
31
- className,
32
- style,
33
- disableFocusRing
34
- } = props;
35
-
36
- // Reserve padding for the error icon when the width of the input is unconstrained.
37
- // When constrained, don't reserve space because adding it only when invalid will
38
- // not cause a layout shift.
39
- let [reservePadding, setReservePadding] = useValueEffect(false);
40
- let onResize = useCallback(() => setReservePadding(function *(reservePadding) {
41
- if (inputRef.current && inputRef.current.parentElement) {
42
- if (reservePadding) {
43
- // Try to collapse padding if the content is clipped.
44
- if (inputRef.current.scrollWidth > inputRef.current.offsetWidth) {
45
- let width = inputRef.current.parentElement.offsetWidth;
46
- yield false;
47
-
48
- // If removing padding causes a layout shift, add it back.
49
- if (inputRef.current.parentElement.offsetWidth !== width) {
50
- yield true;
51
- }
52
- }
53
- } else {
54
- // Try to add padding if the content is not clipped.
55
- if (inputRef.current.offsetWidth >= inputRef.current.scrollWidth) {
56
- let width = inputRef.current.parentElement.offsetWidth;
57
- yield true;
58
-
59
- // If adding padding does not change the width (i.e. width is constrained), remove it again.
60
- if (inputRef.current.parentElement.offsetWidth === width) {
61
- yield false;
62
- }
63
- }
64
- }
65
- }
66
-
67
- }), [inputRef, setReservePadding]);
68
-
69
- useLayoutEffect(onResize, [onResize]);
70
- useResizeObserver({
71
- ref: inputRef,
72
- onResize
73
- });
74
-
75
- // We also need to listen for resize events of the window so we can detect
76
- // when there is enough space for the padding to be re-added. Ideally we'd
77
- // use a resize observer on a parent element, but it's hard to know _what_
78
- // parent element.
79
- useEvent(useRef(typeof window !== 'undefined' ? window : null), 'resize', onResize);
80
-
81
- let {focusProps, isFocusVisible, isFocused} = useFocusRing({
82
- isTextInput: true,
83
- within: true
84
- });
85
-
86
- let isInvalid = validationState === 'invalid' && !isDisabled;
87
- let textfieldClass = classNames(
88
- textfieldStyles,
89
- 'spectrum-Textfield',
90
- {
91
- 'spectrum-Textfield--invalid': isInvalid,
92
- 'spectrum-Textfield--valid': validationState === 'valid' && !isDisabled,
93
- 'spectrum-Textfield--quiet': isQuiet,
94
- 'focus-ring': isFocusVisible && !disableFocusRing
95
- },
96
- classNames(datepickerStyles, 'react-spectrum-Datepicker-field'),
97
- className
98
- );
99
-
100
- let inputClass = classNames(
101
- textfieldStyles,
102
- 'spectrum-Textfield-input',
103
- {
104
- 'is-disabled': isDisabled,
105
- 'is-focused': isFocused
106
- },
107
- classNames(datepickerStyles, 'react-spectrum-DateField-Input'),
108
- reservePadding && classNames(datepickerStyles, 'react-spectrum-Datepicker-input'),
109
- inputClassName
110
- );
111
-
112
- let iconClass = classNames(
113
- textfieldStyles,
114
- 'spectrum-Textfield-validationIcon'
115
- );
116
-
117
- let validationIcon: ReactElement | null = null;
118
- if (validationState === 'invalid' && !isDisabled) {
119
- validationIcon = <Alert data-testid="invalid-icon" UNSAFE_className={iconClass} />;
120
- } else if (validationState === 'valid' && !isDisabled) {
121
- validationIcon = <Checkmark data-testid="valid-icon" UNSAFE_className={iconClass} />;
122
- }
123
-
124
- return (
125
- <div role="presentation" {...mergeProps(fieldProps, focusProps)} className={textfieldClass} style={style}>
126
- <div role="presentation" className={inputClass}>
127
- <div
128
- role="presentation"
129
- className={classNames(datepickerStyles, 'react-spectrum-Datepicker-inputContents')}
130
- ref={mergeRefs(ref, inputRef)}>
131
- <div
132
- role="presentation"
133
- className={classNames(datepickerStyles, 'react-spectrum-Datepicker-inputSized')}
134
- style={{minWidth: props.minWidth}}>
135
- {children}
136
- </div>
137
- </div>
138
- </div>
139
- {validationIcon}
140
- </div>
141
- );
142
- });
package/src/TimeField.tsx DELETED
@@ -1,96 +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 {DatePickerSegment} from './DatePickerSegment';
15
- import datepickerStyles from './styles.css';
16
- import {Field} from '@react-spectrum/label';
17
- import {FocusableRef} from '@react-types/shared';
18
- import {Input} from './Input';
19
- import React, {ReactElement, useRef} from 'react';
20
- import {SpectrumTimeFieldProps, TimeValue} from '@react-types/datepicker';
21
- import {useFocusManagerRef, useFormattedDateWidth} from './utils';
22
- import {useFormProps} from '@react-spectrum/form';
23
- import {useLocale} from '@react-aria/i18n';
24
- import {useProviderProps} from '@react-spectrum/provider';
25
- import {useTimeField} from '@react-aria/datepicker';
26
- import {useTimeFieldState} from '@react-stately/datepicker';
27
-
28
- /**
29
- * TimeFields allow users to enter and edit time values using a keyboard.
30
- * Each part of the time is displayed in an individually editable segment.
31
- */
32
- export const TimeField = React.forwardRef(function TimeField<T extends TimeValue>(props: SpectrumTimeFieldProps<T>, ref: FocusableRef<HTMLElement>) {
33
- props = useProviderProps(props);
34
- props = useFormProps(props);
35
- let {
36
- autoFocus,
37
- isDisabled,
38
- isReadOnly,
39
- isRequired,
40
- isQuiet
41
- } = props;
42
-
43
- let domRef = useFocusManagerRef(ref);
44
- let {locale} = useLocale();
45
- let state = useTimeFieldState({
46
- ...props,
47
- locale
48
- });
49
-
50
- let fieldRef = useRef<HTMLDivElement | null>(null);
51
- let inputRef = useRef<HTMLInputElement | null>(null);
52
- let {labelProps, fieldProps, inputProps, descriptionProps, errorMessageProps, isInvalid, validationErrors, validationDetails} = useTimeField({
53
- ...props,
54
- inputRef
55
- }, state, fieldRef);
56
-
57
- let validationState = state.validationState || (isInvalid ? 'invalid' : null);
58
-
59
- let approximateWidth = useFormattedDateWidth(state) + 'ch';
60
-
61
- return (
62
- <Field
63
- {...props}
64
- ref={domRef}
65
- elementType="span"
66
- labelProps={labelProps}
67
- descriptionProps={descriptionProps}
68
- errorMessageProps={errorMessageProps}
69
- validationState={validationState ?? undefined}
70
- isInvalid={isInvalid}
71
- validationErrors={validationErrors}
72
- validationDetails={validationDetails}
73
- wrapperClassName={classNames(datepickerStyles, 'react-spectrum-TimeField-fieldWrapper')}>
74
- <Input
75
- ref={fieldRef}
76
- fieldProps={fieldProps}
77
- isDisabled={isDisabled}
78
- isQuiet={isQuiet}
79
- autoFocus={autoFocus}
80
- validationState={validationState}
81
- minWidth={approximateWidth}
82
- className={classNames(datepickerStyles, 'react-spectrum-TimeField')}>
83
- {state.segments.map((segment, i) =>
84
- (<DatePickerSegment
85
- key={i}
86
- segment={segment}
87
- state={state}
88
- isDisabled={isDisabled}
89
- isReadOnly={isReadOnly}
90
- isRequired={isRequired} />)
91
- )}
92
- <input {...inputProps} ref={inputRef} />
93
- </Input>
94
- </Field>
95
- );
96
- }) as <T extends TimeValue>(props: SpectrumTimeFieldProps<T> & {ref?: FocusableRef<HTMLElement>}) => ReactElement;
package/src/styles.css DELETED
@@ -1,203 +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
- .react-spectrum-Datepicker-fieldWrapper.react-spectrum-Datepicker-fieldWrapper.react-spectrum-Datepicker-fieldWrapper {
14
- width: auto;
15
- min-width: var(--spectrum-global-dimension-size-2000);
16
- max-width: 100%;
17
- }
18
-
19
- .react-spectrum-Datepicker-startField {
20
- width: auto;
21
- padding-inline-end: var(--spectrum-global-dimension-size-100);
22
- }
23
-
24
- .react-spectrum-Datepicker-endField {
25
- width: auto;
26
- flex: 1;
27
- padding-inline-start: var(--spectrum-global-dimension-size-100);
28
- }
29
-
30
- .react-spectrum-Datepicker-field ~ .react-spectrum-Datepicker-endField > .react-spectrum-Datepicker-input {
31
- border-inline-start-width: 0;
32
- border-start-start-radius: 0;
33
- border-end-start-radius: 0;
34
- }
35
-
36
- .react-spectrum-Datepicker-field.react-spectrum-Datepicker-field {
37
- width: 100%;
38
- }
39
-
40
- .react-spectrum-Datepicker-field .react-spectrum-DateField-Input {
41
- line-height: var(--spectrum-body-4-text-line-height);
42
- }
43
-
44
- /* specificity war with .spectrum-Field--positionSide etc. */
45
- .react-spectrum-DateField.react-spectrum-DateField.react-spectrum-DateField.react-spectrum-DateField {
46
- min-width: var(--spectrum-global-dimension-size-2000);
47
- }
48
-
49
- .react-spectrum-TimeField.react-spectrum-TimeField.react-spectrum-TimeField.react-spectrum-TimeField {
50
- min-width: var(--spectrum-global-dimension-size-1250);
51
- }
52
-
53
- .react-spectrum-TimeField-fieldWrapper.react-spectrum-TimeField-fieldWrapper.react-spectrum-TimeField-fieldWrapper {
54
- width: auto;
55
- min-width: var(--spectrum-global-dimension-size-1250);
56
- }
57
-
58
- .react-spectrum-Datepicker-input.react-spectrum-Datepicker-input.react-spectrum-Datepicker-input {
59
- /* always reserve space for the validation icon */
60
- padding-inline-end: calc(var(--spectrum-textfield-padding-x) + var(--spectrum-icon-alert-medium-width) + var(--spectrum-textfield-icon-margin-left));
61
- cursor: text;
62
- }
63
-
64
- .react-spectrum-Datepicker-inputContents {
65
- display: flex;
66
- align-items: center;
67
- height: 100%;
68
- overflow-x: auto;
69
- scrollbar-width: none; /* Firefox */
70
- -ms-overflow-style: none; /* Internet Explorer 10+ */
71
-
72
- &::-webkit-scrollbar { /* WebKit */
73
- width: 0;
74
- height: 0;
75
- display: none;
76
- }
77
- }
78
-
79
- .react-spectrum-Datepicker-inputSized {
80
- display: inline;
81
- align-items: center;
82
- }
83
-
84
- .react-spectrum-Datepicker-rangeDash {
85
- &:before {
86
- content: '–';
87
- }
88
- }
89
-
90
- .react-spectrum-Datepicker-segments {
91
- display: inline-block;
92
- align-items: center;
93
- }
94
-
95
- .react-spectrum-Datepicker-literal {
96
- white-space: pre;
97
- user-select: none;
98
- color: var(--spectrum-textfield-text-color);
99
- }
100
-
101
- .react-spectrum-DatePicker-cell {
102
- border: none;
103
- background: none;
104
- padding: 0 2px;
105
- border-radius: var(--spectrum-alias-border-radius-small);
106
- font-variant-numeric: tabular-nums;
107
- text-align: end;
108
- box-sizing: content-box;
109
- white-space: nowrap;
110
- color: var(--spectrum-textfield-text-color);
111
-
112
- &::selection {
113
- /* hide the selection because there is no way to fully prevent it in Firefox */
114
- /* https://bugzilla.mozilla.org/show_bug.cgi?id=1742153 */
115
- background: transparent;
116
- }
117
- }
118
-
119
- .react-spectrum-DatePicker-cell.is-placeholder {
120
- color: var(--spectrum-gray-600);
121
-
122
- .react-spectrum-DatePicker-placeholder {
123
- text-align: center;
124
- pointer-events: none;
125
- }
126
- }
127
-
128
- .react-spectrum-DatePicker-cell.is-placeholder ~ .react-spectrum-Datepicker-literal {
129
- color: var(--spectrum-global-color-gray-600);
130
- }
131
-
132
- .react-spectrum-DatePicker-cell.is-read-only {
133
- color: var(--spectrum-global-color-gray-700);
134
- }
135
-
136
- .react-spectrum-DatePicker-cell:focus {
137
- background-color: var(--spectrum-accent-background-color-default);
138
- color: white;
139
- caret-color: transparent;
140
- outline: none;
141
- }
142
-
143
- .react-spectrum-Datepicker-dialog.react-spectrum-Datepicker-dialog {
144
- width: auto;
145
- }
146
-
147
- .react-spectrum-Datepicker-dialogContent {
148
- display: flex;
149
- flex-direction: column;
150
-
151
- .react-spectrum-Datepicker-calendar.is-invalid {
152
- /* Only apply display: contents when the calendar is invalid, which allows us to move the
153
- * error message below the time fields. Otherwise, don't do this because it breaks dragging
154
- * the selected range on Android. */
155
- display: contents;
156
- }
157
-
158
- /* Push the help text within the calendar down to the bottom of the dialog, below the time fields. */
159
- :global(.spectrum-Calendar-helpText) {
160
- order: 10;
161
- margin: var(--spectrum-global-dimension-size-200) var(--spectrum-calendar-day-padding) 0 var(--spectrum-calendar-day-padding);
162
- }
163
- }
164
-
165
- /* when displayed in a tray, reduce the padding of the dialog */
166
- @media (max-width: 700px) {
167
- .react-spectrum-Datepicker-dialog {
168
- --spectrum-dialog-padding-x: 8px;
169
-
170
- .react-spectrum-Datepicker-dialogContent {
171
- margin: 0 auto;
172
- max-width: calc((var(--spectrum-calendar-day-width) * 7) + (var(--spectrum-calendar-day-padding) * 12));
173
- }
174
- }
175
- }
176
-
177
- .react-spectrum-Datepicker-timeFields {
178
- width: 100%;
179
- min-width: calc(var(--spectrum-calendar-day-width) * 7);
180
- max-width: calc((var(--spectrum-calendar-day-width) * 7) + (var(--spectrum-calendar-day-padding) * 12));
181
- padding: 0 var(--spectrum-calendar-day-padding);
182
- box-sizing: border-box;
183
- }
184
-
185
- @media (forced-colors:active) {
186
- .react-spectrum-DatePicker-cell:focus {
187
- forced-color-adjust: none;
188
- background-color: Highlight;
189
- color: HighlightText;
190
- }
191
- .react-spectrum-DatePicker-cell.is-read-only {
192
- color: ButtonText;
193
- &:focus {
194
- color: HighlightText;
195
- }
196
- }
197
- .react-spectrum-DatePicker-cell.is-placeholder {
198
- color: ButtonText;
199
- &:focus {
200
- color: HighlightText;
201
- }
202
- }
203
- }
package/src/utils.tsx DELETED
@@ -1,96 +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
- import {createDOMRef} from '@react-spectrum/utils';
13
- import {createFocusManager} from '@react-aria/focus';
14
- import {DateFormatter, useDateFormatter, useLocale} from '@react-aria/i18n';
15
- import {FocusableRef} from '@react-types/shared';
16
- import {FormatterOptions} from '@react-stately/datepicker';
17
- import React, {ReactNode, useImperativeHandle, useMemo, useRef, useState} from 'react';
18
- import {SpectrumDatePickerBase} from '@react-types/datepicker';
19
- import {useDisplayNames} from '@react-aria/datepicker';
20
- import {useLayoutEffect} from '@react-aria/utils';
21
- import {useProvider} from '@react-spectrum/provider';
22
-
23
- export function useFormatHelpText(props: Pick<SpectrumDatePickerBase<any>, 'description' | 'showFormatHelpText'>): ReactNode {
24
- let formatter = useDateFormatter({dateStyle: 'short'});
25
- let displayNames = useDisplayNames();
26
- return useMemo(() => {
27
- if (props.description) {
28
- return props.description;
29
- }
30
-
31
- if (props.showFormatHelpText) {
32
- return (
33
- formatter.formatToParts(new Date()).map((s, i) => {
34
- if (s.type === 'literal' || s.type === 'unknown' || (s.type as string) === 'yearName') {
35
- return <span key={i}>{` ${s.value} `}</span>;
36
- }
37
-
38
- let type = s.type as string === 'relatedYear' ? 'year' : s.type;
39
- return <span key={i} style={{unicodeBidi: 'embed', direction: 'ltr'}}>{displayNames.of(type)}</span>;
40
- })
41
- );
42
- }
43
-
44
- return '';
45
- }, [props.description, props.showFormatHelpText, formatter, displayNames]);
46
- }
47
-
48
- export function useVisibleMonths(maxVisibleMonths: number): number {
49
- let {scale} = useProvider()!;
50
- let [visibleMonths, setVisibleMonths] = useState(getVisibleMonths(scale));
51
- useLayoutEffect(() => {
52
- let onResize = () => setVisibleMonths(getVisibleMonths(scale));
53
- onResize();
54
-
55
- window.addEventListener('resize', onResize);
56
- return () => {
57
- window.removeEventListener('resize', onResize);
58
- };
59
- }, [scale]);
60
-
61
- return Math.max(1, Math.min(visibleMonths, maxVisibleMonths, 3));
62
- }
63
-
64
- function getVisibleMonths(scale) {
65
- if (typeof window === 'undefined') {
66
- return 1;
67
- }
68
- let monthWidth = scale === 'large' ? 336 : 280;
69
- let gap = scale === 'large' ? 30 : 24;
70
- let popoverPadding = scale === 'large' ? 32 : 48;
71
- return Math.floor((window.innerWidth - popoverPadding * 2) / (monthWidth + gap));
72
- }
73
-
74
- export function useFocusManagerRef(ref: FocusableRef<HTMLElement>): React.RefObject<HTMLElement | null> {
75
- let domRef = useRef<HTMLElement | null>(null);
76
- useImperativeHandle(ref, () => ({
77
- ...createDOMRef(domRef),
78
- focus() {
79
- createFocusManager(domRef).focusFirst({tabbable: true});
80
- }
81
- }));
82
- return domRef;
83
- }
84
-
85
- export function useFormattedDateWidth(state: {getDateFormatter: (locale: string, formatOptions: FormatterOptions) => DateFormatter}): number {
86
- let locale = useLocale()?.locale;
87
- let currentDate = new Date();
88
- let formatedDate = state.getDateFormatter(locale, {shouldForceLeadingZeros: true}).format(currentDate);
89
- let totalCharacters = formatedDate.length;
90
-
91
- // The max of two is for times with only hours.
92
- // As the length of a date grows we need to proportionally increase the width.
93
- // We use the character count with 'ch' units and add extra padding to accomate for
94
- // dates with months and time dashes, which are wider characters.
95
- return (totalCharacters + Math.max(Math.floor(totalCharacters / 5), 2));
96
- }