@mui/x-date-pickers 8.5.3 → 8.7.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/CHANGELOG.md +210 -0
- package/DateCalendar/DateCalendar.js +16 -16
- package/DateCalendar/DayCalendar.js +48 -48
- package/DateCalendar/useCalendarState.js +25 -25
- package/DateCalendar/useIsDateDisabled.js +2 -2
- package/DatePicker/DatePickerToolbar.js +7 -9
- package/DateTimeField/DateTimeField.js +1 -1
- package/DateTimePicker/DateTimePicker.js +1 -1
- package/DateTimePicker/DateTimePickerToolbar.js +12 -13
- package/DateTimePicker/shared.js +3 -3
- package/DesktopDatePicker/DesktopDatePicker.js +3 -3
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +4 -4
- package/DesktopTimePicker/DesktopTimePicker.js +4 -4
- package/DigitalClock/DigitalClock.d.ts +1 -1
- package/DigitalClock/DigitalClock.js +16 -16
- package/LocalizationProvider/LocalizationProvider.d.ts +9 -3
- package/LocalizationProvider/LocalizationProvider.js +28 -19
- package/MobileDatePicker/MobileDatePicker.js +3 -3
- package/MobileDateTimePicker/MobileDateTimePicker.js +4 -4
- package/MobileTimePicker/MobileTimePicker.js +4 -4
- package/MonthCalendar/MonthCalendar.js +19 -18
- package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +32 -32
- package/MultiSectionDigitalClock/MultiSectionDigitalClock.utils.d.ts +4 -4
- package/MultiSectionDigitalClock/MultiSectionDigitalClock.utils.js +7 -7
- package/PickerDay2/PickerDay2.js +3 -3
- package/PickersActionBar/PickersActionBar.d.ts +2 -2
- package/PickersActionBar/PickersActionBar.js +2 -2
- package/PickersCalendarHeader/PickersCalendarHeader.js +7 -8
- package/PickersDay/PickersDay.js +3 -3
- package/PickersDay/usePickerDayOwnerState.js +5 -5
- package/PickersTextField/PickersInputBase/PickersInputBase.js +1 -0
- package/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
- package/StaticTimePicker/StaticTimePicker.js +1 -1
- package/TimeClock/Clock.js +8 -9
- package/TimeClock/ClockNumbers.d.ts +3 -3
- package/TimeClock/ClockNumbers.js +5 -5
- package/TimeClock/TimeClock.js +29 -29
- package/TimeField/TimeField.js +1 -1
- package/TimePicker/TimePicker.js +1 -1
- package/TimePicker/TimePickerToolbar.js +7 -9
- package/TimePicker/shared.js +3 -3
- package/YearCalendar/YearCalendar.js +19 -18
- package/esm/DateCalendar/DateCalendar.js +16 -16
- package/esm/DateCalendar/DayCalendar.js +48 -48
- package/esm/DateCalendar/useCalendarState.js +25 -25
- package/esm/DateCalendar/useIsDateDisabled.js +2 -2
- package/esm/DatePicker/DatePickerToolbar.js +6 -8
- package/esm/DateTimeField/DateTimeField.js +1 -1
- package/esm/DateTimePicker/DateTimePicker.js +1 -1
- package/esm/DateTimePicker/DateTimePickerToolbar.js +11 -12
- package/esm/DateTimePicker/shared.js +3 -3
- package/esm/DesktopDatePicker/DesktopDatePicker.js +3 -3
- package/esm/DesktopDateTimePicker/DesktopDateTimePicker.js +4 -4
- package/esm/DesktopTimePicker/DesktopTimePicker.js +4 -4
- package/esm/DigitalClock/DigitalClock.d.ts +1 -1
- package/esm/DigitalClock/DigitalClock.js +16 -16
- package/esm/LocalizationProvider/LocalizationProvider.d.ts +9 -3
- package/esm/LocalizationProvider/LocalizationProvider.js +27 -18
- package/esm/MobileDatePicker/MobileDatePicker.js +3 -3
- package/esm/MobileDateTimePicker/MobileDateTimePicker.js +4 -4
- package/esm/MobileTimePicker/MobileTimePicker.js +4 -4
- package/esm/MonthCalendar/MonthCalendar.js +20 -19
- package/esm/MultiSectionDigitalClock/MultiSectionDigitalClock.js +32 -32
- package/esm/MultiSectionDigitalClock/MultiSectionDigitalClock.utils.d.ts +4 -4
- package/esm/MultiSectionDigitalClock/MultiSectionDigitalClock.utils.js +7 -7
- package/esm/PickerDay2/PickerDay2.js +3 -3
- package/esm/PickersActionBar/PickersActionBar.d.ts +2 -2
- package/esm/PickersActionBar/PickersActionBar.js +2 -2
- package/esm/PickersCalendarHeader/PickersCalendarHeader.js +6 -7
- package/esm/PickersDay/PickersDay.js +3 -3
- package/esm/PickersDay/usePickerDayOwnerState.js +5 -5
- package/esm/PickersTextField/PickersInputBase/PickersInputBase.js +2 -0
- package/esm/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
- package/esm/StaticTimePicker/StaticTimePicker.js +1 -1
- package/esm/TimeClock/Clock.js +7 -8
- package/esm/TimeClock/ClockNumbers.d.ts +3 -3
- package/esm/TimeClock/ClockNumbers.js +5 -5
- package/esm/TimeClock/TimeClock.js +29 -29
- package/esm/TimeField/TimeField.js +1 -1
- package/esm/TimePicker/TimePicker.js +1 -1
- package/esm/TimePicker/TimePickerToolbar.js +6 -8
- package/esm/TimePicker/shared.js +3 -3
- package/esm/YearCalendar/YearCalendar.js +20 -19
- package/esm/hooks/index.d.ts +2 -1
- package/esm/hooks/index.js +2 -1
- package/esm/hooks/useParsedFormat.js +6 -6
- package/esm/hooks/usePickerAdapter.d.ts +7 -0
- package/esm/hooks/usePickerAdapter.js +20 -0
- package/esm/hooks/usePickerTranslations.js +1 -1
- package/esm/index.js +1 -1
- package/esm/internals/components/PickerFieldUI.js +2 -0
- package/esm/internals/components/PickerPopper/PickerPopper.js +2 -0
- package/esm/internals/components/PickerProvider.js +2 -0
- package/esm/internals/components/pickersToolbarClasses.d.ts +1 -1
- package/esm/internals/demo/DemoContainer.d.ts +2 -3
- package/esm/internals/demo/DemoContainer.js +3 -2
- package/esm/internals/hooks/date-helpers-hooks.js +16 -16
- package/esm/internals/hooks/useClockReferenceDate.d.ts +2 -2
- package/esm/internals/hooks/useClockReferenceDate.js +5 -5
- package/esm/internals/hooks/useControlledValue.d.ts +2 -2
- package/esm/internals/hooks/useControlledValue.js +8 -7
- package/esm/internals/hooks/useField/buildSectionsFromFormat.d.ts +1 -1
- package/esm/internals/hooks/useField/buildSectionsFromFormat.js +17 -17
- package/esm/internals/hooks/useField/useField.types.d.ts +4 -4
- package/esm/internals/hooks/useField/useField.utils.d.ts +10 -10
- package/esm/internals/hooks/useField/useField.utils.js +69 -69
- package/esm/internals/hooks/useField/useFieldCharacterEditing.js +11 -11
- package/esm/internals/hooks/useField/useFieldRootHandleKeyDown.js +7 -7
- package/esm/internals/hooks/useField/useFieldSectionContentProps.js +15 -16
- package/esm/internals/hooks/useField/useFieldState.js +24 -24
- package/esm/internals/hooks/useField/useFieldV6TextField.js +2 -0
- package/esm/internals/hooks/useField/useFieldV7TextField.js +2 -0
- package/esm/internals/hooks/useNullableFieldPrivateContext.js +2 -0
- package/esm/internals/hooks/usePicker/hooks/useOrientation.js +2 -0
- package/esm/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +8 -6
- package/esm/internals/hooks/usePicker/usePicker.js +7 -6
- package/esm/internals/hooks/usePicker/usePicker.types.d.ts +3 -3
- package/esm/internals/hooks/useUtils.d.ts +1 -8
- package/esm/internals/hooks/useUtils.js +3 -19
- package/esm/internals/hooks/useViews.js +2 -0
- package/esm/internals/index.d.ts +2 -1
- package/esm/internals/index.js +2 -1
- package/esm/internals/models/manager.d.ts +17 -17
- package/esm/internals/models/props/time.d.ts +1 -1
- package/esm/internals/utils/date-time-utils.d.ts +1 -1
- package/esm/internals/utils/date-time-utils.js +5 -5
- package/esm/internals/utils/date-utils.d.ts +11 -11
- package/esm/internals/utils/date-utils.js +34 -34
- package/esm/internals/utils/getDefaultReferenceDate.d.ts +2 -2
- package/esm/internals/utils/getDefaultReferenceDate.js +16 -16
- package/esm/internals/utils/time-utils.d.ts +5 -5
- package/esm/internals/utils/time-utils.js +12 -12
- package/esm/internals/utils/valueManagers.js +4 -4
- package/esm/managers/useDateManager.js +12 -12
- package/esm/managers/useDateTimeManager.js +13 -13
- package/esm/managers/useTimeManager.js +9 -10
- package/esm/validation/useValidation.d.ts +2 -3
- package/esm/validation/useValidation.js +2 -2
- package/esm/validation/validateDate.js +6 -6
- package/esm/validation/validateTime.js +6 -6
- package/hooks/index.d.ts +2 -1
- package/hooks/index.js +8 -1
- package/hooks/useParsedFormat.js +6 -6
- package/hooks/usePickerAdapter.d.ts +7 -0
- package/hooks/usePickerAdapter.js +29 -0
- package/hooks/usePickerTranslations.js +2 -2
- package/index.js +1 -1
- package/internals/components/PickerFieldUI.js +1 -0
- package/internals/components/PickerPopper/PickerPopper.js +1 -0
- package/internals/components/PickerProvider.js +1 -0
- package/internals/components/pickersToolbarClasses.d.ts +1 -1
- package/internals/demo/DemoContainer.d.ts +2 -3
- package/internals/demo/DemoContainer.js +3 -2
- package/internals/hooks/date-helpers-hooks.js +16 -16
- package/internals/hooks/useClockReferenceDate.d.ts +2 -2
- package/internals/hooks/useClockReferenceDate.js +5 -5
- package/internals/hooks/useControlledValue.d.ts +2 -2
- package/internals/hooks/useControlledValue.js +7 -7
- package/internals/hooks/useField/buildSectionsFromFormat.d.ts +1 -1
- package/internals/hooks/useField/buildSectionsFromFormat.js +17 -17
- package/internals/hooks/useField/useField.types.d.ts +4 -4
- package/internals/hooks/useField/useField.utils.d.ts +10 -10
- package/internals/hooks/useField/useField.utils.js +69 -69
- package/internals/hooks/useField/useFieldCharacterEditing.js +11 -11
- package/internals/hooks/useField/useFieldRootHandleKeyDown.js +7 -7
- package/internals/hooks/useField/useFieldSectionContentProps.js +14 -15
- package/internals/hooks/useField/useFieldState.js +24 -25
- package/internals/hooks/useField/useFieldV6TextField.js +1 -0
- package/internals/hooks/useField/useFieldV7TextField.js +1 -0
- package/internals/hooks/useNullableFieldPrivateContext.js +1 -0
- package/internals/hooks/usePicker/hooks/useOrientation.js +1 -0
- package/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +7 -6
- package/internals/hooks/usePicker/usePicker.js +6 -6
- package/internals/hooks/usePicker/usePicker.types.d.ts +3 -3
- package/internals/hooks/useUtils.d.ts +1 -8
- package/internals/hooks/useUtils.js +5 -24
- package/internals/hooks/useViews.js +1 -0
- package/internals/index.d.ts +2 -1
- package/internals/index.js +2 -7
- package/internals/models/manager.d.ts +17 -17
- package/internals/models/props/time.d.ts +1 -1
- package/internals/utils/date-time-utils.d.ts +1 -1
- package/internals/utils/date-time-utils.js +5 -5
- package/internals/utils/date-utils.d.ts +11 -11
- package/internals/utils/date-utils.js +34 -34
- package/internals/utils/getDefaultReferenceDate.d.ts +2 -2
- package/internals/utils/getDefaultReferenceDate.js +16 -16
- package/internals/utils/time-utils.d.ts +5 -5
- package/internals/utils/time-utils.js +12 -12
- package/internals/utils/valueManagers.js +4 -4
- package/managers/useDateManager.js +12 -12
- package/managers/useDateTimeManager.js +13 -13
- package/managers/useTimeManager.js +10 -11
- package/package.json +2 -2
- package/validation/useValidation.d.ts +2 -3
- package/validation/useValidation.js +2 -2
- package/validation/validateDate.js +6 -6
- package/validation/validateTime.js +6 -6
|
@@ -12,8 +12,7 @@ import { shouldForwardProp } from '@mui/system/createStyled';
|
|
|
12
12
|
import { PickersToolbarText } from "../internals/components/PickersToolbarText.js";
|
|
13
13
|
import { PickersToolbar } from "../internals/components/PickersToolbar.js";
|
|
14
14
|
import { PickersToolbarButton } from "../internals/components/PickersToolbarButton.js";
|
|
15
|
-
import { usePickerTranslations } from "../hooks/
|
|
16
|
-
import { useUtils } from "../internals/hooks/useUtils.js";
|
|
15
|
+
import { usePickerAdapter, usePickerTranslations } from "../hooks/index.js";
|
|
17
16
|
import { dateTimePickerToolbarClasses, getDateTimePickerToolbarUtilityClass } from "./dateTimePickerToolbarClasses.js";
|
|
18
17
|
import { useMeridiemMode } from "../internals/hooks/date-helpers-hooks.js";
|
|
19
18
|
import { MULTI_SECTION_CLOCK_SECTION_WIDTH } from "../internals/constants/dimensions.js";
|
|
@@ -247,7 +246,7 @@ function DateTimePickerToolbar(inProps) {
|
|
|
247
246
|
const translations = usePickerTranslations();
|
|
248
247
|
const ownerState = useToolbarOwnerState();
|
|
249
248
|
const classes = useUtilityClasses(classesProp, ownerState);
|
|
250
|
-
const
|
|
249
|
+
const adapter = usePickerAdapter();
|
|
251
250
|
const overrides = React.useContext(DateTimePickerToolbarOverrideContext);
|
|
252
251
|
const value = overrides ? overrides.value : valueContext;
|
|
253
252
|
const setValue = overrides ? overrides.setValue : setValueContext;
|
|
@@ -264,19 +263,19 @@ function DateTimePickerToolbar(inProps) {
|
|
|
264
263
|
const showAmPmControl = Boolean(ampm && !ampmInClock);
|
|
265
264
|
const toolbarTitle = inToolbarTitle ?? translations.dateTimePickerToolbarTitle;
|
|
266
265
|
const dateText = React.useMemo(() => {
|
|
267
|
-
if (!
|
|
266
|
+
if (!adapter.isValid(value)) {
|
|
268
267
|
return toolbarPlaceholder;
|
|
269
268
|
}
|
|
270
269
|
if (toolbarFormat) {
|
|
271
|
-
return
|
|
270
|
+
return adapter.formatByString(value, toolbarFormat);
|
|
272
271
|
}
|
|
273
|
-
return
|
|
274
|
-
}, [value, toolbarFormat, toolbarPlaceholder,
|
|
272
|
+
return adapter.format(value, 'shortDate');
|
|
273
|
+
}, [value, toolbarFormat, toolbarPlaceholder, adapter]);
|
|
275
274
|
const formatSection = (format, fallback) => {
|
|
276
|
-
if (!
|
|
275
|
+
if (!adapter.isValid(value)) {
|
|
277
276
|
return fallback;
|
|
278
277
|
}
|
|
279
|
-
return
|
|
278
|
+
return adapter.format(value, format);
|
|
280
279
|
};
|
|
281
280
|
return /*#__PURE__*/_jsxs(DateTimePickerToolbarRoot, _extends({
|
|
282
281
|
className: clsx(classes.root, className),
|
|
@@ -351,14 +350,14 @@ function DateTimePickerToolbar(inProps) {
|
|
|
351
350
|
variant: "subtitle2",
|
|
352
351
|
selected: meridiemMode === 'am',
|
|
353
352
|
typographyClassName: classes.ampmLabel,
|
|
354
|
-
value: formatMeridiem(
|
|
353
|
+
value: formatMeridiem(adapter, 'am'),
|
|
355
354
|
onClick: readOnly ? undefined : () => handleMeridiemChange('am'),
|
|
356
355
|
disabled: disabled
|
|
357
356
|
}), /*#__PURE__*/_jsx(PickersToolbarButton, {
|
|
358
357
|
variant: "subtitle2",
|
|
359
358
|
selected: meridiemMode === 'pm',
|
|
360
359
|
typographyClassName: classes.ampmLabel,
|
|
361
|
-
value: formatMeridiem(
|
|
360
|
+
value: formatMeridiem(adapter, 'pm'),
|
|
362
361
|
onClick: readOnly ? undefined : () => handleMeridiemChange('pm'),
|
|
363
362
|
disabled: disabled
|
|
364
363
|
})]
|
|
@@ -366,7 +365,7 @@ function DateTimePickerToolbar(inProps) {
|
|
|
366
365
|
variant: "h5",
|
|
367
366
|
onClick: () => setView('meridiem'),
|
|
368
367
|
selected: view === 'meridiem',
|
|
369
|
-
value: value && meridiemMode ? formatMeridiem(
|
|
368
|
+
value: value && meridiemMode ? formatMeridiem(adapter, meridiemMode) : '--',
|
|
370
369
|
width: MULTI_SECTION_CLOCK_SECTION_WIDTH
|
|
371
370
|
})]
|
|
372
371
|
})]
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useThemeProps } from '@mui/material/styles';
|
|
4
|
-
import {
|
|
4
|
+
import { usePickerAdapter } from "../hooks/usePickerAdapter.js";
|
|
5
5
|
import { DateTimePickerTabs } from "./DateTimePickerTabs.js";
|
|
6
6
|
import { DateTimePickerToolbar } from "./DateTimePickerToolbar.js";
|
|
7
7
|
import { applyDefaultViewProps } from "../internals/utils/views.js";
|
|
8
8
|
import { resolveTimeViewsResponse } from "../internals/utils/date-time-utils.js";
|
|
9
9
|
import { useApplyDefaultValuesToDateTimeValidationProps } from "../managers/useDateTimeManager.js";
|
|
10
10
|
export function useDateTimePickerDefaultizedProps(props, name) {
|
|
11
|
-
const
|
|
11
|
+
const adapter = usePickerAdapter();
|
|
12
12
|
const themeProps = useThemeProps({
|
|
13
13
|
props,
|
|
14
14
|
name
|
|
15
15
|
});
|
|
16
16
|
const validationProps = useApplyDefaultValuesToDateTimeValidationProps(themeProps);
|
|
17
|
-
const ampm = themeProps.ampm ??
|
|
17
|
+
const ampm = themeProps.ampm ?? adapter.is12HourCycleInCurrentLocale();
|
|
18
18
|
const localeText = React.useMemo(() => {
|
|
19
19
|
if (themeProps.localeText?.toolbarTitle == null) {
|
|
20
20
|
return themeProps.localeText;
|
|
@@ -7,7 +7,7 @@ import resolveComponentProps from '@mui/utils/resolveComponentProps';
|
|
|
7
7
|
import refType from '@mui/utils/refType';
|
|
8
8
|
import { singleItemValueManager } from "../internals/utils/valueManagers.js";
|
|
9
9
|
import { useDatePickerDefaultizedProps } from "../DatePicker/shared.js";
|
|
10
|
-
import {
|
|
10
|
+
import { usePickerAdapter } from "../hooks/usePickerAdapter.js";
|
|
11
11
|
import { validateDate, extractValidationProps } from "../validation/index.js";
|
|
12
12
|
import { useDesktopPicker } from "../internals/hooks/useDesktopPicker/index.js";
|
|
13
13
|
import { DateField } from "../DateField/index.js";
|
|
@@ -24,7 +24,7 @@ import { resolveDateFormat } from "../internals/utils/date-utils.js";
|
|
|
24
24
|
* - [DesktopDatePicker API](https://mui.com/x/api/date-pickers/desktop-date-picker/)
|
|
25
25
|
*/
|
|
26
26
|
const DesktopDatePicker = /*#__PURE__*/React.forwardRef(function DesktopDatePicker(inProps, ref) {
|
|
27
|
-
const
|
|
27
|
+
const adapter = usePickerAdapter();
|
|
28
28
|
|
|
29
29
|
// Props with the default values common to all date pickers
|
|
30
30
|
const defaultizedProps = useDatePickerDefaultizedProps(inProps, 'MuiDesktopDatePicker');
|
|
@@ -38,7 +38,7 @@ const DesktopDatePicker = /*#__PURE__*/React.forwardRef(function DesktopDatePick
|
|
|
38
38
|
const props = _extends({}, defaultizedProps, {
|
|
39
39
|
closeOnSelect: defaultizedProps.closeOnSelect ?? true,
|
|
40
40
|
viewRenderers,
|
|
41
|
-
format: resolveDateFormat(
|
|
41
|
+
format: resolveDateFormat(adapter, defaultizedProps, false),
|
|
42
42
|
yearsPerRow: defaultizedProps.yearsPerRow ?? 4,
|
|
43
43
|
slots: _extends({
|
|
44
44
|
field: DateField
|
|
@@ -12,7 +12,7 @@ import { singleItemValueManager } from "../internals/utils/valueManagers.js";
|
|
|
12
12
|
import { DateTimeField } from "../DateTimeField/index.js";
|
|
13
13
|
import { useDateTimePickerDefaultizedProps } from "../DateTimePicker/shared.js";
|
|
14
14
|
import { renderDateViewCalendar } from "../dateViewRenderers/dateViewRenderers.js";
|
|
15
|
-
import {
|
|
15
|
+
import { usePickerAdapter } from "../hooks/usePickerAdapter.js";
|
|
16
16
|
import { validateDateTime, extractValidationProps } from "../validation/index.js";
|
|
17
17
|
import { useDesktopPicker } from "../internals/hooks/useDesktopPicker/index.js";
|
|
18
18
|
import { resolveDateTimeFormat } from "../internals/utils/date-time-utils.js";
|
|
@@ -90,7 +90,7 @@ if (process.env.NODE_ENV !== "production") rendererInterceptor.displayName = "re
|
|
|
90
90
|
* - [DesktopDateTimePicker API](https://mui.com/x/api/date-pickers/desktop-date-time-picker/)
|
|
91
91
|
*/
|
|
92
92
|
const DesktopDateTimePicker = /*#__PURE__*/React.forwardRef(function DesktopDateTimePicker(inProps, ref) {
|
|
93
|
-
const
|
|
93
|
+
const adapter = usePickerAdapter();
|
|
94
94
|
|
|
95
95
|
// Props with the default values common to all date time pickers
|
|
96
96
|
const defaultizedProps = useDateTimePickerDefaultizedProps(inProps, 'MuiDesktopDateTimePicker');
|
|
@@ -112,7 +112,7 @@ const DesktopDateTimePicker = /*#__PURE__*/React.forwardRef(function DesktopDate
|
|
|
112
112
|
// Props with the default values specific to the desktop variant
|
|
113
113
|
const props = _extends({}, defaultizedProps, {
|
|
114
114
|
viewRenderers,
|
|
115
|
-
format: resolveDateTimeFormat(
|
|
115
|
+
format: resolveDateTimeFormat(adapter, defaultizedProps),
|
|
116
116
|
views,
|
|
117
117
|
yearsPerRow: defaultizedProps.yearsPerRow ?? 4,
|
|
118
118
|
ampmInClock,
|
|
@@ -152,7 +152,7 @@ DesktopDateTimePicker.propTypes = {
|
|
|
152
152
|
// ----------------------------------------------------------------------
|
|
153
153
|
/**
|
|
154
154
|
* 12h/24h view for hour selection clock.
|
|
155
|
-
* @default
|
|
155
|
+
* @default adapter.is12HourCycleInCurrentLocale()
|
|
156
156
|
*/
|
|
157
157
|
ampm: PropTypes.bool,
|
|
158
158
|
/**
|
|
@@ -8,7 +8,7 @@ import refType from '@mui/utils/refType';
|
|
|
8
8
|
import { singleItemValueManager } from "../internals/utils/valueManagers.js";
|
|
9
9
|
import { TimeField } from "../TimeField/index.js";
|
|
10
10
|
import { useTimePickerDefaultizedProps } from "../TimePicker/shared.js";
|
|
11
|
-
import {
|
|
11
|
+
import { usePickerAdapter } from "../hooks/usePickerAdapter.js";
|
|
12
12
|
import { extractValidationProps, validateTime } from "../validation/index.js";
|
|
13
13
|
import { useDesktopPicker } from "../internals/hooks/useDesktopPicker/index.js";
|
|
14
14
|
import { renderDigitalClockTimeView, renderMultiSectionDigitalClockTimeView } from "../timeViewRenderers/index.js";
|
|
@@ -25,7 +25,7 @@ import { resolveTimeViewsResponse } from "../internals/utils/date-time-utils.js"
|
|
|
25
25
|
* - [DesktopTimePicker API](https://mui.com/x/api/date-pickers/desktop-time-picker/)
|
|
26
26
|
*/
|
|
27
27
|
const DesktopTimePicker = /*#__PURE__*/React.forwardRef(function DesktopTimePicker(inProps, ref) {
|
|
28
|
-
const
|
|
28
|
+
const adapter = usePickerAdapter();
|
|
29
29
|
|
|
30
30
|
// Props with the default values common to all time pickers
|
|
31
31
|
const defaultizedProps = useTimePickerDefaultizedProps(inProps, 'MuiDesktopTimePicker');
|
|
@@ -51,7 +51,7 @@ const DesktopTimePicker = /*#__PURE__*/React.forwardRef(function DesktopTimePick
|
|
|
51
51
|
ampmInClock,
|
|
52
52
|
timeSteps,
|
|
53
53
|
viewRenderers,
|
|
54
|
-
format: resolveTimeFormat(
|
|
54
|
+
format: resolveTimeFormat(adapter, defaultizedProps),
|
|
55
55
|
// Setting only `hours` time view in case of single column time picker
|
|
56
56
|
// Allows for easy view lifecycle management
|
|
57
57
|
views: shouldRenderTimeInASingleColumn ? ['hours'] : views,
|
|
@@ -86,7 +86,7 @@ DesktopTimePicker.propTypes = {
|
|
|
86
86
|
// ----------------------------------------------------------------------
|
|
87
87
|
/**
|
|
88
88
|
* 12h/24h view for hour selection clock.
|
|
89
|
-
* @default
|
|
89
|
+
* @default adapter.is12HourCycleInCurrentLocale()
|
|
90
90
|
*/
|
|
91
91
|
ampm: PropTypes.bool,
|
|
92
92
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { DigitalClockProps } from "./DigitalClock.types.js";
|
|
3
|
-
export declare const DigitalClockItem: import("@emotion/styled").StyledComponent<import("@mui/material/MenuItem").MenuItemOwnProps & Omit<import("@mui/material/ButtonBase").ButtonBaseOwnProps, "classes"> & import("@mui/material/OverridableComponent").CommonProps & Omit<React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>, "disabled" | "autoFocus" | "dense" | "
|
|
3
|
+
export declare const DigitalClockItem: import("@emotion/styled").StyledComponent<import("@mui/material/MenuItem").MenuItemOwnProps & Omit<import("@mui/material/ButtonBase").ButtonBaseOwnProps, "classes"> & import("@mui/material/OverridableComponent").CommonProps & Omit<React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>, "disabled" | "autoFocus" | "dense" | "style" | "tabIndex" | "className" | "children" | "classes" | "sx" | "disableGutters" | "divider" | "action" | "centerRipple" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "TouchRippleProps" | "touchRippleRef" | "selected"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
|
|
4
4
|
type DigitalClockComponent = ((props: DigitalClockProps & React.RefAttributes<HTMLDivElement>) => React.JSX.Element) & {
|
|
5
5
|
propTypes?: any;
|
|
6
6
|
};
|
|
@@ -14,8 +14,8 @@ import MenuItem from '@mui/material/MenuItem';
|
|
|
14
14
|
import MenuList from '@mui/material/MenuList';
|
|
15
15
|
import useForkRef from '@mui/utils/useForkRef';
|
|
16
16
|
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
17
|
-
import { usePickerTranslations } from "../hooks/
|
|
18
|
-
import {
|
|
17
|
+
import { usePickerAdapter, usePickerTranslations } from "../hooks/index.js";
|
|
18
|
+
import { useNow } from "../internals/hooks/useUtils.js";
|
|
19
19
|
import { createIsAfterIgnoreDatePart } from "../internals/utils/time-utils.js";
|
|
20
20
|
import { PickerViewRoot } from "../internals/components/PickerViewRoot/index.js";
|
|
21
21
|
import { getDigitalClockUtilityClass } from "./digitalClockClasses.js";
|
|
@@ -100,7 +100,7 @@ export const DigitalClockItem = styled(MenuItem, {
|
|
|
100
100
|
* - [DigitalClock API](https://mui.com/x/api/date-pickers/digital-clock/)
|
|
101
101
|
*/
|
|
102
102
|
export const DigitalClock = /*#__PURE__*/React.forwardRef(function DigitalClock(inProps, ref) {
|
|
103
|
-
const
|
|
103
|
+
const adapter = usePickerAdapter();
|
|
104
104
|
const containerRef = React.useRef(null);
|
|
105
105
|
const handleRef = useForkRef(ref, containerRef);
|
|
106
106
|
const listRef = React.useRef(null);
|
|
@@ -109,7 +109,7 @@ export const DigitalClock = /*#__PURE__*/React.forwardRef(function DigitalClock(
|
|
|
109
109
|
name: 'MuiDigitalClock'
|
|
110
110
|
});
|
|
111
111
|
const {
|
|
112
|
-
ampm =
|
|
112
|
+
ampm = adapter.is12HourCycleInCurrentLocale(),
|
|
113
113
|
timeStep = 30,
|
|
114
114
|
autoFocus,
|
|
115
115
|
slots,
|
|
@@ -171,7 +171,7 @@ export const DigitalClock = /*#__PURE__*/React.forwardRef(function DigitalClock(
|
|
|
171
171
|
const valueOrReferenceDate = useClockReferenceDate({
|
|
172
172
|
value,
|
|
173
173
|
referenceDate: referenceDateProp,
|
|
174
|
-
|
|
174
|
+
adapter,
|
|
175
175
|
props,
|
|
176
176
|
timezone
|
|
177
177
|
});
|
|
@@ -207,7 +207,7 @@ export const DigitalClock = /*#__PURE__*/React.forwardRef(function DigitalClock(
|
|
|
207
207
|
containerRef.current.scrollTop = offsetTop - 4;
|
|
208
208
|
});
|
|
209
209
|
const isTimeDisabled = React.useCallback(valueToCheck => {
|
|
210
|
-
const isAfter = createIsAfterIgnoreDatePart(disableIgnoringDatePartForTimeValidation,
|
|
210
|
+
const isAfter = createIsAfterIgnoreDatePart(disableIgnoringDatePartForTimeValidation, adapter);
|
|
211
211
|
const containsValidTime = () => {
|
|
212
212
|
if (minTime && isAfter(minTime, valueToCheck)) {
|
|
213
213
|
return false;
|
|
@@ -224,7 +224,7 @@ export const DigitalClock = /*#__PURE__*/React.forwardRef(function DigitalClock(
|
|
|
224
224
|
return true;
|
|
225
225
|
};
|
|
226
226
|
const isValidValue = () => {
|
|
227
|
-
if (
|
|
227
|
+
if (adapter.getMinutes(valueToCheck) % minutesStep !== 0) {
|
|
228
228
|
return false;
|
|
229
229
|
}
|
|
230
230
|
if (shouldDisableTime) {
|
|
@@ -233,18 +233,18 @@ export const DigitalClock = /*#__PURE__*/React.forwardRef(function DigitalClock(
|
|
|
233
233
|
return true;
|
|
234
234
|
};
|
|
235
235
|
return !containsValidTime() || !isValidValue();
|
|
236
|
-
}, [disableIgnoringDatePartForTimeValidation,
|
|
236
|
+
}, [disableIgnoringDatePartForTimeValidation, adapter, minTime, maxTime, disableFuture, now, disablePast, minutesStep, shouldDisableTime]);
|
|
237
237
|
const timeOptions = React.useMemo(() => {
|
|
238
238
|
const result = [];
|
|
239
|
-
const startOfDay =
|
|
239
|
+
const startOfDay = adapter.startOfDay(valueOrReferenceDate);
|
|
240
240
|
let nextTimeStepOption = startOfDay;
|
|
241
|
-
while (
|
|
241
|
+
while (adapter.isSameDay(valueOrReferenceDate, nextTimeStepOption)) {
|
|
242
242
|
result.push(nextTimeStepOption);
|
|
243
|
-
nextTimeStepOption =
|
|
243
|
+
nextTimeStepOption = adapter.addMinutes(nextTimeStepOption, timeStep);
|
|
244
244
|
}
|
|
245
245
|
return result;
|
|
246
|
-
}, [valueOrReferenceDate, timeStep,
|
|
247
|
-
const focusedOptionIndex = timeOptions.findIndex(option =>
|
|
246
|
+
}, [valueOrReferenceDate, timeStep, adapter]);
|
|
247
|
+
const focusedOptionIndex = timeOptions.findIndex(option => adapter.isEqual(option, valueOrReferenceDate));
|
|
248
248
|
const handleKeyDown = event => {
|
|
249
249
|
switch (event.key) {
|
|
250
250
|
case 'PageUp':
|
|
@@ -290,8 +290,8 @@ export const DigitalClock = /*#__PURE__*/React.forwardRef(function DigitalClock(
|
|
|
290
290
|
if (skipDisabled && optionDisabled) {
|
|
291
291
|
return null;
|
|
292
292
|
}
|
|
293
|
-
const isSelected =
|
|
294
|
-
const formattedValue =
|
|
293
|
+
const isSelected = adapter.isEqual(option, value);
|
|
294
|
+
const formattedValue = adapter.format(option, ampm ? 'fullTime12h' : 'fullTime24h');
|
|
295
295
|
const isFocused = focusedOptionIndex === index || focusedOptionIndex === -1 && index === 0;
|
|
296
296
|
const tabIndex = isFocused ? 0 : -1;
|
|
297
297
|
return /*#__PURE__*/_jsx(ClockItem, _extends({
|
|
@@ -322,7 +322,7 @@ process.env.NODE_ENV !== "production" ? DigitalClock.propTypes = {
|
|
|
322
322
|
// ----------------------------------------------------------------------
|
|
323
323
|
/**
|
|
324
324
|
* 12h/24h view for hour selection clock.
|
|
325
|
-
* @default
|
|
325
|
+
* @default adapter.is12HourCycleInCurrentLocale()
|
|
326
326
|
*/
|
|
327
327
|
ampm: PropTypes.bool,
|
|
328
328
|
/**
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { AdapterFormats, MuiPickersAdapter, PickerValidDate } from "../models/index.js";
|
|
3
3
|
import { PickersInputLocaleText } from "../locales/index.js";
|
|
4
|
-
export interface
|
|
4
|
+
export interface PickersAdapterContextValue {
|
|
5
5
|
defaultDates: {
|
|
6
6
|
minDate: PickerValidDate;
|
|
7
7
|
maxDate: PickerValidDate;
|
|
8
8
|
};
|
|
9
9
|
utils: MuiPickersAdapter;
|
|
10
|
+
adapter: MuiPickersAdapter;
|
|
10
11
|
localeText: PickersInputLocaleText | undefined;
|
|
11
12
|
}
|
|
12
|
-
export type
|
|
13
|
-
export declare const
|
|
13
|
+
export type PickerAdapterContextNullableValue = { [K in keyof PickersAdapterContextValue]: PickersAdapterContextValue[K] | null };
|
|
14
|
+
export declare const PickerAdapterContext: React.Context<PickerAdapterContextNullableValue | null>;
|
|
15
|
+
/**
|
|
16
|
+
* The context that provides the date adapter and default dates to the pickers.
|
|
17
|
+
* @deprecated Use `usePickersAdapter` hook if you need access to the adapter instead.
|
|
18
|
+
*/
|
|
19
|
+
export declare const MuiPickersAdapterContext: React.Context<PickerAdapterContextNullableValue | null>;
|
|
14
20
|
export interface LocalizationProviderProps<TLocale> {
|
|
15
21
|
children?: React.ReactNode;
|
|
16
22
|
/**
|
|
@@ -7,8 +7,15 @@ import * as React from 'react';
|
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import { useThemeProps } from '@mui/material/styles';
|
|
9
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
-
export const
|
|
11
|
-
|
|
10
|
+
export const PickerAdapterContext = /*#__PURE__*/React.createContext(null);
|
|
11
|
+
|
|
12
|
+
// TODO v9: Remove this public export
|
|
13
|
+
/**
|
|
14
|
+
* The context that provides the date adapter and default dates to the pickers.
|
|
15
|
+
* @deprecated Use `usePickersAdapter` hook if you need access to the adapter instead.
|
|
16
|
+
*/
|
|
17
|
+
if (process.env.NODE_ENV !== "production") PickerAdapterContext.displayName = "PickerAdapterContext";
|
|
18
|
+
export const MuiPickersAdapterContext = PickerAdapterContext;
|
|
12
19
|
/**
|
|
13
20
|
* Demos:
|
|
14
21
|
*
|
|
@@ -27,10 +34,11 @@ export const LocalizationProvider = function LocalizationProvider(inProps) {
|
|
|
27
34
|
} = inProps,
|
|
28
35
|
otherInProps = _objectWithoutPropertiesLoose(inProps, _excluded);
|
|
29
36
|
const {
|
|
30
|
-
|
|
37
|
+
adapter: parentAdapter,
|
|
31
38
|
localeText: parentLocaleText
|
|
32
|
-
} = React.useContext(
|
|
39
|
+
} = React.useContext(PickerAdapterContext) ?? {
|
|
33
40
|
utils: undefined,
|
|
41
|
+
adapter: undefined,
|
|
34
42
|
localeText: undefined
|
|
35
43
|
};
|
|
36
44
|
const props = useThemeProps({
|
|
@@ -48,40 +56,41 @@ export const LocalizationProvider = function LocalizationProvider(inProps) {
|
|
|
48
56
|
localeText: themeLocaleText
|
|
49
57
|
} = props;
|
|
50
58
|
const localeText = React.useMemo(() => _extends({}, themeLocaleText, parentLocaleText, inLocaleText), [themeLocaleText, parentLocaleText, inLocaleText]);
|
|
51
|
-
const
|
|
59
|
+
const adapter = React.useMemo(() => {
|
|
52
60
|
if (!DateAdapter) {
|
|
53
|
-
if (
|
|
54
|
-
return
|
|
61
|
+
if (parentAdapter) {
|
|
62
|
+
return parentAdapter;
|
|
55
63
|
}
|
|
56
64
|
return null;
|
|
57
65
|
}
|
|
58
|
-
const
|
|
66
|
+
const dateAdapter = new DateAdapter({
|
|
59
67
|
locale: adapterLocale,
|
|
60
68
|
formats: dateFormats,
|
|
61
69
|
instance: dateLibInstance
|
|
62
70
|
});
|
|
63
|
-
if (!
|
|
71
|
+
if (!dateAdapter.isMUIAdapter) {
|
|
64
72
|
throw new Error(['MUI X: The date adapter should be imported from `@mui/x-date-pickers` or `@mui/x-date-pickers-pro`, not from `@date-io`', "For example, `import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'` instead of `import AdapterDayjs from '@date-io/dayjs'`", 'More information on the installation documentation: https://mui.com/x/react-date-pickers/quickstart/#installation'].join(`\n`));
|
|
65
73
|
}
|
|
66
|
-
return
|
|
67
|
-
}, [DateAdapter, adapterLocale, dateFormats, dateLibInstance,
|
|
74
|
+
return dateAdapter;
|
|
75
|
+
}, [DateAdapter, adapterLocale, dateFormats, dateLibInstance, parentAdapter]);
|
|
68
76
|
const defaultDates = React.useMemo(() => {
|
|
69
|
-
if (!
|
|
77
|
+
if (!adapter) {
|
|
70
78
|
return null;
|
|
71
79
|
}
|
|
72
80
|
return {
|
|
73
|
-
minDate:
|
|
74
|
-
maxDate:
|
|
81
|
+
minDate: adapter.date('1900-01-01T00:00:00.000'),
|
|
82
|
+
maxDate: adapter.date('2099-12-31T00:00:00.000')
|
|
75
83
|
};
|
|
76
|
-
}, [
|
|
84
|
+
}, [adapter]);
|
|
77
85
|
const contextValue = React.useMemo(() => {
|
|
78
86
|
return {
|
|
79
|
-
utils,
|
|
87
|
+
utils: adapter,
|
|
88
|
+
adapter,
|
|
80
89
|
defaultDates,
|
|
81
90
|
localeText
|
|
82
91
|
};
|
|
83
|
-
}, [defaultDates,
|
|
84
|
-
return /*#__PURE__*/_jsx(
|
|
92
|
+
}, [defaultDates, adapter, localeText]);
|
|
93
|
+
return /*#__PURE__*/_jsx(PickerAdapterContext.Provider, {
|
|
85
94
|
value: contextValue,
|
|
86
95
|
children: children
|
|
87
96
|
});
|
|
@@ -7,7 +7,7 @@ import resolveComponentProps from '@mui/utils/resolveComponentProps';
|
|
|
7
7
|
import refType from '@mui/utils/refType';
|
|
8
8
|
import { useMobilePicker } from "../internals/hooks/useMobilePicker/index.js";
|
|
9
9
|
import { useDatePickerDefaultizedProps } from "../DatePicker/shared.js";
|
|
10
|
-
import {
|
|
10
|
+
import { usePickerAdapter } from "../hooks/usePickerAdapter.js";
|
|
11
11
|
import { extractValidationProps, validateDate } from "../validation/index.js";
|
|
12
12
|
import { DateField } from "../DateField/index.js";
|
|
13
13
|
import { singleItemValueManager } from "../internals/utils/valueManagers.js";
|
|
@@ -24,7 +24,7 @@ import { resolveDateFormat } from "../internals/utils/date-utils.js";
|
|
|
24
24
|
* - [MobileDatePicker API](https://mui.com/x/api/date-pickers/mobile-date-picker/)
|
|
25
25
|
*/
|
|
26
26
|
const MobileDatePicker = /*#__PURE__*/React.forwardRef(function MobileDatePicker(inProps, ref) {
|
|
27
|
-
const
|
|
27
|
+
const adapter = usePickerAdapter();
|
|
28
28
|
|
|
29
29
|
// Props with the default values common to all date pickers
|
|
30
30
|
const defaultizedProps = useDatePickerDefaultizedProps(inProps, 'MuiMobileDatePicker');
|
|
@@ -37,7 +37,7 @@ const MobileDatePicker = /*#__PURE__*/React.forwardRef(function MobileDatePicker
|
|
|
37
37
|
// Props with the default values specific to the mobile variant
|
|
38
38
|
const props = _extends({}, defaultizedProps, {
|
|
39
39
|
viewRenderers,
|
|
40
|
-
format: resolveDateFormat(
|
|
40
|
+
format: resolveDateFormat(adapter, defaultizedProps, false),
|
|
41
41
|
slots: _extends({
|
|
42
42
|
field: DateField
|
|
43
43
|
}, defaultizedProps.slots),
|
|
@@ -8,7 +8,7 @@ import refType from '@mui/utils/refType';
|
|
|
8
8
|
import { singleItemValueManager } from "../internals/utils/valueManagers.js";
|
|
9
9
|
import { DateTimeField } from "../DateTimeField/index.js";
|
|
10
10
|
import { useDateTimePickerDefaultizedProps } from "../DateTimePicker/shared.js";
|
|
11
|
-
import {
|
|
11
|
+
import { usePickerAdapter } from "../hooks/usePickerAdapter.js";
|
|
12
12
|
import { extractValidationProps, validateDateTime } from "../validation/index.js";
|
|
13
13
|
import { useMobilePicker } from "../internals/hooks/useMobilePicker/index.js";
|
|
14
14
|
import { renderDateViewCalendar } from "../dateViewRenderers/index.js";
|
|
@@ -36,7 +36,7 @@ const STEPS = [{
|
|
|
36
36
|
* - [MobileDateTimePicker API](https://mui.com/x/api/date-pickers/mobile-date-time-picker/)
|
|
37
37
|
*/
|
|
38
38
|
const MobileDateTimePicker = /*#__PURE__*/React.forwardRef(function MobileDateTimePicker(inProps, ref) {
|
|
39
|
-
const
|
|
39
|
+
const adapter = usePickerAdapter();
|
|
40
40
|
|
|
41
41
|
// Props with the default values common to all date time pickers
|
|
42
42
|
const defaultizedProps = useDateTimePickerDefaultizedProps(inProps, 'MuiMobileDateTimePicker');
|
|
@@ -58,7 +58,7 @@ const MobileDateTimePicker = /*#__PURE__*/React.forwardRef(function MobileDateTi
|
|
|
58
58
|
// Props with the default values specific to the mobile variant
|
|
59
59
|
const props = _extends({}, defaultizedProps, {
|
|
60
60
|
viewRenderers,
|
|
61
|
-
format: resolveDateTimeFormat(
|
|
61
|
+
format: resolveDateTimeFormat(adapter, defaultizedProps),
|
|
62
62
|
views,
|
|
63
63
|
ampmInClock,
|
|
64
64
|
slots: _extends({
|
|
@@ -118,7 +118,7 @@ MobileDateTimePicker.propTypes = {
|
|
|
118
118
|
// ----------------------------------------------------------------------
|
|
119
119
|
/**
|
|
120
120
|
* 12h/24h view for hour selection clock.
|
|
121
|
-
* @default
|
|
121
|
+
* @default adapter.is12HourCycleInCurrentLocale()
|
|
122
122
|
*/
|
|
123
123
|
ampm: PropTypes.bool,
|
|
124
124
|
/**
|
|
@@ -8,7 +8,7 @@ import refType from '@mui/utils/refType';
|
|
|
8
8
|
import { singleItemValueManager } from "../internals/utils/valueManagers.js";
|
|
9
9
|
import { TimeField } from "../TimeField/index.js";
|
|
10
10
|
import { useTimePickerDefaultizedProps } from "../TimePicker/shared.js";
|
|
11
|
-
import {
|
|
11
|
+
import { usePickerAdapter } from "../hooks/usePickerAdapter.js";
|
|
12
12
|
import { extractValidationProps, validateTime } from "../validation/index.js";
|
|
13
13
|
import { useMobilePicker } from "../internals/hooks/useMobilePicker/index.js";
|
|
14
14
|
import { renderTimeViewClock } from "../timeViewRenderers/index.js";
|
|
@@ -24,7 +24,7 @@ import { resolveTimeFormat } from "../internals/utils/time-utils.js";
|
|
|
24
24
|
* - [MobileTimePicker API](https://mui.com/x/api/date-pickers/mobile-time-picker/)
|
|
25
25
|
*/
|
|
26
26
|
const MobileTimePicker = /*#__PURE__*/React.forwardRef(function MobileTimePicker(inProps, ref) {
|
|
27
|
-
const
|
|
27
|
+
const adapter = usePickerAdapter();
|
|
28
28
|
|
|
29
29
|
// Props with the default values common to all time pickers
|
|
30
30
|
const defaultizedProps = useTimePickerDefaultizedProps(inProps, 'MuiMobileTimePicker');
|
|
@@ -39,7 +39,7 @@ const MobileTimePicker = /*#__PURE__*/React.forwardRef(function MobileTimePicker
|
|
|
39
39
|
const props = _extends({}, defaultizedProps, {
|
|
40
40
|
ampmInClock,
|
|
41
41
|
viewRenderers,
|
|
42
|
-
format: resolveTimeFormat(
|
|
42
|
+
format: resolveTimeFormat(adapter, defaultizedProps),
|
|
43
43
|
slots: _extends({
|
|
44
44
|
field: TimeField
|
|
45
45
|
}, defaultizedProps.slots),
|
|
@@ -71,7 +71,7 @@ MobileTimePicker.propTypes = {
|
|
|
71
71
|
// ----------------------------------------------------------------------
|
|
72
72
|
/**
|
|
73
73
|
* 12h/24h view for hour selection clock.
|
|
74
|
-
* @default
|
|
74
|
+
* @default adapter.is12HourCycleInCurrentLocale()
|
|
75
75
|
*/
|
|
76
76
|
ampm: PropTypes.bool,
|
|
77
77
|
/**
|
|
@@ -13,7 +13,7 @@ import useControlled from '@mui/utils/useControlled';
|
|
|
13
13
|
import composeClasses from '@mui/utils/composeClasses';
|
|
14
14
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
15
15
|
import { MonthCalendarButton } from "./MonthCalendarButton.js";
|
|
16
|
-
import {
|
|
16
|
+
import { useNow } from "../internals/hooks/useUtils.js";
|
|
17
17
|
import { getMonthCalendarUtilityClass } from "./monthCalendarClasses.js";
|
|
18
18
|
import { getMonthsInYear } from "../internals/utils/date-utils.js";
|
|
19
19
|
import { singleItemValueManager } from "../internals/utils/valueManagers.js";
|
|
@@ -22,6 +22,7 @@ import { useControlledValue } from "../internals/hooks/useControlledValue.js";
|
|
|
22
22
|
import { DIALOG_WIDTH } 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 } from "react/jsx-runtime";
|
|
26
27
|
const useUtilityClasses = classes => {
|
|
27
28
|
const slots = {
|
|
@@ -119,13 +120,13 @@ export const MonthCalendar = /*#__PURE__*/React.forwardRef(function MonthCalenda
|
|
|
119
120
|
});
|
|
120
121
|
const now = useNow(timezone);
|
|
121
122
|
const isRtl = useRtl();
|
|
122
|
-
const
|
|
123
|
+
const adapter = usePickerAdapter();
|
|
123
124
|
const {
|
|
124
125
|
ownerState
|
|
125
126
|
} = usePickerPrivateContext();
|
|
126
127
|
const referenceDate = React.useMemo(() => singleItemValueManager.getInitialReferenceValue({
|
|
127
128
|
value,
|
|
128
|
-
|
|
129
|
+
adapter,
|
|
129
130
|
props,
|
|
130
131
|
timezone,
|
|
131
132
|
referenceDate: referenceDateProp,
|
|
@@ -133,14 +134,14 @@ export const MonthCalendar = /*#__PURE__*/React.forwardRef(function MonthCalenda
|
|
|
133
134
|
}), [] // eslint-disable-line react-hooks/exhaustive-deps
|
|
134
135
|
);
|
|
135
136
|
const classes = useUtilityClasses(classesProp);
|
|
136
|
-
const todayMonth = React.useMemo(() =>
|
|
137
|
+
const todayMonth = React.useMemo(() => adapter.getMonth(now), [adapter, now]);
|
|
137
138
|
const selectedMonth = React.useMemo(() => {
|
|
138
139
|
if (value != null) {
|
|
139
|
-
return
|
|
140
|
+
return adapter.getMonth(value);
|
|
140
141
|
}
|
|
141
142
|
return null;
|
|
142
|
-
}, [value,
|
|
143
|
-
const [focusedMonth, setFocusedMonth] = React.useState(() => selectedMonth ||
|
|
143
|
+
}, [value, adapter]);
|
|
144
|
+
const [focusedMonth, setFocusedMonth] = React.useState(() => selectedMonth || adapter.getMonth(referenceDate));
|
|
144
145
|
const [internalHasFocus, setInternalHasFocus] = useControlled({
|
|
145
146
|
name: 'MonthCalendar',
|
|
146
147
|
state: 'hasFocus',
|
|
@@ -154,29 +155,29 @@ export const MonthCalendar = /*#__PURE__*/React.forwardRef(function MonthCalenda
|
|
|
154
155
|
}
|
|
155
156
|
});
|
|
156
157
|
const isMonthDisabled = React.useCallback(dateToValidate => {
|
|
157
|
-
const firstEnabledMonth =
|
|
158
|
-
const lastEnabledMonth =
|
|
159
|
-
const monthToValidate =
|
|
160
|
-
if (
|
|
158
|
+
const firstEnabledMonth = adapter.startOfMonth(disablePast && adapter.isAfter(now, minDate) ? now : minDate);
|
|
159
|
+
const lastEnabledMonth = adapter.startOfMonth(disableFuture && adapter.isBefore(now, maxDate) ? now : maxDate);
|
|
160
|
+
const monthToValidate = adapter.startOfMonth(dateToValidate);
|
|
161
|
+
if (adapter.isBefore(monthToValidate, firstEnabledMonth)) {
|
|
161
162
|
return true;
|
|
162
163
|
}
|
|
163
|
-
if (
|
|
164
|
+
if (adapter.isAfter(monthToValidate, lastEnabledMonth)) {
|
|
164
165
|
return true;
|
|
165
166
|
}
|
|
166
167
|
if (!shouldDisableMonth) {
|
|
167
168
|
return false;
|
|
168
169
|
}
|
|
169
170
|
return shouldDisableMonth(monthToValidate);
|
|
170
|
-
}, [disableFuture, disablePast, maxDate, minDate, now, shouldDisableMonth,
|
|
171
|
+
}, [disableFuture, disablePast, maxDate, minDate, now, shouldDisableMonth, adapter]);
|
|
171
172
|
const handleMonthSelection = useEventCallback((event, month) => {
|
|
172
173
|
if (readOnly) {
|
|
173
174
|
return;
|
|
174
175
|
}
|
|
175
|
-
const newDate =
|
|
176
|
+
const newDate = adapter.setMonth(value ?? referenceDate, month);
|
|
176
177
|
handleValueChange(newDate);
|
|
177
178
|
});
|
|
178
179
|
const focusMonth = useEventCallback(month => {
|
|
179
|
-
if (!isMonthDisabled(
|
|
180
|
+
if (!isMonthDisabled(adapter.setMonth(value ?? referenceDate, month))) {
|
|
180
181
|
setFocusedMonth(month);
|
|
181
182
|
changeHasFocus(true);
|
|
182
183
|
if (onMonthFocus) {
|
|
@@ -227,10 +228,10 @@ export const MonthCalendar = /*#__PURE__*/React.forwardRef(function MonthCalenda
|
|
|
227
228
|
"aria-labelledby": gridLabelId,
|
|
228
229
|
monthsPerRow: monthsPerRow
|
|
229
230
|
}, other, {
|
|
230
|
-
children: getMonthsInYear(
|
|
231
|
-
const monthNumber =
|
|
232
|
-
const monthText =
|
|
233
|
-
const monthLabel =
|
|
231
|
+
children: getMonthsInYear(adapter, value ?? referenceDate).map(month => {
|
|
232
|
+
const monthNumber = adapter.getMonth(month);
|
|
233
|
+
const monthText = adapter.format(month, 'monthShort');
|
|
234
|
+
const monthLabel = adapter.format(month, 'month');
|
|
234
235
|
const isSelected = monthNumber === selectedMonth;
|
|
235
236
|
const isDisabled = disabled || isMonthDisabled(month);
|
|
236
237
|
return /*#__PURE__*/_jsx(MonthCalendarButton, {
|