@react-spectrum/datepicker 3.9.5 → 3.10.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/DateField.main.js +6 -4
- package/dist/DateField.main.js.map +1 -1
- package/dist/DateField.mjs +8 -6
- package/dist/DateField.module.js +7 -5
- package/dist/DateField.module.js.map +1 -1
- package/dist/DatePicker.main.js +32 -30
- package/dist/DatePicker.main.js.map +1 -1
- package/dist/DatePicker.mjs +34 -32
- package/dist/DatePicker.module.js +33 -31
- package/dist/DatePicker.module.js.map +1 -1
- package/dist/DatePickerField.main.js +5 -5
- package/dist/DatePickerField.main.js.map +1 -1
- package/dist/DatePickerField.mjs +6 -6
- package/dist/DatePickerField.module.js +5 -5
- package/dist/DatePickerField.module.js.map +1 -1
- package/dist/DatePickerSegment.main.js +12 -15
- package/dist/DatePickerSegment.main.js.map +1 -1
- package/dist/DatePickerSegment.mjs +13 -16
- package/dist/DatePickerSegment.module.js +12 -15
- package/dist/DatePickerSegment.module.js.map +1 -1
- package/dist/DateRangePicker.main.js +38 -35
- package/dist/DateRangePicker.main.js.map +1 -1
- package/dist/DateRangePicker.mjs +40 -37
- package/dist/DateRangePicker.module.js +39 -36
- package/dist/DateRangePicker.module.js.map +1 -1
- package/dist/Input.main.js +25 -19
- package/dist/Input.main.js.map +1 -1
- package/dist/Input.mjs +26 -20
- package/dist/Input.module.js +25 -19
- package/dist/Input.module.js.map +1 -1
- package/dist/TimeField.main.js +6 -4
- package/dist/TimeField.main.js.map +1 -1
- package/dist/TimeField.mjs +8 -6
- package/dist/TimeField.module.js +7 -5
- package/dist/TimeField.module.js.map +1 -1
- package/dist/ar-AE.mjs +1 -1
- package/dist/bg-BG.mjs +1 -1
- package/dist/cs-CZ.mjs +1 -1
- package/dist/da-DK.mjs +1 -1
- package/dist/de-DE.mjs +1 -1
- package/dist/el-GR.mjs +1 -1
- package/dist/en-US.mjs +1 -1
- package/dist/es-ES.mjs +1 -1
- package/dist/et-EE.mjs +1 -1
- package/dist/fi-FI.mjs +1 -1
- package/dist/fr-FR.mjs +1 -1
- package/dist/he-IL.mjs +1 -1
- package/dist/hr-HR.mjs +1 -1
- package/dist/hu-HU.mjs +1 -1
- package/dist/inputgroup_vars_css.mjs +1 -1
- package/dist/intlStrings.mjs +1 -1
- package/dist/it-IT.mjs +1 -1
- package/dist/ja-JP.mjs +1 -1
- package/dist/ko-KR.mjs +1 -1
- package/dist/lt-LT.mjs +1 -1
- package/dist/lv-LV.mjs +1 -1
- package/dist/nb-NO.mjs +1 -1
- package/dist/nl-NL.mjs +1 -1
- package/dist/pl-PL.mjs +1 -1
- package/dist/pt-BR.mjs +1 -1
- package/dist/pt-PT.mjs +1 -1
- package/dist/ro-RO.mjs +1 -1
- package/dist/ru-RU.mjs +1 -1
- package/dist/sk-SK.mjs +1 -1
- package/dist/sl-SI.mjs +1 -1
- package/dist/sr-SP.mjs +1 -1
- package/dist/{styles.36ea4632.css → styles.b562cf4b.css} +9 -13
- package/dist/styles.b562cf4b.css.map +1 -0
- package/dist/styles_css.main.js +3 -0
- package/dist/styles_css.main.js.map +1 -1
- package/dist/styles_css.mjs +4 -1
- package/dist/styles_css.module.js +3 -0
- package/dist/styles_css.module.js.map +1 -1
- package/dist/sv-SE.mjs +1 -1
- package/dist/textfield_vars_css.mjs +1 -1
- package/dist/tr-TR.mjs +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/uk-UA.mjs +1 -1
- package/dist/utils.main.js +26 -11
- package/dist/utils.main.js.map +1 -1
- package/dist/utils.mjs +28 -14
- package/dist/utils.module.js +27 -13
- package/dist/utils.module.js.map +1 -1
- package/dist/{vars.3692148b.css → vars.3d0e5be0.css} +2 -1
- package/dist/vars.3d0e5be0.css.map +1 -0
- package/dist/zh-CN.mjs +1 -1
- package/dist/zh-TW.mjs +1 -1
- package/package.json +23 -23
- package/src/DateField.tsx +4 -1
- package/src/DatePicker.tsx +6 -3
- package/src/DatePickerField.tsx +2 -2
- package/src/DatePickerSegment.tsx +4 -7
- package/src/DateRangePicker.tsx +7 -3
- package/src/Input.tsx +10 -2
- package/src/TimeField.tsx +4 -1
- package/src/styles.css +8 -12
- package/src/utils.ts +15 -2
- package/dist/styles.36ea4632.css.map +0 -1
- package/dist/vars.3692148b.css.map +0 -1
package/dist/utils.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {createDOMRef as $d7JPl$createDOMRef} from "@react-spectrum/utils";
|
|
2
2
|
import {createFocusManager as $d7JPl$createFocusManager} from "@react-aria/focus";
|
|
3
|
-
import {useDateFormatter as $d7JPl$useDateFormatter} from "@react-aria/i18n";
|
|
3
|
+
import {useDateFormatter as $d7JPl$useDateFormatter, useLocale as $d7JPl$useLocale} from "@react-aria/i18n";
|
|
4
4
|
import {useDisplayNames as $d7JPl$useDisplayNames} from "@react-aria/datepicker";
|
|
5
5
|
import {useMemo as $d7JPl$useMemo, useState as $d7JPl$useState, useRef as $d7JPl$useRef, useImperativeHandle as $d7JPl$useImperativeHandle} from "react";
|
|
6
6
|
import {useLayoutEffect as $d7JPl$useLayoutEffect} from "@react-aria/utils";
|
|
@@ -25,16 +25,16 @@ import {useProvider as $d7JPl$useProvider} from "@react-spectrum/provider";
|
|
|
25
25
|
|
|
26
26
|
function $04e96200274b03de$export$322f4580ccd8dde6(props) {
|
|
27
27
|
let formatter = (0, $d7JPl$useDateFormatter)({
|
|
28
|
-
dateStyle:
|
|
28
|
+
dateStyle: 'short'
|
|
29
29
|
});
|
|
30
30
|
let displayNames = (0, $d7JPl$useDisplayNames)();
|
|
31
31
|
return (0, $d7JPl$useMemo)(()=>{
|
|
32
32
|
if (props.description) return props.description;
|
|
33
33
|
if (props.showFormatHelpText) return formatter.formatToParts(new Date()).map((s)=>{
|
|
34
|
-
if (s.type ===
|
|
34
|
+
if (s.type === 'literal') return s.value;
|
|
35
35
|
return displayNames.of(s.type);
|
|
36
|
-
}).join(
|
|
37
|
-
return
|
|
36
|
+
}).join(' ');
|
|
37
|
+
return '';
|
|
38
38
|
}, [
|
|
39
39
|
props.description,
|
|
40
40
|
props.showFormatHelpText,
|
|
@@ -48,9 +48,9 @@ function $04e96200274b03de$export$12ce2869ce471b1f(maxVisibleMonths) {
|
|
|
48
48
|
(0, $d7JPl$useLayoutEffect)(()=>{
|
|
49
49
|
let onResize = ()=>setVisibleMonths($04e96200274b03de$var$getVisibleMonths(scale));
|
|
50
50
|
onResize();
|
|
51
|
-
window.addEventListener(
|
|
51
|
+
window.addEventListener('resize', onResize);
|
|
52
52
|
return ()=>{
|
|
53
|
-
window.removeEventListener(
|
|
53
|
+
window.removeEventListener('resize', onResize);
|
|
54
54
|
};
|
|
55
55
|
}, [
|
|
56
56
|
scale
|
|
@@ -58,14 +58,14 @@ function $04e96200274b03de$export$12ce2869ce471b1f(maxVisibleMonths) {
|
|
|
58
58
|
return Math.max(1, Math.min(visibleMonths, maxVisibleMonths, 3));
|
|
59
59
|
}
|
|
60
60
|
function $04e96200274b03de$var$getVisibleMonths(scale) {
|
|
61
|
-
if (typeof window ===
|
|
62
|
-
let monthWidth = scale ===
|
|
63
|
-
let gap = scale ===
|
|
64
|
-
let popoverPadding = scale ===
|
|
61
|
+
if (typeof window === 'undefined') return 1;
|
|
62
|
+
let monthWidth = scale === 'large' ? 336 : 280;
|
|
63
|
+
let gap = scale === 'large' ? 30 : 24;
|
|
64
|
+
let popoverPadding = scale === 'large' ? 32 : 48;
|
|
65
65
|
return Math.floor((window.innerWidth - popoverPadding * 2) / (monthWidth + gap));
|
|
66
66
|
}
|
|
67
67
|
function $04e96200274b03de$export$71a23a36270e4bf0(ref) {
|
|
68
|
-
let domRef = (0, $d7JPl$useRef)();
|
|
68
|
+
let domRef = (0, $d7JPl$useRef)(undefined);
|
|
69
69
|
(0, $d7JPl$useImperativeHandle)(ref, ()=>({
|
|
70
70
|
...(0, $d7JPl$createDOMRef)(domRef),
|
|
71
71
|
focus () {
|
|
@@ -76,7 +76,21 @@ function $04e96200274b03de$export$71a23a36270e4bf0(ref) {
|
|
|
76
76
|
}));
|
|
77
77
|
return domRef;
|
|
78
78
|
}
|
|
79
|
+
function $04e96200274b03de$export$31e22e3c931fc056(state) {
|
|
80
|
+
var _useLocale;
|
|
81
|
+
let locale = (_useLocale = (0, $d7JPl$useLocale)()) === null || _useLocale === void 0 ? void 0 : _useLocale.locale;
|
|
82
|
+
let currentDate = new Date();
|
|
83
|
+
let formatedDate = state.getDateFormatter(locale, {
|
|
84
|
+
shouldForceLeadingZeros: true
|
|
85
|
+
}).format(currentDate, locale);
|
|
86
|
+
let totalCharacters = formatedDate.length;
|
|
87
|
+
// The max of two is for times with only hours.
|
|
88
|
+
// As the length of a date grows we need to proportionally increase the width.
|
|
89
|
+
// We use the character count with 'ch' units and add extra padding to accomate for
|
|
90
|
+
// dates with months and time dashes, which are wider characters.
|
|
91
|
+
return totalCharacters + Math.max(Math.floor(totalCharacters / 5), 2);
|
|
92
|
+
}
|
|
79
93
|
|
|
80
94
|
|
|
81
|
-
export {$04e96200274b03de$export$322f4580ccd8dde6 as useFormatHelpText, $04e96200274b03de$export$12ce2869ce471b1f as useVisibleMonths, $04e96200274b03de$export$71a23a36270e4bf0 as useFocusManagerRef};
|
|
82
|
-
//# sourceMappingURL=utils.
|
|
95
|
+
export {$04e96200274b03de$export$322f4580ccd8dde6 as useFormatHelpText, $04e96200274b03de$export$12ce2869ce471b1f as useVisibleMonths, $04e96200274b03de$export$71a23a36270e4bf0 as useFocusManagerRef, $04e96200274b03de$export$31e22e3c931fc056 as useFormattedDateWidth};
|
|
96
|
+
//# sourceMappingURL=utils.module.js.map
|
package/dist/utils.module.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {createDOMRef as $d7JPl$createDOMRef} from "@react-spectrum/utils";
|
|
2
2
|
import {createFocusManager as $d7JPl$createFocusManager} from "@react-aria/focus";
|
|
3
|
-
import {useDateFormatter as $d7JPl$useDateFormatter} from "@react-aria/i18n";
|
|
3
|
+
import {useDateFormatter as $d7JPl$useDateFormatter, useLocale as $d7JPl$useLocale} from "@react-aria/i18n";
|
|
4
4
|
import {useDisplayNames as $d7JPl$useDisplayNames} from "@react-aria/datepicker";
|
|
5
5
|
import {useMemo as $d7JPl$useMemo, useState as $d7JPl$useState, useRef as $d7JPl$useRef, useImperativeHandle as $d7JPl$useImperativeHandle} from "react";
|
|
6
6
|
import {useLayoutEffect as $d7JPl$useLayoutEffect} from "@react-aria/utils";
|
|
@@ -25,16 +25,16 @@ import {useProvider as $d7JPl$useProvider} from "@react-spectrum/provider";
|
|
|
25
25
|
|
|
26
26
|
function $04e96200274b03de$export$322f4580ccd8dde6(props) {
|
|
27
27
|
let formatter = (0, $d7JPl$useDateFormatter)({
|
|
28
|
-
dateStyle:
|
|
28
|
+
dateStyle: 'short'
|
|
29
29
|
});
|
|
30
30
|
let displayNames = (0, $d7JPl$useDisplayNames)();
|
|
31
31
|
return (0, $d7JPl$useMemo)(()=>{
|
|
32
32
|
if (props.description) return props.description;
|
|
33
33
|
if (props.showFormatHelpText) return formatter.formatToParts(new Date()).map((s)=>{
|
|
34
|
-
if (s.type ===
|
|
34
|
+
if (s.type === 'literal') return s.value;
|
|
35
35
|
return displayNames.of(s.type);
|
|
36
|
-
}).join(
|
|
37
|
-
return
|
|
36
|
+
}).join(' ');
|
|
37
|
+
return '';
|
|
38
38
|
}, [
|
|
39
39
|
props.description,
|
|
40
40
|
props.showFormatHelpText,
|
|
@@ -48,9 +48,9 @@ function $04e96200274b03de$export$12ce2869ce471b1f(maxVisibleMonths) {
|
|
|
48
48
|
(0, $d7JPl$useLayoutEffect)(()=>{
|
|
49
49
|
let onResize = ()=>setVisibleMonths($04e96200274b03de$var$getVisibleMonths(scale));
|
|
50
50
|
onResize();
|
|
51
|
-
window.addEventListener(
|
|
51
|
+
window.addEventListener('resize', onResize);
|
|
52
52
|
return ()=>{
|
|
53
|
-
window.removeEventListener(
|
|
53
|
+
window.removeEventListener('resize', onResize);
|
|
54
54
|
};
|
|
55
55
|
}, [
|
|
56
56
|
scale
|
|
@@ -58,14 +58,14 @@ function $04e96200274b03de$export$12ce2869ce471b1f(maxVisibleMonths) {
|
|
|
58
58
|
return Math.max(1, Math.min(visibleMonths, maxVisibleMonths, 3));
|
|
59
59
|
}
|
|
60
60
|
function $04e96200274b03de$var$getVisibleMonths(scale) {
|
|
61
|
-
if (typeof window ===
|
|
62
|
-
let monthWidth = scale ===
|
|
63
|
-
let gap = scale ===
|
|
64
|
-
let popoverPadding = scale ===
|
|
61
|
+
if (typeof window === 'undefined') return 1;
|
|
62
|
+
let monthWidth = scale === 'large' ? 336 : 280;
|
|
63
|
+
let gap = scale === 'large' ? 30 : 24;
|
|
64
|
+
let popoverPadding = scale === 'large' ? 32 : 48;
|
|
65
65
|
return Math.floor((window.innerWidth - popoverPadding * 2) / (monthWidth + gap));
|
|
66
66
|
}
|
|
67
67
|
function $04e96200274b03de$export$71a23a36270e4bf0(ref) {
|
|
68
|
-
let domRef = (0, $d7JPl$useRef)();
|
|
68
|
+
let domRef = (0, $d7JPl$useRef)(undefined);
|
|
69
69
|
(0, $d7JPl$useImperativeHandle)(ref, ()=>({
|
|
70
70
|
...(0, $d7JPl$createDOMRef)(domRef),
|
|
71
71
|
focus () {
|
|
@@ -76,7 +76,21 @@ function $04e96200274b03de$export$71a23a36270e4bf0(ref) {
|
|
|
76
76
|
}));
|
|
77
77
|
return domRef;
|
|
78
78
|
}
|
|
79
|
+
function $04e96200274b03de$export$31e22e3c931fc056(state) {
|
|
80
|
+
var _useLocale;
|
|
81
|
+
let locale = (_useLocale = (0, $d7JPl$useLocale)()) === null || _useLocale === void 0 ? void 0 : _useLocale.locale;
|
|
82
|
+
let currentDate = new Date();
|
|
83
|
+
let formatedDate = state.getDateFormatter(locale, {
|
|
84
|
+
shouldForceLeadingZeros: true
|
|
85
|
+
}).format(currentDate, locale);
|
|
86
|
+
let totalCharacters = formatedDate.length;
|
|
87
|
+
// The max of two is for times with only hours.
|
|
88
|
+
// As the length of a date grows we need to proportionally increase the width.
|
|
89
|
+
// We use the character count with 'ch' units and add extra padding to accomate for
|
|
90
|
+
// dates with months and time dashes, which are wider characters.
|
|
91
|
+
return totalCharacters + Math.max(Math.floor(totalCharacters / 5), 2);
|
|
92
|
+
}
|
|
79
93
|
|
|
80
94
|
|
|
81
|
-
export {$04e96200274b03de$export$322f4580ccd8dde6 as useFormatHelpText, $04e96200274b03de$export$12ce2869ce471b1f as useVisibleMonths, $04e96200274b03de$export$71a23a36270e4bf0 as useFocusManagerRef};
|
|
95
|
+
export {$04e96200274b03de$export$322f4580ccd8dde6 as useFormatHelpText, $04e96200274b03de$export$12ce2869ce471b1f as useVisibleMonths, $04e96200274b03de$export$71a23a36270e4bf0 as useFocusManagerRef, $04e96200274b03de$export$31e22e3c931fc056 as useFormattedDateWidth};
|
|
82
96
|
//# sourceMappingURL=utils.module.js.map
|
package/dist/utils.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAWM,SAAS,0CAAkB,KAA8E;IAC9G,IAAI,YAAY,CAAA,GAAA,uBAAe,EAAE;QAAC,WAAW;IAAO;IACpD,IAAI,eAAe,CAAA,GAAA,sBAAc;IACjC,OAAO,CAAA,GAAA,cAAM,EAAE;QACb,IAAI,MAAM,WAAW,EACnB,OAAO,MAAM,WAAW;QAG1B,IAAI,MAAM,kBAAkB,EAC1B,OAAO,UAAU,aAAa,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAA;YAC7C,IAAI,EAAE,IAAI,KAAK,WACb,OAAO,EAAE,KAAK;YAGhB,OAAO,aAAa,EAAE,CAAC,EAAE,IAAI;QAC/B,GAAG,IAAI,CAAC;QAGV,OAAO;IACT,GAAG;QAAC,MAAM,WAAW;QAAE,MAAM,kBAAkB;QAAE;QAAW;KAAa;AAC3E;AAEO,SAAS,0CAAiB,gBAAwB;IACvD,IAAI,SAAC,KAAK,EAAC,GAAG,CAAA,GAAA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aAAa,MAAM;IAE1C,+CAA+C;IAC/C,8EAA8E;IAC9E,mFAAmF;IACnF,iEAAiE;IACjE,OAAQ,kBAAkB,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,kBAAkB,IAAI;AACtE","sources":["packages/@react-spectrum/datepicker/src/utils.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nimport {createDOMRef} from '@react-spectrum/utils';\nimport {createFocusManager} from '@react-aria/focus';\nimport {FocusableRef} from '@react-types/shared';\nimport {SpectrumDatePickerBase} from '@react-types/datepicker';\nimport {useDateFormatter, useLocale} from '@react-aria/i18n';\nimport {useDisplayNames} from '@react-aria/datepicker';\nimport {useImperativeHandle, useMemo, useRef, useState} from 'react';\nimport {useLayoutEffect} from '@react-aria/utils';\nimport {useProvider} from '@react-spectrum/provider';\n\nexport function useFormatHelpText(props: Pick<SpectrumDatePickerBase<any>, 'description' | 'showFormatHelpText'>) {\n let formatter = useDateFormatter({dateStyle: 'short'});\n let displayNames = useDisplayNames();\n return useMemo(() => {\n if (props.description) {\n return props.description;\n }\n\n if (props.showFormatHelpText) {\n return formatter.formatToParts(new Date()).map(s => {\n if (s.type === 'literal') {\n return s.value;\n }\n\n return displayNames.of(s.type);\n }).join(' ');\n }\n\n return '';\n }, [props.description, props.showFormatHelpText, formatter, displayNames]);\n}\n\nexport function useVisibleMonths(maxVisibleMonths: number) {\n let {scale} = useProvider();\n let [visibleMonths, setVisibleMonths] = useState(getVisibleMonths(scale));\n useLayoutEffect(() => {\n let onResize = () => setVisibleMonths(getVisibleMonths(scale));\n onResize();\n\n window.addEventListener('resize', onResize);\n return () => {\n window.removeEventListener('resize', onResize);\n };\n }, [scale]);\n\n return Math.max(1, Math.min(visibleMonths, maxVisibleMonths, 3));\n}\n\nfunction getVisibleMonths(scale) {\n if (typeof window === 'undefined') {\n return 1;\n }\n let monthWidth = scale === 'large' ? 336 : 280;\n let gap = scale === 'large' ? 30 : 24;\n let popoverPadding = scale === 'large' ? 32 : 48;\n return Math.floor((window.innerWidth - popoverPadding * 2) / (monthWidth + gap));\n}\n\nexport function useFocusManagerRef(ref: FocusableRef<HTMLElement>) {\n let domRef = useRef(undefined);\n useImperativeHandle(ref, () => ({\n ...createDOMRef(domRef),\n focus() {\n createFocusManager(domRef).focusFirst({tabbable: true});\n }\n }));\n return domRef;\n}\n\nexport function useFormattedDateWidth(state) {\n let locale = useLocale()?.locale;\n let currentDate = new Date();\n let formatedDate = state.getDateFormatter(locale, {shouldForceLeadingZeros: true}).format(currentDate, locale);\n let totalCharacters = formatedDate.length;\n\n // The max of two is for times with only hours.\n // As the length of a date grows we need to proportionally increase the width.\n // We use the character count with 'ch' units and add extra padding to accomate for\n // dates with months and time dashes, which are wider characters.\n return (totalCharacters + Math.max(Math.floor(totalCharacters / 5), 2));\n}\n"],"names":[],"version":3,"file":"utils.module.js.map"}
|
|
@@ -244,6 +244,7 @@
|
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
.YO3Nla_spectrum-Textfield-validationIcon {
|
|
247
|
+
box-sizing: content-box;
|
|
247
248
|
pointer-events: all;
|
|
248
249
|
transition: color var(--spectrum-global-animation-duration-100, .13s) ease-in-out;
|
|
249
250
|
padding-inline-end: calc(var(--spectrum-textfield-padding-x, var(--spectrum-global-dimension-size-150)) / 2);
|
|
@@ -546,4 +547,4 @@
|
|
|
546
547
|
border-color: var(--spectrum-textfield-quiet-border-color-key-focus, var(--spectrum-alias-border-color-focus));
|
|
547
548
|
}
|
|
548
549
|
}
|
|
549
|
-
/*# sourceMappingURL=vars.
|
|
550
|
+
/*#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;;;;;;;;;EAUE;;;;;EAKE;;;;;;EAKE","sources":["packages/@adobe/spectrum-css-temp/components/textfield/vars.css"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n@import './index.css';\n@import './skin.css';\n"],"names":[],"version":3,"file":"vars.3d0e5be0.css.map"}
|
package/dist/zh-CN.mjs
CHANGED
package/dist/zh-TW.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-spectrum/datepicker",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -36,25 +36,25 @@
|
|
|
36
36
|
"url": "https://github.com/adobe/react-spectrum"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@internationalized/date": "^3.5.
|
|
40
|
-
"@react-aria/datepicker": "^3.
|
|
41
|
-
"@react-aria/focus": "^3.
|
|
42
|
-
"@react-aria/i18n": "^3.
|
|
43
|
-
"@react-aria/interactions": "^3.
|
|
44
|
-
"@react-aria/utils": "^3.
|
|
45
|
-
"@react-spectrum/button": "^3.16.
|
|
46
|
-
"@react-spectrum/calendar": "^3.4.
|
|
47
|
-
"@react-spectrum/dialog": "^3.8.
|
|
48
|
-
"@react-spectrum/form": "^3.7.
|
|
49
|
-
"@react-spectrum/label": "^3.16.
|
|
50
|
-
"@react-spectrum/layout": "^3.6.
|
|
51
|
-
"@react-spectrum/utils": "^3.11.
|
|
52
|
-
"@react-spectrum/view": "^3.6.
|
|
53
|
-
"@react-stately/datepicker": "^3.
|
|
54
|
-
"@react-types/datepicker": "^3.
|
|
55
|
-
"@react-types/shared": "^3.
|
|
56
|
-
"@spectrum-icons/ui": "^3.6.
|
|
57
|
-
"@spectrum-icons/workflow": "^4.2.
|
|
39
|
+
"@internationalized/date": "^3.5.5",
|
|
40
|
+
"@react-aria/datepicker": "^3.11.0",
|
|
41
|
+
"@react-aria/focus": "^3.18.0",
|
|
42
|
+
"@react-aria/i18n": "^3.12.0",
|
|
43
|
+
"@react-aria/interactions": "^3.22.0",
|
|
44
|
+
"@react-aria/utils": "^3.25.0",
|
|
45
|
+
"@react-spectrum/button": "^3.16.5",
|
|
46
|
+
"@react-spectrum/calendar": "^3.4.10",
|
|
47
|
+
"@react-spectrum/dialog": "^3.8.12",
|
|
48
|
+
"@react-spectrum/form": "^3.7.7",
|
|
49
|
+
"@react-spectrum/label": "^3.16.7",
|
|
50
|
+
"@react-spectrum/layout": "^3.6.6",
|
|
51
|
+
"@react-spectrum/utils": "^3.11.8",
|
|
52
|
+
"@react-spectrum/view": "^3.6.11",
|
|
53
|
+
"@react-stately/datepicker": "^3.10.0",
|
|
54
|
+
"@react-types/datepicker": "^3.8.0",
|
|
55
|
+
"@react-types/shared": "^3.24.0",
|
|
56
|
+
"@spectrum-icons/ui": "^3.6.8",
|
|
57
|
+
"@spectrum-icons/workflow": "^4.2.13",
|
|
58
58
|
"@swc/helpers": "^0.5.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
@@ -63,11 +63,11 @@
|
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"@react-spectrum/provider": "^3.0.0",
|
|
66
|
-
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0",
|
|
67
|
-
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
|
|
66
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0",
|
|
67
|
+
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
|
|
68
68
|
},
|
|
69
69
|
"publishConfig": {
|
|
70
70
|
"access": "public"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "86d80e3216bc32e75108831cf3a5a720bc849206"
|
|
73
73
|
}
|
package/src/DateField.tsx
CHANGED
|
@@ -21,7 +21,7 @@ import {Input} from './Input';
|
|
|
21
21
|
import React, {ReactElement, useRef} from 'react';
|
|
22
22
|
import {useDateField} from '@react-aria/datepicker';
|
|
23
23
|
import {useDateFieldState} from '@react-stately/datepicker';
|
|
24
|
-
import {useFocusManagerRef, useFormatHelpText} from './utils';
|
|
24
|
+
import {useFocusManagerRef, useFormatHelpText, useFormattedDateWidth} from './utils';
|
|
25
25
|
import {useFormProps} from '@react-spectrum/form';
|
|
26
26
|
import {useLocale} from '@react-aria/i18n';
|
|
27
27
|
import {useProviderProps} from '@react-spectrum/provider';
|
|
@@ -61,6 +61,8 @@ function DateField<T extends DateValue>(props: SpectrumDateFieldProps<T>, ref: F
|
|
|
61
61
|
|
|
62
62
|
let validationState = state.validationState || (isInvalid ? 'invalid' : null);
|
|
63
63
|
|
|
64
|
+
let approximateWidth = useFormattedDateWidth(state) + 'ch';
|
|
65
|
+
|
|
64
66
|
return (
|
|
65
67
|
<Field
|
|
66
68
|
{...props}
|
|
@@ -82,6 +84,7 @@ function DateField<T extends DateValue>(props: SpectrumDateFieldProps<T>, ref: F
|
|
|
82
84
|
isQuiet={isQuiet}
|
|
83
85
|
autoFocus={autoFocus}
|
|
84
86
|
validationState={validationState}
|
|
87
|
+
minWidth={approximateWidth}
|
|
85
88
|
className={classNames(datepickerStyles, 'react-spectrum-DateField')}>
|
|
86
89
|
{state.segments.map((segment, i) =>
|
|
87
90
|
(<DatePickerSegment
|
package/src/DatePicker.tsx
CHANGED
|
@@ -31,7 +31,7 @@ import styles from '@adobe/spectrum-css-temp/components/inputgroup/vars.css';
|
|
|
31
31
|
import {TimeField} from './TimeField';
|
|
32
32
|
import {useDatePicker} from '@react-aria/datepicker';
|
|
33
33
|
import {useDatePickerState} from '@react-stately/datepicker';
|
|
34
|
-
import {useFocusManagerRef, useFormatHelpText, useVisibleMonths} from './utils';
|
|
34
|
+
import {useFocusManagerRef, useFormatHelpText, useFormattedDateWidth, useVisibleMonths} from './utils';
|
|
35
35
|
import {useFocusRing} from '@react-aria/focus';
|
|
36
36
|
import {useFormProps} from '@react-spectrum/form';
|
|
37
37
|
import {useHover} from '@react-aria/interactions';
|
|
@@ -50,7 +50,7 @@ function DatePicker<T extends DateValue>(props: SpectrumDatePickerProps<T>, ref:
|
|
|
50
50
|
pageBehavior
|
|
51
51
|
} = props;
|
|
52
52
|
let {hoverProps, isHovered} = useHover({isDisabled});
|
|
53
|
-
let targetRef = useRef<HTMLDivElement>();
|
|
53
|
+
let targetRef = useRef<HTMLDivElement>(undefined);
|
|
54
54
|
let state = useDatePickerState({
|
|
55
55
|
...props,
|
|
56
56
|
shouldCloseOnSelect: () => !state.hasTime
|
|
@@ -112,6 +112,8 @@ function DatePicker<T extends DateValue>(props: SpectrumDatePickerProps<T>, ref:
|
|
|
112
112
|
let visibleMonths = useVisibleMonths(maxVisibleMonths);
|
|
113
113
|
let validationState = state.validationState || (isInvalid ? 'invalid' : null);
|
|
114
114
|
|
|
115
|
+
let approximateWidth = useFormattedDateWidth(state) + 'ch';
|
|
116
|
+
|
|
115
117
|
return (
|
|
116
118
|
<Field
|
|
117
119
|
{...props}
|
|
@@ -136,7 +138,8 @@ function DatePicker<T extends DateValue>(props: SpectrumDatePickerProps<T>, ref:
|
|
|
136
138
|
validationState={validationState}
|
|
137
139
|
className={classNames(styles, 'spectrum-InputGroup-field')}
|
|
138
140
|
inputClassName={fieldClassName}
|
|
139
|
-
disableFocusRing
|
|
141
|
+
disableFocusRing
|
|
142
|
+
minWidth={approximateWidth}>
|
|
140
143
|
<DatePickerField
|
|
141
144
|
{...fieldProps}
|
|
142
145
|
data-testid="date-field"
|
package/src/DatePickerField.tsx
CHANGED
|
@@ -33,7 +33,7 @@ export function DatePickerField<T extends DateValue>(props: DatePickerFieldProps
|
|
|
33
33
|
isRequired,
|
|
34
34
|
inputClassName
|
|
35
35
|
} = props;
|
|
36
|
-
let ref = useRef();
|
|
36
|
+
let ref = useRef(undefined);
|
|
37
37
|
let {locale} = useLocale();
|
|
38
38
|
let state = useDateFieldState({
|
|
39
39
|
...props,
|
|
@@ -41,7 +41,7 @@ export function DatePickerField<T extends DateValue>(props: DatePickerFieldProps
|
|
|
41
41
|
createCalendar
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
let inputRef = useRef();
|
|
44
|
+
let inputRef = useRef(undefined);
|
|
45
45
|
let {fieldProps, inputProps} = useDateField({...props, inputRef}, state, ref);
|
|
46
46
|
|
|
47
47
|
return (
|
|
@@ -50,8 +50,9 @@ function LiteralSegment({segment}: LiteralSegmentProps) {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
function EditableSegment({segment, state}: DatePickerSegmentProps) {
|
|
53
|
-
let ref = useRef();
|
|
53
|
+
let ref = useRef(undefined);
|
|
54
54
|
let {segmentProps} = useDateSegment(segment, state, ref);
|
|
55
|
+
|
|
55
56
|
return (
|
|
56
57
|
<div
|
|
57
58
|
{...segmentProps}
|
|
@@ -60,13 +61,9 @@ function EditableSegment({segment, state}: DatePickerSegmentProps) {
|
|
|
60
61
|
'is-placeholder': segment.isPlaceholder,
|
|
61
62
|
'is-read-only': !segment.isEditable
|
|
62
63
|
})}
|
|
63
|
-
style={
|
|
64
|
-
...segmentProps.style,
|
|
65
|
-
minWidth: segment.maxValue != null ? String(segment.maxValue).length + 'ch' : null
|
|
66
|
-
}}
|
|
64
|
+
style={segmentProps.style}
|
|
67
65
|
data-testid={segment.type}>
|
|
68
|
-
<span aria-hidden="true" className={classNames(styles, 'react-spectrum-DatePicker-placeholder')}>{segment.placeholder}</span>
|
|
69
|
-
{segment.isPlaceholder ? '' : segment.text}
|
|
66
|
+
{segment.isPlaceholder ? <span aria-hidden="true" className={classNames(styles, 'react-spectrum-DatePicker-placeholder')}>{segment.placeholder}</span> : segment.text}
|
|
70
67
|
</div>
|
|
71
68
|
);
|
|
72
69
|
}
|
package/src/DateRangePicker.tsx
CHANGED
|
@@ -31,7 +31,7 @@ import styles from '@adobe/spectrum-css-temp/components/inputgroup/vars.css';
|
|
|
31
31
|
import {TimeField} from './TimeField';
|
|
32
32
|
import {useDateRangePicker} from '@react-aria/datepicker';
|
|
33
33
|
import {useDateRangePickerState} from '@react-stately/datepicker';
|
|
34
|
-
import {useFocusManagerRef, useFormatHelpText, useVisibleMonths} from './utils';
|
|
34
|
+
import {useFocusManagerRef, useFormatHelpText, useFormattedDateWidth, useVisibleMonths} from './utils';
|
|
35
35
|
import {useFocusRing} from '@react-aria/focus';
|
|
36
36
|
import {useFormProps} from '@react-spectrum/form';
|
|
37
37
|
import {useHover} from '@react-aria/interactions';
|
|
@@ -50,7 +50,7 @@ function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePickerProp
|
|
|
50
50
|
pageBehavior
|
|
51
51
|
} = props;
|
|
52
52
|
let {hoverProps, isHovered} = useHover({isDisabled});
|
|
53
|
-
let targetRef = useRef<HTMLDivElement>();
|
|
53
|
+
let targetRef = useRef<HTMLDivElement>(undefined);
|
|
54
54
|
let state = useDateRangePickerState({
|
|
55
55
|
...props,
|
|
56
56
|
shouldCloseOnSelect: () => !state.hasTime
|
|
@@ -112,6 +112,9 @@ function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePickerProp
|
|
|
112
112
|
let visibleMonths = useVisibleMonths(maxVisibleMonths);
|
|
113
113
|
let validationState = state.validationState || (isInvalid ? 'invalid' : null);
|
|
114
114
|
|
|
115
|
+
// Multiplying by two for the two dates, adding one character for the dash, and then the padding around the dash
|
|
116
|
+
let approximateWidth = `calc(${useFormattedDateWidth(state) * 2 + 1}ch + 2 * var(--spectrum-global-dimension-size-100))`;
|
|
117
|
+
|
|
115
118
|
return (
|
|
116
119
|
<Field
|
|
117
120
|
{...props}
|
|
@@ -136,7 +139,8 @@ function DateRangePicker<T extends DateValue>(props: SpectrumDateRangePickerProp
|
|
|
136
139
|
validationState={validationState}
|
|
137
140
|
className={classNames(styles, 'spectrum-InputGroup-field')}
|
|
138
141
|
inputClassName={fieldClassName}
|
|
139
|
-
disableFocusRing
|
|
142
|
+
disableFocusRing
|
|
143
|
+
minWidth={approximateWidth}>
|
|
140
144
|
<DatePickerField
|
|
141
145
|
{...startFieldProps}
|
|
142
146
|
data-testid="start-date"
|
package/src/Input.tsx
CHANGED
|
@@ -124,8 +124,16 @@ function Input(props, ref) {
|
|
|
124
124
|
return (
|
|
125
125
|
<div role="presentation" {...mergeProps(fieldProps, focusProps)} className={textfieldClass} style={style}>
|
|
126
126
|
<div role="presentation" className={inputClass}>
|
|
127
|
-
<div
|
|
128
|
-
|
|
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>
|
|
129
137
|
</div>
|
|
130
138
|
</div>
|
|
131
139
|
{validationIcon}
|
package/src/TimeField.tsx
CHANGED
|
@@ -18,7 +18,7 @@ import {FocusableRef} from '@react-types/shared';
|
|
|
18
18
|
import {Input} from './Input';
|
|
19
19
|
import React, {ReactElement, useRef} from 'react';
|
|
20
20
|
import {SpectrumTimeFieldProps, TimeValue} from '@react-types/datepicker';
|
|
21
|
-
import {useFocusManagerRef} from './utils';
|
|
21
|
+
import {useFocusManagerRef, useFormattedDateWidth} from './utils';
|
|
22
22
|
import {useFormProps} from '@react-spectrum/form';
|
|
23
23
|
import {useLocale} from '@react-aria/i18n';
|
|
24
24
|
import {useProviderProps} from '@react-spectrum/provider';
|
|
@@ -52,6 +52,8 @@ function TimeField<T extends TimeValue>(props: SpectrumTimeFieldProps<T>, ref: F
|
|
|
52
52
|
|
|
53
53
|
let validationState = state.validationState || (isInvalid ? 'invalid' : null);
|
|
54
54
|
|
|
55
|
+
let approximateWidth = useFormattedDateWidth(state) + 'ch';
|
|
56
|
+
|
|
55
57
|
return (
|
|
56
58
|
<Field
|
|
57
59
|
{...props}
|
|
@@ -72,6 +74,7 @@ function TimeField<T extends TimeValue>(props: SpectrumTimeFieldProps<T>, ref: F
|
|
|
72
74
|
isQuiet={isQuiet}
|
|
73
75
|
autoFocus={autoFocus}
|
|
74
76
|
validationState={validationState}
|
|
77
|
+
minWidth={approximateWidth}
|
|
75
78
|
className={classNames(datepickerStyles, 'react-spectrum-TimeField')}>
|
|
76
79
|
{state.segments.map((segment, i) =>
|
|
77
80
|
(<DatePickerSegment
|
package/src/styles.css
CHANGED
|
@@ -76,6 +76,12 @@
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
.react-spectrum-Datepicker-inputSized {
|
|
80
|
+
display: flex;
|
|
81
|
+
height: 100%;
|
|
82
|
+
align-items: center;
|
|
83
|
+
}
|
|
84
|
+
|
|
79
85
|
.react-spectrum-Datepicker-rangeDash {
|
|
80
86
|
&:before {
|
|
81
87
|
content: '–';
|
|
@@ -111,22 +117,12 @@
|
|
|
111
117
|
}
|
|
112
118
|
}
|
|
113
119
|
|
|
114
|
-
.react-spectrum-DatePicker-placeholder {
|
|
115
|
-
display: block;
|
|
116
|
-
width: 100%;
|
|
117
|
-
text-align: center;
|
|
118
|
-
font-style: italic;
|
|
119
|
-
visibility: hidden;
|
|
120
|
-
height: 0;
|
|
121
|
-
pointer-events: none;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
120
|
.react-spectrum-DatePicker-cell.is-placeholder {
|
|
125
121
|
color: var(--spectrum-gray-600);
|
|
126
122
|
|
|
127
123
|
.react-spectrum-DatePicker-placeholder {
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
text-align: center;
|
|
125
|
+
pointer-events: none;
|
|
130
126
|
}
|
|
131
127
|
}
|
|
132
128
|
|
package/src/utils.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {createDOMRef} from '@react-spectrum/utils';
|
|
|
13
13
|
import {createFocusManager} from '@react-aria/focus';
|
|
14
14
|
import {FocusableRef} from '@react-types/shared';
|
|
15
15
|
import {SpectrumDatePickerBase} from '@react-types/datepicker';
|
|
16
|
-
import {useDateFormatter} from '@react-aria/i18n';
|
|
16
|
+
import {useDateFormatter, useLocale} from '@react-aria/i18n';
|
|
17
17
|
import {useDisplayNames} from '@react-aria/datepicker';
|
|
18
18
|
import {useImperativeHandle, useMemo, useRef, useState} from 'react';
|
|
19
19
|
import {useLayoutEffect} from '@react-aria/utils';
|
|
@@ -68,7 +68,7 @@ function getVisibleMonths(scale) {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
export function useFocusManagerRef(ref: FocusableRef<HTMLElement>) {
|
|
71
|
-
let domRef = useRef();
|
|
71
|
+
let domRef = useRef(undefined);
|
|
72
72
|
useImperativeHandle(ref, () => ({
|
|
73
73
|
...createDOMRef(domRef),
|
|
74
74
|
focus() {
|
|
@@ -77,3 +77,16 @@ export function useFocusManagerRef(ref: FocusableRef<HTMLElement>) {
|
|
|
77
77
|
}));
|
|
78
78
|
return domRef;
|
|
79
79
|
}
|
|
80
|
+
|
|
81
|
+
export function useFormattedDateWidth(state) {
|
|
82
|
+
let locale = useLocale()?.locale;
|
|
83
|
+
let currentDate = new Date();
|
|
84
|
+
let formatedDate = state.getDateFormatter(locale, {shouldForceLeadingZeros: true}).format(currentDate, locale);
|
|
85
|
+
let totalCharacters = formatedDate.length;
|
|
86
|
+
|
|
87
|
+
// The max of two is for times with only hours.
|
|
88
|
+
// As the length of a date grows we need to proportionally increase the width.
|
|
89
|
+
// We use the character count with 'ch' units and add extra padding to accomate for
|
|
90
|
+
// dates with months and time dashes, which are wider characters.
|
|
91
|
+
return (totalCharacters + Math.max(Math.floor(totalCharacters / 5), 2));
|
|
92
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAYA;;;;;;AAMA;;;;;AAKA;;;;;;AAMA;;;;AAAA;;;;;AAAA;;;;;AAAA;;;;;AAAA;;;;;AAMA;;;;AAIA;;;;AAMA;;;;AAIA;;;;AAIA;;;;;AAKA;;;;;AAMA;;;;;;;;;AAQE;;;;;;AAQA;;;;AAKF;;;;;AAKA;;;;;;;AAMA;;;;;;;;;;;;AAWE;;;;AAOF;;;;;;;;;;AAUA;;;;AAGE;;;;;AAMF;;;;AAIA;;;;AAIA;;;;;;;AAOA;;;;AAIA;;;;;AAIE;;;;AAQA;;;;;AAQF;EACE;;;;EAGE;;;;;;AAOJ;;;;;;;;AAQA;EACE;;;;;;EAKA;;;;EAEE;;;;EAIF;;;;EAEE","sources":["packages/@react-spectrum/datepicker/src/styles.css"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n.react-spectrum-Datepicker-fieldWrapper.react-spectrum-Datepicker-fieldWrapper.react-spectrum-Datepicker-fieldWrapper {\n width: auto;\n min-width: var(--spectrum-global-dimension-size-2000);\n max-width: 100%;\n }\n\n.react-spectrum-Datepicker-startField {\n width: auto;\n padding-inline-end: var(--spectrum-global-dimension-size-100);\n}\n\n.react-spectrum-Datepicker-endField {\n width: auto;\n flex: 1;\n padding-inline-start: var(--spectrum-global-dimension-size-100);\n}\n\n.react-spectrum-Datepicker-field ~ .react-spectrum-Datepicker-endField > .react-spectrum-Datepicker-input {\n border-inline-start-width: 0;\n border-start-start-radius: 0;\n border-end-start-radius: 0;\n}\n\n.react-spectrum-Datepicker-field.react-spectrum-Datepicker-field {\n width: auto;\n}\n\n.react-spectrum-Datepicker-field .react-spectrum-DateField-Input {\n line-height: var(--spectrum-body-4-text-line-height);\n}\n\n/* specificity war with .spectrum-Field--positionSide etc. */\n.react-spectrum-DateField.react-spectrum-DateField.react-spectrum-DateField.react-spectrum-DateField {\n min-width: var(--spectrum-global-dimension-size-2000);\n}\n\n.react-spectrum-TimeField.react-spectrum-TimeField.react-spectrum-TimeField.react-spectrum-TimeField {\n min-width: var(--spectrum-global-dimension-size-1250);\n}\n\n.react-spectrum-TimeField-fieldWrapper.react-spectrum-TimeField-fieldWrapper.react-spectrum-TimeField-fieldWrapper {\n width: auto;\n min-width: var(--spectrum-global-dimension-size-1250);\n}\n\n.react-spectrum-Datepicker-input.react-spectrum-Datepicker-input.react-spectrum-Datepicker-input {\n /* always reserve space for the validation icon */\n padding-inline-end: calc(var(--spectrum-textfield-padding-x) + var(--spectrum-icon-alert-medium-width) + var(--spectrum-textfield-icon-margin-left));\n cursor: text;\n}\n\n.react-spectrum-Datepicker-inputContents {\n display: flex;\n align-items: center;\n height: 100%;\n overflow-x: auto;\n scrollbar-width: none; /* Firefox */\n -ms-overflow-style: none; /* Internet Explorer 10+ */\n\n &::-webkit-scrollbar { /* WebKit */\n width: 0;\n height: 0;\n display: none;\n }\n}\n\n.react-spectrum-Datepicker-rangeDash {\n &:before {\n content: '–';\n }\n}\n\n.react-spectrum-Datepicker-segments {\n display: flex;\n align-items: center;\n}\n\n.react-spectrum-Datepicker-literal {\n white-space: pre;\n user-select: none;\n color: var(--spectrum-textfield-text-color);\n}\n\n.react-spectrum-DatePicker-cell {\n border: none;\n background: none;\n padding: 0 2px;\n border-radius: var(--spectrum-alias-border-radius-small);\n font-variant-numeric: tabular-nums;\n text-align: end;\n box-sizing: content-box;\n white-space: nowrap;\n color: var(--spectrum-textfield-text-color);\n\n &::selection {\n /* hide the selection because there is no way to fully prevent it in Firefox */\n /* https://bugzilla.mozilla.org/show_bug.cgi?id=1742153 */\n background: transparent;\n }\n}\n\n.react-spectrum-DatePicker-placeholder {\n display: block;\n width: 100%;\n text-align: center;\n font-style: italic;\n visibility: hidden;\n height: 0;\n pointer-events: none;\n}\n\n.react-spectrum-DatePicker-cell.is-placeholder {\n color: var(--spectrum-gray-600);\n\n .react-spectrum-DatePicker-placeholder {\n visibility: visible;\n height: auto;\n }\n}\n\n.react-spectrum-DatePicker-cell.is-placeholder ~ .react-spectrum-Datepicker-literal {\n color: var(--spectrum-global-color-gray-600);\n}\n\n.react-spectrum-DatePicker-cell.is-read-only {\n color: var(--spectrum-global-color-gray-700);\n}\n\n.react-spectrum-DatePicker-cell:focus {\n background-color: var(--spectrum-accent-background-color-default);\n color: white;\n caret-color: transparent;\n outline: none;\n}\n\n.react-spectrum-Datepicker-dialog.react-spectrum-Datepicker-dialog {\n width: auto;\n}\n\n.react-spectrum-Datepicker-dialogContent {\n display: flex;\n flex-direction: column;\n\n .react-spectrum-Datepicker-calendar.is-invalid {\n /* Only apply display: contents when the calendar is invalid, which allows us to move the\n * error message below the time fields. Otherwise, don't do this because it breaks dragging\n * the selected range on Android. */\n display: contents;\n }\n\n /* Push the help text within the calendar down to the bottom of the dialog, below the time fields. */\n :global(.spectrum-Calendar-helpText) {\n order: 10;\n margin: var(--spectrum-global-dimension-size-200) var(--spectrum-calendar-day-padding) 0 var(--spectrum-calendar-day-padding);\n }\n}\n\n/* when displayed in a tray, reduce the padding of the dialog */\n@media (max-width: 700px) {\n .react-spectrum-Datepicker-dialog {\n --spectrum-dialog-padding-x: 8px;\n\n .react-spectrum-Datepicker-dialogContent {\n margin: 0 auto;\n max-width: calc((var(--spectrum-calendar-day-width) * 7) + (var(--spectrum-calendar-day-padding) * 12));\n }\n }\n}\n\n.react-spectrum-Datepicker-timeFields {\n width: 100%;\n min-width: calc(var(--spectrum-calendar-day-width) * 7);\n max-width: calc((var(--spectrum-calendar-day-width) * 7) + (var(--spectrum-calendar-day-padding) * 12));\n padding: 0 var(--spectrum-calendar-day-padding);\n box-sizing: border-box;\n}\n\n@media (forced-colors:active) {\n .react-spectrum-DatePicker-cell:focus {\n forced-color-adjust: none;\n background-color: Highlight;\n color: HighlightText;\n }\n .react-spectrum-DatePicker-cell.is-read-only {\n color: ButtonText;\n &:focus {\n color: HighlightText;\n }\n }\n .react-spectrum-DatePicker-cell.is-placeholder {\n color: ButtonText;\n &:focus {\n color: HighlightText;\n }\n }\n}\n"],"names":[],"version":3,"file":"styles.36ea4632.css.map"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AA4DA;;;;;AAIE;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAQA;;;;AAIA;;;;AAKF;;;;;;;;AAOE;;;;;;;;;;;AAqBE;;;;;AAQF;;;;AAKE;;;;;AAOJ;EACE;;;;EAIE;;;;;AAMJ;;;;;;;AAQE;;;;;;AAWF;;;;;;;;;;;;;;;;;;;;AA4CE;;;;;;;;AAYA;;;;;;;AAWE;;;;AAIA;;;;AAJA;;;;AAIA;;;;AAJA;;;;AAIA;;;;AAJA;;;;AAIA;;;;AAJA;;;;AAIA;;;;AAMA;;;;AAKF;;;;;AAME;;;;AAQF;;;;;AAOA;;;;;AAAA;;;;;AAOA;;;;AAIA;;;;;;;;AAUA;;;;;;;AASA;;;;AAIA;;;;AASF;;;;AAIA;;;;;AAKE;;;;AAIA;;;;;AAME;;;;AAOJ;;;;;;;AASE;;;;AAKF;;;;;;AAAA;;;;AAAA;;;;AAAA;;;;AAAA;;;;AAOA;;;;;;AAAA;;;;AAAA;;;;AAAA;;;;AAAA;;;;AASA;;;;;;;;;AAAA;;;;AAAA;;;;AAAA;;;;AAAA;;;;AAaA;;;;AASE;;;;AAIE;;;;AAAA;;;;AAAA;;;;AAAA;;;;AAKF;;;;;AAQF;;;;;AAAA;;;;AAAA;;;;AAAA;;;;AAAA;;;;AAME;;;;AAiBF;;;;;;AAKE;;;;AAKA;;;;;AAIE;;;;AAMF;;;;;;AAKE;;;;AAMF;;;;AAME;;;;;AAMF;;;;;;;AASE;;;;AAKA;;;;AAdF;;;;;;;AASE;;;;AAKA;;;;AAKF;;;;AAGE;;;;AAcE;;;;;AAOJ;;;;;AAIE;;;;AAIA;;;;AAIA;;;;AAME;;;;;AAMF;;;;;AAOF;;;;AAGE;;;;AAIA;;;;AAIA;;;;AAME;;;;;AASA;;;;AASJ;;;;AAIA;;;;AAKF;EACE;;;;;;;;;;;;EAUE;;;;;EAKE;;;;;;EAKE","sources":["packages/@adobe/spectrum-css-temp/components/textfield/vars.css"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n@import './index.css';\n@import './skin.css';\n"],"names":[],"version":3,"file":"vars.3692148b.css.map"}
|