@povio/ui 3.2.4-rc.4 → 3.2.4-rc.5
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/components/inputs/DateTime/DatePicker/DatePicker.js +1 -0
- package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.js +1 -0
- package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.js +1 -0
- package/dist/components/inputs/DateTime/TimePicker/TimePicker.js +1 -0
- package/dist/components/inputs/DateTime/shared/staticDateTimeSegments.d.ts +6 -4
- package/dist/components/inputs/DateTime/shared/staticDateTimeSegments.js +9 -9
- package/dist/components/inputs/Input/NumberInput/NumberInput.js +1 -2
- package/dist/components/inputs/Input/NumberRangeInput/NumberRangeInput.js +1 -2
- package/dist/config/uiConfig.context.d.ts +3 -1
- package/dist/config/uiConfig.context.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/utils/date-time.utils.d.ts +9 -8
- package/dist/utils/date-time.utils.js +40 -34
- package/dist/utils/intl.utils.d.ts +5 -0
- package/package.json +1 -1
|
@@ -361,6 +361,7 @@ var DatePickerInner = (t0) => {
|
|
|
361
361
|
const disableManualEntry = props.disableManualEntry ?? ui.dateInput.disableManualEntry;
|
|
362
362
|
const showDropdown = !props.disableDropdown || disableManualEntry;
|
|
363
363
|
const staticSegments = getStaticCalendarDateSegments({
|
|
364
|
+
intl: ui.intl,
|
|
364
365
|
value: dateValue,
|
|
365
366
|
locale,
|
|
366
367
|
shouldForceLeadingZeros,
|
|
@@ -817,6 +817,7 @@ var DateRangePickerInner = (t0) => {
|
|
|
817
817
|
const disableManualEntry = props.disableManualEntry ?? ui.dateInput.disableManualEntry;
|
|
818
818
|
const showDropdown = !props.disableDropdown || disableManualEntry;
|
|
819
819
|
const staticSegments = getStaticDateRangeSegments({
|
|
820
|
+
intl: ui.intl,
|
|
820
821
|
start: startDateValue,
|
|
821
822
|
end: endDateValue,
|
|
822
823
|
locale,
|
|
@@ -285,6 +285,7 @@ var DateTimePickerInner = (t0) => {
|
|
|
285
285
|
const disableManualEntry = props.disableManualEntry ?? ui.dateInput.disableManualEntry;
|
|
286
286
|
const showDropdown = !props.disableDropdown || disableManualEntry;
|
|
287
287
|
const staticSegments = getStaticCalendarDateTimeSegments({
|
|
288
|
+
intl: ui.intl,
|
|
288
289
|
value: dateTimeValue,
|
|
289
290
|
locale,
|
|
290
291
|
shouldForceLeadingZeros,
|
|
@@ -503,6 +503,7 @@ var TimePickerInner = (t0) => {
|
|
|
503
503
|
const shouldForceLeadingZeros = props.shouldForceLeadingZeros ?? ui.dateInput.shouldForceLeadingZeros;
|
|
504
504
|
const showDropdown = !props.disableDropdown || disableManualEntry;
|
|
505
505
|
const staticSegments = getStaticTimeSegments({
|
|
506
|
+
intl: ui.intl,
|
|
506
507
|
value: timeValue_0,
|
|
507
508
|
locale,
|
|
508
509
|
shouldForceLeadingZeros,
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { CalendarDate } from '@internationalized/date';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { DateValue, TimeValue } from 'react-aria';
|
|
4
|
+
import { IntlFormatters } from '../../../../utils/intl.utils';
|
|
4
5
|
interface StaticSegmentProps {
|
|
5
6
|
isDisabled?: boolean;
|
|
6
7
|
hidePlaceholder?: boolean;
|
|
8
|
+
intl?: IntlFormatters;
|
|
7
9
|
}
|
|
8
10
|
interface StaticManualEntryPlaceholderProps {
|
|
9
11
|
disableManualEntry?: boolean;
|
|
@@ -32,10 +34,10 @@ interface StaticTimeSegmentsProps extends StaticSegmentProps, StaticManualEntryP
|
|
|
32
34
|
locale: string;
|
|
33
35
|
shouldForceLeadingZeros?: boolean;
|
|
34
36
|
}
|
|
35
|
-
export declare const getStaticCalendarDateSegments: ({ value, locale, shouldForceLeadingZeros, isDisabled, hidePlaceholder, disableManualEntry, placeholder, dateGranularity, }: StaticCalendarDateSegmentsProps) => import("react/jsx-runtime").JSX.Element;
|
|
36
|
-
export declare const getStaticCalendarDateTimeSegments: ({ value, locale, shouldForceLeadingZeros, isDisabled, hidePlaceholder, disableManualEntry, placeholder, }: StaticCalendarDateTimeSegmentsProps) => import("react/jsx-runtime").JSX.Element;
|
|
37
|
-
export declare const getStaticDateRangeSegments: ({ start, end, locale, shouldForceLeadingZeros, isDisabled, hidePlaceholder, disableManualEntry, placeholder, }: StaticDateRangeSegmentsProps) => import("react/jsx-runtime").JSX.Element;
|
|
38
|
-
export declare const getStaticTimeSegments: ({ value, locale, shouldForceLeadingZeros, isDisabled, hidePlaceholder, disableManualEntry, placeholder, }: StaticTimeSegmentsProps) => import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
export declare const getStaticCalendarDateSegments: ({ value, locale, shouldForceLeadingZeros, isDisabled, hidePlaceholder, disableManualEntry, placeholder, intl, dateGranularity, }: StaticCalendarDateSegmentsProps) => import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
export declare const getStaticCalendarDateTimeSegments: ({ value, locale, shouldForceLeadingZeros, isDisabled, hidePlaceholder, disableManualEntry, placeholder, intl, }: StaticCalendarDateTimeSegmentsProps) => import("react/jsx-runtime").JSX.Element;
|
|
39
|
+
export declare const getStaticDateRangeSegments: ({ start, end, locale, shouldForceLeadingZeros, isDisabled, hidePlaceholder, disableManualEntry, placeholder, intl, }: StaticDateRangeSegmentsProps) => import("react/jsx-runtime").JSX.Element;
|
|
40
|
+
export declare const getStaticTimeSegments: ({ value, locale, shouldForceLeadingZeros, isDisabled, hidePlaceholder, disableManualEntry, placeholder, intl, }: StaticTimeSegmentsProps) => import("react/jsx-runtime").JSX.Element;
|
|
39
41
|
export declare const getStaticDateTimePlaceholder: (placeholder: ReactNode) => import("react/jsx-runtime").JSX.Element;
|
|
40
42
|
export declare const getStaticDateTimeFocusTarget: (container: HTMLElement, staticTarget: EventTarget | null) => HTMLElement | null;
|
|
41
43
|
export {};
|
|
@@ -3,28 +3,28 @@ import { DateSegmentItemView } from "./DateSegmentItem.js";
|
|
|
3
3
|
import { DateTimeUtils } from "../../../../utils/date-time.utils.js";
|
|
4
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
//#region src/components/inputs/DateTime/shared/staticDateTimeSegments.tsx
|
|
6
|
-
var getStaticCalendarDateSegments = ({ value, locale, shouldForceLeadingZeros, isDisabled, hidePlaceholder, disableManualEntry, placeholder, dateGranularity = "day" }) => {
|
|
6
|
+
var getStaticCalendarDateSegments = ({ value, locale, shouldForceLeadingZeros, isDisabled, hidePlaceholder, disableManualEntry, placeholder, intl, dateGranularity = "day" }) => {
|
|
7
7
|
if (disableManualEntry && placeholder && !value) return getStaticDateTimePlaceholder(placeholder);
|
|
8
|
-
return renderStaticDateTimeParts(DateTimeUtils.formatCalendarDatePartsLocalized(value, locale, { shouldForceLeadingZeros }), {
|
|
8
|
+
return renderStaticDateTimeParts(DateTimeUtils.formatCalendarDatePartsLocalized(value, locale, { shouldForceLeadingZeros }, intl), {
|
|
9
9
|
isDisabled,
|
|
10
10
|
hidePlaceholder,
|
|
11
11
|
dateGranularity
|
|
12
12
|
});
|
|
13
13
|
};
|
|
14
|
-
var getStaticCalendarDateTimeSegments = ({ value, locale, shouldForceLeadingZeros, isDisabled, hidePlaceholder, disableManualEntry, placeholder }) => {
|
|
14
|
+
var getStaticCalendarDateTimeSegments = ({ value, locale, shouldForceLeadingZeros, isDisabled, hidePlaceholder, disableManualEntry, placeholder, intl }) => {
|
|
15
15
|
const hasValue = !!(value && "hour" in value);
|
|
16
16
|
if (disableManualEntry && placeholder && !hasValue) return getStaticDateTimePlaceholder(placeholder);
|
|
17
|
-
return renderStaticDateTimeParts(DateTimeUtils.formatCalendarDateTimePartsLocalized(hasValue ? value : null, locale, { shouldForceLeadingZeros }), {
|
|
17
|
+
return renderStaticDateTimeParts(DateTimeUtils.formatCalendarDateTimePartsLocalized(hasValue ? value : null, locale, { shouldForceLeadingZeros }, intl), {
|
|
18
18
|
isDisabled,
|
|
19
19
|
hidePlaceholder,
|
|
20
20
|
segmentRole: "spinbutton"
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
-
var getStaticDateRangeSegments = ({ start, end, locale, shouldForceLeadingZeros, isDisabled, hidePlaceholder, disableManualEntry, placeholder }) => {
|
|
23
|
+
var getStaticDateRangeSegments = ({ start, end, locale, shouldForceLeadingZeros, isDisabled, hidePlaceholder, disableManualEntry, placeholder, intl }) => {
|
|
24
24
|
if (disableManualEntry && placeholder && !start && !end) return getStaticDateTimePlaceholder(placeholder);
|
|
25
25
|
const showSeparator = !hidePlaceholder;
|
|
26
26
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
27
|
-
renderStaticDateTimeParts(DateTimeUtils.formatCalendarDatePartsLocalized(start, locale, { shouldForceLeadingZeros }), {
|
|
27
|
+
renderStaticDateTimeParts(DateTimeUtils.formatCalendarDatePartsLocalized(start, locale, { shouldForceLeadingZeros }, intl), {
|
|
28
28
|
isDisabled,
|
|
29
29
|
hidePlaceholder: hidePlaceholder && !start,
|
|
30
30
|
segmentGroup: "start"
|
|
@@ -33,16 +33,16 @@ var getStaticDateRangeSegments = ({ start, end, locale, shouldForceLeadingZeros,
|
|
|
33
33
|
className: isDisabled ? "pointer-events-none select-none text-interactive-text-secondary-disabled" : "pointer-events-none select-none",
|
|
34
34
|
children: "–"
|
|
35
35
|
}),
|
|
36
|
-
renderStaticDateTimeParts(DateTimeUtils.formatCalendarDatePartsLocalized(end, locale, { shouldForceLeadingZeros }), {
|
|
36
|
+
renderStaticDateTimeParts(DateTimeUtils.formatCalendarDatePartsLocalized(end, locale, { shouldForceLeadingZeros }, intl), {
|
|
37
37
|
isDisabled,
|
|
38
38
|
hidePlaceholder: hidePlaceholder && !end,
|
|
39
39
|
segmentGroup: "end"
|
|
40
40
|
})
|
|
41
41
|
] });
|
|
42
42
|
};
|
|
43
|
-
var getStaticTimeSegments = ({ value, locale, shouldForceLeadingZeros, isDisabled, hidePlaceholder, disableManualEntry, placeholder }) => {
|
|
43
|
+
var getStaticTimeSegments = ({ value, locale, shouldForceLeadingZeros, isDisabled, hidePlaceholder, disableManualEntry, placeholder, intl }) => {
|
|
44
44
|
if (disableManualEntry && placeholder && !value) return getStaticDateTimePlaceholder(placeholder);
|
|
45
|
-
return renderStaticDateTimeParts(DateTimeUtils.formatTimePartsLocalized(value, locale, { shouldForceLeadingZeros }), {
|
|
45
|
+
return renderStaticDateTimeParts(DateTimeUtils.formatTimePartsLocalized(value, locale, { shouldForceLeadingZeros }, intl), {
|
|
46
46
|
isDisabled,
|
|
47
47
|
hidePlaceholder,
|
|
48
48
|
timePickerOnly: true
|
|
@@ -2,7 +2,6 @@ import { UIOverrides } from "../../../../config/uiOverrides.context.js";
|
|
|
2
2
|
import { UIConfig } from "../../../../config/uiConfig.context.js";
|
|
3
3
|
import { FormField } from "../../FormField/FormField.js";
|
|
4
4
|
import { inputBaseDefinition } from "../../shared/input.cva.js";
|
|
5
|
-
import { IntlUtils } from "../../../../utils/intl.utils.js";
|
|
6
5
|
import { TooltipWrapper } from "../../shared/TooltipWrapper.js";
|
|
7
6
|
import { InputFrame } from "../../Skeleton/InputFrame.js";
|
|
8
7
|
import { useStaticInputHandoff } from "../../shared/useStaticInputHandoff.js";
|
|
@@ -339,7 +338,7 @@ var NumberInputInner = (t0) => {
|
|
|
339
338
|
if (!renderInput) {
|
|
340
339
|
const staticValue = props.value ?? props.defaultValue;
|
|
341
340
|
const formatOptions = props.formatOptions ?? ui.numberInput.formatOptions;
|
|
342
|
-
const displayValue = getStaticNumberDisplayValue(staticValue,
|
|
341
|
+
const displayValue = getStaticNumberDisplayValue(staticValue, ui.intl.getNumberFormatter(locale, formatOptions)) ?? "";
|
|
343
342
|
const hasValue = displayValue !== "";
|
|
344
343
|
const as = props.as ?? ui.input.as;
|
|
345
344
|
let isDisabled = !!props.isDisabled;
|
|
@@ -2,7 +2,6 @@ import { UIOverrides } from "../../../../config/uiOverrides.context.js";
|
|
|
2
2
|
import { UIConfig } from "../../../../config/uiConfig.context.js";
|
|
3
3
|
import { FormFieldLabel } from "../../FormField/FormFieldLabel.js";
|
|
4
4
|
import { inputBaseDefinition, inputSizeDefinition } from "../../shared/input.cva.js";
|
|
5
|
-
import { IntlUtils } from "../../../../utils/intl.utils.js";
|
|
6
5
|
import { InputClear } from "../../shared/InputClear.js";
|
|
7
6
|
import { InputFrame } from "../../Skeleton/InputFrame.js";
|
|
8
7
|
import { useStaticInputHandoff } from "../../shared/useStaticInputHandoff.js";
|
|
@@ -382,7 +381,7 @@ var NumberRangeInputInner = (t0) => {
|
|
|
382
381
|
if (!renderInput) {
|
|
383
382
|
const staticValue = normalizeRangeValue(props.value, props.minValue, props.maxValue);
|
|
384
383
|
const formatOptions = props.formatOptions ?? ui.numberInput.formatOptions;
|
|
385
|
-
const formatter =
|
|
384
|
+
const formatter = ui.intl.getNumberFormatter(locale, formatOptions);
|
|
386
385
|
const minDisplay = getStaticNumberDisplayValue(staticValue.min, formatter);
|
|
387
386
|
const maxDisplay = getStaticNumberDisplayValue(staticValue.max, formatter);
|
|
388
387
|
const hasValue = minDisplay !== null || maxDisplay !== null;
|
|
@@ -15,11 +15,13 @@ import { ToastPosition } from 'react-toastify';
|
|
|
15
15
|
import { CellTextProps } from '../components/table/CellText';
|
|
16
16
|
import { HeaderTextProps } from '../components/table/HeaderText';
|
|
17
17
|
import { TagProps } from '../components/text/Tag/Tag';
|
|
18
|
+
import { IntlFormatters } from '../utils/intl.utils';
|
|
18
19
|
export declare namespace UIConfig {
|
|
19
20
|
type DeepRequired<T> = {
|
|
20
|
-
[P in keyof T]-?: T[P] extends object ? DeepRequired<T[P]> : Exclude<T[P], null | undefined>;
|
|
21
|
+
[P in keyof T]-?: T[P] extends (...args: never[]) => unknown ? Exclude<T[P], null | undefined> : T[P] extends object ? DeepRequired<T[P]> : Exclude<T[P], null | undefined>;
|
|
21
22
|
};
|
|
22
23
|
export interface Options {
|
|
24
|
+
intl: IntlFormatters;
|
|
23
25
|
renderStaticInput: boolean;
|
|
24
26
|
input: Pick<TextInputProps, "variant" | "isClearable" | "hideLabel" | "as" | "size"> & {
|
|
25
27
|
alwaysShowClear?: boolean;
|
|
@@ -3,6 +3,7 @@ import { ClockIcon } from "../assets/icons/Clock.js";
|
|
|
3
3
|
import { DateTimeIcon } from "../assets/icons/DateTime.js";
|
|
4
4
|
import { ObjectUtils } from "../utils/object.utils.js";
|
|
5
5
|
import { useDeepCompareMemo } from "../hooks/useDeepCompare.js";
|
|
6
|
+
import { IntlUtils } from "../utils/intl.utils.js";
|
|
6
7
|
import { c } from "react/compiler-runtime";
|
|
7
8
|
import { jsx } from "react/jsx-runtime";
|
|
8
9
|
import { createContext, use } from "react";
|
|
@@ -10,6 +11,7 @@ import { createContext, use } from "react";
|
|
|
10
11
|
var UIConfig;
|
|
11
12
|
(function(_UIConfig) {
|
|
12
13
|
const DEFAULT_CONFIG = {
|
|
14
|
+
intl: IntlUtils,
|
|
13
15
|
renderStaticInput: true,
|
|
14
16
|
input: {
|
|
15
17
|
variant: "outlined",
|
package/dist/index.d.ts
CHANGED
|
@@ -183,6 +183,7 @@ export { UIRouter } from './config/router.context';
|
|
|
183
183
|
export { ThemeContext } from './config/theme.context';
|
|
184
184
|
export { UIConfig } from './config/uiConfig.context';
|
|
185
185
|
export { UIOverrides } from './config/uiOverrides.context';
|
|
186
|
+
export type { IntlFormatters } from './utils/intl.utils';
|
|
186
187
|
export { breadcrumbChevronDefinition, breadcrumbIconDefinition, breadcrumbItemDefinition, breadcrumbsDefinition, breadcrumbSegmentDefinition, } from './components/Breadcrumbs/breadcrumbs.cva';
|
|
187
188
|
export { buttonContentDefinition, buttonDefinition, buttonIconSizeDefinition, buttonSizeDefinition, } from './components/buttons/Button/button.cva';
|
|
188
189
|
export { pillButtonContentDefinition, pillButtonDefinition } from './components/buttons/PillButton/pillButton.cva';
|
package/dist/index.js
CHANGED
|
@@ -53,6 +53,7 @@ import { Loader } from "./components/status/Loader/Loader.js";
|
|
|
53
53
|
import { ObjectUtils } from "./utils/object.utils.js";
|
|
54
54
|
import { isEqual } from "./utils/isEqual.js";
|
|
55
55
|
import { useDeepCompareEffect, useDeepCompareLayoutEffect, useDeepCompareMemo } from "./hooks/useDeepCompare.js";
|
|
56
|
+
import { IntlUtils } from "./utils/intl.utils.js";
|
|
56
57
|
import { UIConfig } from "./config/uiConfig.context.js";
|
|
57
58
|
import { uiOutlineClass } from "./components/outline.clsx.js";
|
|
58
59
|
import { compoundMapper } from "./utils/compoundMapper.js";
|
|
@@ -82,7 +83,6 @@ import { inputBaseDefinition, inputClearClassDefinition, inputContentWrapperDefi
|
|
|
82
83
|
import { CheckboxGroup } from "./components/inputs/Checkbox/CheckboxGroup.js";
|
|
83
84
|
import { useLongPressRepeat } from "./hooks/useLongPressRepeat.js";
|
|
84
85
|
import { useScrollableListBox } from "./hooks/useScrollableListBox.js";
|
|
85
|
-
import { IntlUtils } from "./utils/intl.utils.js";
|
|
86
86
|
import { DateTimeUtils } from "./utils/date-time.utils.js";
|
|
87
87
|
import { datePickerInputContentRowDefinition } from "./components/inputs/DateTime/shared/datePickerInput.cva.js";
|
|
88
88
|
import { popoverDefinition } from "./components/shared/popover.cva.js";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CalendarDate, CalendarDateTime, DateValue, ZonedDateTime } from '@internationalized/date';
|
|
2
|
+
import { IntlFormatters } from './intl.utils';
|
|
2
3
|
export declare namespace DateTimeUtils {
|
|
3
4
|
interface LocalizedDateFormatOptions {
|
|
4
5
|
shouldForceLeadingZeros?: boolean;
|
|
@@ -9,22 +10,22 @@ export declare namespace DateTimeUtils {
|
|
|
9
10
|
placeholder: string;
|
|
10
11
|
isPlaceholder: boolean;
|
|
11
12
|
}
|
|
12
|
-
export function getDatePlaceholder(locale?: string, options?: LocalizedDateFormatOptions): string;
|
|
13
|
-
export function getTimePlaceholder(locale?: string): string;
|
|
13
|
+
export function getDatePlaceholder(locale?: string, options?: LocalizedDateFormatOptions, intl?: IntlFormatters): string;
|
|
14
|
+
export function getTimePlaceholder(locale?: string, intl?: IntlFormatters): string;
|
|
14
15
|
export function getDateTimePlaceholder(locale?: string, options?: LocalizedDateFormatOptions): string;
|
|
15
16
|
export function getDateRangePlaceholder(locale?: string, options?: LocalizedDateFormatOptions): string;
|
|
16
|
-
export function formatCalendarDateLocalized(calendarDate: CalendarDate, locale?: string, options?: LocalizedDateFormatOptions): string;
|
|
17
|
-
export function formatCalendarDatePartsLocalized(calendarDate?: CalendarDate | null, locale?: string, options?: LocalizedDateFormatOptions): LocalizedDatePart[];
|
|
18
|
-
export function formatCalendarDateTimePartsLocalized(calendarDateTime?: Pick<CalendarDateTime, "day" | "month" | "year" | "hour" | "minute"> | null, locale?: string, options?: LocalizedDateFormatOptions): LocalizedDatePart[];
|
|
17
|
+
export function formatCalendarDateLocalized(calendarDate: CalendarDate, locale?: string, options?: LocalizedDateFormatOptions, intl?: IntlFormatters): string;
|
|
18
|
+
export function formatCalendarDatePartsLocalized(calendarDate?: CalendarDate | null, locale?: string, options?: LocalizedDateFormatOptions, intl?: IntlFormatters): LocalizedDatePart[];
|
|
19
|
+
export function formatCalendarDateTimePartsLocalized(calendarDateTime?: Pick<CalendarDateTime, "day" | "month" | "year" | "hour" | "minute"> | null, locale?: string, options?: LocalizedDateFormatOptions, intl?: IntlFormatters): LocalizedDatePart[];
|
|
19
20
|
export function formatTimeLocalized(timeValue: {
|
|
20
21
|
hour: number;
|
|
21
22
|
minute: number;
|
|
22
|
-
}, locale?: string, options?: LocalizedDateFormatOptions): string;
|
|
23
|
+
}, locale?: string, options?: LocalizedDateFormatOptions, intl?: IntlFormatters): string;
|
|
23
24
|
export function formatTimePartsLocalized(timeValue?: {
|
|
24
25
|
hour: number;
|
|
25
26
|
minute: number;
|
|
26
|
-
} | null, locale?: string, options?: LocalizedDateFormatOptions): LocalizedDatePart[];
|
|
27
|
-
export function formatCalendarDateTimeLocalized(calendarDateTime: Pick<CalendarDateTime, "day" | "month" | "year" | "hour" | "minute">, locale?: string, options?: LocalizedDateFormatOptions): string;
|
|
27
|
+
} | null, locale?: string, options?: LocalizedDateFormatOptions, intl?: IntlFormatters): LocalizedDatePart[];
|
|
28
|
+
export function formatCalendarDateTimeLocalized(calendarDateTime: Pick<CalendarDateTime, "day" | "month" | "year" | "hour" | "minute">, locale?: string, options?: LocalizedDateFormatOptions, intl?: IntlFormatters): string;
|
|
28
29
|
export function fromISOtoZonedDateTime(isoString: string, timeZone?: string): ZonedDateTime;
|
|
29
30
|
export function fromDateValueToISO(dateValue: DateValue, timeZone?: string): string;
|
|
30
31
|
export function fromDateValueFieldsToUTCISO(dateValue: DateValue): string;
|
|
@@ -9,27 +9,32 @@ var DateTimeUtils;
|
|
|
9
9
|
const timeFormatters = /* @__PURE__ */ new Map();
|
|
10
10
|
const getDayMonthFormat = (shouldForceLeadingZeros = false) => shouldForceLeadingZeros ? "2-digit" : "numeric";
|
|
11
11
|
const getTimeHourFormat = (shouldForceLeadingZeros = false) => shouldForceLeadingZeros ? "2-digit" : "numeric";
|
|
12
|
-
const getDatePlaceholderFormatter = (locale, options) =>
|
|
12
|
+
const getDatePlaceholderFormatter = (locale, options, intl = IntlUtils) => intl.getDateTimeFormatter(locale, {
|
|
13
13
|
day: getDayMonthFormat(options?.shouldForceLeadingZeros),
|
|
14
14
|
month: getDayMonthFormat(options?.shouldForceLeadingZeros),
|
|
15
15
|
year: "numeric"
|
|
16
16
|
});
|
|
17
|
-
const getTimePlaceholderFormatter = (locale) =>
|
|
17
|
+
const getTimePlaceholderFormatter = (locale, intl = IntlUtils) => intl.getDateTimeFormatter(locale, {
|
|
18
18
|
hour: "2-digit",
|
|
19
19
|
minute: "2-digit"
|
|
20
20
|
});
|
|
21
|
-
const getResolvedLocale = (locale) => {
|
|
21
|
+
const getResolvedLocale = (locale, intl = IntlUtils) => {
|
|
22
22
|
if (locale) return locale;
|
|
23
|
-
return
|
|
23
|
+
return intl.getDateTimeFormatter().resolvedOptions().locale;
|
|
24
24
|
};
|
|
25
|
-
const getDateFormatter = (locale, options) =>
|
|
25
|
+
const getDateFormatter = (locale, options, intl = IntlUtils) => intl.getDateTimeFormatter(getResolvedLocale(locale, intl), {
|
|
26
26
|
day: getDayMonthFormat(options?.shouldForceLeadingZeros),
|
|
27
27
|
month: getDayMonthFormat(options?.shouldForceLeadingZeros),
|
|
28
28
|
year: "numeric",
|
|
29
29
|
timeZone: "UTC"
|
|
30
30
|
});
|
|
31
|
-
const getTimeFormatter = (locale, options) => {
|
|
32
|
-
const resolvedLocale = getResolvedLocale(locale);
|
|
31
|
+
const getTimeFormatter = (locale, options, intl = IntlUtils) => {
|
|
32
|
+
const resolvedLocale = getResolvedLocale(locale, intl);
|
|
33
|
+
if (intl !== IntlUtils) return intl.getDateTimeFormatter(resolvedLocale, {
|
|
34
|
+
hour: getTimeHourFormat(options?.shouldForceLeadingZeros),
|
|
35
|
+
minute: "2-digit",
|
|
36
|
+
timeZone: "UTC"
|
|
37
|
+
});
|
|
33
38
|
const key = `${resolvedLocale}|${options?.shouldForceLeadingZeros ?? false}`;
|
|
34
39
|
const cachedFormatter = timeFormatters.get(key);
|
|
35
40
|
if (cachedFormatter) return cachedFormatter;
|
|
@@ -41,7 +46,7 @@ var DateTimeUtils;
|
|
|
41
46
|
timeFormatters.set(key, formatter);
|
|
42
47
|
return formatter;
|
|
43
48
|
};
|
|
44
|
-
const getDateTimeFormatter = (locale, options) =>
|
|
49
|
+
const getDateTimeFormatter = (locale, options, intl = IntlUtils) => intl.getDateTimeFormatter(getResolvedLocale(locale, intl), {
|
|
45
50
|
day: getDayMonthFormat(options?.shouldForceLeadingZeros),
|
|
46
51
|
month: getDayMonthFormat(options?.shouldForceLeadingZeros),
|
|
47
52
|
year: "numeric",
|
|
@@ -49,46 +54,47 @@ var DateTimeUtils;
|
|
|
49
54
|
minute: "2-digit",
|
|
50
55
|
timeZone: "UTC"
|
|
51
56
|
});
|
|
52
|
-
const repeatLocalizedFieldLabel = (type, length, locale) => {
|
|
53
|
-
const
|
|
57
|
+
const repeatLocalizedFieldLabel = (type, length, locale, intl = IntlUtils) => {
|
|
58
|
+
const resolvedLocale = getResolvedLocale(locale, intl);
|
|
59
|
+
const placeholderChar = intl.getDisplayNamesFormatter(resolvedLocale, { type: "dateTimeField" }).of(type)?.trim().charAt(0).toLocaleLowerCase(resolvedLocale);
|
|
54
60
|
if (!placeholderChar) return null;
|
|
55
61
|
return placeholderChar.repeat(length);
|
|
56
62
|
};
|
|
57
|
-
const mapTypeToPlaceholder = (type, locale) => {
|
|
63
|
+
const mapTypeToPlaceholder = (type, locale, intl = IntlUtils) => {
|
|
58
64
|
switch (type) {
|
|
59
|
-
case "day": return repeatLocalizedFieldLabel(type, 2, locale);
|
|
60
|
-
case "month": return repeatLocalizedFieldLabel(type, 2, locale);
|
|
61
|
-
case "year": return repeatLocalizedFieldLabel(type, 4, locale);
|
|
65
|
+
case "day": return repeatLocalizedFieldLabel(type, 2, locale, intl);
|
|
66
|
+
case "month": return repeatLocalizedFieldLabel(type, 2, locale, intl);
|
|
67
|
+
case "year": return repeatLocalizedFieldLabel(type, 4, locale, intl);
|
|
62
68
|
case "hour": return "hh";
|
|
63
69
|
case "minute": return "mm";
|
|
64
70
|
default: return null;
|
|
65
71
|
}
|
|
66
72
|
};
|
|
67
|
-
const formatPlaceholder = (formatter, sampleDate) => {
|
|
68
|
-
return formatter.formatToParts(sampleDate).map((part) => mapTypeToPlaceholder(part.type, formatter.resolvedOptions().locale) ?? part.value).join("");
|
|
73
|
+
const formatPlaceholder = (formatter, sampleDate, intl = IntlUtils) => {
|
|
74
|
+
return formatter.formatToParts(sampleDate).map((part) => mapTypeToPlaceholder(part.type, formatter.resolvedOptions().locale, intl) ?? part.value).join("");
|
|
69
75
|
};
|
|
70
76
|
const removeDateSeparatorSpacing = (value) => value.replace(/([./-])\s+(?=[\p{Letter}\p{Number}])/gu, "$1");
|
|
71
77
|
const formatLocalizedDateParts = (formatter, date) => {
|
|
72
78
|
return removeDateSeparatorSpacing(formatter.format(date));
|
|
73
79
|
};
|
|
74
|
-
const formatLocalizedDatePartList = (formatter, date, isPlaceholder) => {
|
|
80
|
+
const formatLocalizedDatePartList = (formatter, date, isPlaceholder, intl = IntlUtils) => {
|
|
75
81
|
const locale = formatter.resolvedOptions().locale;
|
|
76
82
|
return formatter.formatToParts(date).map((part) => {
|
|
77
83
|
const value = part.type === "literal" ? part.value.replace(/([./-])\s+/gu, "$1") : part.value.replace(/\s+/gu, "");
|
|
78
84
|
return {
|
|
79
85
|
type: part.type,
|
|
80
86
|
value,
|
|
81
|
-
placeholder: mapTypeToPlaceholder(part.type, locale) ?? value,
|
|
87
|
+
placeholder: mapTypeToPlaceholder(part.type, locale, intl) ?? value,
|
|
82
88
|
isPlaceholder
|
|
83
89
|
};
|
|
84
90
|
});
|
|
85
91
|
};
|
|
86
|
-
function getDatePlaceholder(locale, options) {
|
|
87
|
-
return removeDateSeparatorSpacing(formatPlaceholder(getDatePlaceholderFormatter(locale, options), DATE_SAMPLE_DATE_UTC));
|
|
92
|
+
function getDatePlaceholder(locale, options, intl = IntlUtils) {
|
|
93
|
+
return removeDateSeparatorSpacing(formatPlaceholder(getDatePlaceholderFormatter(locale, options, intl), DATE_SAMPLE_DATE_UTC, intl));
|
|
88
94
|
}
|
|
89
95
|
_DateTimeUtils.getDatePlaceholder = getDatePlaceholder;
|
|
90
|
-
function getTimePlaceholder(locale) {
|
|
91
|
-
return formatPlaceholder(getTimePlaceholderFormatter(locale), TIME_SAMPLE_DATE_UTC);
|
|
96
|
+
function getTimePlaceholder(locale, intl = IntlUtils) {
|
|
97
|
+
return formatPlaceholder(getTimePlaceholderFormatter(locale, intl), TIME_SAMPLE_DATE_UTC, intl);
|
|
92
98
|
}
|
|
93
99
|
_DateTimeUtils.getTimePlaceholder = getTimePlaceholder;
|
|
94
100
|
function getDateTimePlaceholder(locale, options) {
|
|
@@ -100,32 +106,32 @@ var DateTimeUtils;
|
|
|
100
106
|
return `${datePlaceholder} – ${datePlaceholder}`;
|
|
101
107
|
}
|
|
102
108
|
_DateTimeUtils.getDateRangePlaceholder = getDateRangePlaceholder;
|
|
103
|
-
function formatCalendarDateLocalized(calendarDate, locale, options) {
|
|
104
|
-
return formatLocalizedDateParts(getDateFormatter(locale, options), calendarDate.toDate("UTC"));
|
|
109
|
+
function formatCalendarDateLocalized(calendarDate, locale, options, intl = IntlUtils) {
|
|
110
|
+
return formatLocalizedDateParts(getDateFormatter(locale, options, intl), calendarDate.toDate("UTC"));
|
|
105
111
|
}
|
|
106
112
|
_DateTimeUtils.formatCalendarDateLocalized = formatCalendarDateLocalized;
|
|
107
|
-
function formatCalendarDatePartsLocalized(calendarDate, locale, options) {
|
|
108
|
-
return formatLocalizedDatePartList(getDateFormatter(locale, options), calendarDate?.toDate("UTC") ?? DATE_SAMPLE_DATE_UTC, !calendarDate);
|
|
113
|
+
function formatCalendarDatePartsLocalized(calendarDate, locale, options, intl = IntlUtils) {
|
|
114
|
+
return formatLocalizedDatePartList(getDateFormatter(locale, options, intl), calendarDate?.toDate("UTC") ?? DATE_SAMPLE_DATE_UTC, !calendarDate, intl);
|
|
109
115
|
}
|
|
110
116
|
_DateTimeUtils.formatCalendarDatePartsLocalized = formatCalendarDatePartsLocalized;
|
|
111
|
-
function formatCalendarDateTimePartsLocalized(calendarDateTime, locale, options) {
|
|
117
|
+
function formatCalendarDateTimePartsLocalized(calendarDateTime, locale, options, intl = IntlUtils) {
|
|
112
118
|
const normalizedValue = calendarDateTime ? new CalendarDateTime(calendarDateTime.year, calendarDateTime.month, calendarDateTime.day, calendarDateTime.hour, calendarDateTime.minute) : null;
|
|
113
|
-
return formatLocalizedDatePartList(getDateTimeFormatter(locale, options), normalizedValue?.toDate("UTC") ?? TIME_SAMPLE_DATE_UTC, !calendarDateTime);
|
|
119
|
+
return formatLocalizedDatePartList(getDateTimeFormatter(locale, options, intl), normalizedValue?.toDate("UTC") ?? TIME_SAMPLE_DATE_UTC, !calendarDateTime, intl);
|
|
114
120
|
}
|
|
115
121
|
_DateTimeUtils.formatCalendarDateTimePartsLocalized = formatCalendarDateTimePartsLocalized;
|
|
116
|
-
function formatTimeLocalized(timeValue, locale, options) {
|
|
122
|
+
function formatTimeLocalized(timeValue, locale, options, intl = IntlUtils) {
|
|
117
123
|
const dateTime = new CalendarDateTime(2e3, 11, 22, timeValue.hour, timeValue.minute);
|
|
118
|
-
return getTimeFormatter(locale, options).format(dateTime.toDate("UTC"));
|
|
124
|
+
return getTimeFormatter(locale, options, intl).format(dateTime.toDate("UTC"));
|
|
119
125
|
}
|
|
120
126
|
_DateTimeUtils.formatTimeLocalized = formatTimeLocalized;
|
|
121
|
-
function formatTimePartsLocalized(timeValue, locale, options) {
|
|
127
|
+
function formatTimePartsLocalized(timeValue, locale, options, intl = IntlUtils) {
|
|
122
128
|
const normalizedValue = new CalendarDateTime(2e3, 11, 22, timeValue?.hour ?? 6, timeValue?.minute ?? 45);
|
|
123
|
-
return formatLocalizedDatePartList(getTimeFormatter(locale, options), normalizedValue.toDate("UTC"), !timeValue);
|
|
129
|
+
return formatLocalizedDatePartList(getTimeFormatter(locale, options, intl), normalizedValue.toDate("UTC"), !timeValue, intl);
|
|
124
130
|
}
|
|
125
131
|
_DateTimeUtils.formatTimePartsLocalized = formatTimePartsLocalized;
|
|
126
|
-
function formatCalendarDateTimeLocalized(calendarDateTime, locale, options) {
|
|
132
|
+
function formatCalendarDateTimeLocalized(calendarDateTime, locale, options, intl = IntlUtils) {
|
|
127
133
|
const normalizedValue = new CalendarDateTime(calendarDateTime.year, calendarDateTime.month, calendarDateTime.day, calendarDateTime.hour, calendarDateTime.minute);
|
|
128
|
-
return formatLocalizedDateParts(getDateTimeFormatter(locale, options), normalizedValue.toDate("UTC"));
|
|
134
|
+
return formatLocalizedDateParts(getDateTimeFormatter(locale, options, intl), normalizedValue.toDate("UTC"));
|
|
129
135
|
}
|
|
130
136
|
_DateTimeUtils.formatCalendarDateTimeLocalized = formatCalendarDateTimeLocalized;
|
|
131
137
|
function resolveTimeZone(timeZone) {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
type IntlLocale = Intl.LocalesArgument;
|
|
2
|
+
export interface IntlFormatters {
|
|
3
|
+
getDateTimeFormatter: (locale?: IntlLocale, options?: Intl.DateTimeFormatOptions) => Intl.DateTimeFormat;
|
|
4
|
+
getDisplayNamesFormatter: (locale: IntlLocale, options: Intl.DisplayNamesOptions) => Intl.DisplayNames;
|
|
5
|
+
getNumberFormatter: (locale?: IntlLocale, options?: Intl.NumberFormatOptions) => Intl.NumberFormat;
|
|
6
|
+
}
|
|
2
7
|
export declare namespace IntlUtils {
|
|
3
8
|
const getDateTimeFormatter: (locale?: IntlLocale, options?: Intl.DateTimeFormatOptions) => Intl.DateTimeFormat;
|
|
4
9
|
const getDisplayNamesFormatter: (locale: IntlLocale, options: Intl.DisplayNamesOptions) => Intl.DisplayNames;
|