@synerise/ds-core 1.11.0 → 1.11.1
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/CHANGELOG.md +4 -0
- package/dist/i18n/{en.json → en.json.d.ts} +4 -2
- package/dist/i18n/en.json.js +8 -0
- package/dist/i18n/{es.json → es.json.d.ts} +4 -2
- package/dist/i18n/es.json.js +8 -0
- package/dist/i18n/index.js +14 -11
- package/dist/i18n/{pl.json → pl.json.d.ts} +4 -2
- package/dist/i18n/pl.json.js +8 -0
- package/dist/i18n/{pt.json → pt.json.d.ts} +4 -2
- package/dist/i18n/pt.json.js +8 -0
- package/dist/js/DSProvider/DSProvider.d.ts +5 -6
- package/dist/js/DSProvider/DSProvider.js +36 -31
- package/dist/js/DSProvider/LocaleProvider/LocaleProvider.d.ts +2 -2
- package/dist/js/DSProvider/LocaleProvider/LocaleProvider.js +29 -38
- package/dist/js/DSProvider/LocaleProvider/LocaleProvider.types.d.ts +3 -3
- package/dist/js/DSProvider/LocaleProvider/LocaleProvider.types.js +1 -1
- package/dist/js/DSProvider/LocaleProvider/LocaleProvider.utils.d.ts +1 -1
- package/dist/js/DSProvider/LocaleProvider/LocaleProvider.utils.js +22 -19
- package/dist/js/DSProvider/LocaleProvider/antLocales.d.ts +6 -6
- package/dist/js/DSProvider/LocaleProvider/antLocales.js +16 -13
- package/dist/js/DSProvider/LocaleProvider/index.js +4 -1
- package/dist/js/DSProvider/ThemeProvider/ThemeProvider.d.ts +2 -2
- package/dist/js/DSProvider/ThemeProvider/ThemeProvider.js +14 -12
- package/dist/js/DSProvider/ThemeProvider/breakpoints.js +5 -2
- package/dist/js/DSProvider/ThemeProvider/index.js +4 -1
- package/dist/js/DSProvider/ThemeProvider/theme.d.ts +1 -1
- package/dist/js/DSProvider/ThemeProvider/theme.js +17 -17
- package/dist/js/DSProvider/ThemeProvider/variables.d.ts +8 -0
- package/dist/js/DSProvider/ThemeProvider/variables.js +531 -530
- package/dist/js/DSProvider/index.js +4 -1
- package/dist/js/DropdownContext/DropdownContext/DropdownContextProvider.d.ts +2 -2
- package/dist/js/DropdownContext/DropdownContext/DropdownContextProvider.js +11 -11
- package/dist/js/DropdownContext/DropdownContext.d.ts +1 -1
- package/dist/js/DropdownContext/DropdownContext.js +5 -2
- package/dist/js/DropdownContext/DropdownContextProvider.d.ts +2 -2
- package/dist/js/DropdownContext/DropdownContextProvider.js +11 -11
- package/dist/js/DropdownContext/index.js +8 -3
- package/dist/js/DropdownContext/useDropdown.d.ts +1 -1
- package/dist/js/DropdownContext/useDropdown.js +7 -4
- package/dist/js/data-format/components/FormattedDate.d.ts +4 -4
- package/dist/js/data-format/components/FormattedDate.js +23 -9
- package/dist/js/data-format/components/FormattedDateTime.d.ts +4 -4
- package/dist/js/data-format/components/FormattedDateTime.js +26 -12
- package/dist/js/data-format/components/FormattedNumber.d.ts +2 -2
- package/dist/js/data-format/components/FormattedNumber.js +23 -9
- package/dist/js/data-format/components/FormattedRelativeDateTime.d.ts +3 -3
- package/dist/js/data-format/components/FormattedRelativeDateTime.js +40 -21
- package/dist/js/data-format/components/FormattedTime.d.ts +4 -4
- package/dist/js/data-format/components/FormattedTime.js +26 -12
- package/dist/js/data-format/components/index.js +13 -5
- package/dist/js/data-format/constants/dataFormat.constants.d.ts +2 -2
- package/dist/js/data-format/constants/dataFormat.constants.js +85 -49
- package/dist/js/data-format/constants/dataFormatConfig.constants.d.ts +2 -2
- package/dist/js/data-format/constants/dataFormatConfig.constants.js +15 -8
- package/dist/js/data-format/constants/dateTimeParts.constants.d.ts +1 -1
- package/dist/js/data-format/constants/dateTimeParts.constants.js +10 -4
- package/dist/js/data-format/constants/index.js +48 -3
- package/dist/js/data-format/contexts/DataFormatConfigContext.d.ts +2 -2
- package/dist/js/data-format/contexts/DataFormatConfigContext.js +6 -3
- package/dist/js/data-format/contexts/DataFormatIntlsContext.d.ts +2 -2
- package/dist/js/data-format/contexts/DataFormatIntlsContext.js +7 -4
- package/dist/js/data-format/contexts/index.js +6 -2
- package/dist/js/data-format/hocs/withDataFormat.d.ts +2 -2
- package/dist/js/data-format/hocs/withDataFormat.js +23 -9
- package/dist/js/data-format/hooks/index.js +14 -6
- package/dist/js/data-format/hooks/useDataFormat.d.ts +1 -1
- package/dist/js/data-format/hooks/useDataFormat.js +93 -90
- package/dist/js/data-format/hooks/useDataFormatConfig.d.ts +1 -1
- package/dist/js/data-format/hooks/useDataFormatConfig.js +8 -4
- package/dist/js/data-format/hooks/useDataFormatIntls.d.ts +1 -1
- package/dist/js/data-format/hooks/useDataFormatIntls.js +8 -4
- package/dist/js/data-format/hooks/useDataFormatUtils.d.ts +4 -4
- package/dist/js/data-format/hooks/useDataFormatUtils.js +62 -63
- package/dist/js/data-format/hooks/useRelativeDateTimeUpdate.d.ts +2 -2
- package/dist/js/data-format/hooks/useRelativeDateTimeUpdate.js +19 -23
- package/dist/js/data-format/hooks/useSingleIntl.d.ts +1 -1
- package/dist/js/data-format/hooks/useSingleIntl.js +11 -8
- package/dist/js/data-format/index.js +83 -7
- package/dist/js/data-format/providers/DataFormatConfigProvider.d.ts +2 -2
- package/dist/js/data-format/providers/DataFormatConfigProvider.js +37 -26
- package/dist/js/data-format/types/dataFormat.types.d.ts +3 -3
- package/dist/js/data-format/types/dataFormat.types.js +1 -5
- package/dist/js/data-format/types/dataFormatConfig.types.d.ts +1 -1
- package/dist/js/data-format/types/dataFormatConfig.types.js +1 -2
- package/dist/js/data-format/types/dateTimeParts.types.js +1 -2
- package/dist/js/data-format/types/index.js +1 -1
- package/dist/js/data-format/utils/dataFormat.utils.d.ts +2 -2
- package/dist/js/data-format/utils/dataFormat.utils.js +82 -67
- package/dist/js/data-format/utils/dataFormatConfig.utils.d.ts +1 -1
- package/dist/js/data-format/utils/dataFormatConfig.utils.js +9 -8
- package/dist/js/data-format/utils/date.utils.d.ts +2 -2
- package/dist/js/data-format/utils/date.utils.js +25 -21
- package/dist/js/data-format/utils/dateTimeParts.utils.d.ts +2 -2
- package/dist/js/data-format/utils/dateTimeParts.utils.js +68 -52
- package/dist/js/data-format/utils/index.js +41 -5
- package/dist/js/data-format/utils/timeZone.utils.d.ts +1 -1
- package/dist/js/data-format/utils/timeZone.utils.js +59 -51
- package/dist/js/index.js +112 -7
- package/dist/js/mediaQuery/mediaQuery.d.ts +2 -2
- package/dist/js/mediaQuery/mediaQuery.js +15 -25
- package/dist/js/style.d.ts +0 -2
- package/dist/js/style.js +1 -2
- package/dist/js/testing/index.js +6 -2
- package/dist/js/testing/renderWithProvider/renderWithProvider.d.ts +4 -4
- package/dist/js/testing/renderWithProvider/renderWithProvider.js +35 -27
- package/dist/js/testing/sleep.js +6 -8
- package/dist/js/toaster/Toaster.d.ts +1 -1
- package/dist/js/toaster/Toaster.js +12 -8
- package/dist/js/toaster/Toaster.types.js +1 -1
- package/dist/js/toaster/constants.d.ts +1 -1
- package/dist/js/toaster/constants.js +7 -4
- package/dist/js/toaster/contexts/ToasterContext.d.ts +2 -2
- package/dist/js/toaster/contexts/ToasterContext.js +9 -5
- package/dist/js/toaster/hooks/useToaster.d.ts +1 -1
- package/dist/js/toaster/hooks/useToaster.js +7 -4
- package/dist/js/toaster/index.js +12 -5
- package/dist/js/toaster/providers/ToasterProvider.d.ts +2 -2
- package/dist/js/toaster/providers/ToasterProvider.js +17 -17
- package/package.json +4 -4
- package/dist/js/testing/renderWithProvider/renderWithProvider.spec.d.ts +0 -1
- package/dist/style/colors.less +0 -137
- package/dist/style/config.less +0 -521
- package/dist/style/core.less +0 -55
- package/dist/style/variables.less +0 -2
- /package/dist/{style/variables.css → assets/style/core-tn0RQdqM.css} +0 -0
|
@@ -1,3 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { DEFAULT_DATA_FORMAT_CONFIG, DEFAULT_DATA_FORMAT_INTL, DEFAULT_DATA_FORMAT_NOTATION, EU_NOTATION, US_NOTATION } from "./dataFormatConfig.constants.js";
|
|
2
|
+
import { COMPACT_DECIMAL_LARGER_NUMBER, COMPACT_LARGER_NUMBER, DATE, DATETIME, DATE_CONSTANTS_TARGET_FORMATS, DEFAULT_FORMAT_DATE_OPTIONS, DEFAULT_FORMAT_MONTH_LONG_OPTIONS, DEFAULT_FORMAT_MONTH_SHORT_OPTIONS, DEFAULT_FORMAT_NUMBER_OPTIONS, DEFAULT_FORMAT_TIME_OPTIONS, DEFAULT_FORMAT_WEEKDAY_LONG_OPTIONS, DEFAULT_FORMAT_WEEKDAY_SHORT_OPTIONS, EU_DECIMAL_DELIMITER, EU_THOUSAND_DELIMITER, LARGER_NUMBER_LIMIT, LOWER_CASE, LOWER_FIRST, MONTHS_LONG, MONTHS_SHORT, MONTH_LONG, MONTH_SHORT, RELATIVE_FROM, RELATIVE_FROM_WITHOUT_SUFFIX, RELATIVE_TO, RELATIVE_TO_WITHOUT_SUFFIX, TIME, UPPER_CASE, UPPER_FIRST, US_DECIMAL_DELIMITER, US_THOUSAND_DELIMITER, WEEKDAYS_LONG, WEEKDAYS_SHORT, WEEKDAY_LONG, WEEKDAY_SHORT } from "./dataFormat.constants.js";
|
|
3
|
+
import { LONG, MONTH, SHORT, WEEKDAY } from "./dateTimeParts.constants.js";
|
|
4
|
+
export {
|
|
5
|
+
COMPACT_DECIMAL_LARGER_NUMBER,
|
|
6
|
+
COMPACT_LARGER_NUMBER,
|
|
7
|
+
DATE,
|
|
8
|
+
DATETIME,
|
|
9
|
+
DATE_CONSTANTS_TARGET_FORMATS,
|
|
10
|
+
DEFAULT_DATA_FORMAT_CONFIG,
|
|
11
|
+
DEFAULT_DATA_FORMAT_INTL,
|
|
12
|
+
DEFAULT_DATA_FORMAT_NOTATION,
|
|
13
|
+
DEFAULT_FORMAT_DATE_OPTIONS,
|
|
14
|
+
DEFAULT_FORMAT_MONTH_LONG_OPTIONS,
|
|
15
|
+
DEFAULT_FORMAT_MONTH_SHORT_OPTIONS,
|
|
16
|
+
DEFAULT_FORMAT_NUMBER_OPTIONS,
|
|
17
|
+
DEFAULT_FORMAT_TIME_OPTIONS,
|
|
18
|
+
DEFAULT_FORMAT_WEEKDAY_LONG_OPTIONS,
|
|
19
|
+
DEFAULT_FORMAT_WEEKDAY_SHORT_OPTIONS,
|
|
20
|
+
EU_DECIMAL_DELIMITER,
|
|
21
|
+
EU_NOTATION,
|
|
22
|
+
EU_THOUSAND_DELIMITER,
|
|
23
|
+
LARGER_NUMBER_LIMIT,
|
|
24
|
+
LONG,
|
|
25
|
+
LOWER_CASE,
|
|
26
|
+
LOWER_FIRST,
|
|
27
|
+
MONTH,
|
|
28
|
+
MONTHS_LONG,
|
|
29
|
+
MONTHS_SHORT,
|
|
30
|
+
MONTH_LONG,
|
|
31
|
+
MONTH_SHORT,
|
|
32
|
+
RELATIVE_FROM,
|
|
33
|
+
RELATIVE_FROM_WITHOUT_SUFFIX,
|
|
34
|
+
RELATIVE_TO,
|
|
35
|
+
RELATIVE_TO_WITHOUT_SUFFIX,
|
|
36
|
+
SHORT,
|
|
37
|
+
TIME,
|
|
38
|
+
UPPER_CASE,
|
|
39
|
+
UPPER_FIRST,
|
|
40
|
+
US_DECIMAL_DELIMITER,
|
|
41
|
+
US_NOTATION,
|
|
42
|
+
US_THOUSAND_DELIMITER,
|
|
43
|
+
WEEKDAY,
|
|
44
|
+
WEEKDAYS_LONG,
|
|
45
|
+
WEEKDAYS_SHORT,
|
|
46
|
+
WEEKDAY_LONG,
|
|
47
|
+
WEEKDAY_SHORT
|
|
48
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const DataFormatConfigContext: import(
|
|
1
|
+
import { DataFormatConfig } from '../types';
|
|
2
|
+
export declare const DataFormatConfigContext: import('react').Context<DataFormatConfig>;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import { createContext } from
|
|
2
|
-
import { DEFAULT_DATA_FORMAT_CONFIG } from
|
|
3
|
-
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
import { DEFAULT_DATA_FORMAT_CONFIG } from "../constants/dataFormatConfig.constants.js";
|
|
3
|
+
const DataFormatConfigContext = createContext(DEFAULT_DATA_FORMAT_CONFIG);
|
|
4
|
+
export {
|
|
5
|
+
DataFormatConfigContext
|
|
6
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const DataFormatIntlsContext: import(
|
|
1
|
+
import { DataFormatIntls } from '../types';
|
|
2
|
+
export declare const DataFormatIntlsContext: import('react').Context<DataFormatIntls>;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { createContext } from
|
|
2
|
-
import { DEFAULT_DATA_FORMAT_INTL } from
|
|
3
|
-
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
import { DEFAULT_DATA_FORMAT_INTL } from "../constants/dataFormatConfig.constants.js";
|
|
3
|
+
const DataFormatIntlsContext = createContext({
|
|
4
4
|
timeFormatIntl: DEFAULT_DATA_FORMAT_INTL,
|
|
5
5
|
numberFormatIntl: DEFAULT_DATA_FORMAT_INTL,
|
|
6
6
|
dateFormatIntl: DEFAULT_DATA_FORMAT_INTL
|
|
7
|
-
});
|
|
7
|
+
});
|
|
8
|
+
export {
|
|
9
|
+
DataFormatIntlsContext
|
|
10
|
+
};
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { DataFormatConfigContext } from "./DataFormatConfigContext.js";
|
|
2
|
+
import { DataFormatIntlsContext } from "./DataFormatIntlsContext.js";
|
|
3
|
+
export {
|
|
4
|
+
DataFormatConfigContext,
|
|
5
|
+
DataFormatIntlsContext
|
|
6
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
import { UseDataFormatProps } from '../hooks';
|
|
3
3
|
export type WithDataFormatProps = UseDataFormatProps;
|
|
4
4
|
export declare const withDataFormat: <Props extends object>(WrappedComponent: ComponentType<Props>) => ComponentType<Omit<Props, keyof UseDataFormatProps>>;
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import "../contexts/DataFormatConfigContext.js";
|
|
4
|
+
import "../contexts/DataFormatIntlsContext.js";
|
|
5
|
+
import { useDataFormat } from "../hooks/useDataFormat.js";
|
|
6
|
+
import "dayjs";
|
|
7
|
+
import "moment";
|
|
8
|
+
import "react-intl";
|
|
9
|
+
import "../constants/dataFormatConfig.constants.js";
|
|
10
|
+
import "../utils/timeZone.utils.js";
|
|
11
|
+
import "../utils/dataFormat.utils.js";
|
|
12
|
+
const withDataFormat = (WrappedComponent) => {
|
|
13
|
+
return (props) => {
|
|
14
|
+
const dataFormatProps = useDataFormat();
|
|
15
|
+
const newProps = {
|
|
16
|
+
...props,
|
|
17
|
+
...dataFormatProps
|
|
18
|
+
};
|
|
19
|
+
return /* @__PURE__ */ jsx(WrappedComponent, { ...newProps });
|
|
9
20
|
};
|
|
10
|
-
};
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
withDataFormat
|
|
24
|
+
};
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { useDataFormatConfig } from "./useDataFormatConfig.js";
|
|
2
|
+
import { useDataFormat } from "./useDataFormat.js";
|
|
3
|
+
import { useDataFormatUtils } from "./useDataFormatUtils.js";
|
|
4
|
+
import { useSingleIntl } from "./useSingleIntl.js";
|
|
5
|
+
import { useDataFormatIntls } from "./useDataFormatIntls.js";
|
|
6
|
+
import { useRelativeDateTimeUpdate } from "./useRelativeDateTimeUpdate.js";
|
|
7
|
+
export {
|
|
8
|
+
useDataFormat,
|
|
9
|
+
useDataFormatConfig,
|
|
10
|
+
useDataFormatIntls,
|
|
11
|
+
useDataFormatUtils,
|
|
12
|
+
useRelativeDateTimeUpdate,
|
|
13
|
+
useSingleIntl
|
|
14
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Delimiter, OverloadFormatMultipleValues, OverloadFormatValue, OverloadGetConstants } from '../types';
|
|
2
2
|
export type UseDataFormatProps = {
|
|
3
3
|
firstDayOfWeek: number;
|
|
4
4
|
isSundayFirstWeekDay: boolean;
|
|
@@ -1,96 +1,99 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { DATE_CONSTANTS_TARGET_FORMATS } from
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (value instanceof moment) {
|
|
44
|
-
result = getFormattedDateFromMoment(value, dateFormatIntl, timeFormatIntl, options);
|
|
45
|
-
}
|
|
46
|
-
if (isDayjs(value)) {
|
|
47
|
-
result = getFormattedDateFromDayjs(value, dateFormatIntl, timeFormatIntl, options);
|
|
48
|
-
}
|
|
49
|
-
if (value instanceof Date) {
|
|
50
|
-
if (!isValidDate(value)) {
|
|
51
|
-
console.warn('invalid date', value);
|
|
52
|
-
return value.toString();
|
|
1
|
+
import { isDayjs } from "dayjs";
|
|
2
|
+
import moment from "moment";
|
|
3
|
+
import { useMemo, useCallback } from "react";
|
|
4
|
+
import "../constants/dataFormatConfig.constants.js";
|
|
5
|
+
import { DATE_CONSTANTS_TARGET_FORMATS } from "../constants/dataFormat.constants.js";
|
|
6
|
+
import "../utils/timeZone.utils.js";
|
|
7
|
+
import "../utils/dataFormat.utils.js";
|
|
8
|
+
import { isValidDate, getConstantDatesAndFormattingOptions } from "../utils/date.utils.js";
|
|
9
|
+
import { useDataFormatConfig } from "./useDataFormatConfig.js";
|
|
10
|
+
import { useDataFormatIntls } from "./useDataFormatIntls.js";
|
|
11
|
+
import { useDataFormatUtils } from "./useDataFormatUtils.js";
|
|
12
|
+
const useDataFormat = () => {
|
|
13
|
+
const {
|
|
14
|
+
numberFormatIntl,
|
|
15
|
+
timeFormatIntl,
|
|
16
|
+
dateFormatIntl
|
|
17
|
+
} = useDataFormatIntls();
|
|
18
|
+
const {
|
|
19
|
+
startWeekDayNotation,
|
|
20
|
+
timeFormatNotation,
|
|
21
|
+
numberFormatNotation
|
|
22
|
+
} = useDataFormatConfig();
|
|
23
|
+
const {
|
|
24
|
+
getFirstDayOfWeekFromNotation,
|
|
25
|
+
getIs12HoursClockFromNotation,
|
|
26
|
+
getFormattedNumber,
|
|
27
|
+
getFormattedDate,
|
|
28
|
+
getFormattedDateFromMoment,
|
|
29
|
+
getFormattedDateFromDayjs,
|
|
30
|
+
getFormattedValueUsingCommonOptions,
|
|
31
|
+
getThousandDelimiterFromNotation,
|
|
32
|
+
getDecimalDelimiterFromNotation
|
|
33
|
+
} = useDataFormatUtils();
|
|
34
|
+
const firstDayOfWeek = useMemo(() => getFirstDayOfWeekFromNotation(startWeekDayNotation), [startWeekDayNotation, getFirstDayOfWeekFromNotation]);
|
|
35
|
+
const isSundayFirstWeekDay = useMemo(() => firstDayOfWeek === 0, [firstDayOfWeek]);
|
|
36
|
+
const is12HoursClock = useMemo(() => getIs12HoursClockFromNotation(timeFormatNotation), [timeFormatNotation, getIs12HoursClockFromNotation]);
|
|
37
|
+
const formatValue = useCallback(
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
(value, options) => {
|
|
40
|
+
let result = "";
|
|
41
|
+
if (value instanceof moment) {
|
|
42
|
+
result = getFormattedDateFromMoment(value, dateFormatIntl, timeFormatIntl, options);
|
|
53
43
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
44
|
+
if (isDayjs(value)) {
|
|
45
|
+
result = getFormattedDateFromDayjs(value, dateFormatIntl, timeFormatIntl, options);
|
|
46
|
+
}
|
|
47
|
+
if (value instanceof Date) {
|
|
48
|
+
if (!isValidDate(value)) {
|
|
49
|
+
console.warn("invalid date", value);
|
|
50
|
+
return value.toString();
|
|
51
|
+
}
|
|
52
|
+
result = getFormattedDate(value, dateFormatIntl, timeFormatIntl, options);
|
|
53
|
+
}
|
|
54
|
+
if (typeof value === "number") {
|
|
55
|
+
result = getFormattedNumber(value, numberFormatIntl, options);
|
|
56
|
+
}
|
|
57
|
+
if (typeof value === "string") {
|
|
58
|
+
result = value;
|
|
59
|
+
}
|
|
60
|
+
return getFormattedValueUsingCommonOptions(result, options);
|
|
61
|
+
},
|
|
62
|
+
[numberFormatIntl, dateFormatIntl, timeFormatIntl, getFormattedDate, getFormattedDateFromMoment, getFormattedNumber, getFormattedDateFromDayjs, getFormattedValueUsingCommonOptions]
|
|
63
|
+
);
|
|
64
|
+
const formatMultipleValues = useCallback(
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
|
+
(values, options) => {
|
|
67
|
+
return values.map((value) => formatValue(value, options));
|
|
68
|
+
},
|
|
69
|
+
[formatValue]
|
|
70
|
+
);
|
|
71
|
+
const getConstants = useCallback((targetFormat, options, customStartDate, customEndDate, interval) => {
|
|
72
72
|
if (DATE_CONSTANTS_TARGET_FORMATS.includes(targetFormat)) {
|
|
73
|
-
|
|
74
|
-
constantDates
|
|
75
|
-
defaultOptions
|
|
76
|
-
|
|
73
|
+
const {
|
|
74
|
+
constantDates,
|
|
75
|
+
defaultOptions
|
|
76
|
+
} = getConstantDatesAndFormattingOptions(targetFormat, isSundayFirstWeekDay, customStartDate, customEndDate, interval);
|
|
77
|
+
return formatMultipleValues(constantDates, {
|
|
78
|
+
...defaultOptions,
|
|
79
|
+
...options
|
|
80
|
+
});
|
|
77
81
|
}
|
|
78
|
-
return
|
|
82
|
+
return void 0;
|
|
79
83
|
}, [formatMultipleValues, isSundayFirstWeekDay]);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}, [numberFormatNotation, getThousandDelimiterFromNotation]);
|
|
83
|
-
var decimalDelimiter = useMemo(function () {
|
|
84
|
-
return getDecimalDelimiterFromNotation(numberFormatNotation);
|
|
85
|
-
}, [numberFormatNotation, getDecimalDelimiterFromNotation]);
|
|
84
|
+
const thousandDelimiter = useMemo(() => getThousandDelimiterFromNotation(numberFormatNotation), [numberFormatNotation, getThousandDelimiterFromNotation]);
|
|
85
|
+
const decimalDelimiter = useMemo(() => getDecimalDelimiterFromNotation(numberFormatNotation), [numberFormatNotation, getDecimalDelimiterFromNotation]);
|
|
86
86
|
return {
|
|
87
|
-
firstDayOfWeek
|
|
88
|
-
isSundayFirstWeekDay
|
|
89
|
-
is12HoursClock
|
|
90
|
-
formatValue
|
|
91
|
-
formatMultipleValues
|
|
92
|
-
getConstants
|
|
93
|
-
thousandDelimiter
|
|
94
|
-
decimalDelimiter
|
|
87
|
+
firstDayOfWeek,
|
|
88
|
+
isSundayFirstWeekDay,
|
|
89
|
+
is12HoursClock,
|
|
90
|
+
formatValue,
|
|
91
|
+
formatMultipleValues,
|
|
92
|
+
getConstants,
|
|
93
|
+
thousandDelimiter,
|
|
94
|
+
decimalDelimiter
|
|
95
95
|
};
|
|
96
|
-
};
|
|
96
|
+
};
|
|
97
|
+
export {
|
|
98
|
+
useDataFormat
|
|
99
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DataFormatConfig } from '../types';
|
|
2
2
|
export declare const useDataFormatConfig: () => DataFormatConfig;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { useContext } from
|
|
2
|
-
import { DataFormatConfigContext } from
|
|
3
|
-
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { DataFormatConfigContext } from "../contexts/DataFormatConfigContext.js";
|
|
3
|
+
import "../contexts/DataFormatIntlsContext.js";
|
|
4
|
+
const useDataFormatConfig = () => {
|
|
4
5
|
return useContext(DataFormatConfigContext);
|
|
5
|
-
};
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
useDataFormatConfig
|
|
9
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DataFormatIntls } from '../types';
|
|
2
2
|
export declare const useDataFormatIntls: () => DataFormatIntls;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { useContext } from
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import "../contexts/DataFormatConfigContext.js";
|
|
3
|
+
import { DataFormatIntlsContext } from "../contexts/DataFormatIntlsContext.js";
|
|
4
|
+
const useDataFormatIntls = () => {
|
|
4
5
|
return useContext(DataFormatIntlsContext);
|
|
5
|
-
};
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
useDataFormatIntls
|
|
9
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { Dayjs } from 'dayjs';
|
|
2
|
+
import { Moment } from 'moment';
|
|
3
|
+
import { IntlShape } from 'react-intl';
|
|
4
|
+
import { CommonFormatOptions, DataFormatNotationType, DateToFormatOptions, Delimiter, NumberToFormatOptions } from '../types';
|
|
5
5
|
export declare const useDataFormatUtils: () => {
|
|
6
6
|
getLocaleFromNotation: (notation?: DataFormatNotationType) => string;
|
|
7
7
|
getFirstDayOfWeekFromNotation: (notation?: DataFormatNotationType) => number;
|
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
import dayjs from
|
|
2
|
-
import moment from
|
|
3
|
-
import { useCallback } from
|
|
4
|
-
import { useIntl } from
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { getLocalDateInTimeZone } from
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import moment from "moment";
|
|
3
|
+
import { useCallback } from "react";
|
|
4
|
+
import { useIntl } from "react-intl";
|
|
5
|
+
import { US_NOTATION, EU_NOTATION } from "../constants/dataFormatConfig.constants.js";
|
|
6
|
+
import { US_THOUSAND_DELIMITER, EU_THOUSAND_DELIMITER, US_DECIMAL_DELIMITER, EU_DECIMAL_DELIMITER, DATETIME, TIME, RELATIVE_TO, RELATIVE_TO_WITHOUT_SUFFIX, RELATIVE_FROM, RELATIVE_FROM_WITHOUT_SUFFIX, WEEKDAY_LONG, WEEKDAY_SHORT, MONTH_LONG, MONTH_SHORT, DATE } from "../constants/dataFormat.constants.js";
|
|
7
|
+
import { getLocalDateInTimeZone } from "../utils/timeZone.utils.js";
|
|
8
|
+
import { convertNumberString, convertDateToDateTimeString, convertDateToTimeString, convertDateToRelativeToString, convertDateToRelativeFromString, convertDateToWeekdayLongString, convertDateToWeekdayShortString, convertDateToMonthLongString, convertDateToMonthShortString, convertDateToDateString, addPrefix, addSuffix, changeNamingConvention } from "../utils/dataFormat.utils.js";
|
|
9
|
+
import { useDataFormatConfig } from "./useDataFormatConfig.js";
|
|
10
|
+
const useDataFormatUtils = () => {
|
|
11
|
+
const languageIntl = useIntl();
|
|
12
|
+
const {
|
|
13
|
+
numberFormatNotation,
|
|
14
|
+
applyTimeZoneOffset
|
|
15
|
+
} = useDataFormatConfig();
|
|
16
|
+
const getLocaleFromNotation = useCallback((notation) => {
|
|
15
17
|
switch (notation) {
|
|
16
18
|
case EU_NOTATION:
|
|
17
|
-
return
|
|
19
|
+
return "pl";
|
|
18
20
|
case US_NOTATION:
|
|
19
|
-
return
|
|
21
|
+
return "en-US";
|
|
20
22
|
default:
|
|
21
|
-
return
|
|
23
|
+
return "pl";
|
|
22
24
|
}
|
|
23
25
|
}, []);
|
|
24
|
-
|
|
26
|
+
const getFirstDayOfWeekFromNotation = useCallback((notation) => {
|
|
25
27
|
switch (notation) {
|
|
26
28
|
case EU_NOTATION:
|
|
27
29
|
return 1;
|
|
@@ -31,84 +33,81 @@ export var useDataFormatUtils = function useDataFormatUtils() {
|
|
|
31
33
|
return 1;
|
|
32
34
|
}
|
|
33
35
|
}, []);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var getIs12HoursClockFromNotation = useCallback(function (notation) {
|
|
41
|
-
return notation === US_NOTATION;
|
|
42
|
-
}, []);
|
|
43
|
-
var getFormattedNumber = useCallback(function (value, numberFormatIntl, options) {
|
|
44
|
-
var thousandDelimiter = getThousandDelimiterFromNotation(numberFormatNotation);
|
|
45
|
-
var decimalDelimiter = getDecimalDelimiterFromNotation(numberFormatNotation);
|
|
36
|
+
const getThousandDelimiterFromNotation = useCallback((notation) => notation === US_NOTATION ? US_THOUSAND_DELIMITER : EU_THOUSAND_DELIMITER, []);
|
|
37
|
+
const getDecimalDelimiterFromNotation = useCallback((notation) => notation === US_NOTATION ? US_DECIMAL_DELIMITER : EU_DECIMAL_DELIMITER, []);
|
|
38
|
+
const getIs12HoursClockFromNotation = useCallback((notation) => notation === US_NOTATION, []);
|
|
39
|
+
const getFormattedNumber = useCallback((value, numberFormatIntl, options) => {
|
|
40
|
+
const thousandDelimiter = getThousandDelimiterFromNotation(numberFormatNotation);
|
|
41
|
+
const decimalDelimiter = getDecimalDelimiterFromNotation(numberFormatNotation);
|
|
46
42
|
return convertNumberString(value, numberFormatIntl, languageIntl, thousandDelimiter, decimalDelimiter, options);
|
|
47
43
|
}, [languageIntl, numberFormatNotation, getThousandDelimiterFromNotation, getDecimalDelimiterFromNotation]);
|
|
48
|
-
|
|
49
|
-
globalTimeZone
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (
|
|
44
|
+
const {
|
|
45
|
+
timeZone: globalTimeZone
|
|
46
|
+
} = useIntl();
|
|
47
|
+
const getFormattedDate = useCallback((value, dateFormatIntl, timeFormatIntl, options) => {
|
|
48
|
+
const valueInContextTimeZone = options?.applyTimeZoneOffset ?? applyTimeZoneOffset;
|
|
49
|
+
const valueInTimezone = globalTimeZone && valueInContextTimeZone ? getLocalDateInTimeZone(value.toISOString(), globalTimeZone) : value;
|
|
50
|
+
if (options?.targetFormat === DATETIME) {
|
|
55
51
|
return convertDateToDateTimeString(valueInTimezone, dateFormatIntl, timeFormatIntl, languageIntl, options);
|
|
56
52
|
}
|
|
57
|
-
if (
|
|
53
|
+
if (options?.targetFormat === TIME) {
|
|
58
54
|
return convertDateToTimeString(valueInTimezone, timeFormatIntl, options);
|
|
59
55
|
}
|
|
60
|
-
if (
|
|
56
|
+
if (options?.targetFormat === RELATIVE_TO) {
|
|
61
57
|
return convertDateToRelativeToString(value);
|
|
62
58
|
}
|
|
63
|
-
if (
|
|
59
|
+
if (options?.targetFormat === RELATIVE_TO_WITHOUT_SUFFIX) {
|
|
64
60
|
return convertDateToRelativeToString(value, true);
|
|
65
61
|
}
|
|
66
|
-
if (
|
|
62
|
+
if (options?.targetFormat === RELATIVE_FROM) {
|
|
67
63
|
return convertDateToRelativeFromString(value);
|
|
68
64
|
}
|
|
69
|
-
if (
|
|
65
|
+
if (options?.targetFormat === RELATIVE_FROM_WITHOUT_SUFFIX) {
|
|
70
66
|
return convertDateToRelativeFromString(value, true);
|
|
71
67
|
}
|
|
72
|
-
if (
|
|
68
|
+
if (options?.targetFormat === WEEKDAY_LONG) {
|
|
73
69
|
return convertDateToWeekdayLongString(valueInTimezone, dateFormatIntl, languageIntl, options);
|
|
74
70
|
}
|
|
75
|
-
if (
|
|
71
|
+
if (options?.targetFormat === WEEKDAY_SHORT) {
|
|
76
72
|
return convertDateToWeekdayShortString(valueInTimezone, dateFormatIntl, languageIntl, options);
|
|
77
73
|
}
|
|
78
|
-
if (
|
|
74
|
+
if (options?.targetFormat === MONTH_LONG) {
|
|
79
75
|
return convertDateToMonthLongString(valueInTimezone, dateFormatIntl, languageIntl, options);
|
|
80
76
|
}
|
|
81
|
-
if (
|
|
77
|
+
if (options?.targetFormat === MONTH_SHORT) {
|
|
82
78
|
return convertDateToMonthShortString(valueInTimezone, dateFormatIntl, languageIntl, options);
|
|
83
79
|
}
|
|
84
|
-
if (
|
|
80
|
+
if (options?.targetFormat === DATE || !options?.targetFormat) {
|
|
85
81
|
return convertDateToDateString(valueInTimezone, dateFormatIntl, languageIntl, options);
|
|
86
82
|
}
|
|
87
|
-
return
|
|
83
|
+
return value?.toString() ?? "";
|
|
88
84
|
}, [globalTimeZone, applyTimeZoneOffset, languageIntl]);
|
|
89
|
-
|
|
85
|
+
const getFormattedDateFromMoment = useCallback((value, dateFormatIntl, timeFormatIntl, options) => {
|
|
90
86
|
return getFormattedDate(moment(value).toDate(), dateFormatIntl, timeFormatIntl, options);
|
|
91
87
|
}, [getFormattedDate]);
|
|
92
|
-
|
|
88
|
+
const getFormattedDateFromDayjs = useCallback((value, dateFormatIntl, timeFormatIntl, options) => {
|
|
93
89
|
return getFormattedDate(dayjs(value).toDate(), dateFormatIntl, timeFormatIntl, options);
|
|
94
90
|
}, [getFormattedDate]);
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
const getFormattedValueUsingCommonOptions = useCallback((value, options) => {
|
|
92
|
+
let result = value;
|
|
97
93
|
result = addPrefix(result, options);
|
|
98
94
|
result = addSuffix(result, options);
|
|
99
95
|
result = changeNamingConvention(result, options);
|
|
100
96
|
return result;
|
|
101
97
|
}, []);
|
|
102
98
|
return {
|
|
103
|
-
getLocaleFromNotation
|
|
104
|
-
getFirstDayOfWeekFromNotation
|
|
105
|
-
getIs12HoursClockFromNotation
|
|
106
|
-
getFormattedNumber
|
|
107
|
-
getFormattedDate
|
|
108
|
-
getFormattedDateFromMoment
|
|
109
|
-
getFormattedDateFromDayjs
|
|
110
|
-
getFormattedValueUsingCommonOptions
|
|
111
|
-
getThousandDelimiterFromNotation
|
|
112
|
-
getDecimalDelimiterFromNotation
|
|
99
|
+
getLocaleFromNotation,
|
|
100
|
+
getFirstDayOfWeekFromNotation,
|
|
101
|
+
getIs12HoursClockFromNotation,
|
|
102
|
+
getFormattedNumber,
|
|
103
|
+
getFormattedDate,
|
|
104
|
+
getFormattedDateFromMoment,
|
|
105
|
+
getFormattedDateFromDayjs,
|
|
106
|
+
getFormattedValueUsingCommonOptions,
|
|
107
|
+
getThousandDelimiterFromNotation,
|
|
108
|
+
getDecimalDelimiterFromNotation
|
|
113
109
|
};
|
|
114
|
-
};
|
|
110
|
+
};
|
|
111
|
+
export {
|
|
112
|
+
useDataFormatUtils
|
|
113
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Dayjs } from 'dayjs';
|
|
2
|
+
import { Moment } from 'moment';
|
|
3
3
|
export declare const useRelativeDateTimeUpdate: (value: Date | Moment | Dayjs) => number;
|