@synerise/ds-core 1.5.1 → 1.5.2
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 +8 -0
- package/README.md +181 -0
- package/dist/i18n/es.json +0 -1
- package/dist/i18n/index.d.ts +1 -1
- package/dist/js/DSProvider/DSProvider.d.ts +2 -2
- package/dist/js/DSProvider/DSProvider.js +2 -2
- package/dist/js/DSProvider/LocaleProvider/LocaleProvider.utils.d.ts +1 -1
- package/dist/js/DSProvider/ThemeProvider/breakpoints.d.ts +5 -1
- package/dist/js/data-format/components/FormattedDate.d.ts +9 -0
- package/dist/js/data-format/components/FormattedDate.js +9 -0
- package/dist/js/data-format/components/FormattedDateTime.d.ts +9 -0
- package/dist/js/data-format/components/FormattedDateTime.js +13 -0
- package/dist/js/data-format/components/FormattedNumber.d.ts +7 -0
- package/dist/js/data-format/components/FormattedNumber.js +9 -0
- package/dist/js/data-format/components/FormattedRelativeDateTime.d.ts +10 -0
- package/dist/js/data-format/components/FormattedRelativeDateTime.js +24 -0
- package/dist/js/data-format/components/FormattedTime.d.ts +9 -0
- package/dist/js/data-format/components/FormattedTime.js +13 -0
- package/dist/js/data-format/components/index.d.ts +5 -0
- package/dist/js/data-format/components/index.js +5 -0
- package/dist/js/data-format/constants/dataFormat.constants.d.ts +36 -0
- package/dist/js/data-format/constants/dataFormat.constants.js +52 -0
- package/dist/js/data-format/constants/dataFormatConfig.constants.d.ts +7 -0
- package/dist/js/data-format/constants/dataFormatConfig.constants.js +14 -0
- package/dist/js/data-format/constants/dateTimeParts.constants.d.ts +5 -0
- package/dist/js/data-format/constants/dateTimeParts.constants.js +4 -0
- package/dist/js/data-format/constants/index.d.ts +3 -0
- package/dist/js/data-format/constants/index.js +3 -0
- package/dist/js/data-format/contexts/DataFormatConfigContext.d.ts +2 -0
- package/dist/js/data-format/contexts/DataFormatConfigContext.js +3 -0
- package/dist/js/data-format/contexts/DataFormatIntlsContext.d.ts +2 -0
- package/dist/js/data-format/contexts/DataFormatIntlsContext.js +7 -0
- package/dist/js/data-format/contexts/index.d.ts +2 -0
- package/dist/js/data-format/contexts/index.js +2 -0
- package/dist/js/data-format/hocs/withDataFormat.d.ts +4 -0
- package/dist/js/data-format/hocs/withDataFormat.js +10 -0
- package/dist/js/data-format/hooks/index.d.ts +5 -0
- package/dist/js/data-format/hooks/index.js +5 -0
- package/dist/js/data-format/hooks/useDataFormat.d.ts +12 -0
- package/dist/js/data-format/hooks/useDataFormat.js +96 -0
- package/dist/js/data-format/hooks/useDataFormatConfig.d.ts +2 -0
- package/dist/js/data-format/hooks/useDataFormatConfig.js +5 -0
- package/dist/js/data-format/hooks/useDataFormatIntls.d.ts +2 -0
- package/dist/js/data-format/hooks/useDataFormatIntls.js +5 -0
- package/dist/js/data-format/hooks/useDataFormatUtils.d.ts +16 -0
- package/dist/js/data-format/hooks/useDataFormatUtils.js +113 -0
- package/dist/js/data-format/hooks/useSingleIntl.d.ts +4 -0
- package/dist/js/data-format/hooks/useSingleIntl.js +12 -0
- package/dist/js/data-format/index.d.ts +8 -0
- package/dist/js/data-format/index.js +7 -0
- package/dist/js/data-format/providers/DataFormatConfigProvider.d.ts +7 -0
- package/dist/js/data-format/providers/DataFormatConfigProvider.js +26 -0
- package/dist/js/data-format/types/dataFormat.types.d.ts +42 -0
- package/dist/js/data-format/types/dataFormat.types.js +5 -0
- package/dist/js/data-format/types/dataFormatConfig.types.d.ts +16 -0
- package/dist/js/data-format/types/dataFormatConfig.types.js +2 -0
- package/dist/js/data-format/types/dateTimeParts.types.d.ts +3 -0
- package/dist/js/data-format/types/dateTimeParts.types.js +2 -0
- package/dist/js/data-format/types/index.d.ts +3 -0
- package/dist/js/data-format/types/index.js +1 -0
- package/dist/js/data-format/utils/dataFormat.utils.d.ts +16 -0
- package/dist/js/data-format/utils/dataFormat.utils.js +119 -0
- package/dist/js/data-format/utils/dataFormatConfig.utils.d.ts +2 -0
- package/dist/js/data-format/utils/dataFormatConfig.utils.js +8 -0
- package/dist/js/data-format/utils/date.utils.d.ts +8 -0
- package/dist/js/data-format/utils/date.utils.js +50 -0
- package/dist/js/data-format/utils/dateTimeParts.utils.d.ts +14 -0
- package/dist/js/data-format/utils/dateTimeParts.utils.js +86 -0
- package/dist/js/data-format/utils/index.d.ts +5 -0
- package/dist/js/data-format/utils/index.js +5 -0
- package/dist/js/data-format/utils/timeZone.utils.d.ts +16 -0
- package/dist/js/data-format/utils/timeZone.utils.js +94 -0
- package/dist/js/index.d.ts +3 -0
- package/dist/js/index.js +4 -1
- package/dist/js/mediaQuery/mediaQuery.d.ts +1 -5
- package/dist/js/testing/index.d.ts +2 -0
- package/dist/js/testing/index.js +2 -0
- package/dist/js/testing/renderWithProvider/renderWithProvider.d.ts +10 -0
- package/dist/js/testing/renderWithProvider/renderWithProvider.js +28 -0
- package/dist/js/testing/renderWithProvider/renderWithProvider.spec.d.ts +1 -0
- package/dist/js/testing/sleep.d.ts +1 -0
- package/dist/js/testing/sleep.js +8 -0
- package/dist/js/toaster/Toaster.d.ts +2 -0
- package/dist/js/toaster/Toaster.js +8 -0
- package/dist/js/toaster/Toaster.types.d.ts +1 -0
- package/dist/js/toaster/Toaster.types.js +1 -0
- package/dist/js/toaster/constants.d.ts +2 -0
- package/dist/js/toaster/constants.js +8 -0
- package/dist/js/toaster/contexts/ToasterContext.d.ts +6 -0
- package/dist/js/toaster/contexts/ToasterContext.js +6 -0
- package/dist/js/toaster/hooks/useToaster.d.ts +1 -0
- package/dist/js/toaster/hooks/useToaster.js +5 -0
- package/dist/js/toaster/index.d.ts +6 -0
- package/dist/js/toaster/index.js +5 -0
- package/dist/js/toaster/providers/ToasterProvider.d.ts +6 -0
- package/dist/js/toaster/providers/ToasterProvider.js +17 -0
- package/package.json +14 -7
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type FormatDateOptions, type IntlShape } from 'react-intl';
|
|
2
|
+
import { type DateToFormatOptions, type Delimiter } from '../types';
|
|
3
|
+
export declare const getDateParts: (value: Date, dateFormatIntl: IntlShape, option?: FormatDateOptions) => Intl.DateTimeFormatPart[];
|
|
4
|
+
export declare const getTimeParts: (value: Date, timeFormatIntl: IntlShape, option?: FormatDateOptions) => Intl.DateTimeFormatPart[];
|
|
5
|
+
export declare const getWeekdayLongDateParts: (value: Date, dateFormatIntl: IntlShape, option?: FormatDateOptions) => Intl.DateTimeFormatPart[];
|
|
6
|
+
export declare const getWeekdayShortDateParts: (value: Date, dateFormatIntl: IntlShape, option?: FormatDateOptions) => Intl.DateTimeFormatPart[];
|
|
7
|
+
export declare const getMonthLongDateParts: (value: Date, dateFormatIntl: IntlShape, option?: FormatDateOptions) => Intl.DateTimeFormatPart[];
|
|
8
|
+
export declare const getMonthShortDateParts: (value: Date, dateFormatIntl: IntlShape, option?: FormatDateOptions) => Intl.DateTimeFormatPart[];
|
|
9
|
+
export declare const getDateTimePartsSubset: (dateTimeParts: Intl.DateTimeFormatPart[], subsetTypes: Intl.DateTimeFormatPartTypes[]) => Intl.DateTimeFormatPart[];
|
|
10
|
+
export declare const nbspToSpace: (text: string) => string;
|
|
11
|
+
export declare const numberPartsToString: (numberParts: Intl.NumberFormatPart[], thousandDelimiter: Delimiter, decimalDelimiter: Delimiter) => string;
|
|
12
|
+
export declare const dateTimePartsToString: (dateTimeParts: Intl.DateTimeFormatPart[]) => string;
|
|
13
|
+
export declare const replaceDateTimeParts: (dateTimeParts: Intl.DateTimeFormatPart[], replacementDateTimeParts: Intl.DateTimeFormatPart[], replacementDateTimeFormatPartTypes: Intl.DateTimeFormatPartTypes[]) => Intl.DateTimeFormatPart[];
|
|
14
|
+
export declare const translateDateTimeParts: (dateTimeParts: Intl.DateTimeFormatPart[], dateTimePartsFromLanguageIntl: Intl.DateTimeFormatPart[], options?: DateToFormatOptions) => Intl.DateTimeFormatPart[];
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
import { DEFAULT_FORMAT_DATE_OPTIONS, DEFAULT_FORMAT_MONTH_LONG_OPTIONS, DEFAULT_FORMAT_MONTH_SHORT_OPTIONS, DEFAULT_FORMAT_TIME_OPTIONS, DEFAULT_FORMAT_WEEKDAY_LONG_OPTIONS, DEFAULT_FORMAT_WEEKDAY_SHORT_OPTIONS, LONG, MONTH, MONTH_LONG, MONTH_SHORT, SHORT, WEEKDAY, WEEKDAY_LONG, WEEKDAY_SHORT } from '../constants';
|
|
3
|
+
import { dateToIsoWithOffset } from './timeZone.utils';
|
|
4
|
+
export var getDateParts = function getDateParts(value, dateFormatIntl, option) {
|
|
5
|
+
return dateFormatIntl.formatDateToParts(dateToIsoWithOffset(value, dateFormatIntl), _extends({}, DEFAULT_FORMAT_DATE_OPTIONS, option));
|
|
6
|
+
};
|
|
7
|
+
export var getTimeParts = function getTimeParts(value, timeFormatIntl, option) {
|
|
8
|
+
return timeFormatIntl.formatDateToParts(dateToIsoWithOffset(value, timeFormatIntl), _extends({}, DEFAULT_FORMAT_TIME_OPTIONS, option));
|
|
9
|
+
};
|
|
10
|
+
export var getWeekdayLongDateParts = function getWeekdayLongDateParts(value, dateFormatIntl, option) {
|
|
11
|
+
return dateFormatIntl.formatDateToParts(value, _extends({}, DEFAULT_FORMAT_WEEKDAY_LONG_OPTIONS, option));
|
|
12
|
+
};
|
|
13
|
+
export var getWeekdayShortDateParts = function getWeekdayShortDateParts(value, dateFormatIntl, option) {
|
|
14
|
+
return dateFormatIntl.formatDateToParts(value, _extends({}, DEFAULT_FORMAT_WEEKDAY_SHORT_OPTIONS, option));
|
|
15
|
+
};
|
|
16
|
+
export var getMonthLongDateParts = function getMonthLongDateParts(value, dateFormatIntl, option) {
|
|
17
|
+
return dateFormatIntl.formatDateToParts(value, _extends({}, DEFAULT_FORMAT_MONTH_LONG_OPTIONS, option));
|
|
18
|
+
};
|
|
19
|
+
export var getMonthShortDateParts = function getMonthShortDateParts(value, dateFormatIntl, option) {
|
|
20
|
+
return dateFormatIntl.formatDateToParts(value, _extends({}, DEFAULT_FORMAT_MONTH_SHORT_OPTIONS, option));
|
|
21
|
+
};
|
|
22
|
+
export var getDateTimePartsSubset = function getDateTimePartsSubset(dateTimeParts, subsetTypes) {
|
|
23
|
+
var resultDateTimeParts = [];
|
|
24
|
+
dateTimeParts.forEach(function (dateTimePart) {
|
|
25
|
+
if (subsetTypes.includes(dateTimePart.type)) {
|
|
26
|
+
resultDateTimeParts.push(dateTimePart);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return resultDateTimeParts;
|
|
30
|
+
};
|
|
31
|
+
export var nbspToSpace = function nbspToSpace(text) {
|
|
32
|
+
return text.replace(/ /g, ' ').replace(/\u00A0/g, ' ');
|
|
33
|
+
};
|
|
34
|
+
export var numberPartsToString = function numberPartsToString(numberParts, thousandDelimiter, decimalDelimiter) {
|
|
35
|
+
var numberPartsWithReplacedDelimiters = numberParts.map(function (numberPart) {
|
|
36
|
+
var numberPartWithReplacedDelimiters = numberPart;
|
|
37
|
+
if (numberPartWithReplacedDelimiters.type === 'group') {
|
|
38
|
+
numberPartWithReplacedDelimiters.value = thousandDelimiter;
|
|
39
|
+
}
|
|
40
|
+
if (numberPartWithReplacedDelimiters.type === 'decimal') {
|
|
41
|
+
numberPartWithReplacedDelimiters.value = decimalDelimiter;
|
|
42
|
+
}
|
|
43
|
+
return numberPartWithReplacedDelimiters;
|
|
44
|
+
});
|
|
45
|
+
var joinedNumberParts = numberPartsWithReplacedDelimiters.map(function (numberPart) {
|
|
46
|
+
return numberPart.value;
|
|
47
|
+
}).join('');
|
|
48
|
+
return nbspToSpace(joinedNumberParts);
|
|
49
|
+
};
|
|
50
|
+
export var dateTimePartsToString = function dateTimePartsToString(dateTimeParts) {
|
|
51
|
+
var joinedDateTimeParts = dateTimeParts.map(function (dateTimePart) {
|
|
52
|
+
return dateTimePart.value;
|
|
53
|
+
}).join('');
|
|
54
|
+
return nbspToSpace(joinedDateTimeParts);
|
|
55
|
+
};
|
|
56
|
+
export var replaceDateTimeParts = function replaceDateTimeParts(dateTimeParts, replacementDateTimeParts, replacementDateTimeFormatPartTypes) {
|
|
57
|
+
return dateTimeParts.map(function (dateTimePart) {
|
|
58
|
+
var dateTimePartToReplace = dateTimePart;
|
|
59
|
+
if (replacementDateTimeFormatPartTypes != null && replacementDateTimeFormatPartTypes.includes(dateTimePartToReplace.type)) {
|
|
60
|
+
var foundedReplacementDateTimePart = replacementDateTimeParts == null ? void 0 : replacementDateTimeParts.find(function (replacementDateTimePart) {
|
|
61
|
+
return replacementDateTimePart.type === dateTimePartToReplace.type;
|
|
62
|
+
});
|
|
63
|
+
if (foundedReplacementDateTimePart) {
|
|
64
|
+
dateTimePartToReplace.value = foundedReplacementDateTimePart.value;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return dateTimePartToReplace;
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
export var translateDateTimeParts = function translateDateTimeParts(dateTimeParts, dateTimePartsFromLanguageIntl, options) {
|
|
71
|
+
var _options$dateOptions, _options$dateOptions2;
|
|
72
|
+
var replacementDateTimeFormatPartTypes = [];
|
|
73
|
+
if ((options == null ? void 0 : options.targetFormat) === WEEKDAY_LONG || (options == null ? void 0 : options.targetFormat) === WEEKDAY_SHORT) {
|
|
74
|
+
replacementDateTimeFormatPartTypes.push(WEEKDAY);
|
|
75
|
+
}
|
|
76
|
+
if ((options == null ? void 0 : options.targetFormat) === MONTH_LONG || (options == null ? void 0 : options.targetFormat) === MONTH_SHORT) {
|
|
77
|
+
replacementDateTimeFormatPartTypes.push(MONTH);
|
|
78
|
+
}
|
|
79
|
+
if ((options == null || (_options$dateOptions = options.dateOptions) == null ? void 0 : _options$dateOptions.month) === LONG || (options == null || (_options$dateOptions2 = options.dateOptions) == null ? void 0 : _options$dateOptions2.month) === SHORT) {
|
|
80
|
+
replacementDateTimeFormatPartTypes.push(MONTH);
|
|
81
|
+
}
|
|
82
|
+
if ((options == null ? void 0 : options.month) === LONG || (options == null ? void 0 : options.month) === SHORT) {
|
|
83
|
+
replacementDateTimeFormatPartTypes.push(MONTH);
|
|
84
|
+
}
|
|
85
|
+
return replaceDateTimeParts(dateTimeParts, dateTimePartsFromLanguageIntl, replacementDateTimeFormatPartTypes);
|
|
86
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { getDataFormatConfigFromNotation } from './dataFormatConfig.utils';
|
|
2
|
+
export { getDateParts, getTimeParts, getWeekdayLongDateParts, getWeekdayShortDateParts, getDateTimePartsSubset, nbspToSpace, numberPartsToString, dateTimePartsToString, replaceDateTimeParts, translateDateTimeParts, getMonthLongDateParts, getMonthShortDateParts, } from './dateTimeParts.utils';
|
|
3
|
+
export { convertNumberString, convertDateToDateTimeString, convertDateToRelativeToString, convertDateToRelativeFromString, convertDateToTimeString, convertDateToDateString, convertDateToWeekdayLongString, convertDateToWeekdayShortString, convertDateToMonthLongString, convertDateToMonthShortString, addPrefix, addSuffix, changeNamingConvention, getDefaultDataTimeOptions, } from './dataFormat.utils';
|
|
4
|
+
export { getConstantDatesAndFormattingOptions } from './date.utils';
|
|
5
|
+
export { applyTimezoneOffset, currentTimeInTimezone, getValueAsLocalDate, getTimeZone, dateStringTimeZoneParts, removeTimeZoneOffset, } from './timeZone.utils';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { getDataFormatConfigFromNotation } from './dataFormatConfig.utils';
|
|
2
|
+
export { getDateParts, getTimeParts, getWeekdayLongDateParts, getWeekdayShortDateParts, getDateTimePartsSubset, nbspToSpace, numberPartsToString, dateTimePartsToString, replaceDateTimeParts, translateDateTimeParts, getMonthLongDateParts, getMonthShortDateParts } from './dateTimeParts.utils';
|
|
3
|
+
export { convertNumberString, convertDateToDateTimeString, convertDateToRelativeToString, convertDateToRelativeFromString, convertDateToTimeString, convertDateToDateString, convertDateToWeekdayLongString, convertDateToWeekdayShortString, convertDateToMonthLongString, convertDateToMonthShortString, addPrefix, addSuffix, changeNamingConvention, getDefaultDataTimeOptions } from './dataFormat.utils';
|
|
4
|
+
export { getConstantDatesAndFormattingOptions } from './date.utils';
|
|
5
|
+
export { applyTimezoneOffset, currentTimeInTimezone, getValueAsLocalDate, getTimeZone, dateStringTimeZoneParts, removeTimeZoneOffset } from './timeZone.utils';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type IntlShape } from 'react-intl';
|
|
2
|
+
export declare const TIMEZONE_OFFSET_REGEX: RegExp;
|
|
3
|
+
export declare const dateToIsoWithOffset: (value: Date, intlObject: IntlShape) => string;
|
|
4
|
+
export declare const applyTimezoneOffset: (date: Date | undefined, timezoneOffset: true | string | undefined, intl?: IntlShape) => string | Date | undefined;
|
|
5
|
+
export declare const removeTimeZoneOffset: (dateString: string | Date) => string;
|
|
6
|
+
export declare const extractTimeZoneOffset: (datestring: string) => string | null;
|
|
7
|
+
export declare const dateStringTimeZoneParts: (dateTimeIsoString: string) => {
|
|
8
|
+
dateTimeString: string;
|
|
9
|
+
offsetString: string | null;
|
|
10
|
+
};
|
|
11
|
+
export declare const getLocalDateInTimeZone: (dateIsoString: string, timezone: string) => Date;
|
|
12
|
+
export declare function toIsoString(date: Date, timeZone?: string | undefined): string;
|
|
13
|
+
export declare const currentTimeInTimezone: (timezoneString: string) => Date;
|
|
14
|
+
export declare const dateTimeStringToLocalDate: (value?: string, timeZone?: string) => Date;
|
|
15
|
+
export declare const getValueAsLocalDate: (value?: Date | string, timeZone?: string) => Date;
|
|
16
|
+
export declare const getTimeZone: (timeZone?: boolean | string, intl?: IntlShape) => string | undefined;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { format, getTimezoneOffset, utcToZonedTime } from 'date-fns-tz';
|
|
2
|
+
export var TIMEZONE_OFFSET_REGEX = /([+-]\d\d:\d\d)|([Z])$/;
|
|
3
|
+
var defaultTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
4
|
+
export var dateToIsoWithOffset = function dateToIsoWithOffset(value, intlObject) {
|
|
5
|
+
return format(value, "yyyy-MM-dd'T'HH:mm:ssxxx", {
|
|
6
|
+
timeZone: (intlObject == null ? void 0 : intlObject.timeZone) || defaultTimezone
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
export var applyTimezoneOffset = function applyTimezoneOffset(date, timezoneOffset, intl) {
|
|
10
|
+
if (!timezoneOffset) {
|
|
11
|
+
return date;
|
|
12
|
+
}
|
|
13
|
+
var timezoneString = getTimeZone(timezoneOffset, intl);
|
|
14
|
+
return toIsoString(date, timezoneString);
|
|
15
|
+
};
|
|
16
|
+
export var removeTimeZoneOffset = function removeTimeZoneOffset(dateString) {
|
|
17
|
+
var date = dateString instanceof Date ? dateString.toISOString() : dateString;
|
|
18
|
+
var finalDate = date.replace(TIMEZONE_OFFSET_REGEX, '');
|
|
19
|
+
return finalDate;
|
|
20
|
+
};
|
|
21
|
+
export var extractTimeZoneOffset = function extractTimeZoneOffset(datestring) {
|
|
22
|
+
var date = datestring.toString();
|
|
23
|
+
var found = date.match(TIMEZONE_OFFSET_REGEX);
|
|
24
|
+
return found && found[0];
|
|
25
|
+
};
|
|
26
|
+
export var dateStringTimeZoneParts = function dateStringTimeZoneParts(dateTimeIsoString) {
|
|
27
|
+
return {
|
|
28
|
+
dateTimeString: removeTimeZoneOffset(dateTimeIsoString),
|
|
29
|
+
offsetString: extractTimeZoneOffset(dateTimeIsoString)
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export var getLocalDateInTimeZone = function getLocalDateInTimeZone(dateIsoString, timezone) {
|
|
33
|
+
var _dateStringTimeZonePa = dateStringTimeZoneParts(dateIsoString),
|
|
34
|
+
offsetString = _dateStringTimeZonePa.offsetString,
|
|
35
|
+
dateTimeString = _dateStringTimeZonePa.dateTimeString;
|
|
36
|
+
var localDate = new Date(dateTimeString);
|
|
37
|
+
var localTimezoneOffset = getTimezoneOffset(timezone, localDate); // +2
|
|
38
|
+
var dateTimezoneOffset = offsetString ? getTimezoneOffset(offsetString, localDate) : 0; // -4
|
|
39
|
+
|
|
40
|
+
var offsetDiff = localTimezoneOffset - dateTimezoneOffset;
|
|
41
|
+
localDate.setMilliseconds(localDate.getMilliseconds() + offsetDiff);
|
|
42
|
+
return localDate;
|
|
43
|
+
};
|
|
44
|
+
var pad = function pad(num) {
|
|
45
|
+
return (num < 10 ? '0' : '') + num;
|
|
46
|
+
};
|
|
47
|
+
export function toIsoString(date, timeZone) {
|
|
48
|
+
if (timeZone === void 0) {
|
|
49
|
+
timeZone = 'UTC';
|
|
50
|
+
}
|
|
51
|
+
if (!timeZone) {
|
|
52
|
+
return date.toISOString();
|
|
53
|
+
}
|
|
54
|
+
var timeZoneOffset = getTimezoneOffset(timeZone, date);
|
|
55
|
+
var dif = timeZoneOffset >= 0 ? '+' : '-';
|
|
56
|
+
var tzHours = pad(Math.floor(Math.abs(timeZoneOffset) / 60 / 60 / 1000));
|
|
57
|
+
var tzMinutes = pad(Math.abs(timeZoneOffset) / 60 / 1000 % 60);
|
|
58
|
+
return date.getFullYear() + "-" + pad(date.getMonth() + 1) + "-" + pad(date.getDate()) + "T" + pad(date.getHours()) + ":" + pad(date.getMinutes()) + ":" + pad(date.getSeconds()) + dif + tzHours + ":" + tzMinutes;
|
|
59
|
+
}
|
|
60
|
+
export var currentTimeInTimezone = function currentTimeInTimezone(timezoneString) {
|
|
61
|
+
var now = new Date();
|
|
62
|
+
return utcToZonedTime(now.toISOString(), timezoneString);
|
|
63
|
+
};
|
|
64
|
+
export var dateTimeStringToLocalDate = function dateTimeStringToLocalDate(value, timeZone) {
|
|
65
|
+
if (!value || !timeZone) {
|
|
66
|
+
return new Date();
|
|
67
|
+
}
|
|
68
|
+
if (timeZone !== undefined) {
|
|
69
|
+
return getLocalDateInTimeZone(value, timeZone);
|
|
70
|
+
}
|
|
71
|
+
// FIXME ????
|
|
72
|
+
return typeof value === 'string' ? new Date(value) : value;
|
|
73
|
+
};
|
|
74
|
+
export var getValueAsLocalDate = function getValueAsLocalDate(value, timeZone) {
|
|
75
|
+
if (!value) {
|
|
76
|
+
return new Date();
|
|
77
|
+
}
|
|
78
|
+
if (timeZone !== undefined) {
|
|
79
|
+
if (typeof value !== 'string') {
|
|
80
|
+
return getLocalDateInTimeZone(value.toISOString(), timeZone);
|
|
81
|
+
}
|
|
82
|
+
return getLocalDateInTimeZone(value, timeZone);
|
|
83
|
+
}
|
|
84
|
+
return typeof value === 'string' ? new Date(value) : value;
|
|
85
|
+
};
|
|
86
|
+
export var getTimeZone = function getTimeZone(timeZone, intl) {
|
|
87
|
+
if (!timeZone) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
if (timeZone === true) {
|
|
91
|
+
return (intl == null ? void 0 : intl.timeZone) || defaultTimezone;
|
|
92
|
+
}
|
|
93
|
+
return timeZone;
|
|
94
|
+
};
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export { default as DSProvider, type DSProviderProps } from './DSProvider';
|
|
2
2
|
export { default as mediaQuery } from './mediaQuery/mediaQuery';
|
|
3
3
|
export { theme, useTheme, defaultColorsOrder, themeVariables, type ThemePropsVars, type ThemeProps, type WithTheme, type DefaultColor, } from './DSProvider/ThemeProvider/theme';
|
|
4
|
+
export * from './data-format';
|
|
5
|
+
export * from './testing';
|
|
6
|
+
export * from './toaster';
|
package/dist/js/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export { default as DSProvider } from './DSProvider';
|
|
2
2
|
export { default as mediaQuery } from './mediaQuery/mediaQuery';
|
|
3
|
-
export { theme, useTheme, defaultColorsOrder, themeVariables } from './DSProvider/ThemeProvider/theme';
|
|
3
|
+
export { theme, useTheme, defaultColorsOrder, themeVariables } from './DSProvider/ThemeProvider/theme';
|
|
4
|
+
export * from './data-format';
|
|
5
|
+
export * from './testing';
|
|
6
|
+
export * from './toaster';
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { type FlattenSimpleInterpolation, type SimpleInterpolation } from 'styled-components';
|
|
2
|
-
|
|
3
|
-
export type BreakpointsData = Record<BreakpointKey, {
|
|
4
|
-
min: number;
|
|
5
|
-
max: number;
|
|
6
|
-
}>;
|
|
2
|
+
import { type BreakpointKey } from '../DSProvider/ThemeProvider/breakpoints';
|
|
7
3
|
export type Media = {
|
|
8
4
|
from: BreakpointsType;
|
|
9
5
|
to: BreakpointsType;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type RenderOptions, type RenderResult } from '@testing-library/react';
|
|
3
|
+
import { type DSProviderProps } from '../../DSProvider/DSProvider';
|
|
4
|
+
import { type DataFormatNotationType } from '../../data-format';
|
|
5
|
+
type Options = Omit<RenderOptions, 'queries'>;
|
|
6
|
+
declare const renderWithProvider: (node: ReactNode, options?: Options, props?: Partial<Omit<DSProviderProps, "onErrorIntl" | "dataFormatConfig">> & {
|
|
7
|
+
notation?: DataFormatNotationType;
|
|
8
|
+
applyTimeZoneOffset?: boolean;
|
|
9
|
+
}) => RenderResult;
|
|
10
|
+
export default renderWithProvider;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var _excluded = ["notation", "applyTimeZoneOffset"];
|
|
2
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { render } from '@testing-library/react';
|
|
6
|
+
import DSProvider from '../../DSProvider/DSProvider';
|
|
7
|
+
import { getDataFormatConfigFromNotation } from '../../data-format';
|
|
8
|
+
var _renderWithProvider = function renderWithProvider(node, options, props) {
|
|
9
|
+
var _ref = props || {},
|
|
10
|
+
notation = _ref.notation,
|
|
11
|
+
applyTimeZoneOffset = _ref.applyTimeZoneOffset,
|
|
12
|
+
providerProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
13
|
+
var dataFormatConfigProps = applyTimeZoneOffset !== undefined || notation ? _extends({}, notation ? getDataFormatConfigFromNotation(notation) : {}, {
|
|
14
|
+
applyTimeZoneOffset: applyTimeZoneOffset
|
|
15
|
+
}) : {};
|
|
16
|
+
var rendered = render(/*#__PURE__*/React.createElement(DSProvider, _extends({
|
|
17
|
+
onErrorIntl: function onErrorIntl() {},
|
|
18
|
+
dataFormatConfig: dataFormatConfigProps
|
|
19
|
+
}, providerProps), node), options);
|
|
20
|
+
return _extends({}, rendered, {
|
|
21
|
+
rerender: function rerender(ui, opt) {
|
|
22
|
+
return _renderWithProvider(ui, _extends({
|
|
23
|
+
container: rendered.container
|
|
24
|
+
}, opt));
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
export default _renderWithProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sleep: (duration?: number) => Promise<unknown>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Toaster as BaseToaster } from 'react-hot-toast';
|
|
3
|
+
import { useToaster } from './hooks/useToaster';
|
|
4
|
+
export var Toaster = function Toaster() {
|
|
5
|
+
var _useToaster = useToaster(),
|
|
6
|
+
options = _useToaster.options;
|
|
7
|
+
return /*#__PURE__*/React.createElement(BaseToaster, options);
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { ToasterProps } from 'react-hot-toast';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useToaster: () => import("../contexts/ToasterContext").ToastContextType;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Toaster as default } from './Toaster';
|
|
2
|
+
export { TOASTER_DEFAULTS } from './constants';
|
|
3
|
+
export { ToasterContext, type ToastContextType, } from './contexts/ToasterContext';
|
|
4
|
+
export { useToaster } from './hooks/useToaster';
|
|
5
|
+
export { ToasterProvider } from './providers/ToasterProvider';
|
|
6
|
+
export type { ToasterProps } from './Toaster.types';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Toaster as default } from './Toaster';
|
|
2
|
+
export { TOASTER_DEFAULTS } from './constants';
|
|
3
|
+
export { ToasterContext } from './contexts/ToasterContext';
|
|
4
|
+
export { useToaster } from './hooks/useToaster';
|
|
5
|
+
export { ToasterProvider } from './providers/ToasterProvider';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { TOASTER_DEFAULTS } from '../constants';
|
|
3
|
+
import { ToasterContext } from '../contexts/ToasterContext';
|
|
4
|
+
export var ToasterProvider = function ToasterProvider(_ref) {
|
|
5
|
+
var children = _ref.children,
|
|
6
|
+
_ref$toasterProps = _ref.toasterProps,
|
|
7
|
+
toasterProps = _ref$toasterProps === void 0 ? TOASTER_DEFAULTS : _ref$toasterProps;
|
|
8
|
+
var _useState = useState(toasterProps),
|
|
9
|
+
options = _useState[0],
|
|
10
|
+
setOptions = _useState[1];
|
|
11
|
+
return /*#__PURE__*/React.createElement(ToasterContext.Provider, {
|
|
12
|
+
value: {
|
|
13
|
+
options: options,
|
|
14
|
+
setOptions: setOptions
|
|
15
|
+
}
|
|
16
|
+
}, children);
|
|
17
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-core",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "Core Components for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "synerise/synerise-design",
|
|
7
7
|
"main": "dist/js/index.js",
|
|
8
|
+
"types": "dist/js/index.d.ts",
|
|
8
9
|
"files": [
|
|
9
10
|
"/dist",
|
|
10
11
|
"CHANGELOG.md",
|
|
@@ -24,18 +25,24 @@
|
|
|
24
25
|
"defs": "tsc --declaration --outDir dist/ --emitDeclarationOnly",
|
|
25
26
|
"pack:ci": "npm pack --pack-destination ../../storybook/storybook-static/static",
|
|
26
27
|
"prepublish": "npm run build",
|
|
27
|
-
"test": "jest",
|
|
28
|
+
"test": "jest && yarn test:timezones",
|
|
29
|
+
"test:timezone-ny": "TZ=America/New_York jest -t TimezoneTesting",
|
|
30
|
+
"test:timezone-utc": "TZ=UTC jest -t TimezoneTesting",
|
|
31
|
+
"test:timezone-waw": "TZ=Europe/Warsaw jest -t TimezoneTesting",
|
|
32
|
+
"test:timezones": "yarn test:timezone-utc && yarn test:timezone-ny && yarn test:timezone-waw",
|
|
28
33
|
"test:watch": "npm run test -- --watchAll",
|
|
29
34
|
"types": "tsc --noEmit",
|
|
35
|
+
"check:circular-dependencies": "madge --circular --extensions ts,tsx,js,jsx --ts-config tsconfig.json src/ --exclude '/dist/'",
|
|
30
36
|
"upgrade:ds": "ncu -f \"@synerise/ds-*\" -u",
|
|
31
37
|
"vars": "node ./build/vars.js"
|
|
32
38
|
},
|
|
33
|
-
"types": "dist/js/index.js",
|
|
34
39
|
"dependencies": {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
40
|
+
"date-fns-tz": "^1.1.4",
|
|
41
|
+
"dayjs": "^1.8.36",
|
|
37
42
|
"deepmerge": "^4.2.2",
|
|
38
|
-
"flat": "^5.0.2"
|
|
43
|
+
"flat": "^5.0.2",
|
|
44
|
+
"moment": "^2.30.1",
|
|
45
|
+
"react-hot-toast": "^2.5.2"
|
|
39
46
|
},
|
|
40
47
|
"peerDependencies": {
|
|
41
48
|
"antd": "4.24.16",
|
|
@@ -49,5 +56,5 @@
|
|
|
49
56
|
"hex-rgb": "^5.0.0",
|
|
50
57
|
"less-vars-to-js": "^1.3.0"
|
|
51
58
|
},
|
|
52
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "5beb6ab5f2d77b9e98e04caab7dff20b8436078b"
|
|
53
60
|
}
|