@mui/x-date-pickers 8.5.3 → 8.6.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 (176) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/DateCalendar/DateCalendar.js +16 -16
  3. package/DateCalendar/DayCalendar.js +48 -48
  4. package/DateCalendar/useCalendarState.js +25 -25
  5. package/DateCalendar/useIsDateDisabled.js +2 -2
  6. package/DatePicker/DatePickerToolbar.js +7 -9
  7. package/DateTimeField/DateTimeField.js +1 -1
  8. package/DateTimePicker/DateTimePicker.js +1 -1
  9. package/DateTimePicker/DateTimePickerToolbar.js +12 -13
  10. package/DateTimePicker/shared.js +3 -3
  11. package/DesktopDatePicker/DesktopDatePicker.js +3 -3
  12. package/DesktopDateTimePicker/DesktopDateTimePicker.js +4 -4
  13. package/DesktopTimePicker/DesktopTimePicker.js +4 -4
  14. package/DigitalClock/DigitalClock.d.ts +1 -1
  15. package/DigitalClock/DigitalClock.js +16 -16
  16. package/LocalizationProvider/LocalizationProvider.d.ts +9 -3
  17. package/LocalizationProvider/LocalizationProvider.js +28 -19
  18. package/MobileDatePicker/MobileDatePicker.js +3 -3
  19. package/MobileDateTimePicker/MobileDateTimePicker.js +4 -4
  20. package/MobileTimePicker/MobileTimePicker.js +4 -4
  21. package/MonthCalendar/MonthCalendar.js +19 -18
  22. package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +32 -32
  23. package/MultiSectionDigitalClock/MultiSectionDigitalClock.utils.d.ts +4 -4
  24. package/MultiSectionDigitalClock/MultiSectionDigitalClock.utils.js +7 -7
  25. package/PickerDay2/PickerDay2.js +3 -3
  26. package/PickersActionBar/PickersActionBar.d.ts +2 -2
  27. package/PickersActionBar/PickersActionBar.js +2 -2
  28. package/PickersCalendarHeader/PickersCalendarHeader.js +7 -8
  29. package/PickersDay/PickersDay.js +3 -3
  30. package/PickersDay/usePickerDayOwnerState.js +5 -5
  31. package/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
  32. package/StaticTimePicker/StaticTimePicker.js +1 -1
  33. package/TimeClock/Clock.js +8 -9
  34. package/TimeClock/ClockNumbers.d.ts +3 -3
  35. package/TimeClock/ClockNumbers.js +5 -5
  36. package/TimeClock/TimeClock.js +29 -29
  37. package/TimeField/TimeField.js +1 -1
  38. package/TimePicker/TimePicker.js +1 -1
  39. package/TimePicker/TimePickerToolbar.js +7 -9
  40. package/TimePicker/shared.js +3 -3
  41. package/YearCalendar/YearCalendar.js +19 -18
  42. package/esm/DateCalendar/DateCalendar.js +16 -16
  43. package/esm/DateCalendar/DayCalendar.js +48 -48
  44. package/esm/DateCalendar/useCalendarState.js +25 -25
  45. package/esm/DateCalendar/useIsDateDisabled.js +2 -2
  46. package/esm/DatePicker/DatePickerToolbar.js +6 -8
  47. package/esm/DateTimeField/DateTimeField.js +1 -1
  48. package/esm/DateTimePicker/DateTimePicker.js +1 -1
  49. package/esm/DateTimePicker/DateTimePickerToolbar.js +11 -12
  50. package/esm/DateTimePicker/shared.js +3 -3
  51. package/esm/DesktopDatePicker/DesktopDatePicker.js +3 -3
  52. package/esm/DesktopDateTimePicker/DesktopDateTimePicker.js +4 -4
  53. package/esm/DesktopTimePicker/DesktopTimePicker.js +4 -4
  54. package/esm/DigitalClock/DigitalClock.d.ts +1 -1
  55. package/esm/DigitalClock/DigitalClock.js +16 -16
  56. package/esm/LocalizationProvider/LocalizationProvider.d.ts +9 -3
  57. package/esm/LocalizationProvider/LocalizationProvider.js +27 -18
  58. package/esm/MobileDatePicker/MobileDatePicker.js +3 -3
  59. package/esm/MobileDateTimePicker/MobileDateTimePicker.js +4 -4
  60. package/esm/MobileTimePicker/MobileTimePicker.js +4 -4
  61. package/esm/MonthCalendar/MonthCalendar.js +20 -19
  62. package/esm/MultiSectionDigitalClock/MultiSectionDigitalClock.js +32 -32
  63. package/esm/MultiSectionDigitalClock/MultiSectionDigitalClock.utils.d.ts +4 -4
  64. package/esm/MultiSectionDigitalClock/MultiSectionDigitalClock.utils.js +7 -7
  65. package/esm/PickerDay2/PickerDay2.js +3 -3
  66. package/esm/PickersActionBar/PickersActionBar.d.ts +2 -2
  67. package/esm/PickersActionBar/PickersActionBar.js +2 -2
  68. package/esm/PickersCalendarHeader/PickersCalendarHeader.js +6 -7
  69. package/esm/PickersDay/PickersDay.js +3 -3
  70. package/esm/PickersDay/usePickerDayOwnerState.js +5 -5
  71. package/esm/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
  72. package/esm/StaticTimePicker/StaticTimePicker.js +1 -1
  73. package/esm/TimeClock/Clock.js +7 -8
  74. package/esm/TimeClock/ClockNumbers.d.ts +3 -3
  75. package/esm/TimeClock/ClockNumbers.js +5 -5
  76. package/esm/TimeClock/TimeClock.js +29 -29
  77. package/esm/TimeField/TimeField.js +1 -1
  78. package/esm/TimePicker/TimePicker.js +1 -1
  79. package/esm/TimePicker/TimePickerToolbar.js +6 -8
  80. package/esm/TimePicker/shared.js +3 -3
  81. package/esm/YearCalendar/YearCalendar.js +20 -19
  82. package/esm/hooks/index.d.ts +2 -1
  83. package/esm/hooks/index.js +2 -1
  84. package/esm/hooks/useParsedFormat.js +6 -6
  85. package/esm/hooks/usePickerAdapter.d.ts +7 -0
  86. package/esm/hooks/usePickerAdapter.js +20 -0
  87. package/esm/hooks/usePickerTranslations.js +1 -1
  88. package/esm/index.js +1 -1
  89. package/esm/internals/components/pickersToolbarClasses.d.ts +1 -1
  90. package/esm/internals/demo/DemoContainer.d.ts +2 -3
  91. package/esm/internals/demo/DemoContainer.js +3 -2
  92. package/esm/internals/hooks/date-helpers-hooks.js +16 -16
  93. package/esm/internals/hooks/useClockReferenceDate.d.ts +2 -2
  94. package/esm/internals/hooks/useClockReferenceDate.js +3 -3
  95. package/esm/internals/hooks/useControlledValue.js +8 -7
  96. package/esm/internals/hooks/useField/buildSectionsFromFormat.d.ts +1 -1
  97. package/esm/internals/hooks/useField/buildSectionsFromFormat.js +17 -17
  98. package/esm/internals/hooks/useField/useField.types.d.ts +2 -2
  99. package/esm/internals/hooks/useField/useField.utils.d.ts +10 -10
  100. package/esm/internals/hooks/useField/useField.utils.js +69 -69
  101. package/esm/internals/hooks/useField/useFieldCharacterEditing.js +11 -11
  102. package/esm/internals/hooks/useField/useFieldRootHandleKeyDown.js +7 -7
  103. package/esm/internals/hooks/useField/useFieldSectionContentProps.js +15 -16
  104. package/esm/internals/hooks/useField/useFieldState.js +22 -24
  105. package/esm/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +6 -6
  106. package/esm/internals/hooks/usePicker/usePicker.js +5 -6
  107. package/esm/internals/hooks/useUtils.d.ts +1 -8
  108. package/esm/internals/hooks/useUtils.js +3 -19
  109. package/esm/internals/index.d.ts +2 -1
  110. package/esm/internals/index.js +2 -1
  111. package/esm/internals/models/manager.d.ts +14 -14
  112. package/esm/internals/models/props/time.d.ts +1 -1
  113. package/esm/internals/utils/date-time-utils.d.ts +1 -1
  114. package/esm/internals/utils/date-time-utils.js +5 -5
  115. package/esm/internals/utils/date-utils.d.ts +11 -11
  116. package/esm/internals/utils/date-utils.js +34 -34
  117. package/esm/internals/utils/getDefaultReferenceDate.d.ts +2 -2
  118. package/esm/internals/utils/getDefaultReferenceDate.js +16 -16
  119. package/esm/internals/utils/time-utils.d.ts +5 -5
  120. package/esm/internals/utils/time-utils.js +12 -12
  121. package/esm/internals/utils/valueManagers.js +4 -4
  122. package/esm/managers/useDateManager.js +12 -12
  123. package/esm/managers/useDateTimeManager.js +13 -13
  124. package/esm/managers/useTimeManager.js +9 -10
  125. package/esm/validation/useValidation.d.ts +2 -3
  126. package/esm/validation/useValidation.js +2 -2
  127. package/esm/validation/validateDate.js +6 -6
  128. package/esm/validation/validateTime.js +6 -6
  129. package/hooks/index.d.ts +2 -1
  130. package/hooks/index.js +8 -1
  131. package/hooks/useParsedFormat.js +6 -6
  132. package/hooks/usePickerAdapter.d.ts +7 -0
  133. package/hooks/usePickerAdapter.js +29 -0
  134. package/hooks/usePickerTranslations.js +2 -2
  135. package/index.js +1 -1
  136. package/internals/components/pickersToolbarClasses.d.ts +1 -1
  137. package/internals/demo/DemoContainer.d.ts +2 -3
  138. package/internals/demo/DemoContainer.js +3 -2
  139. package/internals/hooks/date-helpers-hooks.js +16 -16
  140. package/internals/hooks/useClockReferenceDate.d.ts +2 -2
  141. package/internals/hooks/useClockReferenceDate.js +3 -3
  142. package/internals/hooks/useControlledValue.js +7 -7
  143. package/internals/hooks/useField/buildSectionsFromFormat.d.ts +1 -1
  144. package/internals/hooks/useField/buildSectionsFromFormat.js +17 -17
  145. package/internals/hooks/useField/useField.types.d.ts +2 -2
  146. package/internals/hooks/useField/useField.utils.d.ts +10 -10
  147. package/internals/hooks/useField/useField.utils.js +69 -69
  148. package/internals/hooks/useField/useFieldCharacterEditing.js +11 -11
  149. package/internals/hooks/useField/useFieldRootHandleKeyDown.js +7 -7
  150. package/internals/hooks/useField/useFieldSectionContentProps.js +14 -15
  151. package/internals/hooks/useField/useFieldState.js +23 -25
  152. package/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +6 -6
  153. package/internals/hooks/usePicker/usePicker.js +5 -6
  154. package/internals/hooks/useUtils.d.ts +1 -8
  155. package/internals/hooks/useUtils.js +5 -24
  156. package/internals/index.d.ts +2 -1
  157. package/internals/index.js +2 -7
  158. package/internals/models/manager.d.ts +14 -14
  159. package/internals/models/props/time.d.ts +1 -1
  160. package/internals/utils/date-time-utils.d.ts +1 -1
  161. package/internals/utils/date-time-utils.js +5 -5
  162. package/internals/utils/date-utils.d.ts +11 -11
  163. package/internals/utils/date-utils.js +34 -34
  164. package/internals/utils/getDefaultReferenceDate.d.ts +2 -2
  165. package/internals/utils/getDefaultReferenceDate.js +16 -16
  166. package/internals/utils/time-utils.d.ts +5 -5
  167. package/internals/utils/time-utils.js +12 -12
  168. package/internals/utils/valueManagers.js +4 -4
  169. package/managers/useDateManager.js +12 -12
  170. package/managers/useDateTimeManager.js +13 -13
  171. package/managers/useTimeManager.js +10 -11
  172. package/package.json +2 -2
  173. package/validation/useValidation.d.ts +2 -3
  174. package/validation/useValidation.js +2 -2
  175. package/validation/validateDate.js +6 -6
  176. package/validation/validateTime.js +6 -6
@@ -14,7 +14,7 @@ import composeClasses from '@mui/utils/composeClasses';
14
14
  import useControlled from '@mui/utils/useControlled';
15
15
  import useEventCallback from '@mui/utils/useEventCallback';
16
16
  import { YearCalendarButton } from "./YearCalendarButton.js";
17
- import { useUtils, useNow } from "../internals/hooks/useUtils.js";
17
+ import { useNow } from "../internals/hooks/useUtils.js";
18
18
  import { getYearCalendarUtilityClass } from "./yearCalendarClasses.js";
19
19
  import { singleItemValueManager } from "../internals/utils/valueManagers.js";
20
20
  import { SECTION_TYPE_GRANULARITY } from "../internals/utils/getDefaultReferenceDate.js";
@@ -22,6 +22,7 @@ import { useControlledValue } from "../internals/hooks/useControlledValue.js";
22
22
  import { DIALOG_WIDTH, MAX_CALENDAR_HEIGHT } from "../internals/constants/dimensions.js";
23
23
  import { usePickerPrivateContext } from "../internals/hooks/usePickerPrivateContext.js";
24
24
  import { useApplyDefaultValuesToDateValidationProps } from "../managers/useDateManager.js";
25
+ import { usePickerAdapter } from "../hooks/usePickerAdapter.js";
25
26
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
26
27
  const useUtilityClasses = classes => {
27
28
  const slots = {
@@ -133,13 +134,13 @@ export const YearCalendar = /*#__PURE__*/React.forwardRef(function YearCalendar(
133
134
  });
134
135
  const now = useNow(timezone);
135
136
  const isRtl = useRtl();
136
- const utils = useUtils();
137
+ const adapter = usePickerAdapter();
137
138
  const {
138
139
  ownerState
139
140
  } = usePickerPrivateContext();
140
141
  const referenceDate = React.useMemo(() => singleItemValueManager.getInitialReferenceValue({
141
142
  value,
142
- utils,
143
+ adapter,
143
144
  props,
144
145
  timezone,
145
146
  referenceDate: referenceDateProp,
@@ -147,14 +148,14 @@ export const YearCalendar = /*#__PURE__*/React.forwardRef(function YearCalendar(
147
148
  }), [] // eslint-disable-line react-hooks/exhaustive-deps
148
149
  );
149
150
  const classes = useUtilityClasses(classesProp);
150
- const todayYear = React.useMemo(() => utils.getYear(now), [utils, now]);
151
+ const todayYear = React.useMemo(() => adapter.getYear(now), [adapter, now]);
151
152
  const selectedYear = React.useMemo(() => {
152
153
  if (value != null) {
153
- return utils.getYear(value);
154
+ return adapter.getYear(value);
154
155
  }
155
156
  return null;
156
- }, [value, utils]);
157
- const [focusedYear, setFocusedYear] = React.useState(() => selectedYear || utils.getYear(referenceDate));
157
+ }, [value, adapter]);
158
+ const [focusedYear, setFocusedYear] = React.useState(() => selectedYear || adapter.getYear(referenceDate));
158
159
  const [internalHasFocus, setInternalHasFocus] = useControlled({
159
160
  name: 'YearCalendar',
160
161
  state: 'hasFocus',
@@ -168,33 +169,33 @@ export const YearCalendar = /*#__PURE__*/React.forwardRef(function YearCalendar(
168
169
  }
169
170
  });
170
171
  const isYearDisabled = React.useCallback(dateToValidate => {
171
- if (disablePast && utils.isBeforeYear(dateToValidate, now)) {
172
+ if (disablePast && adapter.isBeforeYear(dateToValidate, now)) {
172
173
  return true;
173
174
  }
174
- if (disableFuture && utils.isAfterYear(dateToValidate, now)) {
175
+ if (disableFuture && adapter.isAfterYear(dateToValidate, now)) {
175
176
  return true;
176
177
  }
177
- if (minDate && utils.isBeforeYear(dateToValidate, minDate)) {
178
+ if (minDate && adapter.isBeforeYear(dateToValidate, minDate)) {
178
179
  return true;
179
180
  }
180
- if (maxDate && utils.isAfterYear(dateToValidate, maxDate)) {
181
+ if (maxDate && adapter.isAfterYear(dateToValidate, maxDate)) {
181
182
  return true;
182
183
  }
183
184
  if (!shouldDisableYear) {
184
185
  return false;
185
186
  }
186
- const yearToValidate = utils.startOfYear(dateToValidate);
187
+ const yearToValidate = adapter.startOfYear(dateToValidate);
187
188
  return shouldDisableYear(yearToValidate);
188
- }, [disableFuture, disablePast, maxDate, minDate, now, shouldDisableYear, utils]);
189
+ }, [disableFuture, disablePast, maxDate, minDate, now, shouldDisableYear, adapter]);
189
190
  const handleYearSelection = useEventCallback((event, year) => {
190
191
  if (readOnly) {
191
192
  return;
192
193
  }
193
- const newDate = utils.setYear(value ?? referenceDate, year);
194
+ const newDate = adapter.setYear(value ?? referenceDate, year);
194
195
  handleValueChange(newDate);
195
196
  });
196
197
  const focusYear = useEventCallback(year => {
197
- if (!isYearDisabled(utils.setYear(value ?? referenceDate, year))) {
198
+ if (!isYearDisabled(adapter.setYear(value ?? referenceDate, year))) {
198
199
  setFocusedYear(year);
199
200
  changeHasFocus(true);
200
201
  onYearFocus?.(year);
@@ -258,7 +259,7 @@ export const YearCalendar = /*#__PURE__*/React.forwardRef(function YearCalendar(
258
259
  }
259
260
  scrollerRef.current.scrollTop = elementBottom - clientHeight / 2 - offsetHeight / 2;
260
261
  }, [autoFocus]);
261
- const yearRange = utils.getYearRange([minDate, maxDate]);
262
+ const yearRange = adapter.getYearRange([minDate, maxDate]);
262
263
  if (yearsOrder === 'desc') {
263
264
  yearRange.reverse();
264
265
  }
@@ -275,7 +276,7 @@ export const YearCalendar = /*#__PURE__*/React.forwardRef(function YearCalendar(
275
276
  yearsPerRow: yearsPerRow
276
277
  }, other, {
277
278
  children: [yearRange.map(year => {
278
- const yearNumber = utils.getYear(year);
279
+ const yearNumber = adapter.getYear(year);
279
280
  const isSelected = yearNumber === selectedYear;
280
281
  const isDisabled = disabled || isYearDisabled(year);
281
282
  return /*#__PURE__*/_jsx(YearCalendarButton, {
@@ -292,8 +293,8 @@ export const YearCalendar = /*#__PURE__*/React.forwardRef(function YearCalendar(
292
293
  slots: slots,
293
294
  slotProps: slotProps,
294
295
  classes: classesProp,
295
- children: utils.format(year, 'year')
296
- }, utils.format(year, 'year'));
296
+ children: adapter.format(year, 'year')
297
+ }, adapter.format(year, 'year'));
297
298
  }), Array.from({
298
299
  length: fillerAmount
299
300
  }, (_, index) => /*#__PURE__*/_jsx(YearCalendarButtonFiller, {}, index))]
@@ -3,4 +3,5 @@ export { useSplitFieldProps } from "./useSplitFieldProps.js";
3
3
  export { useParsedFormat } from "./useParsedFormat.js";
4
4
  export { usePickerContext } from "./usePickerContext.js";
5
5
  export { usePickerActionsContext } from "./usePickerActionsContext.js";
6
- export { useIsValidValue } from "./useIsValidValue.js";
6
+ export { useIsValidValue } from "./useIsValidValue.js";
7
+ export { usePickerAdapter } from "./usePickerAdapter.js";
@@ -3,4 +3,5 @@ export { useSplitFieldProps } from "./useSplitFieldProps.js";
3
3
  export { useParsedFormat } from "./useParsedFormat.js";
4
4
  export { usePickerContext } from "./usePickerContext.js";
5
5
  export { usePickerActionsContext } from "./usePickerActionsContext.js";
6
- export { useIsValidValue } from "./useIsValidValue.js";
6
+ export { useIsValidValue } from "./useIsValidValue.js";
7
+ export { usePickerAdapter } from "./usePickerAdapter.js";
@@ -2,7 +2,7 @@
2
2
 
3
3
  import * as React from 'react';
4
4
  import { useRtl } from '@mui/system/RtlProvider';
5
- import { useUtils } from "../internals/hooks/useUtils.js";
5
+ import { usePickerAdapter } from "./usePickerAdapter.js";
6
6
  import { buildSectionsFromFormat } from "../internals/hooks/useField/buildSectionsFromFormat.js";
7
7
  import { getLocalizedDigits } from "../internals/hooks/useField/useField.utils.js";
8
8
  import { usePickerTranslations } from "./usePickerTranslations.js";
@@ -16,16 +16,16 @@ import { useNullablePickerContext } from "../internals/hooks/useNullablePickerCo
16
16
  */
17
17
  export const useParsedFormat = (parameters = {}) => {
18
18
  const pickerContext = useNullablePickerContext();
19
- const utils = useUtils();
19
+ const adapter = usePickerAdapter();
20
20
  const isRtl = useRtl();
21
21
  const translations = usePickerTranslations();
22
- const localizedDigits = React.useMemo(() => getLocalizedDigits(utils), [utils]);
22
+ const localizedDigits = React.useMemo(() => getLocalizedDigits(adapter), [adapter]);
23
23
  const {
24
- format = pickerContext?.fieldFormat ?? utils.formats.fullDate
24
+ format = pickerContext?.fieldFormat ?? adapter.formats.fullDate
25
25
  } = parameters;
26
26
  return React.useMemo(() => {
27
27
  const sections = buildSectionsFromFormat({
28
- utils,
28
+ adapter,
29
29
  format,
30
30
  formatDensity: 'dense',
31
31
  isRtl,
@@ -37,5 +37,5 @@ export const useParsedFormat = (parameters = {}) => {
37
37
  enableAccessibleFieldDOMStructure: false
38
38
  });
39
39
  return sections.map(section => `${section.startSeparator}${section.placeholder}${section.endSeparator}`).join('');
40
- }, [utils, isRtl, translations, localizedDigits, format]);
40
+ }, [adapter, isRtl, translations, localizedDigits, format]);
41
41
  };
@@ -0,0 +1,7 @@
1
+ import { PickersAdapterContextValue } from "../LocalizationProvider/LocalizationProvider.js";
2
+ import { PickersLocaleText } from "../locales/utils/pickersLocaleTextApi.js";
3
+ export declare const useLocalizationContext: () => UseLocalizationContextReturnValue;
4
+ export interface UseLocalizationContextReturnValue extends Omit<PickersAdapterContextValue, 'localeText'> {
5
+ localeText: PickersLocaleText;
6
+ }
7
+ export declare const usePickerAdapter: () => import("@mui/x-date-pickers/models").MuiPickersAdapter<any>;
@@ -0,0 +1,20 @@
1
+ 'use client';
2
+
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import * as React from 'react';
5
+ import { DEFAULT_LOCALE } from "../locales/enUS.js";
6
+ import { PickerAdapterContext } from "../LocalizationProvider/LocalizationProvider.js";
7
+ export const useLocalizationContext = () => {
8
+ const localization = React.useContext(PickerAdapterContext);
9
+ if (localization === null) {
10
+ throw new Error(['MUI X: Can not find the date and time pickers localization context.', 'It looks like you forgot to wrap your component in LocalizationProvider.', 'This can also happen if you are bundling multiple versions of the `@mui/x-date-pickers` package'].join('\n'));
11
+ }
12
+ if (localization.adapter === null) {
13
+ throw new Error(['MUI X: Can not find the date and time pickers adapter from its localization context.', 'It looks like you forgot to pass a `dateAdapter` to your LocalizationProvider.'].join('\n'));
14
+ }
15
+ const localeText = React.useMemo(() => _extends({}, DEFAULT_LOCALE, localization.localeText), [localization.localeText]);
16
+ return React.useMemo(() => _extends({}, localization, {
17
+ localeText
18
+ }), [localization, localeText]);
19
+ };
20
+ export const usePickerAdapter = () => useLocalizationContext().adapter;
@@ -1,4 +1,4 @@
1
1
  'use client';
2
2
 
3
- import { useLocalizationContext } from "../internals/hooks/useUtils.js";
3
+ import { useLocalizationContext } from "./usePickerAdapter.js";
4
4
  export const usePickerTranslations = () => useLocalizationContext().localeText;
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-date-pickers v8.5.3
2
+ * @mui/x-date-pickers v8.6.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -8,4 +8,4 @@ export interface PickersToolbarClasses {
8
8
  }
9
9
  export type PickersToolbarClassKey = keyof PickersToolbarClasses;
10
10
  export declare function getPickersToolbarUtilityClass(slot: string): string;
11
- export declare const pickersToolbarClasses: Record<"root" | "content" | "title", string>;
11
+ export declare const pickersToolbarClasses: Record<"root" | "title" | "content", string>;
@@ -1,15 +1,14 @@
1
1
  import * as React from 'react';
2
+ import { StackProps } from '@mui/material/Stack';
2
3
  import { SxProps, Theme } from '@mui/material/styles';
3
4
  interface DemoGridProps {
4
5
  children: React.ReactNode;
5
6
  components: string[];
6
7
  sx?: SxProps<Theme>;
7
8
  }
8
- interface DemoItemProps {
9
+ interface DemoItemProps extends Omit<StackProps, 'component'> {
9
10
  label?: React.ReactNode;
10
11
  component?: string;
11
- children: React.ReactNode;
12
- sx?: SxProps<Theme>;
13
12
  }
14
13
  /**
15
14
  * WARNING: This is an internal component used in documentation to achieve a desired layout.
@@ -41,7 +41,8 @@ export function DemoItem(props) {
41
41
  label,
42
42
  children,
43
43
  component,
44
- sx: sxProp
44
+ sx: sxProp,
45
+ alignItems = 'stretch'
45
46
  } = props;
46
47
  let spacing;
47
48
  let sx = sxProp;
@@ -57,7 +58,7 @@ export function DemoItem(props) {
57
58
  }
58
59
  return /*#__PURE__*/_jsxs(Stack, {
59
60
  direction: "column",
60
- alignItems: "stretch",
61
+ alignItems: alignItems,
61
62
  spacing: spacing,
62
63
  sx: sx,
63
64
  children: [label && /*#__PURE__*/_jsx(Typography, {
@@ -1,38 +1,38 @@
1
1
  import * as React from 'react';
2
- import { useUtils } from "./useUtils.js";
3
2
  import { getMeridiem, convertToMeridiem } from "../utils/time-utils.js";
3
+ import { usePickerAdapter } from "../../hooks/usePickerAdapter.js";
4
4
  export function useNextMonthDisabled(month, {
5
5
  disableFuture,
6
6
  maxDate,
7
7
  timezone
8
8
  }) {
9
- const utils = useUtils();
9
+ const adapter = usePickerAdapter();
10
10
  return React.useMemo(() => {
11
- const now = utils.date(undefined, timezone);
12
- const lastEnabledMonth = utils.startOfMonth(disableFuture && utils.isBefore(now, maxDate) ? now : maxDate);
13
- return !utils.isAfter(lastEnabledMonth, month);
14
- }, [disableFuture, maxDate, month, utils, timezone]);
11
+ const now = adapter.date(undefined, timezone);
12
+ const lastEnabledMonth = adapter.startOfMonth(disableFuture && adapter.isBefore(now, maxDate) ? now : maxDate);
13
+ return !adapter.isAfter(lastEnabledMonth, month);
14
+ }, [disableFuture, maxDate, month, adapter, timezone]);
15
15
  }
16
16
  export function usePreviousMonthDisabled(month, {
17
17
  disablePast,
18
18
  minDate,
19
19
  timezone
20
20
  }) {
21
- const utils = useUtils();
21
+ const adapter = usePickerAdapter();
22
22
  return React.useMemo(() => {
23
- const now = utils.date(undefined, timezone);
24
- const firstEnabledMonth = utils.startOfMonth(disablePast && utils.isAfter(now, minDate) ? now : minDate);
25
- return !utils.isBefore(firstEnabledMonth, month);
26
- }, [disablePast, minDate, month, utils, timezone]);
23
+ const now = adapter.date(undefined, timezone);
24
+ const firstEnabledMonth = adapter.startOfMonth(disablePast && adapter.isAfter(now, minDate) ? now : minDate);
25
+ return !adapter.isBefore(firstEnabledMonth, month);
26
+ }, [disablePast, minDate, month, adapter, timezone]);
27
27
  }
28
28
  export function useMeridiemMode(date, ampm, onChange, selectionState) {
29
- const utils = useUtils();
30
- const cleanDate = React.useMemo(() => !utils.isValid(date) ? null : date, [utils, date]);
31
- const meridiemMode = getMeridiem(cleanDate, utils);
29
+ const adapter = usePickerAdapter();
30
+ const cleanDate = React.useMemo(() => !adapter.isValid(date) ? null : date, [adapter, date]);
31
+ const meridiemMode = getMeridiem(cleanDate, adapter);
32
32
  const handleMeridiemChange = React.useCallback(mode => {
33
- const timeWithMeridiem = cleanDate == null ? null : convertToMeridiem(cleanDate, mode, Boolean(ampm), utils);
33
+ const timeWithMeridiem = cleanDate == null ? null : convertToMeridiem(cleanDate, mode, Boolean(ampm), adapter);
34
34
  onChange(timeWithMeridiem, selectionState ?? 'partial');
35
- }, [ampm, cleanDate, onChange, selectionState, utils]);
35
+ }, [ampm, cleanDate, onChange, selectionState, adapter]);
36
36
  return {
37
37
  meridiemMode,
38
38
  handleMeridiemChange
@@ -3,13 +3,13 @@ import { PickerValue } from "../models/index.js";
3
3
  export declare const useClockReferenceDate: <TProps extends {}>({
4
4
  value,
5
5
  referenceDate: referenceDateProp,
6
- utils,
6
+ adapter,
7
7
  props,
8
8
  timezone
9
9
  }: {
10
10
  value: PickerValue;
11
11
  referenceDate: PickerValidDate | undefined;
12
- utils: MuiPickersAdapter;
12
+ adapter: MuiPickersAdapter;
13
13
  props: TProps;
14
14
  timezone: PickersTimezone;
15
15
  }) => PickerValidDate;
@@ -5,18 +5,18 @@ import { SECTION_TYPE_GRANULARITY } from "../utils/getDefaultReferenceDate.js";
5
5
  export const useClockReferenceDate = ({
6
6
  value,
7
7
  referenceDate: referenceDateProp,
8
- utils,
8
+ adapter,
9
9
  props,
10
10
  timezone
11
11
  }) => {
12
12
  const referenceDate = React.useMemo(() => singleItemValueManager.getInitialReferenceValue({
13
13
  value,
14
- utils,
14
+ adapter,
15
15
  props,
16
16
  referenceDate: referenceDateProp,
17
17
  granularity: SECTION_TYPE_GRANULARITY.day,
18
18
  timezone,
19
- getTodayDate: () => getTodayDate(utils, timezone, 'date')
19
+ getTodayDate: () => getTodayDate(adapter, timezone, 'date')
20
20
  }),
21
21
  // We only want to compute the reference date on mount.
22
22
  [] // eslint-disable-line react-hooks/exhaustive-deps
@@ -1,7 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import useEventCallback from '@mui/utils/useEventCallback';
3
3
  import useControlled from '@mui/utils/useControlled';
4
- import { useUtils } from "./useUtils.js";
4
+ import { usePickerAdapter } from "../../hooks/usePickerAdapter.js";
5
+
5
6
  /**
6
7
  * Hooks controlling the value while making sure that:
7
8
  * - The value returned by `onChange` always have the timezone of `props.value` or `props.defaultValue` if defined
@@ -16,19 +17,19 @@ export const useControlledValue = ({
16
17
  onChange: onChangeProp,
17
18
  valueManager
18
19
  }) => {
19
- const utils = useUtils();
20
+ const adapter = usePickerAdapter();
20
21
  const [valueWithInputTimezone, setValue] = useControlled({
21
22
  name,
22
23
  state: 'value',
23
24
  controlled: valueProp,
24
25
  default: defaultValue ?? valueManager.emptyValue
25
26
  });
26
- const inputTimezone = React.useMemo(() => valueManager.getTimezone(utils, valueWithInputTimezone), [utils, valueManager, valueWithInputTimezone]);
27
+ const inputTimezone = React.useMemo(() => valueManager.getTimezone(adapter, valueWithInputTimezone), [adapter, valueManager, valueWithInputTimezone]);
27
28
  const setInputTimezone = useEventCallback(newValue => {
28
29
  if (inputTimezone == null) {
29
30
  return newValue;
30
31
  }
31
- return valueManager.setTimezone(utils, inputTimezone, newValue);
32
+ return valueManager.setTimezone(adapter, inputTimezone, newValue);
32
33
  });
33
34
  const timezoneToRender = React.useMemo(() => {
34
35
  if (timezoneProp) {
@@ -38,11 +39,11 @@ export const useControlledValue = ({
38
39
  return inputTimezone;
39
40
  }
40
41
  if (referenceDate) {
41
- return utils.getTimezone(referenceDate);
42
+ return adapter.getTimezone(referenceDate);
42
43
  }
43
44
  return 'default';
44
- }, [timezoneProp, inputTimezone, referenceDate, utils]);
45
- const valueWithTimezoneToRender = React.useMemo(() => valueManager.setTimezone(utils, timezoneToRender, valueWithInputTimezone), [valueManager, utils, timezoneToRender, valueWithInputTimezone]);
45
+ }, [timezoneProp, inputTimezone, referenceDate, adapter]);
46
+ const valueWithTimezoneToRender = React.useMemo(() => valueManager.setTimezone(adapter, timezoneToRender, valueWithInputTimezone), [valueManager, adapter, timezoneToRender, valueWithInputTimezone]);
46
47
  const handleValueChange = useEventCallback((newValue, ...otherParams) => {
47
48
  const newValueWithInputTimezone = setInputTimezone(newValue);
48
49
  setValue(newValueWithInputTimezone);
@@ -1,7 +1,7 @@
1
1
  import { FieldSection, MuiPickersAdapter, PickerValidDate } from "../../../models/index.js";
2
2
  import { PickersLocaleText } from "../../../locales/index.js";
3
3
  interface BuildSectionsFromFormatParameters {
4
- utils: MuiPickersAdapter;
4
+ adapter: MuiPickersAdapter;
5
5
  format: string;
6
6
  formatDensity: 'dense' | 'spacious';
7
7
  isRtl: boolean;
@@ -1,16 +1,16 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import { applyLocalizedDigits, cleanLeadingZeros, doesSectionFormatHaveLeadingZeros, getDateSectionConfigFromFormatToken, removeLocalizedDigits } from "./useField.utils.js";
3
3
  const expandFormat = ({
4
- utils,
4
+ adapter,
5
5
  format
6
6
  }) => {
7
7
  // Expand the provided format
8
8
  let formatExpansionOverflow = 10;
9
9
  let prevFormat = format;
10
- let nextFormat = utils.expandFormat(format);
10
+ let nextFormat = adapter.expandFormat(format);
11
11
  while (nextFormat !== prevFormat) {
12
12
  prevFormat = nextFormat;
13
- nextFormat = utils.expandFormat(prevFormat);
13
+ nextFormat = adapter.expandFormat(prevFormat);
14
14
  formatExpansionOverflow -= 1;
15
15
  if (formatExpansionOverflow < 0) {
16
16
  throw new Error('MUI X: The format expansion seems to be in an infinite loop. Please open an issue with the format passed to the component.');
@@ -19,14 +19,14 @@ const expandFormat = ({
19
19
  return nextFormat;
20
20
  };
21
21
  const getEscapedPartsFromFormat = ({
22
- utils,
22
+ adapter,
23
23
  expandedFormat
24
24
  }) => {
25
25
  const escapedParts = [];
26
26
  const {
27
27
  start: startChar,
28
28
  end: endChar
29
- } = utils.escapedCharacters;
29
+ } = adapter.escapedCharacters;
30
30
  const regExp = new RegExp(`(\\${startChar}[^\\${endChar}]*\\${endChar})+`, 'g');
31
31
  let match = null;
32
32
  // eslint-disable-next-line no-cond-assign
@@ -38,12 +38,12 @@ const getEscapedPartsFromFormat = ({
38
38
  }
39
39
  return escapedParts;
40
40
  };
41
- const getSectionPlaceholder = (utils, localeText, sectionConfig, sectionFormat) => {
41
+ const getSectionPlaceholder = (adapter, localeText, sectionConfig, sectionFormat) => {
42
42
  switch (sectionConfig.type) {
43
43
  case 'year':
44
44
  {
45
45
  return localeText.fieldYearPlaceholder({
46
- digitAmount: utils.formatByString(utils.date(undefined, 'default'), sectionFormat).length,
46
+ digitAmount: adapter.formatByString(adapter.date(undefined, 'default'), sectionFormat).length,
47
47
  format: sectionFormat
48
48
  });
49
49
  }
@@ -98,7 +98,7 @@ const getSectionPlaceholder = (utils, localeText, sectionConfig, sectionFormat)
98
98
  }
99
99
  };
100
100
  const createSection = ({
101
- utils,
101
+ adapter,
102
102
  date,
103
103
  shouldRespectLeadingZeros,
104
104
  localeText,
@@ -110,15 +110,15 @@ const createSection = ({
110
110
  if (token === '') {
111
111
  throw new Error('MUI X: Should not call `commitToken` with an empty token');
112
112
  }
113
- const sectionConfig = getDateSectionConfigFromFormatToken(utils, token);
114
- const hasLeadingZerosInFormat = doesSectionFormatHaveLeadingZeros(utils, sectionConfig.contentType, sectionConfig.type, token);
113
+ const sectionConfig = getDateSectionConfigFromFormatToken(adapter, token);
114
+ const hasLeadingZerosInFormat = doesSectionFormatHaveLeadingZeros(adapter, sectionConfig.contentType, sectionConfig.type, token);
115
115
  const hasLeadingZerosInInput = shouldRespectLeadingZeros ? hasLeadingZerosInFormat : sectionConfig.contentType === 'digit';
116
- const isValidDate = utils.isValid(date);
117
- let sectionValue = isValidDate ? utils.formatByString(date, token) : '';
116
+ const isValidDate = adapter.isValid(date);
117
+ let sectionValue = isValidDate ? adapter.formatByString(date, token) : '';
118
118
  let maxLength = null;
119
119
  if (hasLeadingZerosInInput) {
120
120
  if (hasLeadingZerosInFormat) {
121
- maxLength = sectionValue === '' ? utils.formatByString(now, token).length : sectionValue.length;
121
+ maxLength = sectionValue === '' ? adapter.formatByString(now, token).length : sectionValue.length;
122
122
  } else {
123
123
  if (sectionConfig.maxLength == null) {
124
124
  throw new Error(`MUI X: The token ${token} should have a 'maxLength' property on it's adapter`);
@@ -133,7 +133,7 @@ const createSection = ({
133
133
  format: token,
134
134
  maxLength,
135
135
  value: sectionValue,
136
- placeholder: getSectionPlaceholder(utils, localeText, sectionConfig, token),
136
+ placeholder: getSectionPlaceholder(adapter, localeText, sectionConfig, token),
137
137
  hasLeadingZerosInFormat,
138
138
  hasLeadingZerosInInput,
139
139
  startSeparator,
@@ -143,16 +143,16 @@ const createSection = ({
143
143
  };
144
144
  const buildSections = parameters => {
145
145
  const {
146
- utils,
146
+ adapter,
147
147
  expandedFormat,
148
148
  escapedParts
149
149
  } = parameters;
150
- const now = utils.date(undefined);
150
+ const now = adapter.date(undefined);
151
151
  const sections = [];
152
152
  let startSeparator = '';
153
153
 
154
154
  // This RegExp tests if the beginning of a string corresponds to a supported token
155
- const validTokens = Object.keys(utils.formatTokenMap).sort((a, b) => b.length - a.length); // Sort to put longest word first
155
+ const validTokens = Object.keys(adapter.formatTokenMap).sort((a, b) => b.length - a.length); // Sort to put longest word first
156
156
 
157
157
  const regExpFirstWordInFormat = /^([a-zA-Z]+)/;
158
158
  const regExpWordOnlyComposedOfTokens = new RegExp(`^(${validTokens.join('|')})*$`);
@@ -201,12 +201,12 @@ export interface FieldValueManager<TValue extends PickerValidValue> {
201
201
  * Update the reference value with the new value.
202
202
  * This method must make sure that no date inside the returned `referenceValue` is invalid.
203
203
  * @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
204
- * @param {MuiPickersAdapter} utils The utils to manipulate the date.
204
+ * @param {MuiPickersAdapter} adapter The adapter to manipulate the date.
205
205
  * @param {TValue} value The new value from which we want to take all valid dates in the `referenceValue` state.
206
206
  * @param {TValue} prevReferenceValue The previous reference value. It is used as a fallback for invalid dates in the new value.
207
207
  * @returns {TValue} The new reference value with no invalid date.
208
208
  */
209
- updateReferenceValue: (utils: MuiPickersAdapter, value: TValue, prevReferenceValue: InferNonNullablePickerValue<TValue>) => InferNonNullablePickerValue<TValue>;
209
+ updateReferenceValue: (adapter: MuiPickersAdapter, value: TValue, prevReferenceValue: InferNonNullablePickerValue<TValue>) => InferNonNullablePickerValue<TValue>;
210
210
  /**
211
211
  * Extract from the given value the date that contains the given section.
212
212
  * @param {TValue} value The value to extract the date from.
@@ -1,13 +1,13 @@
1
1
  import { FieldSectionsValueBoundaries, SectionOrdering, FieldSectionValueBoundaries, FieldParsedSelectedSections } from "./useField.types.js";
2
2
  import { FieldSectionType, FieldSection, MuiPickersAdapter, FieldSectionContentType, PickersTimezone, PickerValidDate, FieldSelectedSections, PickerValueType, InferFieldSection } from "../../../models/index.js";
3
3
  import { PickerValidValue } from "../../models/index.js";
4
- export declare const getDateSectionConfigFromFormatToken: (utils: MuiPickersAdapter, formatToken: string) => Pick<FieldSection, "type" | "contentType"> & {
4
+ export declare const getDateSectionConfigFromFormatToken: (adapter: MuiPickersAdapter, formatToken: string) => Pick<FieldSection, "type" | "contentType"> & {
5
5
  maxLength: number | undefined;
6
6
  };
7
- export declare const getDaysInWeekStr: (utils: MuiPickersAdapter, format: string) => string[];
8
- export declare const getLetterEditingOptions: (utils: MuiPickersAdapter, timezone: PickersTimezone, sectionType: FieldSectionType, format: string) => string[];
7
+ export declare const getDaysInWeekStr: (adapter: MuiPickersAdapter, format: string) => string[];
8
+ export declare const getLetterEditingOptions: (adapter: MuiPickersAdapter, timezone: PickersTimezone, sectionType: FieldSectionType, format: string) => string[];
9
9
  export declare const FORMAT_SECONDS_NO_LEADING_ZEROS = "s";
10
- export declare const getLocalizedDigits: (utils: MuiPickersAdapter) => string[];
10
+ export declare const getLocalizedDigits: (adapter: MuiPickersAdapter) => string[];
11
11
  export declare const removeLocalizedDigits: (valueStr: string, localizedDigits: string[]) => string;
12
12
  export declare const applyLocalizedDigits: (valueStr: string, localizedDigits: string[]) => string;
13
13
  export declare const isStringNumber: (valueStr: string, localizedDigits: string[]) => boolean;
@@ -17,20 +17,20 @@ export declare const isStringNumber: (valueStr: string, localizedDigits: string[
17
17
  * Warning: Should only be called with non-localized digits. Call `removeLocalizedDigits` with your value if needed.
18
18
  */
19
19
  export declare const cleanLeadingZeros: (valueStr: string, size: number) => string;
20
- export declare const cleanDigitSectionValue: (utils: MuiPickersAdapter, value: number, sectionBoundaries: FieldSectionValueBoundaries<any>, localizedDigits: string[], section: Pick<FieldSection, "format" | "type" | "contentType" | "hasLeadingZerosInFormat" | "hasLeadingZerosInInput" | "maxLength">) => string;
20
+ export declare const cleanDigitSectionValue: (adapter: MuiPickersAdapter, value: number, sectionBoundaries: FieldSectionValueBoundaries<any>, localizedDigits: string[], section: Pick<FieldSection, "format" | "type" | "contentType" | "hasLeadingZerosInFormat" | "hasLeadingZerosInInput" | "maxLength">) => string;
21
21
  export declare const getSectionVisibleValue: (section: FieldSection, target: "input-rtl" | "input-ltr" | "non-input", localizedDigits: string[]) => string;
22
- export declare const changeSectionValueFormat: (utils: MuiPickersAdapter, valueStr: string, currentFormat: string, newFormat: string) => string;
23
- export declare const doesSectionFormatHaveLeadingZeros: (utils: MuiPickersAdapter, contentType: FieldSectionContentType, sectionType: FieldSectionType, format: string) => boolean;
22
+ export declare const changeSectionValueFormat: (adapter: MuiPickersAdapter, valueStr: string, currentFormat: string, newFormat: string) => string;
23
+ export declare const doesSectionFormatHaveLeadingZeros: (adapter: MuiPickersAdapter, contentType: FieldSectionContentType, sectionType: FieldSectionType, format: string) => boolean;
24
24
  /**
25
25
  * Some date libraries like `dayjs` don't support parsing from date with escaped characters.
26
26
  * To make sure that the parsing works, we are building a format and a date without any separator.
27
27
  */
28
- export declare const getDateFromDateSections: (utils: MuiPickersAdapter, sections: FieldSection[], localizedDigits: string[]) => PickerValidDate;
28
+ export declare const getDateFromDateSections: (adapter: MuiPickersAdapter, sections: FieldSection[], localizedDigits: string[]) => PickerValidDate;
29
29
  export declare const createDateStrForV7HiddenInputFromSections: (sections: FieldSection[]) => string;
30
30
  export declare const createDateStrForV6InputFromSections: (sections: FieldSection[], localizedDigits: string[], isRtl: boolean) => string;
31
- export declare const getSectionsBoundaries: (utils: MuiPickersAdapter, localizedDigits: string[], timezone: PickersTimezone) => FieldSectionsValueBoundaries;
31
+ export declare const getSectionsBoundaries: (adapter: MuiPickersAdapter, localizedDigits: string[], timezone: PickersTimezone) => FieldSectionsValueBoundaries;
32
32
  export declare const validateSections: <TValue extends PickerValidValue>(sections: InferFieldSection<TValue>[], valueType: PickerValueType) => void;
33
- export declare const mergeDateIntoReferenceDate: (utils: MuiPickersAdapter, dateToTransferFrom: PickerValidDate, sections: FieldSection[], referenceDate: PickerValidDate, shouldLimitToEditedSections: boolean) => PickerValidDate;
33
+ export declare const mergeDateIntoReferenceDate: (adapter: MuiPickersAdapter, dateToTransferFrom: PickerValidDate, sections: FieldSection[], referenceDate: PickerValidDate, shouldLimitToEditedSections: boolean) => PickerValidDate;
34
34
  export declare const isAndroid: () => boolean;
35
35
  export declare const getSectionOrder: (sections: FieldSection[], shouldApplyRTL: boolean) => SectionOrdering;
36
36
  export declare const parseSelectedSections: (selectedSections: FieldSelectedSections, sections: FieldSection[]) => FieldParsedSelectedSections;