@react-stately/datepicker 3.9.3 → 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 (68) hide show
  1. package/dist/ar-AE.mjs +1 -1
  2. package/dist/bg-BG.mjs +1 -1
  3. package/dist/cs-CZ.mjs +1 -1
  4. package/dist/da-DK.mjs +1 -1
  5. package/dist/de-DE.mjs +1 -1
  6. package/dist/el-GR.mjs +1 -1
  7. package/dist/en-US.mjs +1 -1
  8. package/dist/es-ES.mjs +1 -1
  9. package/dist/et-EE.mjs +1 -1
  10. package/dist/fi-FI.mjs +1 -1
  11. package/dist/fr-FR.mjs +1 -1
  12. package/dist/he-IL.mjs +1 -1
  13. package/dist/hr-HR.mjs +1 -1
  14. package/dist/hu-HU.mjs +1 -1
  15. package/dist/intlStrings.mjs +1 -1
  16. package/dist/it-IT.mjs +1 -1
  17. package/dist/ja-JP.mjs +1 -1
  18. package/dist/ko-KR.mjs +1 -1
  19. package/dist/lt-LT.mjs +1 -1
  20. package/dist/lv-LV.mjs +1 -1
  21. package/dist/nb-NO.mjs +1 -1
  22. package/dist/nl-NL.mjs +1 -1
  23. package/dist/pl-PL.mjs +1 -1
  24. package/dist/placeholders.main.js +155 -155
  25. package/dist/placeholders.mjs +156 -156
  26. package/dist/placeholders.module.js +155 -155
  27. package/dist/pt-BR.mjs +1 -1
  28. package/dist/pt-PT.mjs +1 -1
  29. package/dist/ro-RO.mjs +1 -1
  30. package/dist/ru-RU.mjs +1 -1
  31. package/dist/sk-SK.mjs +1 -1
  32. package/dist/sl-SI.mjs +1 -1
  33. package/dist/sr-SP.mjs +1 -1
  34. package/dist/sv-SE.mjs +1 -1
  35. package/dist/tr-TR.mjs +1 -1
  36. package/dist/types.d.ts +16 -1
  37. package/dist/types.d.ts.map +1 -1
  38. package/dist/uk-UA.mjs +1 -1
  39. package/dist/useDateFieldState.main.js +50 -42
  40. package/dist/useDateFieldState.main.js.map +1 -1
  41. package/dist/useDateFieldState.mjs +51 -43
  42. package/dist/useDateFieldState.module.js +50 -42
  43. package/dist/useDateFieldState.module.js.map +1 -1
  44. package/dist/useDatePickerState.main.js +17 -9
  45. package/dist/useDatePickerState.main.js.map +1 -1
  46. package/dist/useDatePickerState.mjs +18 -10
  47. package/dist/useDatePickerState.module.js +17 -9
  48. package/dist/useDatePickerState.module.js.map +1 -1
  49. package/dist/useDateRangePickerState.main.js +26 -18
  50. package/dist/useDateRangePickerState.main.js.map +1 -1
  51. package/dist/useDateRangePickerState.mjs +27 -19
  52. package/dist/useDateRangePickerState.module.js +26 -18
  53. package/dist/useDateRangePickerState.module.js.map +1 -1
  54. package/dist/useTimeFieldState.main.js +7 -7
  55. package/dist/useTimeFieldState.mjs +8 -8
  56. package/dist/useTimeFieldState.module.js +7 -7
  57. package/dist/utils.main.js +31 -31
  58. package/dist/utils.main.js.map +1 -1
  59. package/dist/utils.mjs +32 -32
  60. package/dist/utils.module.js +31 -31
  61. package/dist/utils.module.js.map +1 -1
  62. package/dist/zh-CN.mjs +1 -1
  63. package/dist/zh-TW.mjs +1 -1
  64. package/package.json +10 -10
  65. package/src/useDateFieldState.ts +10 -3
  66. package/src/useDatePickerState.ts +9 -2
  67. package/src/useDateRangePickerState.ts +10 -2
  68. package/src/utils.ts +1 -1
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import {Calendar, DateFormatter, getMinimumDayInMonth, getMinimumMonthInYear, GregorianCalendar, toCalendar} from '@internationalized/date';
14
- import {convertValue, createPlaceholderDate, FieldOptions, getFormatOptions, getValidationResult, useDefaultProps} from './utils';
14
+ import {convertValue, createPlaceholderDate, FieldOptions, FormatterOptions, getFormatOptions, getValidationResult, useDefaultProps} from './utils';
15
15
  import {DatePickerProps, DateValue, Granularity} from '@react-types/datepicker';
16
16
  import {FormValidationState, useFormValidationState} from '@react-stately/form';
17
17
  import {getPlaceholder} from './placeholders';
@@ -93,7 +93,9 @@ export interface DateFieldState extends FormValidationState {
93
93
  /** Clears the value of the given segment, reverting it to the placeholder. */
94
94
  clearSegment(type: SegmentType): void,
95
95
  /** Formats the current date value using the given options. */
96
- formatValue(fieldOptions: FieldOptions): string
96
+ formatValue(fieldOptions: FieldOptions): string,
97
+ /** Gets a formatter based on state's props. */
98
+ getDateFormatter(locale: string, formatOptions: FormatterOptions): DateFormatter
97
99
  }
98
100
 
99
101
  const EDITABLE_SEGMENTS = {
@@ -212,7 +214,7 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
212
214
  () => props.value || props.defaultValue ? {...allSegments} : {}
213
215
  );
214
216
 
215
- let clearedSegment = useRef<string>();
217
+ let clearedSegment = useRef<string>(undefined);
216
218
 
217
219
  // Reset placeholder when calendar changes
218
220
  let lastCalendarIdentifier = useRef(calendar.identifier);
@@ -412,6 +414,11 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
412
414
  let formatOptions = getFormatOptions(fieldOptions, formatOpts);
413
415
  let formatter = new DateFormatter(locale, formatOptions);
414
416
  return formatter.format(dateValue);
417
+ },
418
+ getDateFormatter(locale, formatOptions: FormatterOptions) {
419
+ let newOptions = {...formatOpts, ...formatOptions};
420
+ let newFormatOptions = getFormatOptions({}, newOptions);
421
+ return new DateFormatter(locale, newFormatOptions);
415
422
  }
416
423
  };
417
424
  }
@@ -12,7 +12,7 @@
12
12
 
13
13
  import {CalendarDate, DateFormatter, toCalendarDate, toCalendarDateTime} from '@internationalized/date';
14
14
  import {DatePickerProps, DateValue, Granularity, TimeValue} from '@react-types/datepicker';
15
- import {FieldOptions, getFormatOptions, getPlaceholderTime, getValidationResult, useDefaultProps} from './utils';
15
+ import {FieldOptions, FormatterOptions, getFormatOptions, getPlaceholderTime, getValidationResult, useDefaultProps} from './utils';
16
16
  import {FormValidationState, useFormValidationState} from '@react-stately/form';
17
17
  import {OverlayTriggerState, useOverlayTriggerState} from '@react-stately/overlays';
18
18
  import {useControlledState} from '@react-stately/utils';
@@ -62,7 +62,9 @@ export interface DatePickerState extends OverlayTriggerState, FormValidationStat
62
62
  /** Whether the date picker is invalid, based on the `isInvalid`, `minValue`, and `maxValue` props. */
63
63
  isInvalid: boolean,
64
64
  /** Formats the selected value using the given options. */
65
- formatValue(locale: string, fieldOptions: FieldOptions): string
65
+ formatValue(locale: string, fieldOptions: FieldOptions): string,
66
+ /** Gets a formatter based on state's props. */
67
+ getDateFormatter(locale: string, formatOptions: FormatterOptions): DateFormatter
66
68
  }
67
69
 
68
70
  /**
@@ -187,6 +189,11 @@ export function useDatePickerState<T extends DateValue = DateValue>(props: DateP
187
189
  let formatOptions = getFormatOptions(fieldOptions, formatOpts);
188
190
  let formatter = new DateFormatter(locale, formatOptions);
189
191
  return formatter.format(dateValue);
192
+ },
193
+ getDateFormatter(locale, formatOptions: FormatterOptions) {
194
+ let newOptions = {...formatOpts, ...formatOptions};
195
+ let newFormatOptions = getFormatOptions({}, newOptions);
196
+ return new DateFormatter(locale, newFormatOptions);
190
197
  }
191
198
  };
192
199
  }
@@ -10,9 +10,10 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
+
13
14
  import {DateFormatter, toCalendarDate, toCalendarDateTime} from '@internationalized/date';
14
15
  import {DateRange, DateRangePickerProps, DateValue, Granularity, TimeValue} from '@react-types/datepicker';
15
- import {FieldOptions, getFormatOptions, getPlaceholderTime, getRangeValidationResult, useDefaultProps} from './utils';
16
+ import {FieldOptions, FormatterOptions, getFormatOptions, getPlaceholderTime, getRangeValidationResult, useDefaultProps} from './utils';
16
17
  import {FormValidationState, useFormValidationState} from '@react-stately/form';
17
18
  import {OverlayTriggerState, useOverlayTriggerState} from '@react-stately/overlays';
18
19
  import {RangeValue, ValidationState} from '@react-types/shared';
@@ -69,7 +70,9 @@ export interface DateRangePickerState extends OverlayTriggerState, FormValidatio
69
70
  /** Whether the date range picker is invalid, based on the `isInvalid`, `minValue`, and `maxValue` props. */
70
71
  isInvalid: boolean,
71
72
  /** Formats the selected range using the given options. */
72
- formatValue(locale: string, fieldOptions: FieldOptions): {start: string, end: string}
73
+ formatValue(locale: string, fieldOptions: FieldOptions): {start: string, end: string},
74
+ /** Gets a formatter based on state's props. */
75
+ getDateFormatter(locale: string, formatOptions: FormatterOptions): DateFormatter
73
76
  }
74
77
 
75
78
  /**
@@ -295,6 +298,11 @@ export function useDateRangePickerState<T extends DateValue = DateValue>(props:
295
298
  start: startFormatter.format(startDate),
296
299
  end: endFormatter.format(endDate)
297
300
  };
301
+ },
302
+ getDateFormatter(locale, formatOptions: FormatterOptions) {
303
+ let newOptions = {...formatOpts, ...formatOptions};
304
+ let newFormatOptions = getFormatOptions({}, newOptions);
305
+ return new DateFormatter(locale, newFormatOptions);
298
306
  }
299
307
  };
300
308
  }
package/src/utils.ts CHANGED
@@ -122,7 +122,7 @@ export function getRangeValidationResult(
122
122
  }
123
123
 
124
124
  export type FieldOptions = Pick<Intl.DateTimeFormatOptions, 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'>;
125
- interface FormatterOptions {
125
+ export interface FormatterOptions {
126
126
  timeZone?: string,
127
127
  hideTimeZone?: boolean,
128
128
  granularity?: DatePickerProps<any>['granularity'],