@mantine/dates 7.0.0-beta.6 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/components/Calendar/Calendar.js +13 -6
- package/cjs/components/Calendar/Calendar.js.map +1 -1
- package/cjs/components/CalendarHeader/CalendarHeader.js +1 -2
- package/cjs/components/CalendarHeader/CalendarHeader.js.map +1 -1
- package/cjs/components/DateInput/DateInput.js +9 -8
- package/cjs/components/DateInput/DateInput.js.map +1 -1
- package/cjs/components/DateInput/date-string-parser/date-string-parser.js +4 -2
- package/cjs/components/DateInput/date-string-parser/date-string-parser.js.map +1 -1
- package/cjs/components/DatePicker/DatePicker.js +17 -5
- package/cjs/components/DatePicker/DatePicker.js.map +1 -1
- package/cjs/components/DatePickerInput/DatePickerInput.js +8 -4
- package/cjs/components/DatePickerInput/DatePickerInput.js.map +1 -1
- package/cjs/components/DateTimePicker/DateTimePicker.js +9 -7
- package/cjs/components/DateTimePicker/DateTimePicker.js.map +1 -1
- package/cjs/components/DatesProvider/DatesProvider.js +1 -0
- package/cjs/components/DatesProvider/DatesProvider.js.map +1 -1
- package/cjs/components/DatesProvider/use-dates-context.js +5 -0
- package/cjs/components/DatesProvider/use-dates-context.js.map +1 -1
- package/cjs/components/Day/Day.js +4 -1
- package/cjs/components/Day/Day.js.map +1 -1
- package/cjs/components/DecadeLevelGroup/DecadeLevelGroup.js +1 -2
- package/cjs/components/DecadeLevelGroup/DecadeLevelGroup.js.map +1 -1
- package/cjs/components/Month/Month.js +0 -1
- package/cjs/components/Month/Month.js.map +1 -1
- package/cjs/components/Month/get-month-days/get-month-days.js +12 -3
- package/cjs/components/Month/get-month-days/get-month-days.js.map +1 -1
- package/cjs/components/MonthPicker/MonthPicker.js +16 -5
- package/cjs/components/MonthPicker/MonthPicker.js.map +1 -1
- package/cjs/components/MonthPickerInput/MonthPickerInput.js +7 -3
- package/cjs/components/MonthPickerInput/MonthPickerInput.js.map +1 -1
- package/cjs/components/MonthsList/MonthsList.js +0 -1
- package/cjs/components/MonthsList/MonthsList.js.map +1 -1
- package/cjs/components/PickerControl/PickerControl.js +1 -3
- package/cjs/components/PickerControl/PickerControl.js.map +1 -1
- package/cjs/components/PickerInputBase/PickerInputBase.js +2 -1
- package/cjs/components/PickerInputBase/PickerInputBase.js.map +1 -1
- package/cjs/components/YearLevel/YearLevel.js +1 -2
- package/cjs/components/YearLevel/YearLevel.js.map +1 -1
- package/cjs/components/YearLevelGroup/YearLevelGroup.js +1 -2
- package/cjs/components/YearLevelGroup/YearLevelGroup.js.map +1 -1
- package/cjs/components/YearPicker/YearPicker.js +17 -5
- package/cjs/components/YearPicker/YearPicker.js.map +1 -1
- package/cjs/components/YearPickerInput/YearPickerInput.js +8 -4
- package/cjs/components/YearPickerInput/YearPickerInput.js.map +1 -1
- package/cjs/components/YearsList/YearsList.js +0 -1
- package/cjs/components/YearsList/YearsList.js.map +1 -1
- package/cjs/hooks/use-dates-state/use-dates-state.js +9 -2
- package/cjs/hooks/use-dates-state/use-dates-state.js.map +1 -1
- package/cjs/hooks/use-uncontrolled-dates/use-uncontrolled-dates.js +13 -7
- package/cjs/hooks/use-uncontrolled-dates/use-uncontrolled-dates.js.map +1 -1
- package/cjs/utils/get-default-clamped-date.js +3 -2
- package/cjs/utils/get-default-clamped-date.js.map +1 -1
- package/cjs/utils/get-timezone-offset.js +25 -0
- package/cjs/utils/get-timezone-offset.js.map +1 -0
- package/cjs/utils/shift-timezone.js +36 -0
- package/cjs/utils/shift-timezone.js.map +1 -0
- package/esm/components/Calendar/Calendar.js +13 -6
- package/esm/components/Calendar/Calendar.js.map +1 -1
- package/esm/components/CalendarHeader/CalendarHeader.js +1 -2
- package/esm/components/CalendarHeader/CalendarHeader.js.map +1 -1
- package/esm/components/DateInput/DateInput.js +10 -9
- package/esm/components/DateInput/DateInput.js.map +1 -1
- package/esm/components/DateInput/date-string-parser/date-string-parser.js +4 -2
- package/esm/components/DateInput/date-string-parser/date-string-parser.js.map +1 -1
- package/esm/components/DatePicker/DatePicker.js +17 -5
- package/esm/components/DatePicker/DatePicker.js.map +1 -1
- package/esm/components/DatePickerInput/DatePickerInput.js +8 -4
- package/esm/components/DatePickerInput/DatePickerInput.js.map +1 -1
- package/esm/components/DateTimePicker/DateTimePicker.js +10 -8
- package/esm/components/DateTimePicker/DateTimePicker.js.map +1 -1
- package/esm/components/DatesProvider/DatesProvider.js +1 -0
- package/esm/components/DatesProvider/DatesProvider.js.map +1 -1
- package/esm/components/DatesProvider/use-dates-context.js +5 -0
- package/esm/components/DatesProvider/use-dates-context.js.map +1 -1
- package/esm/components/Day/Day.js +4 -1
- package/esm/components/Day/Day.js.map +1 -1
- package/esm/components/DecadeLevelGroup/DecadeLevelGroup.js +1 -2
- package/esm/components/DecadeLevelGroup/DecadeLevelGroup.js.map +1 -1
- package/esm/components/Month/Month.js +0 -1
- package/esm/components/Month/Month.js.map +1 -1
- package/esm/components/Month/get-month-days/get-month-days.js +12 -3
- package/esm/components/Month/get-month-days/get-month-days.js.map +1 -1
- package/esm/components/MonthPicker/MonthPicker.js +16 -5
- package/esm/components/MonthPicker/MonthPicker.js.map +1 -1
- package/esm/components/MonthPickerInput/MonthPickerInput.js +7 -3
- package/esm/components/MonthPickerInput/MonthPickerInput.js.map +1 -1
- package/esm/components/MonthsList/MonthsList.js +0 -1
- package/esm/components/MonthsList/MonthsList.js.map +1 -1
- package/esm/components/PickerControl/PickerControl.js +1 -3
- package/esm/components/PickerControl/PickerControl.js.map +1 -1
- package/esm/components/PickerInputBase/PickerInputBase.js +2 -1
- package/esm/components/PickerInputBase/PickerInputBase.js.map +1 -1
- package/esm/components/YearLevel/YearLevel.js +1 -2
- package/esm/components/YearLevel/YearLevel.js.map +1 -1
- package/esm/components/YearLevelGroup/YearLevelGroup.js +1 -2
- package/esm/components/YearLevelGroup/YearLevelGroup.js.map +1 -1
- package/esm/components/YearPicker/YearPicker.js +17 -5
- package/esm/components/YearPicker/YearPicker.js.map +1 -1
- package/esm/components/YearPickerInput/YearPickerInput.js +8 -4
- package/esm/components/YearPickerInput/YearPickerInput.js.map +1 -1
- package/esm/components/YearsList/YearsList.js +0 -1
- package/esm/components/YearsList/YearsList.js.map +1 -1
- package/esm/hooks/use-dates-state/use-dates-state.js +9 -2
- package/esm/hooks/use-dates-state/use-dates-state.js.map +1 -1
- package/esm/hooks/use-uncontrolled-dates/use-uncontrolled-dates.js +13 -7
- package/esm/hooks/use-uncontrolled-dates/use-uncontrolled-dates.js.map +1 -1
- package/esm/utils/get-default-clamped-date.js +3 -2
- package/esm/utils/get-default-clamped-date.js.map +1 -1
- package/esm/utils/get-timezone-offset.js +15 -0
- package/esm/utils/get-timezone-offset.js.map +1 -0
- package/esm/utils/shift-timezone.js +28 -0
- package/esm/utils/shift-timezone.js.map +1 -0
- package/lib/components/PickerInputBase/PickerInputBase.d.ts.map +1 -1
- package/package.json +3 -3
- package/cjs/_virtual/_commonjsHelpers.js +0 -8
- package/cjs/_virtual/_commonjsHelpers.js.map +0 -1
- package/cjs/_virtual/timezone.js_commonjs-module +0 -8
- package/cjs/_virtual/timezone.js_commonjs-module.map +0 -1
- package/cjs/_virtual/utc.js_commonjs-module +0 -8
- package/cjs/_virtual/utc.js_commonjs-module.map +0 -1
- package/esm/_virtual/_commonjsHelpers.js +0 -4
- package/esm/_virtual/_commonjsHelpers.js.map +0 -1
- package/esm/_virtual/timezone.js_commonjs-module +0 -4
- package/esm/_virtual/timezone.js_commonjs-module.map +0 -1
- package/esm/_virtual/utc.js_commonjs-module +0 -4
- package/esm/_virtual/utc.js_commonjs-module.map +0 -1
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import { useUncontrolled } from '@mantine/hooks';
|
|
2
2
|
import { useRef } from 'react';
|
|
3
|
+
import { useDatesContext } from '../../components/DatesProvider/use-dates-context.js';
|
|
4
|
+
import { shiftTimezone } from '../../utils/shift-timezone.js';
|
|
3
5
|
|
|
4
6
|
const getEmptyValue = (type) => type === "range" ? [null, null] : type === "multiple" ? [] : null;
|
|
5
7
|
function useUncontrolledDates({
|
|
6
8
|
type,
|
|
7
9
|
value,
|
|
8
10
|
defaultValue,
|
|
9
|
-
onChange
|
|
11
|
+
onChange,
|
|
12
|
+
applyTimezone = true
|
|
10
13
|
}) {
|
|
11
14
|
const storedType = useRef(type);
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
finalValue: getEmptyValue(type)
|
|
15
|
+
const ctx = useDatesContext();
|
|
16
|
+
const [_value, _setValue, controlled] = useUncontrolled({
|
|
17
|
+
value: shiftTimezone("add", value, ctx.getTimezone(), !applyTimezone),
|
|
18
|
+
defaultValue: shiftTimezone("add", defaultValue, ctx.getTimezone(), !applyTimezone),
|
|
19
|
+
finalValue: getEmptyValue(type),
|
|
20
|
+
onChange: (newDate) => {
|
|
21
|
+
onChange == null ? void 0 : onChange(shiftTimezone("remove", newDate, ctx.getTimezone(), !applyTimezone));
|
|
22
|
+
}
|
|
17
23
|
});
|
|
18
24
|
let _finalValue = _value;
|
|
19
25
|
if (storedType.current !== type) {
|
|
@@ -47,7 +53,7 @@ function useUncontrolledDates({
|
|
|
47
53
|
}
|
|
48
54
|
}
|
|
49
55
|
}
|
|
50
|
-
return [_finalValue, _setValue];
|
|
56
|
+
return [_finalValue, _setValue, controlled];
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
export { useUncontrolledDates };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-uncontrolled-dates.js","sources":["../../../src/hooks/use-uncontrolled-dates/use-uncontrolled-dates.ts"],"sourcesContent":["import { useUncontrolled } from '@mantine/hooks';\nimport { useRef } from 'react';\nimport { DatePickerType, DatePickerValue } from '../../types';\n\ninterface UseUncontrolledDates<Type extends DatePickerType = 'default'> {\n type: Type;\n value: DatePickerValue<Type> | undefined;\n defaultValue: DatePickerValue<Type> | undefined;\n onChange: ((value: DatePickerValue<Type>) => void) | undefined;\n}\n\nconst getEmptyValue = <Type extends DatePickerType = 'default'>(type: Type) =>\n type === 'range' ? [null, null] : type === 'multiple' ? [] : null;\n\nexport function useUncontrolledDates<Type extends DatePickerType = 'default'>({\n type,\n value,\n defaultValue,\n onChange,\n}: UseUncontrolledDates<Type>) {\n const storedType = useRef<Type>(type);\n const [_value, _setValue] = useUncontrolled<any>({\n value,\n defaultValue,\n
|
|
1
|
+
{"version":3,"file":"use-uncontrolled-dates.js","sources":["../../../src/hooks/use-uncontrolled-dates/use-uncontrolled-dates.ts"],"sourcesContent":["import { useUncontrolled } from '@mantine/hooks';\nimport { useRef } from 'react';\nimport { DatePickerType, DatePickerValue } from '../../types';\nimport { shiftTimezone } from '../../utils';\nimport { useDatesContext } from '../../components/DatesProvider';\n\ninterface UseUncontrolledDates<Type extends DatePickerType = 'default'> {\n type: Type;\n value: DatePickerValue<Type> | undefined;\n defaultValue: DatePickerValue<Type> | undefined;\n onChange: ((value: DatePickerValue<Type>) => void) | undefined;\n applyTimezone?: boolean;\n}\n\nconst getEmptyValue = <Type extends DatePickerType = 'default'>(type: Type) =>\n type === 'range' ? [null, null] : type === 'multiple' ? [] : null;\n\nexport function useUncontrolledDates<Type extends DatePickerType = 'default'>({\n type,\n value,\n defaultValue,\n onChange,\n applyTimezone = true,\n}: UseUncontrolledDates<Type>) {\n const storedType = useRef<Type>(type);\n const ctx = useDatesContext();\n const [_value, _setValue, controlled] = useUncontrolled<any>({\n value: shiftTimezone('add', value, ctx.getTimezone(), !applyTimezone),\n defaultValue: shiftTimezone('add', defaultValue, ctx.getTimezone(), !applyTimezone),\n finalValue: getEmptyValue(type),\n onChange: (newDate) => {\n onChange?.(shiftTimezone('remove', newDate, ctx.getTimezone(), !applyTimezone));\n },\n });\n\n let _finalValue = _value;\n\n if (storedType.current !== type) {\n // Type has changed. Do some checks or resets\n\n storedType.current = type;\n if (value === undefined) {\n // Reset uncontrolled value as types aren't compatible\n _finalValue = defaultValue !== undefined ? defaultValue : getEmptyValue(type);\n _setValue(_finalValue);\n } else if (process.env.NODE_ENV === 'development') {\n // Throw errors in dev mode in case type of value isn't correct\n switch (type) {\n case 'default':\n if (value !== null && typeof value !== 'string') {\n // eslint-disable-next-line no-console\n console.error(\n '[@mantine/dates/use-uncontrolled-dates] Value must be type of `null` or `string`'\n );\n }\n break;\n case 'multiple':\n if (!(value instanceof Array)) {\n // eslint-disable-next-line no-console\n console.error(\n '[@mantine/dates/use-uncontrolled-dates] Value must be type of `string[]`'\n );\n }\n break;\n case 'range':\n if (!(value instanceof Array) || value.length !== 2) {\n // eslint-disable-next-line no-console\n console.error(\n '[@mantine/dates/use-uncontrolled-dates] Value must be type of `[string, string]`'\n );\n }\n break;\n }\n }\n }\n\n return [_finalValue, _setValue, controlled];\n}\n"],"names":[],"mappings":";;;;;AAIA,MAAM,aAAa,GAAG,CAAC,IAAI,KAAK,IAAI,KAAK,OAAO,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,IAAI,KAAK,UAAU,GAAG,EAAE,GAAG,IAAI,CAAC;AAC3F,SAAS,oBAAoB,CAAC;AACrC,EAAE,IAAI;AACN,EAAE,KAAK;AACP,EAAE,YAAY;AACd,EAAE,QAAQ;AACV,EAAE,aAAa,GAAG,IAAI;AACtB,CAAC,EAAE;AACH,EAAE,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAClC,EAAE,MAAM,GAAG,GAAG,eAAe,EAAE,CAAC;AAChC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,GAAG,eAAe,CAAC;AAC1D,IAAI,KAAK,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,aAAa,CAAC;AACzE,IAAI,YAAY,EAAE,aAAa,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,aAAa,CAAC;AACvF,IAAI,UAAU,EAAE,aAAa,CAAC,IAAI,CAAC;AACnC,I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,WAAW;AACX,UAAU,MAAM;AAChB,OAAO;AACP,KAAK;AACL,GAAG;AACH,EAAE,OAAO,CAAC,WAAW,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AAC9C;;;;"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
|
+
import { shiftTimezone } from './shift-timezone.js';
|
|
2
3
|
|
|
3
|
-
function getDefaultClampedDate({ minDate, maxDate }) {
|
|
4
|
-
const today = /* @__PURE__ */ new Date();
|
|
4
|
+
function getDefaultClampedDate({ minDate, maxDate, timezone }) {
|
|
5
|
+
const today = shiftTimezone("add", /* @__PURE__ */ new Date(), timezone);
|
|
5
6
|
if (!minDate && !maxDate) {
|
|
6
7
|
return today;
|
|
7
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-default-clamped-date.js","sources":["../../src/utils/get-default-clamped-date.ts"],"sourcesContent":["import dayjs from 'dayjs';\n\ninterface GetDefaultClampedDate {\n minDate: Date | undefined;\n maxDate: Date | undefined;\n}\n\nexport function getDefaultClampedDate({ minDate, maxDate }: GetDefaultClampedDate) {\n const today = new Date();\n\n if (!minDate && !maxDate) {\n return today;\n }\n\n if (minDate && dayjs(today).isBefore(minDate)) {\n return minDate;\n }\n\n if (maxDate && dayjs(today).isAfter(maxDate)) {\n return maxDate;\n }\n\n return today;\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-default-clamped-date.js","sources":["../../src/utils/get-default-clamped-date.ts"],"sourcesContent":["import dayjs from 'dayjs';\nimport { shiftTimezone } from './shift-timezone';\n\ninterface GetDefaultClampedDate {\n minDate: Date | undefined;\n maxDate: Date | undefined;\n timezone?: string;\n}\n\nexport function getDefaultClampedDate({ minDate, maxDate, timezone }: GetDefaultClampedDate) {\n const today = shiftTimezone('add', new Date(), timezone);\n\n if (!minDate && !maxDate) {\n return today;\n }\n\n if (minDate && dayjs(today).isBefore(minDate)) {\n return minDate;\n }\n\n if (maxDate && dayjs(today).isAfter(maxDate)) {\n return maxDate;\n }\n\n return today;\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,qBAAqB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE;AACtE,EAAE,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,kBAAkB,IAAI,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC;AAC3E,EAAE,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE;AAC5B,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG;AACH,EAAE,IAAI,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;AACjD,IAAI,OAAO,OAAO,CAAC;AACnB,GAAG;AACH,EAAE,IAAI,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;AAChD,IAAI,OAAO,OAAO,CAAC;AACnB,GAAG;AACH,EAAE,OAAO,KAAK,CAAC;AACf;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import utcPlugin from 'dayjs/plugin/utc';
|
|
3
|
+
import timezonePlugin from 'dayjs/plugin/timezone';
|
|
4
|
+
|
|
5
|
+
dayjs.extend(utcPlugin);
|
|
6
|
+
dayjs.extend(timezonePlugin);
|
|
7
|
+
function getTimezoneOffset(date, timezone) {
|
|
8
|
+
if (timezone) {
|
|
9
|
+
return dayjs(date).tz(timezone).utcOffset() + date.getTimezoneOffset();
|
|
10
|
+
}
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { getTimezoneOffset };
|
|
15
|
+
//# sourceMappingURL=get-timezone-offset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-timezone-offset.js","sources":["../../src/utils/get-timezone-offset.ts"],"sourcesContent":["import dayjs from 'dayjs';\nimport utcPlugin from 'dayjs/plugin/utc';\nimport timezonePlugin from 'dayjs/plugin/timezone';\n\ndayjs.extend(utcPlugin);\ndayjs.extend(timezonePlugin);\n\nexport function getTimezoneOffset(date: Date, timezone?: string) {\n if (timezone) {\n return dayjs(date).tz(timezone).utcOffset() + date.getTimezoneOffset();\n }\n return 0;\n}\n"],"names":[],"mappings":";;;;AAGA,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACxB,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;AACtB,SAAS,iBAAiB,CAAC,IAAI,EAAE,QAAQ,EAAE;AAClD,EAAE,IAAI,QAAQ,EAAE;AAChB,IAAI,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;AAC3E,GAAG;AACH,EAAE,OAAO,CAAC,CAAC;AACX;;;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import { getTimezoneOffset } from './get-timezone-offset.js';
|
|
3
|
+
|
|
4
|
+
const updateTimezone = (date, timezone, direction) => {
|
|
5
|
+
if (!date) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
if (!timezone) {
|
|
9
|
+
return date;
|
|
10
|
+
}
|
|
11
|
+
let offset = getTimezoneOffset(date, timezone);
|
|
12
|
+
if (direction === "remove") {
|
|
13
|
+
offset *= -1;
|
|
14
|
+
}
|
|
15
|
+
return dayjs(date).add(offset, "minutes").toDate();
|
|
16
|
+
};
|
|
17
|
+
function shiftTimezone(direction, date, timezone, disabled) {
|
|
18
|
+
if (disabled || !date) {
|
|
19
|
+
return date;
|
|
20
|
+
}
|
|
21
|
+
if (Array.isArray(date)) {
|
|
22
|
+
return date.map((d) => updateTimezone(d, timezone, direction));
|
|
23
|
+
}
|
|
24
|
+
return updateTimezone(date, timezone, direction);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { shiftTimezone };
|
|
28
|
+
//# sourceMappingURL=shift-timezone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shift-timezone.js","sources":["../../src/utils/shift-timezone.ts"],"sourcesContent":["import dayjs from 'dayjs';\nimport { getTimezoneOffset } from './get-timezone-offset';\nimport { DatesRangeValue, DateValue } from '../types';\n\ntype TimeShiftDirection = 'add' | 'remove';\n\nconst updateTimezone = (\n date: DateValue | undefined,\n timezone?: string,\n direction?: TimeShiftDirection\n): DateValue => {\n if (!date) {\n return null;\n }\n if (!timezone) {\n return date;\n }\n let offset = getTimezoneOffset(date, timezone);\n if (direction === 'remove') {\n offset *= -1;\n }\n return dayjs(date).add(offset, 'minutes').toDate();\n};\n\nexport function shiftTimezone<T extends DateValue | Date[] | DatesRangeValue | undefined>(\n direction: TimeShiftDirection,\n date: T,\n timezone?: string,\n disabled?: boolean\n): T {\n if (disabled || !date) {\n return date;\n }\n if (Array.isArray(date)) {\n return date.map((d) => updateTimezone(d, timezone, direction)) as T;\n }\n return updateTimezone(date, timezone, direction) as T;\n}\n"],"names":[],"mappings":";;;AAEA,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,KAAK;AACtD,EAAE,IAAI,CAAC,IAAI,EAAE;AACb,IAAI,OAAO,IAAI,CAAC;AAChB,GAAG;AACH,EAAE,IAAI,CAAC,QAAQ,EAAE;AACjB,IAAI,OAAO,IAAI,CAAC;AAChB,GAAG;AACH,EAAE,IAAI,MAAM,GAAG,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACjD,EAAE,IAAI,SAAS,KAAK,QAAQ,EAAE;AAC9B,IAAI,MAAM,IAAI,CAAC,CAAC,CAAC;AACjB,GAAG;AACH,EAAE,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,MAAM,EAAE,CAAC;AACrD,CAAC,CA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MAAM,eAAe;WARnB,oBAAoB;SACtB,iBAAiB;iBACT,0BAA0B;aAC9B,YAAY;EAoHrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mantine/dates",
|
|
3
3
|
"description": "Calendars, date and time pickers based on Mantine components",
|
|
4
|
-
"version": "7.0.0
|
|
4
|
+
"version": "7.0.0",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"module": "./esm/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"picker"
|
|
39
39
|
],
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@mantine/core": "7.0.0
|
|
42
|
-
"@mantine/hooks": "7.0.0
|
|
41
|
+
"@mantine/core": "7.0.0",
|
|
42
|
+
"@mantine/hooks": "7.0.0",
|
|
43
43
|
"dayjs": "^1.10.5",
|
|
44
44
|
"react": "^18.2.0",
|
|
45
45
|
"react-dom": "^18.2.0"
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
6
|
-
|
|
7
|
-
exports.commonjsGlobal = commonjsGlobal;
|
|
8
|
-
//# sourceMappingURL=_commonjsHelpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_commonjsHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timezone.js_commonjs-module","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utc.js_commonjs-module","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_commonjsHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timezone.js_commonjs-module","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utc.js_commonjs-module","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|