|
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 = {
|
@@ -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 | }
|
|
0 commit comments