@mantine/dates 7.0.0-beta.7 → 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.
Files changed (125) hide show
  1. package/cjs/components/Calendar/Calendar.js +13 -6
  2. package/cjs/components/Calendar/Calendar.js.map +1 -1
  3. package/cjs/components/CalendarHeader/CalendarHeader.js +1 -2
  4. package/cjs/components/CalendarHeader/CalendarHeader.js.map +1 -1
  5. package/cjs/components/DateInput/DateInput.js +9 -8
  6. package/cjs/components/DateInput/DateInput.js.map +1 -1
  7. package/cjs/components/DateInput/date-string-parser/date-string-parser.js +4 -2
  8. package/cjs/components/DateInput/date-string-parser/date-string-parser.js.map +1 -1
  9. package/cjs/components/DatePicker/DatePicker.js +17 -5
  10. package/cjs/components/DatePicker/DatePicker.js.map +1 -1
  11. package/cjs/components/DatePickerInput/DatePickerInput.js +8 -4
  12. package/cjs/components/DatePickerInput/DatePickerInput.js.map +1 -1
  13. package/cjs/components/DateTimePicker/DateTimePicker.js +9 -7
  14. package/cjs/components/DateTimePicker/DateTimePicker.js.map +1 -1
  15. package/cjs/components/DatesProvider/DatesProvider.js +1 -0
  16. package/cjs/components/DatesProvider/DatesProvider.js.map +1 -1
  17. package/cjs/components/DatesProvider/use-dates-context.js +5 -0
  18. package/cjs/components/DatesProvider/use-dates-context.js.map +1 -1
  19. package/cjs/components/Day/Day.js +4 -1
  20. package/cjs/components/Day/Day.js.map +1 -1
  21. package/cjs/components/DecadeLevelGroup/DecadeLevelGroup.js +1 -2
  22. package/cjs/components/DecadeLevelGroup/DecadeLevelGroup.js.map +1 -1
  23. package/cjs/components/Month/Month.js +0 -1
  24. package/cjs/components/Month/Month.js.map +1 -1
  25. package/cjs/components/Month/get-month-days/get-month-days.js +12 -3
  26. package/cjs/components/Month/get-month-days/get-month-days.js.map +1 -1
  27. package/cjs/components/MonthPicker/MonthPicker.js +16 -5
  28. package/cjs/components/MonthPicker/MonthPicker.js.map +1 -1
  29. package/cjs/components/MonthPickerInput/MonthPickerInput.js +7 -3
  30. package/cjs/components/MonthPickerInput/MonthPickerInput.js.map +1 -1
  31. package/cjs/components/MonthsList/MonthsList.js +0 -1
  32. package/cjs/components/MonthsList/MonthsList.js.map +1 -1
  33. package/cjs/components/PickerControl/PickerControl.js +1 -3
  34. package/cjs/components/PickerControl/PickerControl.js.map +1 -1
  35. package/cjs/components/PickerInputBase/PickerInputBase.js +2 -1
  36. package/cjs/components/PickerInputBase/PickerInputBase.js.map +1 -1
  37. package/cjs/components/YearLevel/YearLevel.js +1 -2
  38. package/cjs/components/YearLevel/YearLevel.js.map +1 -1
  39. package/cjs/components/YearLevelGroup/YearLevelGroup.js +1 -2
  40. package/cjs/components/YearLevelGroup/YearLevelGroup.js.map +1 -1
  41. package/cjs/components/YearPicker/YearPicker.js +17 -5
  42. package/cjs/components/YearPicker/YearPicker.js.map +1 -1
  43. package/cjs/components/YearPickerInput/YearPickerInput.js +8 -4
  44. package/cjs/components/YearPickerInput/YearPickerInput.js.map +1 -1
  45. package/cjs/components/YearsList/YearsList.js +0 -1
  46. package/cjs/components/YearsList/YearsList.js.map +1 -1
  47. package/cjs/hooks/use-dates-state/use-dates-state.js +9 -2
  48. package/cjs/hooks/use-dates-state/use-dates-state.js.map +1 -1
  49. package/cjs/hooks/use-uncontrolled-dates/use-uncontrolled-dates.js +13 -7
  50. package/cjs/hooks/use-uncontrolled-dates/use-uncontrolled-dates.js.map +1 -1
  51. package/cjs/utils/get-default-clamped-date.js +3 -2
  52. package/cjs/utils/get-default-clamped-date.js.map +1 -1
  53. package/cjs/utils/get-timezone-offset.js +25 -0
  54. package/cjs/utils/get-timezone-offset.js.map +1 -0
  55. package/cjs/utils/shift-timezone.js +36 -0
  56. package/cjs/utils/shift-timezone.js.map +1 -0
  57. package/esm/components/Calendar/Calendar.js +13 -6
  58. package/esm/components/Calendar/Calendar.js.map +1 -1
  59. package/esm/components/CalendarHeader/CalendarHeader.js +1 -2
  60. package/esm/components/CalendarHeader/CalendarHeader.js.map +1 -1
  61. package/esm/components/DateInput/DateInput.js +10 -9
  62. package/esm/components/DateInput/DateInput.js.map +1 -1
  63. package/esm/components/DateInput/date-string-parser/date-string-parser.js +4 -2
  64. package/esm/components/DateInput/date-string-parser/date-string-parser.js.map +1 -1
  65. package/esm/components/DatePicker/DatePicker.js +17 -5
  66. package/esm/components/DatePicker/DatePicker.js.map +1 -1
  67. package/esm/components/DatePickerInput/DatePickerInput.js +8 -4
  68. package/esm/components/DatePickerInput/DatePickerInput.js.map +1 -1
  69. package/esm/components/DateTimePicker/DateTimePicker.js +10 -8
  70. package/esm/components/DateTimePicker/DateTimePicker.js.map +1 -1
  71. package/esm/components/DatesProvider/DatesProvider.js +1 -0
  72. package/esm/components/DatesProvider/DatesProvider.js.map +1 -1
  73. package/esm/components/DatesProvider/use-dates-context.js +5 -0
  74. package/esm/components/DatesProvider/use-dates-context.js.map +1 -1
  75. package/esm/components/Day/Day.js +4 -1
  76. package/esm/components/Day/Day.js.map +1 -1
  77. package/esm/components/DecadeLevelGroup/DecadeLevelGroup.js +1 -2
  78. package/esm/components/DecadeLevelGroup/DecadeLevelGroup.js.map +1 -1
  79. package/esm/components/Month/Month.js +0 -1
  80. package/esm/components/Month/Month.js.map +1 -1
  81. package/esm/components/Month/get-month-days/get-month-days.js +12 -3
  82. package/esm/components/Month/get-month-days/get-month-days.js.map +1 -1
  83. package/esm/components/MonthPicker/MonthPicker.js +16 -5
  84. package/esm/components/MonthPicker/MonthPicker.js.map +1 -1
  85. package/esm/components/MonthPickerInput/MonthPickerInput.js +7 -3
  86. package/esm/components/MonthPickerInput/MonthPickerInput.js.map +1 -1
  87. package/esm/components/MonthsList/MonthsList.js +0 -1
  88. package/esm/components/MonthsList/MonthsList.js.map +1 -1
  89. package/esm/components/PickerControl/PickerControl.js +1 -3
  90. package/esm/components/PickerControl/PickerControl.js.map +1 -1
  91. package/esm/components/PickerInputBase/PickerInputBase.js +2 -1
  92. package/esm/components/PickerInputBase/PickerInputBase.js.map +1 -1
  93. package/esm/components/YearLevel/YearLevel.js +1 -2
  94. package/esm/components/YearLevel/YearLevel.js.map +1 -1
  95. package/esm/components/YearLevelGroup/YearLevelGroup.js +1 -2
  96. package/esm/components/YearLevelGroup/YearLevelGroup.js.map +1 -1
  97. package/esm/components/YearPicker/YearPicker.js +17 -5
  98. package/esm/components/YearPicker/YearPicker.js.map +1 -1
  99. package/esm/components/YearPickerInput/YearPickerInput.js +8 -4
  100. package/esm/components/YearPickerInput/YearPickerInput.js.map +1 -1
  101. package/esm/components/YearsList/YearsList.js +0 -1
  102. package/esm/components/YearsList/YearsList.js.map +1 -1
  103. package/esm/hooks/use-dates-state/use-dates-state.js +9 -2
  104. package/esm/hooks/use-dates-state/use-dates-state.js.map +1 -1
  105. package/esm/hooks/use-uncontrolled-dates/use-uncontrolled-dates.js +13 -7
  106. package/esm/hooks/use-uncontrolled-dates/use-uncontrolled-dates.js.map +1 -1
  107. package/esm/utils/get-default-clamped-date.js +3 -2
  108. package/esm/utils/get-default-clamped-date.js.map +1 -1
  109. package/esm/utils/get-timezone-offset.js +15 -0
  110. package/esm/utils/get-timezone-offset.js.map +1 -0
  111. package/esm/utils/shift-timezone.js +28 -0
  112. package/esm/utils/shift-timezone.js.map +1 -0
  113. package/package.json +3 -3
  114. package/cjs/_virtual/_commonjsHelpers.js +0 -8
  115. package/cjs/_virtual/_commonjsHelpers.js.map +0 -1
  116. package/cjs/_virtual/timezone.js_commonjs-module +0 -8
  117. package/cjs/_virtual/timezone.js_commonjs-module.map +0 -1
  118. package/cjs/_virtual/utc.js_commonjs-module +0 -8
  119. package/cjs/_virtual/utc.js_commonjs-module.map +0 -1
  120. package/esm/_virtual/_commonjsHelpers.js +0 -4
  121. package/esm/_virtual/_commonjsHelpers.js.map +0 -1
  122. package/esm/_virtual/timezone.js_commonjs-module +0 -4
  123. package/esm/_virtual/timezone.js_commonjs-module.map +0 -1
  124. package/esm/_virtual/utc.js_commonjs-module +0 -4
  125. 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 [_value, _setValue] = useUncontrolled({
13
- value,
14
- defaultValue,
15
- onChange,
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 onChange,\n finalValue: getEmptyValue(type),\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];\n}\n"],"names":[],"mappings":";;;AAEA,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,CAAC,EAAE;AACH,EAAE,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,C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,KAAK;AACL,GAAG;AACH,EAAE,OAAO,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AAClC;;;;"}
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,IAAI,QAAQ,EAAE,CAAC,OAAO,KAAK;AAC3B,MAAM,QAAQ,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,CA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 @@
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":";;AACO,SAAS,qBAAqB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;AAC5D,EAAE,MAAM,KAAK,mBAAmB,IAAI,IAAI,EAAE,CAAC;AAC3C,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;;;;"}
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,CAAC;AACK,SAAS,aAAa,CAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE;AACnE,EAAE,IAAI,QAAQ,IAAI,CAAC,IAAI,EAAE;AACzB,IAAI,OAAO,IAAI,CAAC;AAChB,GAAG;AACH,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;AAC3B,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AACnE,GAAG;AACH,EAAE,OAAO,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AACnD;;;;"}
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-beta.7",
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-beta.7",
42
- "@mantine/hooks": "7.0.0-beta.7",
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,8 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var timezone = {exports: {}};
6
-
7
- exports.timezone = timezone;
8
- //# sourceMappingURL=timezone.js_commonjs-module.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"timezone.js_commonjs-module","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var utc = {exports: {}};
6
-
7
- exports.utc = utc;
8
- //# sourceMappingURL=utc.js_commonjs-module.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utc.js_commonjs-module","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -1,4 +0,0 @@
1
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2
-
3
- export { commonjsGlobal };
4
- //# sourceMappingURL=_commonjsHelpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_commonjsHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -1,4 +0,0 @@
1
- var timezone = {exports: {}};
2
-
3
- export { timezone as t };
4
- //# sourceMappingURL=timezone.js_commonjs-module.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"timezone.js_commonjs-module","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -1,4 +0,0 @@
1
- var utc = {exports: {}};
2
-
3
- export { utc as u };
4
- //# sourceMappingURL=utc.js_commonjs-module.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utc.js_commonjs-module","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}