@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
|
@@ -28,6 +28,7 @@ var _useControlledValue = require("../internals/hooks/useControlledValue");
|
|
|
28
28
|
var _dimensions = require("../internals/constants/dimensions");
|
|
29
29
|
var _usePickerPrivateContext = require("../internals/hooks/usePickerPrivateContext");
|
|
30
30
|
var _useDateManager = require("../managers/useDateManager");
|
|
31
|
+
var _usePickerAdapter = require("../hooks/usePickerAdapter");
|
|
31
32
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
32
33
|
const _excluded = ["autoFocus", "className", "classes", "value", "defaultValue", "referenceDate", "disabled", "disableFuture", "disablePast", "maxDate", "minDate", "onChange", "readOnly", "shouldDisableYear", "disableHighlightToday", "onYearFocus", "hasFocus", "onFocusedViewChange", "yearsOrder", "yearsPerRow", "timezone", "gridLabelId", "slots", "slotProps"];
|
|
33
34
|
const useUtilityClasses = classes => {
|
|
@@ -140,13 +141,13 @@ const YearCalendar = exports.YearCalendar = /*#__PURE__*/React.forwardRef(functi
|
|
|
140
141
|
});
|
|
141
142
|
const now = (0, _useUtils.useNow)(timezone);
|
|
142
143
|
const isRtl = (0, _RtlProvider.useRtl)();
|
|
143
|
-
const
|
|
144
|
+
const adapter = (0, _usePickerAdapter.usePickerAdapter)();
|
|
144
145
|
const {
|
|
145
146
|
ownerState
|
|
146
147
|
} = (0, _usePickerPrivateContext.usePickerPrivateContext)();
|
|
147
148
|
const referenceDate = React.useMemo(() => _valueManagers.singleItemValueManager.getInitialReferenceValue({
|
|
148
149
|
value,
|
|
149
|
-
|
|
150
|
+
adapter,
|
|
150
151
|
props,
|
|
151
152
|
timezone,
|
|
152
153
|
referenceDate: referenceDateProp,
|
|
@@ -154,14 +155,14 @@ const YearCalendar = exports.YearCalendar = /*#__PURE__*/React.forwardRef(functi
|
|
|
154
155
|
}), [] // eslint-disable-line react-hooks/exhaustive-deps
|
|
155
156
|
);
|
|
156
157
|
const classes = useUtilityClasses(classesProp);
|
|
157
|
-
const todayYear = React.useMemo(() =>
|
|
158
|
+
const todayYear = React.useMemo(() => adapter.getYear(now), [adapter, now]);
|
|
158
159
|
const selectedYear = React.useMemo(() => {
|
|
159
160
|
if (value != null) {
|
|
160
|
-
return
|
|
161
|
+
return adapter.getYear(value);
|
|
161
162
|
}
|
|
162
163
|
return null;
|
|
163
|
-
}, [value,
|
|
164
|
-
const [focusedYear, setFocusedYear] = React.useState(() => selectedYear ||
|
|
164
|
+
}, [value, adapter]);
|
|
165
|
+
const [focusedYear, setFocusedYear] = React.useState(() => selectedYear || adapter.getYear(referenceDate));
|
|
165
166
|
const [internalHasFocus, setInternalHasFocus] = (0, _useControlled.default)({
|
|
166
167
|
name: 'YearCalendar',
|
|
167
168
|
state: 'hasFocus',
|
|
@@ -175,33 +176,33 @@ const YearCalendar = exports.YearCalendar = /*#__PURE__*/React.forwardRef(functi
|
|
|
175
176
|
}
|
|
176
177
|
});
|
|
177
178
|
const isYearDisabled = React.useCallback(dateToValidate => {
|
|
178
|
-
if (disablePast &&
|
|
179
|
+
if (disablePast && adapter.isBeforeYear(dateToValidate, now)) {
|
|
179
180
|
return true;
|
|
180
181
|
}
|
|
181
|
-
if (disableFuture &&
|
|
182
|
+
if (disableFuture && adapter.isAfterYear(dateToValidate, now)) {
|
|
182
183
|
return true;
|
|
183
184
|
}
|
|
184
|
-
if (minDate &&
|
|
185
|
+
if (minDate && adapter.isBeforeYear(dateToValidate, minDate)) {
|
|
185
186
|
return true;
|
|
186
187
|
}
|
|
187
|
-
if (maxDate &&
|
|
188
|
+
if (maxDate && adapter.isAfterYear(dateToValidate, maxDate)) {
|
|
188
189
|
return true;
|
|
189
190
|
}
|
|
190
191
|
if (!shouldDisableYear) {
|
|
191
192
|
return false;
|
|
192
193
|
}
|
|
193
|
-
const yearToValidate =
|
|
194
|
+
const yearToValidate = adapter.startOfYear(dateToValidate);
|
|
194
195
|
return shouldDisableYear(yearToValidate);
|
|
195
|
-
}, [disableFuture, disablePast, maxDate, minDate, now, shouldDisableYear,
|
|
196
|
+
}, [disableFuture, disablePast, maxDate, minDate, now, shouldDisableYear, adapter]);
|
|
196
197
|
const handleYearSelection = (0, _useEventCallback.default)((event, year) => {
|
|
197
198
|
if (readOnly) {
|
|
198
199
|
return;
|
|
199
200
|
}
|
|
200
|
-
const newDate =
|
|
201
|
+
const newDate = adapter.setYear(value ?? referenceDate, year);
|
|
201
202
|
handleValueChange(newDate);
|
|
202
203
|
});
|
|
203
204
|
const focusYear = (0, _useEventCallback.default)(year => {
|
|
204
|
-
if (!isYearDisabled(
|
|
205
|
+
if (!isYearDisabled(adapter.setYear(value ?? referenceDate, year))) {
|
|
205
206
|
setFocusedYear(year);
|
|
206
207
|
changeHasFocus(true);
|
|
207
208
|
onYearFocus?.(year);
|
|
@@ -265,7 +266,7 @@ const YearCalendar = exports.YearCalendar = /*#__PURE__*/React.forwardRef(functi
|
|
|
265
266
|
}
|
|
266
267
|
scrollerRef.current.scrollTop = elementBottom - clientHeight / 2 - offsetHeight / 2;
|
|
267
268
|
}, [autoFocus]);
|
|
268
|
-
const yearRange =
|
|
269
|
+
const yearRange = adapter.getYearRange([minDate, maxDate]);
|
|
269
270
|
if (yearsOrder === 'desc') {
|
|
270
271
|
yearRange.reverse();
|
|
271
272
|
}
|
|
@@ -282,7 +283,7 @@ const YearCalendar = exports.YearCalendar = /*#__PURE__*/React.forwardRef(functi
|
|
|
282
283
|
yearsPerRow: yearsPerRow
|
|
283
284
|
}, other, {
|
|
284
285
|
children: [yearRange.map(year => {
|
|
285
|
-
const yearNumber =
|
|
286
|
+
const yearNumber = adapter.getYear(year);
|
|
286
287
|
const isSelected = yearNumber === selectedYear;
|
|
287
288
|
const isDisabled = disabled || isYearDisabled(year);
|
|
288
289
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_YearCalendarButton.YearCalendarButton, {
|
|
@@ -299,8 +300,8 @@ const YearCalendar = exports.YearCalendar = /*#__PURE__*/React.forwardRef(functi
|
|
|
299
300
|
slots: slots,
|
|
300
301
|
slotProps: slotProps,
|
|
301
302
|
classes: classesProp,
|
|
302
|
-
children:
|
|
303
|
-
},
|
|
303
|
+
children: adapter.format(year, 'year')
|
|
304
|
+
}, adapter.format(year, 'year'));
|
|
304
305
|
}), Array.from({
|
|
305
306
|
length: fillerAmount
|
|
306
307
|
}, (_, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)(YearCalendarButtonFiller, {}, index))]
|
|
@@ -12,7 +12,6 @@ import composeClasses from '@mui/utils/composeClasses';
|
|
|
12
12
|
import useId from '@mui/utils/useId';
|
|
13
13
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
14
14
|
import { useCalendarState } from "./useCalendarState.js";
|
|
15
|
-
import { useUtils } from "../internals/hooks/useUtils.js";
|
|
16
15
|
import { PickersFadeTransitionGroup } from "./PickersFadeTransitionGroup.js";
|
|
17
16
|
import { DayCalendar } from "./DayCalendar.js";
|
|
18
17
|
import { MonthCalendar } from "../MonthCalendar/index.js";
|
|
@@ -28,6 +27,7 @@ import { singleItemValueManager } from "../internals/utils/valueManagers.js";
|
|
|
28
27
|
import { VIEW_HEIGHT } from "../internals/constants/dimensions.js";
|
|
29
28
|
import { usePickerPrivateContext } from "../internals/hooks/usePickerPrivateContext.js";
|
|
30
29
|
import { useApplyDefaultValuesToDateValidationProps } from "../managers/useDateManager.js";
|
|
30
|
+
import { usePickerAdapter } from "../hooks/usePickerAdapter.js";
|
|
31
31
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
32
32
|
const useUtilityClasses = classes => {
|
|
33
33
|
const slots = {
|
|
@@ -77,7 +77,7 @@ const DateCalendarViewTransitionContainer = styled(PickersFadeTransitionGroup, {
|
|
|
77
77
|
* - [DateCalendar API](https://mui.com/x/api/date-pickers/date-calendar/)
|
|
78
78
|
*/
|
|
79
79
|
export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(inProps, ref) {
|
|
80
|
-
const
|
|
80
|
+
const adapter = usePickerAdapter();
|
|
81
81
|
const {
|
|
82
82
|
ownerState
|
|
83
83
|
} = usePickerPrivateContext();
|
|
@@ -171,10 +171,10 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
|
|
|
171
171
|
disableFuture,
|
|
172
172
|
timezone,
|
|
173
173
|
getCurrentMonthFromVisibleDate: (visibleDate, prevMonth) => {
|
|
174
|
-
if (
|
|
174
|
+
if (adapter.isSameMonth(visibleDate, prevMonth)) {
|
|
175
175
|
return prevMonth;
|
|
176
176
|
}
|
|
177
|
-
return
|
|
177
|
+
return adapter.startOfMonth(visibleDate);
|
|
178
178
|
}
|
|
179
179
|
});
|
|
180
180
|
|
|
@@ -208,13 +208,13 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
|
|
|
208
208
|
ownerState
|
|
209
209
|
});
|
|
210
210
|
const handleDateMonthChange = useEventCallback(newDate => {
|
|
211
|
-
const startOfMonth =
|
|
212
|
-
const endOfMonth =
|
|
211
|
+
const startOfMonth = adapter.startOfMonth(newDate);
|
|
212
|
+
const endOfMonth = adapter.endOfMonth(newDate);
|
|
213
213
|
const closestEnabledDate = isDateDisabled(newDate) ? findClosestEnabledDate({
|
|
214
|
-
|
|
214
|
+
adapter,
|
|
215
215
|
date: newDate,
|
|
216
|
-
minDate:
|
|
217
|
-
maxDate:
|
|
216
|
+
minDate: adapter.isBefore(minDate, startOfMonth) ? startOfMonth : minDate,
|
|
217
|
+
maxDate: adapter.isAfter(maxDate, endOfMonth) ? endOfMonth : maxDate,
|
|
218
218
|
disablePast,
|
|
219
219
|
disableFuture,
|
|
220
220
|
isDateDisabled,
|
|
@@ -235,13 +235,13 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
|
|
|
235
235
|
}
|
|
236
236
|
});
|
|
237
237
|
const handleDateYearChange = useEventCallback(newDate => {
|
|
238
|
-
const startOfYear =
|
|
239
|
-
const endOfYear =
|
|
238
|
+
const startOfYear = adapter.startOfYear(newDate);
|
|
239
|
+
const endOfYear = adapter.endOfYear(newDate);
|
|
240
240
|
const closestEnabledDate = isDateDisabled(newDate) ? findClosestEnabledDate({
|
|
241
|
-
|
|
241
|
+
adapter,
|
|
242
242
|
date: newDate,
|
|
243
|
-
minDate:
|
|
244
|
-
maxDate:
|
|
243
|
+
minDate: adapter.isBefore(minDate, startOfYear) ? startOfYear : minDate,
|
|
244
|
+
maxDate: adapter.isAfter(maxDate, endOfYear) ? endOfYear : maxDate,
|
|
245
245
|
disablePast,
|
|
246
246
|
disableFuture,
|
|
247
247
|
isDateDisabled,
|
|
@@ -264,12 +264,12 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
|
|
|
264
264
|
const handleSelectedDayChange = useEventCallback(day => {
|
|
265
265
|
if (day) {
|
|
266
266
|
// If there is a date already selected, then we want to keep its time
|
|
267
|
-
return handleValueChange(mergeDateAndTime(
|
|
267
|
+
return handleValueChange(mergeDateAndTime(adapter, day, value ?? referenceDate), 'finish', view);
|
|
268
268
|
}
|
|
269
269
|
return handleValueChange(day, 'finish', view);
|
|
270
270
|
});
|
|
271
271
|
React.useEffect(() => {
|
|
272
|
-
if (
|
|
272
|
+
if (adapter.isValid(value)) {
|
|
273
273
|
setVisibleDate({
|
|
274
274
|
target: value,
|
|
275
275
|
reason: 'controlled-value-change'
|
|
@@ -13,8 +13,8 @@ import { styled, useThemeProps } from '@mui/material/styles';
|
|
|
13
13
|
import composeClasses from '@mui/utils/composeClasses';
|
|
14
14
|
import clsx from 'clsx';
|
|
15
15
|
import { PickersDay } from "../PickersDay/index.js";
|
|
16
|
-
import { usePickerTranslations } from "../hooks/
|
|
17
|
-
import {
|
|
16
|
+
import { usePickerAdapter, usePickerTranslations } from "../hooks/index.js";
|
|
17
|
+
import { useNow } from "../internals/hooks/useUtils.js";
|
|
18
18
|
import { DAY_SIZE, DAY_MARGIN } from "../internals/constants/dimensions.js";
|
|
19
19
|
import { PickersSlideTransition } from "./PickersSlideTransition.js";
|
|
20
20
|
import { useIsDateDisabled } from "./useIsDateDisabled.js";
|
|
@@ -144,14 +144,14 @@ function WrappedDay(_ref) {
|
|
|
144
144
|
slotProps,
|
|
145
145
|
timezone
|
|
146
146
|
} = parentProps;
|
|
147
|
-
const
|
|
147
|
+
const adapter = usePickerAdapter();
|
|
148
148
|
const now = useNow(timezone);
|
|
149
|
-
const isFocusableDay = focusedDay != null &&
|
|
149
|
+
const isFocusableDay = focusedDay != null && adapter.isSameDay(day, focusedDay);
|
|
150
150
|
const isFocusedDay = isViewFocused && isFocusableDay;
|
|
151
|
-
const isSelected = selectedDays.some(selectedDay =>
|
|
152
|
-
const isToday =
|
|
151
|
+
const isSelected = selectedDays.some(selectedDay => adapter.isSameDay(selectedDay, day));
|
|
152
|
+
const isToday = adapter.isSameDay(day, now);
|
|
153
153
|
const isDisabled = React.useMemo(() => disabled || isDateDisabled(day), [disabled, isDateDisabled, day]);
|
|
154
|
-
const isOutsideCurrentMonth = React.useMemo(() =>
|
|
154
|
+
const isOutsideCurrentMonth = React.useMemo(() => adapter.getMonth(day) !== currentMonthNumber, [adapter, day, currentMonthNumber]);
|
|
155
155
|
const ownerState = usePickerDayOwnerState({
|
|
156
156
|
day,
|
|
157
157
|
selected: isSelected,
|
|
@@ -174,7 +174,7 @@ function WrappedDay(_ref) {
|
|
|
174
174
|
role: 'gridcell',
|
|
175
175
|
isAnimating: isMonthSwitchingAnimating,
|
|
176
176
|
// it is used in date range dragging logic by accessing `dataset.timestamp`
|
|
177
|
-
'data-timestamp':
|
|
177
|
+
'data-timestamp': adapter.toJsDate(day).valueOf()
|
|
178
178
|
}, other),
|
|
179
179
|
ownerState: _extends({}, ownerState, {
|
|
180
180
|
day,
|
|
@@ -184,19 +184,19 @@ function WrappedDay(_ref) {
|
|
|
184
184
|
}),
|
|
185
185
|
dayProps = _objectWithoutPropertiesLoose(_useSlotProps, _excluded2);
|
|
186
186
|
const isFirstVisibleCell = React.useMemo(() => {
|
|
187
|
-
const startOfMonth =
|
|
187
|
+
const startOfMonth = adapter.startOfMonth(adapter.setMonth(day, currentMonthNumber));
|
|
188
188
|
if (!showDaysOutsideCurrentMonth) {
|
|
189
|
-
return
|
|
189
|
+
return adapter.isSameDay(day, startOfMonth);
|
|
190
190
|
}
|
|
191
|
-
return
|
|
192
|
-
}, [currentMonthNumber, day, showDaysOutsideCurrentMonth,
|
|
191
|
+
return adapter.isSameDay(day, adapter.startOfWeek(startOfMonth));
|
|
192
|
+
}, [currentMonthNumber, day, showDaysOutsideCurrentMonth, adapter]);
|
|
193
193
|
const isLastVisibleCell = React.useMemo(() => {
|
|
194
|
-
const endOfMonth =
|
|
194
|
+
const endOfMonth = adapter.endOfMonth(adapter.setMonth(day, currentMonthNumber));
|
|
195
195
|
if (!showDaysOutsideCurrentMonth) {
|
|
196
|
-
return
|
|
196
|
+
return adapter.isSameDay(day, endOfMonth);
|
|
197
197
|
}
|
|
198
|
-
return
|
|
199
|
-
}, [currentMonthNumber, day, showDaysOutsideCurrentMonth,
|
|
198
|
+
return adapter.isSameDay(day, adapter.endOfWeek(endOfMonth));
|
|
199
|
+
}, [currentMonthNumber, day, showDaysOutsideCurrentMonth, adapter]);
|
|
200
200
|
return /*#__PURE__*/_jsx(Day, _extends({}, dayProps, {
|
|
201
201
|
day: day,
|
|
202
202
|
disabled: isDisabled,
|
|
@@ -220,7 +220,7 @@ export function DayCalendar(inProps) {
|
|
|
220
220
|
props: inProps,
|
|
221
221
|
name: 'MuiDayCalendar'
|
|
222
222
|
});
|
|
223
|
-
const
|
|
223
|
+
const adapter = usePickerAdapter();
|
|
224
224
|
const {
|
|
225
225
|
onFocusedDayChange,
|
|
226
226
|
className,
|
|
@@ -245,7 +245,7 @@ export function DayCalendar(inProps) {
|
|
|
245
245
|
shouldDisableDate,
|
|
246
246
|
shouldDisableMonth,
|
|
247
247
|
shouldDisableYear,
|
|
248
|
-
dayOfWeekFormatter = date =>
|
|
248
|
+
dayOfWeekFormatter = date => adapter.format(date, 'weekdayShort').charAt(0).toUpperCase(),
|
|
249
249
|
hasFocus,
|
|
250
250
|
onFocusedViewChange,
|
|
251
251
|
gridLabelId,
|
|
@@ -282,22 +282,22 @@ export function DayCalendar(inProps) {
|
|
|
282
282
|
const handleKeyDown = useEventCallback((event, day) => {
|
|
283
283
|
switch (event.key) {
|
|
284
284
|
case 'ArrowUp':
|
|
285
|
-
focusDay(
|
|
285
|
+
focusDay(adapter.addDays(day, -7));
|
|
286
286
|
event.preventDefault();
|
|
287
287
|
break;
|
|
288
288
|
case 'ArrowDown':
|
|
289
|
-
focusDay(
|
|
289
|
+
focusDay(adapter.addDays(day, 7));
|
|
290
290
|
event.preventDefault();
|
|
291
291
|
break;
|
|
292
292
|
case 'ArrowLeft':
|
|
293
293
|
{
|
|
294
|
-
const newFocusedDayDefault =
|
|
295
|
-
const nextAvailableMonth =
|
|
294
|
+
const newFocusedDayDefault = adapter.addDays(day, isRtl ? 1 : -1);
|
|
295
|
+
const nextAvailableMonth = adapter.addMonths(day, isRtl ? 1 : -1);
|
|
296
296
|
const closestDayToFocus = findClosestEnabledDate({
|
|
297
|
-
|
|
297
|
+
adapter,
|
|
298
298
|
date: newFocusedDayDefault,
|
|
299
|
-
minDate: isRtl ? newFocusedDayDefault :
|
|
300
|
-
maxDate: isRtl ?
|
|
299
|
+
minDate: isRtl ? newFocusedDayDefault : adapter.startOfMonth(nextAvailableMonth),
|
|
300
|
+
maxDate: isRtl ? adapter.endOfMonth(nextAvailableMonth) : newFocusedDayDefault,
|
|
301
301
|
isDateDisabled,
|
|
302
302
|
timezone
|
|
303
303
|
});
|
|
@@ -307,13 +307,13 @@ export function DayCalendar(inProps) {
|
|
|
307
307
|
}
|
|
308
308
|
case 'ArrowRight':
|
|
309
309
|
{
|
|
310
|
-
const newFocusedDayDefault =
|
|
311
|
-
const nextAvailableMonth =
|
|
310
|
+
const newFocusedDayDefault = adapter.addDays(day, isRtl ? -1 : 1);
|
|
311
|
+
const nextAvailableMonth = adapter.addMonths(day, isRtl ? -1 : 1);
|
|
312
312
|
const closestDayToFocus = findClosestEnabledDate({
|
|
313
|
-
|
|
313
|
+
adapter,
|
|
314
314
|
date: newFocusedDayDefault,
|
|
315
|
-
minDate: isRtl ?
|
|
316
|
-
maxDate: isRtl ? newFocusedDayDefault :
|
|
315
|
+
minDate: isRtl ? adapter.startOfMonth(nextAvailableMonth) : newFocusedDayDefault,
|
|
316
|
+
maxDate: isRtl ? newFocusedDayDefault : adapter.endOfMonth(nextAvailableMonth),
|
|
317
317
|
isDateDisabled,
|
|
318
318
|
timezone
|
|
319
319
|
});
|
|
@@ -322,19 +322,19 @@ export function DayCalendar(inProps) {
|
|
|
322
322
|
break;
|
|
323
323
|
}
|
|
324
324
|
case 'Home':
|
|
325
|
-
focusDay(
|
|
325
|
+
focusDay(adapter.startOfWeek(day));
|
|
326
326
|
event.preventDefault();
|
|
327
327
|
break;
|
|
328
328
|
case 'End':
|
|
329
|
-
focusDay(
|
|
329
|
+
focusDay(adapter.endOfWeek(day));
|
|
330
330
|
event.preventDefault();
|
|
331
331
|
break;
|
|
332
332
|
case 'PageUp':
|
|
333
|
-
focusDay(
|
|
333
|
+
focusDay(adapter.addMonths(day, 1));
|
|
334
334
|
event.preventDefault();
|
|
335
335
|
break;
|
|
336
336
|
case 'PageDown':
|
|
337
|
-
focusDay(
|
|
337
|
+
focusDay(adapter.addMonths(day, -1));
|
|
338
338
|
event.preventDefault();
|
|
339
339
|
break;
|
|
340
340
|
default:
|
|
@@ -343,33 +343,33 @@ export function DayCalendar(inProps) {
|
|
|
343
343
|
});
|
|
344
344
|
const handleFocus = useEventCallback((event, day) => focusDay(day));
|
|
345
345
|
const handleBlur = useEventCallback((event, day) => {
|
|
346
|
-
if (focusedDay != null &&
|
|
346
|
+
if (focusedDay != null && adapter.isSameDay(focusedDay, day)) {
|
|
347
347
|
onFocusedViewChange?.(false);
|
|
348
348
|
}
|
|
349
349
|
});
|
|
350
|
-
const currentMonthNumber =
|
|
351
|
-
const currentYearNumber =
|
|
352
|
-
const validSelectedDays = React.useMemo(() => selectedDays.filter(day => !!day).map(day =>
|
|
350
|
+
const currentMonthNumber = adapter.getMonth(currentMonth);
|
|
351
|
+
const currentYearNumber = adapter.getYear(currentMonth);
|
|
352
|
+
const validSelectedDays = React.useMemo(() => selectedDays.filter(day => !!day).map(day => adapter.startOfDay(day)), [adapter, selectedDays]);
|
|
353
353
|
|
|
354
354
|
// need a new ref whenever the `key` of the transition changes: https://reactcommunity.org/react-transition-group/transition/#Transition-prop-nodeRef.
|
|
355
355
|
const transitionKey = `${currentYearNumber}-${currentMonthNumber}`;
|
|
356
356
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
357
357
|
const slideNodeRef = React.useMemo(() => /*#__PURE__*/React.createRef(), [transitionKey]);
|
|
358
358
|
const weeksToDisplay = React.useMemo(() => {
|
|
359
|
-
const toDisplay =
|
|
360
|
-
let nextMonth =
|
|
359
|
+
const toDisplay = adapter.getWeekArray(currentMonth);
|
|
360
|
+
let nextMonth = adapter.addMonths(currentMonth, 1);
|
|
361
361
|
while (fixedWeekNumber && toDisplay.length < fixedWeekNumber) {
|
|
362
|
-
const additionalWeeks =
|
|
363
|
-
const hasCommonWeek =
|
|
362
|
+
const additionalWeeks = adapter.getWeekArray(nextMonth);
|
|
363
|
+
const hasCommonWeek = adapter.isSameDay(toDisplay[toDisplay.length - 1][0], additionalWeeks[0][0]);
|
|
364
364
|
additionalWeeks.slice(hasCommonWeek ? 1 : 0).forEach(week => {
|
|
365
365
|
if (toDisplay.length < fixedWeekNumber) {
|
|
366
366
|
toDisplay.push(week);
|
|
367
367
|
}
|
|
368
368
|
});
|
|
369
|
-
nextMonth =
|
|
369
|
+
nextMonth = adapter.addMonths(nextMonth, 1);
|
|
370
370
|
}
|
|
371
371
|
return toDisplay;
|
|
372
|
-
}, [currentMonth, fixedWeekNumber,
|
|
372
|
+
}, [currentMonth, fixedWeekNumber, adapter]);
|
|
373
373
|
return /*#__PURE__*/_jsxs(PickersCalendarDayRoot, {
|
|
374
374
|
role: "grid",
|
|
375
375
|
"aria-labelledby": gridLabelId,
|
|
@@ -383,10 +383,10 @@ export function DayCalendar(inProps) {
|
|
|
383
383
|
"aria-label": translations.calendarWeekNumberHeaderLabel,
|
|
384
384
|
className: classes.weekNumberLabel,
|
|
385
385
|
children: translations.calendarWeekNumberHeaderText
|
|
386
|
-
}), getWeekdays(
|
|
386
|
+
}), getWeekdays(adapter, now).map((weekday, i) => /*#__PURE__*/_jsx(PickersCalendarWeekDayLabel, {
|
|
387
387
|
variant: "caption",
|
|
388
388
|
role: "columnheader",
|
|
389
|
-
"aria-label":
|
|
389
|
+
"aria-label": adapter.format(weekday, 'weekday'),
|
|
390
390
|
className: classes.weekDayLabel,
|
|
391
391
|
children: dayOfWeekFormatter(weekday)
|
|
392
392
|
}, i.toString()))]
|
|
@@ -415,8 +415,8 @@ export function DayCalendar(inProps) {
|
|
|
415
415
|
children: [displayWeekNumber && /*#__PURE__*/_jsx(PickersCalendarWeekNumber, {
|
|
416
416
|
className: classes.weekNumber,
|
|
417
417
|
role: "rowheader",
|
|
418
|
-
"aria-label": translations.calendarWeekNumberAriaLabelText(
|
|
419
|
-
children: translations.calendarWeekNumberText(
|
|
418
|
+
"aria-label": translations.calendarWeekNumberAriaLabelText(adapter.getWeekNumber(week[0])),
|
|
419
|
+
children: translations.calendarWeekNumberText(adapter.getWeekNumber(week[0]))
|
|
420
420
|
}), week.map((day, dayIndex) => /*#__PURE__*/_jsx(WrappedDay, {
|
|
421
421
|
parentProps: props,
|
|
422
422
|
day: day,
|
|
@@ -4,28 +4,28 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
6
6
|
import { useIsDateDisabled } from "./useIsDateDisabled.js";
|
|
7
|
-
import { useUtils } from "../internals/hooks/useUtils.js";
|
|
8
7
|
import { singleItemValueManager } from "../internals/utils/valueManagers.js";
|
|
9
8
|
import { SECTION_TYPE_GRANULARITY } from "../internals/utils/getDefaultReferenceDate.js";
|
|
10
9
|
import { findClosestEnabledDate } from "../internals/utils/date-utils.js";
|
|
11
|
-
|
|
10
|
+
import { usePickerAdapter } from "../hooks/usePickerAdapter.js";
|
|
11
|
+
const createCalendarStateReducer = (reduceAnimations, adapter) => (state, action) => {
|
|
12
12
|
switch (action.type) {
|
|
13
13
|
case 'setVisibleDate':
|
|
14
14
|
return _extends({}, state, {
|
|
15
15
|
slideDirection: action.direction,
|
|
16
16
|
currentMonth: action.month,
|
|
17
|
-
isMonthSwitchingAnimating: !
|
|
17
|
+
isMonthSwitchingAnimating: !adapter.isSameMonth(action.month, state.currentMonth) && !reduceAnimations && !action.skipAnimation,
|
|
18
18
|
focusedDay: action.focusedDay
|
|
19
19
|
});
|
|
20
20
|
case 'changeMonthTimezone':
|
|
21
21
|
{
|
|
22
22
|
const newTimezone = action.newTimezone;
|
|
23
|
-
if (
|
|
23
|
+
if (adapter.getTimezone(state.currentMonth) === newTimezone) {
|
|
24
24
|
return state;
|
|
25
25
|
}
|
|
26
|
-
let newCurrentMonth =
|
|
27
|
-
if (
|
|
28
|
-
newCurrentMonth =
|
|
26
|
+
let newCurrentMonth = adapter.setTimezone(state.currentMonth, newTimezone);
|
|
27
|
+
if (adapter.getMonth(newCurrentMonth) !== adapter.getMonth(state.currentMonth)) {
|
|
28
|
+
newCurrentMonth = adapter.setMonth(newCurrentMonth, adapter.getMonth(state.currentMonth));
|
|
29
29
|
}
|
|
30
30
|
return _extends({}, state, {
|
|
31
31
|
currentMonth: newCurrentMonth
|
|
@@ -54,12 +54,12 @@ export const useCalendarState = params => {
|
|
|
54
54
|
timezone,
|
|
55
55
|
getCurrentMonthFromVisibleDate
|
|
56
56
|
} = params;
|
|
57
|
-
const
|
|
58
|
-
const reducerFn = React.useRef(createCalendarStateReducer(Boolean(reduceAnimations),
|
|
57
|
+
const adapter = usePickerAdapter();
|
|
58
|
+
const reducerFn = React.useRef(createCalendarStateReducer(Boolean(reduceAnimations), adapter)).current;
|
|
59
59
|
const referenceDate = React.useMemo(() => {
|
|
60
60
|
return singleItemValueManager.getInitialReferenceValue({
|
|
61
61
|
value,
|
|
62
|
-
|
|
62
|
+
adapter,
|
|
63
63
|
timezone,
|
|
64
64
|
props: params,
|
|
65
65
|
referenceDate: referenceDateProp,
|
|
@@ -72,7 +72,7 @@ export const useCalendarState = params => {
|
|
|
72
72
|
const [calendarState, dispatch] = React.useReducer(reducerFn, {
|
|
73
73
|
isMonthSwitchingAnimating: false,
|
|
74
74
|
focusedDay: referenceDate,
|
|
75
|
-
currentMonth:
|
|
75
|
+
currentMonth: adapter.startOfMonth(referenceDate),
|
|
76
76
|
slideDirection: 'left'
|
|
77
77
|
});
|
|
78
78
|
const isDateDisabled = useIsDateDisabled({
|
|
@@ -89,14 +89,14 @@ export const useCalendarState = params => {
|
|
|
89
89
|
React.useEffect(() => {
|
|
90
90
|
dispatch({
|
|
91
91
|
type: 'changeMonthTimezone',
|
|
92
|
-
newTimezone:
|
|
92
|
+
newTimezone: adapter.getTimezone(referenceDate)
|
|
93
93
|
});
|
|
94
|
-
}, [referenceDate,
|
|
94
|
+
}, [referenceDate, adapter]);
|
|
95
95
|
const setVisibleDate = useEventCallback(({
|
|
96
96
|
target,
|
|
97
97
|
reason
|
|
98
98
|
}) => {
|
|
99
|
-
if (reason === 'cell-interaction' && calendarState.focusedDay != null &&
|
|
99
|
+
if (reason === 'cell-interaction' && calendarState.focusedDay != null && adapter.isSameDay(target, calendarState.focusedDay)) {
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
102
|
const skipAnimation = reason === 'cell-interaction';
|
|
@@ -106,18 +106,18 @@ export const useCalendarState = params => {
|
|
|
106
106
|
month = getCurrentMonthFromVisibleDate(target, calendarState.currentMonth);
|
|
107
107
|
focusedDay = target;
|
|
108
108
|
} else {
|
|
109
|
-
month =
|
|
109
|
+
month = adapter.isSameMonth(target, calendarState.currentMonth) ? calendarState.currentMonth : adapter.startOfMonth(target);
|
|
110
110
|
focusedDay = target;
|
|
111
111
|
|
|
112
112
|
// If the date is disabled, we try to find a non-disabled date inside the same month.
|
|
113
113
|
if (isDateDisabled(focusedDay)) {
|
|
114
|
-
const startOfMonth =
|
|
115
|
-
const endOfMonth =
|
|
114
|
+
const startOfMonth = adapter.startOfMonth(target);
|
|
115
|
+
const endOfMonth = adapter.endOfMonth(target);
|
|
116
116
|
focusedDay = findClosestEnabledDate({
|
|
117
|
-
|
|
117
|
+
adapter,
|
|
118
118
|
date: focusedDay,
|
|
119
|
-
minDate:
|
|
120
|
-
maxDate:
|
|
119
|
+
minDate: adapter.isBefore(minDate, startOfMonth) ? startOfMonth : minDate,
|
|
120
|
+
maxDate: adapter.isAfter(maxDate, endOfMonth) ? endOfMonth : maxDate,
|
|
121
121
|
disablePast,
|
|
122
122
|
disableFuture,
|
|
123
123
|
isDateDisabled,
|
|
@@ -125,19 +125,19 @@ export const useCalendarState = params => {
|
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
-
const hasChangedMonth = !
|
|
129
|
-
const hasChangedYear = !
|
|
128
|
+
const hasChangedMonth = !adapter.isSameMonth(calendarState.currentMonth, month);
|
|
129
|
+
const hasChangedYear = !adapter.isSameYear(calendarState.currentMonth, month);
|
|
130
130
|
if (hasChangedMonth) {
|
|
131
131
|
onMonthChange?.(month);
|
|
132
132
|
}
|
|
133
133
|
if (hasChangedYear) {
|
|
134
|
-
onYearChange?.(
|
|
134
|
+
onYearChange?.(adapter.startOfYear(month));
|
|
135
135
|
}
|
|
136
136
|
dispatch({
|
|
137
137
|
type: 'setVisibleDate',
|
|
138
138
|
month,
|
|
139
|
-
direction:
|
|
140
|
-
focusedDay: calendarState.focusedDay != null && focusedDay != null &&
|
|
139
|
+
direction: adapter.isAfterDay(month, calendarState.currentMonth) ? 'left' : 'right',
|
|
140
|
+
focusedDay: calendarState.focusedDay != null && focusedDay != null && adapter.isSameDay(focusedDay, calendarState.focusedDay) ? calendarState.focusedDay : focusedDay,
|
|
141
141
|
skipAnimation
|
|
142
142
|
});
|
|
143
143
|
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { validateDate } from "../validation/index.js";
|
|
5
|
-
import {
|
|
5
|
+
import { usePickerAdapter } from "../hooks/usePickerAdapter.js";
|
|
6
6
|
export const useIsDateDisabled = ({
|
|
7
7
|
shouldDisableDate,
|
|
8
8
|
shouldDisableMonth,
|
|
@@ -13,7 +13,7 @@ export const useIsDateDisabled = ({
|
|
|
13
13
|
disablePast,
|
|
14
14
|
timezone
|
|
15
15
|
}) => {
|
|
16
|
-
const adapter =
|
|
16
|
+
const adapter = usePickerAdapter();
|
|
17
17
|
return React.useCallback(day => validateDate({
|
|
18
18
|
adapter,
|
|
19
19
|
value: day,
|
|
@@ -10,12 +10,10 @@ import Typography from '@mui/material/Typography';
|
|
|
10
10
|
import { styled, useThemeProps } from '@mui/material/styles';
|
|
11
11
|
import composeClasses from '@mui/utils/composeClasses';
|
|
12
12
|
import { PickersToolbar } from "../internals/components/PickersToolbar.js";
|
|
13
|
-
import { usePickerTranslations } from "../hooks/
|
|
14
|
-
import { useUtils } from "../internals/hooks/useUtils.js";
|
|
13
|
+
import { usePickerAdapter, usePickerContext, usePickerTranslations } from "../hooks/index.js";
|
|
15
14
|
import { getDatePickerToolbarUtilityClass } from "./datePickerToolbarClasses.js";
|
|
16
15
|
import { resolveDateFormat } from "../internals/utils/date-utils.js";
|
|
17
16
|
import { useToolbarOwnerState } from "../internals/hooks/useToolbarOwnerState.js";
|
|
18
|
-
import { usePickerContext } from "../hooks/index.js";
|
|
19
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
18
|
const useUtilityClasses = classes => {
|
|
21
19
|
const slots = {
|
|
@@ -63,7 +61,7 @@ export const DatePickerToolbar = /*#__PURE__*/React.forwardRef(function DatePick
|
|
|
63
61
|
classes: classesProp
|
|
64
62
|
} = props,
|
|
65
63
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
66
|
-
const
|
|
64
|
+
const adapter = usePickerAdapter();
|
|
67
65
|
const {
|
|
68
66
|
value,
|
|
69
67
|
views,
|
|
@@ -73,15 +71,15 @@ export const DatePickerToolbar = /*#__PURE__*/React.forwardRef(function DatePick
|
|
|
73
71
|
const ownerState = useToolbarOwnerState();
|
|
74
72
|
const classes = useUtilityClasses(classesProp);
|
|
75
73
|
const dateText = React.useMemo(() => {
|
|
76
|
-
if (!
|
|
74
|
+
if (!adapter.isValid(value)) {
|
|
77
75
|
return toolbarPlaceholder;
|
|
78
76
|
}
|
|
79
|
-
const formatFromViews = resolveDateFormat(
|
|
77
|
+
const formatFromViews = resolveDateFormat(adapter, {
|
|
80
78
|
format: toolbarFormat,
|
|
81
79
|
views
|
|
82
80
|
}, true);
|
|
83
|
-
return
|
|
84
|
-
}, [value, toolbarFormat, toolbarPlaceholder,
|
|
81
|
+
return adapter.formatByString(value, formatFromViews);
|
|
82
|
+
}, [value, toolbarFormat, toolbarPlaceholder, adapter, views]);
|
|
85
83
|
return /*#__PURE__*/_jsx(DatePickerToolbarRoot, _extends({
|
|
86
84
|
ref: ref,
|
|
87
85
|
toolbarTitle: translations.datePickerToolbarTitle,
|
|
@@ -51,7 +51,7 @@ process.env.NODE_ENV !== "production" ? DateTimeField.propTypes = {
|
|
|
51
51
|
// ----------------------------------------------------------------------
|
|
52
52
|
/**
|
|
53
53
|
* 12h/24h view for hour selection clock.
|
|
54
|
-
* @default
|
|
54
|
+
* @default adapter.is12HourCycleInCurrentLocale()
|
|
55
55
|
*/
|
|
56
56
|
ampm: PropTypes.bool,
|
|
57
57
|
/**
|
|
@@ -53,7 +53,7 @@ process.env.NODE_ENV !== "production" ? DateTimePicker.propTypes = {
|
|
|
53
53
|
// ----------------------------------------------------------------------
|
|
54
54
|
/**
|
|
55
55
|
* 12h/24h view for hour selection clock.
|
|
56
|
-
* @default
|
|
56
|
+
* @default adapter.is12HourCycleInCurrentLocale()
|
|
57
57
|
*/
|
|
58
58
|
ampm: PropTypes.bool,
|
|
59
59
|
/**
|