@react-spectrum/datepicker 3.9.6 → 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.
Files changed (62) hide show
  1. package/dist/DateField.main.js +3 -1
  2. package/dist/DateField.main.js.map +1 -1
  3. package/dist/DateField.mjs +4 -2
  4. package/dist/DateField.module.js +4 -2
  5. package/dist/DateField.module.js.map +1 -1
  6. package/dist/DatePicker.main.js +6 -4
  7. package/dist/DatePicker.main.js.map +1 -1
  8. package/dist/DatePicker.mjs +7 -5
  9. package/dist/DatePicker.module.js +7 -5
  10. package/dist/DatePicker.module.js.map +1 -1
  11. package/dist/DatePickerField.main.js +3 -3
  12. package/dist/DatePickerField.main.js.map +1 -1
  13. package/dist/DatePickerField.mjs +3 -3
  14. package/dist/DatePickerField.module.js +3 -3
  15. package/dist/DatePickerField.module.js.map +1 -1
  16. package/dist/DatePickerSegment.main.js +5 -8
  17. package/dist/DatePickerSegment.main.js.map +1 -1
  18. package/dist/DatePickerSegment.mjs +5 -8
  19. package/dist/DatePickerSegment.module.js +5 -8
  20. package/dist/DatePickerSegment.module.js.map +1 -1
  21. package/dist/DateRangePicker.main.js +6 -3
  22. package/dist/DateRangePicker.main.js.map +1 -1
  23. package/dist/DateRangePicker.mjs +7 -4
  24. package/dist/DateRangePicker.module.js +7 -4
  25. package/dist/DateRangePicker.module.js.map +1 -1
  26. package/dist/Input.main.js +9 -3
  27. package/dist/Input.main.js.map +1 -1
  28. package/dist/Input.mjs +9 -3
  29. package/dist/Input.module.js +9 -3
  30. package/dist/Input.module.js.map +1 -1
  31. package/dist/TimeField.main.js +3 -1
  32. package/dist/TimeField.main.js.map +1 -1
  33. package/dist/TimeField.mjs +4 -2
  34. package/dist/TimeField.module.js +4 -2
  35. package/dist/TimeField.module.js.map +1 -1
  36. package/dist/{styles.36ea4632.css → styles.b562cf4b.css} +9 -13
  37. package/dist/styles.b562cf4b.css.map +1 -0
  38. package/dist/styles_css.main.js +3 -0
  39. package/dist/styles_css.main.js.map +1 -1
  40. package/dist/styles_css.mjs +3 -0
  41. package/dist/styles_css.module.js +3 -0
  42. package/dist/styles_css.module.js.map +1 -1
  43. package/dist/types.d.ts.map +1 -1
  44. package/dist/utils.main.js +16 -1
  45. package/dist/utils.main.js.map +1 -1
  46. package/dist/utils.mjs +17 -3
  47. package/dist/utils.module.js +17 -3
  48. package/dist/utils.module.js.map +1 -1
  49. package/dist/{vars.3692148b.css → vars.3d0e5be0.css} +2 -1
  50. package/dist/vars.3d0e5be0.css.map +1 -0
  51. package/package.json +23 -23
  52. package/src/DateField.tsx +4 -1
  53. package/src/DatePicker.tsx +6 -3
  54. package/src/DatePickerField.tsx +2 -2
  55. package/src/DatePickerSegment.tsx +4 -7
  56. package/src/DateRangePicker.tsx +7 -3
  57. package/src/Input.tsx +10 -2
  58. package/src/TimeField.tsx +4 -1
  59. package/src/styles.css +8 -12
  60. package/src/utils.ts +15 -2
  61. package/dist/styles.36ea4632.css.map +0 -1
  62. package/dist/vars.3692148b.css.map +0 -1
@@ -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
  }
@@ -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 role="presentation" className={classNames(datepickerStyles, 'react-spectrum-Datepicker-inputContents')} ref={mergeRefs(ref, inputRef)}>
128
- {children}
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
- visibility: visible;
129
- height: auto;
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"}