@mui/x-date-pickers 6.6.0 → 6.8.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/AdapterDateFns/AdapterDateFns.js +20 -19
- package/AdapterDateFnsJalali/AdapterDateFnsJalali.js +17 -16
- package/AdapterDayjs/AdapterDayjs.js +12 -11
- package/AdapterLuxon/AdapterLuxon.js +20 -19
- package/AdapterMoment/AdapterMoment.js +12 -11
- package/AdapterMomentHijri/AdapterMomentHijri.js +20 -19
- package/AdapterMomentJalaali/AdapterMomentJalaali.js +20 -19
- package/CHANGELOG.md +147 -13
- package/DateCalendar/DateCalendar.js +16 -6
- package/DateCalendar/DateCalendar.types.d.ts +6 -1
- package/DateCalendar/useCalendarState.d.ts +3 -2
- package/DateCalendar/useCalendarState.js +36 -15
- package/DateField/DateField.js +1 -1
- package/DatePicker/DatePicker.js +1 -1
- package/DatePicker/DatePickerToolbar.js +6 -15
- package/DatePicker/shared.d.ts +1 -5
- package/DatePicker/shared.js +1 -16
- package/DateTimeField/DateTimeField.js +1 -1
- package/DateTimePicker/DateTimePicker.js +1 -1
- package/DesktopDatePicker/DesktopDatePicker.js +4 -3
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -2
- package/DesktopTimePicker/DesktopTimePicker.js +5 -1
- package/LocalizationProvider/LocalizationProvider.js +1 -0
- package/MobileDatePicker/MobileDatePicker.js +4 -3
- package/MobileDateTimePicker/MobileDateTimePicker.js +6 -2
- package/MobileTimePicker/MobileTimePicker.js +5 -1
- package/MonthCalendar/MonthCalendar.js +28 -11
- package/MonthCalendar/MonthCalendar.types.d.ts +5 -0
- package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +1 -1
- package/PickersLayout/PickersLayout.js +1 -0
- package/PickersLayout/usePickerLayout.js +4 -3
- package/PickersShortcuts/PickersShortcuts.d.ts +12 -2
- package/PickersShortcuts/PickersShortcuts.js +10 -2
- package/PickersShortcuts/index.d.ts +1 -1
- package/StaticDatePicker/StaticDatePicker.js +1 -1
- package/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
- package/TimeField/TimeField.js +1 -1
- package/TimePicker/shared.d.ts +1 -1
- package/YearCalendar/YearCalendar.js +26 -9
- package/YearCalendar/YearCalendar.types.d.ts +5 -0
- package/index.js +1 -1
- package/internals/hooks/useField/useField.types.d.ts +1 -1
- package/internals/hooks/useField/useFieldState.js +0 -1
- package/internals/hooks/usePicker/usePickerValue.js +22 -2
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +6 -2
- package/internals/utils/date-time-utils.d.ts +6 -0
- package/internals/utils/date-time-utils.js +41 -0
- package/internals/utils/date-utils.d.ts +5 -2
- package/internals/utils/date-utils.js +33 -10
- package/internals/utils/getDefaultReferenceDate.d.ts +11 -3
- package/internals/utils/getDefaultReferenceDate.js +2 -3
- package/internals/utils/time-utils.d.ts +6 -1
- package/internals/utils/time-utils.js +27 -0
- package/internals/utils/validation/extractValidationProps.d.ts +1 -1
- package/internals/utils/views.d.ts +2 -3
- package/internals/utils/views.js +6 -2
- package/legacy/AdapterDateFns/AdapterDateFns.js +20 -19
- package/legacy/AdapterDateFnsJalali/AdapterDateFnsJalali.js +17 -16
- package/legacy/AdapterDayjs/AdapterDayjs.js +12 -11
- package/legacy/AdapterLuxon/AdapterLuxon.js +20 -19
- package/legacy/AdapterMoment/AdapterMoment.js +12 -11
- package/legacy/AdapterMomentHijri/AdapterMomentHijri.js +20 -19
- package/legacy/AdapterMomentJalaali/AdapterMomentJalaali.js +20 -19
- package/legacy/DateCalendar/DateCalendar.js +16 -6
- package/legacy/DateCalendar/useCalendarState.js +35 -15
- package/legacy/DateField/DateField.js +1 -1
- package/legacy/DatePicker/DatePicker.js +1 -1
- package/legacy/DatePicker/DatePickerToolbar.js +6 -15
- package/legacy/DatePicker/shared.js +1 -15
- package/legacy/DateTimeField/DateTimeField.js +1 -1
- package/legacy/DateTimePicker/DateTimePicker.js +1 -1
- package/legacy/DesktopDatePicker/DesktopDatePicker.js +4 -3
- package/legacy/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -2
- package/legacy/DesktopTimePicker/DesktopTimePicker.js +5 -1
- package/legacy/LocalizationProvider/LocalizationProvider.js +1 -0
- package/legacy/MobileDatePicker/MobileDatePicker.js +4 -3
- package/legacy/MobileDateTimePicker/MobileDateTimePicker.js +6 -2
- package/legacy/MobileTimePicker/MobileTimePicker.js +5 -1
- package/legacy/MonthCalendar/MonthCalendar.js +30 -13
- package/legacy/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +1 -1
- package/legacy/PickersLayout/PickersLayout.js +1 -0
- package/legacy/PickersLayout/usePickerLayout.js +3 -2
- package/legacy/PickersShortcuts/PickersShortcuts.js +10 -2
- package/legacy/StaticDatePicker/StaticDatePicker.js +1 -1
- package/legacy/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
- package/legacy/TimeField/TimeField.js +1 -1
- package/legacy/YearCalendar/YearCalendar.js +28 -11
- package/legacy/index.js +1 -1
- package/legacy/internals/hooks/useField/useFieldState.js +0 -1
- package/legacy/internals/hooks/usePicker/usePickerValue.js +24 -2
- package/legacy/internals/utils/date-time-utils.js +39 -0
- package/legacy/internals/utils/date-utils.js +31 -9
- package/legacy/internals/utils/getDefaultReferenceDate.js +2 -3
- package/legacy/internals/utils/time-utils.js +26 -0
- package/legacy/internals/utils/views.js +7 -5
- package/legacy/locales/deDE.js +2 -2
- package/legacy/locales/elGR.js +93 -0
- package/legacy/locales/index.js +17 -15
- package/legacy/locales/roRO.js +81 -0
- package/locales/deDE.js +2 -2
- package/locales/elGR.d.ts +53 -0
- package/locales/elGR.js +57 -0
- package/locales/index.d.ts +17 -15
- package/locales/index.js +17 -15
- package/locales/roRO.d.ts +53 -0
- package/locales/roRO.js +63 -0
- package/models/adapters.d.ts +137 -37
- package/modern/AdapterDateFns/AdapterDateFns.js +20 -19
- package/modern/AdapterDateFnsJalali/AdapterDateFnsJalali.js +17 -16
- package/modern/AdapterDayjs/AdapterDayjs.js +12 -11
- package/modern/AdapterLuxon/AdapterLuxon.js +20 -19
- package/modern/AdapterMoment/AdapterMoment.js +12 -11
- package/modern/AdapterMomentHijri/AdapterMomentHijri.js +20 -19
- package/modern/AdapterMomentJalaali/AdapterMomentJalaali.js +20 -19
- package/modern/DateCalendar/DateCalendar.js +16 -6
- package/modern/DateCalendar/useCalendarState.js +36 -14
- package/modern/DateField/DateField.js +1 -1
- package/modern/DatePicker/DatePicker.js +1 -1
- package/modern/DatePicker/DatePickerToolbar.js +6 -15
- package/modern/DatePicker/shared.js +1 -16
- package/modern/DateTimeField/DateTimeField.js +1 -1
- package/modern/DateTimePicker/DateTimePicker.js +1 -1
- package/modern/DesktopDatePicker/DesktopDatePicker.js +4 -3
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -2
- package/modern/DesktopTimePicker/DesktopTimePicker.js +5 -1
- package/modern/LocalizationProvider/LocalizationProvider.js +1 -0
- package/modern/MobileDatePicker/MobileDatePicker.js +4 -3
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +6 -2
- package/modern/MobileTimePicker/MobileTimePicker.js +5 -1
- package/modern/MonthCalendar/MonthCalendar.js +28 -11
- package/modern/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +1 -1
- package/modern/PickersLayout/PickersLayout.js +1 -0
- package/modern/PickersLayout/usePickerLayout.js +4 -3
- package/modern/PickersShortcuts/PickersShortcuts.js +10 -2
- package/modern/StaticDatePicker/StaticDatePicker.js +1 -1
- package/modern/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
- package/modern/TimeField/TimeField.js +1 -1
- package/modern/YearCalendar/YearCalendar.js +26 -9
- package/modern/index.js +1 -1
- package/modern/internals/hooks/useField/useFieldState.js +0 -1
- package/modern/internals/hooks/usePicker/usePickerValue.js +22 -2
- package/modern/internals/utils/date-time-utils.js +41 -0
- package/modern/internals/utils/date-utils.js +33 -10
- package/modern/internals/utils/getDefaultReferenceDate.js +2 -3
- package/modern/internals/utils/time-utils.js +27 -0
- package/modern/internals/utils/views.js +6 -2
- package/modern/locales/deDE.js +2 -2
- package/modern/locales/elGR.js +57 -0
- package/modern/locales/index.js +17 -15
- package/modern/locales/roRO.js +60 -0
- package/node/AdapterDateFns/AdapterDateFns.js +20 -19
- package/node/AdapterDateFnsJalali/AdapterDateFnsJalali.js +17 -16
- package/node/AdapterDayjs/AdapterDayjs.js +12 -11
- package/node/AdapterLuxon/AdapterLuxon.js +20 -19
- package/node/AdapterMoment/AdapterMoment.js +12 -11
- package/node/AdapterMomentHijri/AdapterMomentHijri.js +20 -19
- package/node/AdapterMomentJalaali/AdapterMomentJalaali.js +20 -19
- package/node/DateCalendar/DateCalendar.js +16 -6
- package/node/DateCalendar/useCalendarState.js +36 -14
- package/node/DateField/DateField.js +1 -1
- package/node/DatePicker/DatePicker.js +1 -1
- package/node/DatePicker/DatePickerToolbar.js +6 -15
- package/node/DatePicker/shared.js +0 -17
- package/node/DateTimeField/DateTimeField.js +1 -1
- package/node/DateTimePicker/DateTimePicker.js +1 -1
- package/node/DesktopDatePicker/DesktopDatePicker.js +3 -2
- package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +8 -4
- package/node/DesktopTimePicker/DesktopTimePicker.js +7 -3
- package/node/LocalizationProvider/LocalizationProvider.js +1 -0
- package/node/MobileDatePicker/MobileDatePicker.js +3 -2
- package/node/MobileDateTimePicker/MobileDateTimePicker.js +8 -4
- package/node/MobileTimePicker/MobileTimePicker.js +7 -3
- package/node/MonthCalendar/MonthCalendar.js +28 -11
- package/node/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +1 -1
- package/node/PickersLayout/PickersLayout.js +1 -0
- package/node/PickersLayout/usePickerLayout.js +4 -3
- package/node/PickersShortcuts/PickersShortcuts.js +10 -2
- package/node/StaticDatePicker/StaticDatePicker.js +1 -1
- package/node/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
- package/node/TimeField/TimeField.js +1 -1
- package/node/YearCalendar/YearCalendar.js +26 -9
- package/node/index.js +1 -1
- package/node/internals/hooks/useField/useFieldState.js +0 -1
- package/node/internals/hooks/usePicker/usePickerValue.js +22 -2
- package/node/internals/utils/date-time-utils.js +49 -0
- package/node/internals/utils/date-utils.js +35 -12
- package/node/internals/utils/getDefaultReferenceDate.js +3 -3
- package/node/internals/utils/time-utils.js +30 -2
- package/node/internals/utils/views.js +8 -5
- package/node/locales/deDE.js +2 -2
- package/node/locales/elGR.js +64 -0
- package/node/locales/index.js +112 -90
- package/node/locales/roRO.js +67 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["autoFocus", "onViewChange", "value", "defaultValue", "disableFuture", "disablePast", "defaultCalendarMonth", "onChange", "onYearChange", "onMonthChange", "reduceAnimations", "shouldDisableDate", "shouldDisableMonth", "shouldDisableYear", "view", "views", "openTo", "className", "disabled", "readOnly", "minDate", "maxDate", "disableHighlightToday", "focusedView", "onFocusedViewChange", "showDaysOutsideCurrentMonth", "fixedWeekNumber", "dayOfWeekFormatter", "components", "componentsProps", "slots", "slotProps", "loading", "renderLoading", "displayWeekNumber", "yearsPerRow", "monthsPerRow"];
|
|
3
|
+
const _excluded = ["autoFocus", "onViewChange", "value", "defaultValue", "referenceDate", "disableFuture", "disablePast", "defaultCalendarMonth", "onChange", "onYearChange", "onMonthChange", "reduceAnimations", "shouldDisableDate", "shouldDisableMonth", "shouldDisableYear", "view", "views", "openTo", "className", "disabled", "readOnly", "minDate", "maxDate", "disableHighlightToday", "focusedView", "onFocusedViewChange", "showDaysOutsideCurrentMonth", "fixedWeekNumber", "dayOfWeekFormatter", "components", "componentsProps", "slots", "slotProps", "loading", "renderLoading", "displayWeekNumber", "yearsPerRow", "monthsPerRow"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import clsx from 'clsx';
|
|
@@ -84,6 +84,7 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
|
|
|
84
84
|
onViewChange,
|
|
85
85
|
value: valueProp,
|
|
86
86
|
defaultValue,
|
|
87
|
+
referenceDate: referenceDateProp,
|
|
87
88
|
disableFuture,
|
|
88
89
|
disablePast,
|
|
89
90
|
defaultCalendarMonth,
|
|
@@ -147,6 +148,7 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
|
|
|
147
148
|
onFocusedViewChange
|
|
148
149
|
});
|
|
149
150
|
const {
|
|
151
|
+
referenceDate,
|
|
150
152
|
calendarState,
|
|
151
153
|
changeFocusedDay,
|
|
152
154
|
changeMonth,
|
|
@@ -156,6 +158,7 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
|
|
|
156
158
|
} = useCalendarState({
|
|
157
159
|
value,
|
|
158
160
|
defaultCalendarMonth,
|
|
161
|
+
referenceDate: referenceDateProp,
|
|
159
162
|
reduceAnimations,
|
|
160
163
|
onMonthChange,
|
|
161
164
|
minDate,
|
|
@@ -207,9 +210,9 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
|
|
|
207
210
|
changeFocusedDay(closestEnabledDate, true);
|
|
208
211
|
});
|
|
209
212
|
const handleSelectedDayChange = useEventCallback(day => {
|
|
210
|
-
if (
|
|
213
|
+
if (day) {
|
|
211
214
|
// If there is a date already selected, then we want to keep its time
|
|
212
|
-
return handleValueChange(mergeDateAndTime(utils, day, value), 'finish');
|
|
215
|
+
return handleValueChange(mergeDateAndTime(utils, day, value != null ? value : referenceDate), 'finish');
|
|
213
216
|
}
|
|
214
217
|
return handleValueChange(day, 'finish');
|
|
215
218
|
});
|
|
@@ -286,7 +289,8 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
|
|
|
286
289
|
shouldDisableYear: shouldDisableYear,
|
|
287
290
|
hasFocus: hasFocus,
|
|
288
291
|
onFocusedViewChange: isViewFocused => setFocusedView('year', isViewFocused),
|
|
289
|
-
yearsPerRow: yearsPerRow
|
|
292
|
+
yearsPerRow: yearsPerRow,
|
|
293
|
+
referenceDate: referenceDate
|
|
290
294
|
})), view === 'month' && /*#__PURE__*/_jsx(MonthCalendar, _extends({}, baseDateValidationProps, commonViewProps, {
|
|
291
295
|
hasFocus: hasFocus,
|
|
292
296
|
className: className,
|
|
@@ -294,7 +298,8 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
|
|
|
294
298
|
onChange: handleDateMonthChange,
|
|
295
299
|
shouldDisableMonth: shouldDisableMonth,
|
|
296
300
|
onFocusedViewChange: isViewFocused => setFocusedView('month', isViewFocused),
|
|
297
|
-
monthsPerRow: monthsPerRow
|
|
301
|
+
monthsPerRow: monthsPerRow,
|
|
302
|
+
referenceDate: referenceDate
|
|
298
303
|
})), view === 'day' && /*#__PURE__*/_jsx(DayCalendar, _extends({}, calendarState, baseDateValidationProps, commonViewProps, {
|
|
299
304
|
onMonthSwitchingAnimationEnd: onMonthSwitchingAnimationEnd,
|
|
300
305
|
onFocusedDayChange: changeFocusedDay,
|
|
@@ -356,7 +361,7 @@ process.env.NODE_ENV !== "production" ? DateCalendar.propTypes = {
|
|
|
356
361
|
*/
|
|
357
362
|
dayOfWeekFormatter: PropTypes.func,
|
|
358
363
|
/**
|
|
359
|
-
* Default calendar month displayed when `value
|
|
364
|
+
* Default calendar month displayed when `value` and `defaultValue` are empty.
|
|
360
365
|
*/
|
|
361
366
|
defaultCalendarMonth: PropTypes.any,
|
|
362
367
|
/**
|
|
@@ -465,6 +470,11 @@ process.env.NODE_ENV !== "production" ? DateCalendar.propTypes = {
|
|
|
465
470
|
* @default typeof navigator !== 'undefined' && /(android)/i.test(navigator.userAgent)
|
|
466
471
|
*/
|
|
467
472
|
reduceAnimations: PropTypes.bool,
|
|
473
|
+
/**
|
|
474
|
+
* The date used to generate the new value when both `value` and `defaultValue` are empty.
|
|
475
|
+
* @default The closest valid date using the validation props, except callbacks such as `shouldDisableDate`.
|
|
476
|
+
*/
|
|
477
|
+
referenceDate: PropTypes.any,
|
|
468
478
|
/**
|
|
469
479
|
* Component displaying when passed `loading` true.
|
|
470
480
|
* @returns {React.ReactNode} The node to render when loading.
|
|
@@ -18,7 +18,7 @@ export interface DateCalendarSlotsComponentsProps<TDate> extends PickersCalendar
|
|
|
18
18
|
}
|
|
19
19
|
export interface ExportedDateCalendarProps<TDate> extends ExportedDayCalendarProps, ExportedMonthCalendarProps, ExportedYearCalendarProps, BaseDateValidationProps<TDate>, DayValidationProps<TDate>, YearValidationProps<TDate>, MonthValidationProps<TDate> {
|
|
20
20
|
/**
|
|
21
|
-
* Default calendar month displayed when `value
|
|
21
|
+
* Default calendar month displayed when `value` and `defaultValue` are empty.
|
|
22
22
|
*/
|
|
23
23
|
defaultCalendarMonth?: TDate;
|
|
24
24
|
/**
|
|
@@ -66,6 +66,11 @@ export interface DateCalendarProps<TDate> extends ExportedDateCalendarProps<TDat
|
|
|
66
66
|
* Used when the component is not controlled.
|
|
67
67
|
*/
|
|
68
68
|
defaultValue?: TDate | null;
|
|
69
|
+
/**
|
|
70
|
+
* The date used to generate the new value when both `value` and `defaultValue` are empty.
|
|
71
|
+
* @default The closest valid date using the validation props, except callbacks such as `shouldDisableDate`.
|
|
72
|
+
*/
|
|
73
|
+
referenceDate?: TDate;
|
|
69
74
|
/**
|
|
70
75
|
* Callback fired when the value changes.
|
|
71
76
|
* @template TDate
|
|
@@ -25,10 +25,11 @@ interface ChangeFocusedDayPayload<TDate> {
|
|
|
25
25
|
export declare const createCalendarStateReducer: <TDate extends unknown>(reduceAnimations: boolean, disableSwitchToMonthOnDayFocus: boolean, utils: MuiPickersAdapter<TDate, any>) => (state: CalendarState<TDate>, action: {
|
|
26
26
|
type: "finishMonthSwitchingAnimation";
|
|
27
27
|
} | ReducerAction<"changeMonth", ChangeMonthPayload<TDate>> | ReducerAction<"changeFocusedDay", ChangeFocusedDayPayload<TDate>>) => CalendarState<TDate>;
|
|
28
|
-
interface
|
|
28
|
+
interface UseCalendarStateParams<TDate> extends Pick<DateCalendarDefaultizedProps<TDate>, 'value' | 'referenceDate' | 'defaultCalendarMonth' | 'disableFuture' | 'disablePast' | 'minDate' | 'maxDate' | 'onMonthChange' | 'reduceAnimations' | 'shouldDisableDate'> {
|
|
29
29
|
disableSwitchToMonthOnDayFocus?: boolean;
|
|
30
30
|
}
|
|
31
|
-
export declare const useCalendarState: <TDate extends unknown>(
|
|
31
|
+
export declare const useCalendarState: <TDate extends unknown>(params: UseCalendarStateParams<TDate>) => {
|
|
32
|
+
referenceDate: any;
|
|
32
33
|
calendarState: CalendarState<TDate>;
|
|
33
34
|
changeMonth: (newDate: TDate) => void;
|
|
34
35
|
changeFocusedDay: (newFocusedDate: TDate | null, withoutMonthSwitchingAnimation?: boolean | undefined) => void;
|
|
@@ -3,7 +3,8 @@ import * as React from 'react';
|
|
|
3
3
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
4
4
|
import { useIsDateDisabled } from './useIsDateDisabled';
|
|
5
5
|
import { useUtils, useNow } from '../internals/hooks/useUtils';
|
|
6
|
-
import {
|
|
6
|
+
import { singleItemValueManager } from '../internals/utils/valueManagers';
|
|
7
|
+
import { SECTION_TYPE_GRANULARITY } from '../internals/utils/getDefaultReferenceDate';
|
|
7
8
|
export const createCalendarStateReducer = (reduceAnimations, disableSwitchToMonthOnDayFocus, utils) => (state, action) => {
|
|
8
9
|
switch (action.type) {
|
|
9
10
|
case 'changeMonth':
|
|
@@ -33,26 +34,45 @@ export const createCalendarStateReducer = (reduceAnimations, disableSwitchToMont
|
|
|
33
34
|
throw new Error('missing support');
|
|
34
35
|
}
|
|
35
36
|
};
|
|
36
|
-
export const useCalendarState =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
export const useCalendarState = params => {
|
|
38
|
+
const {
|
|
39
|
+
value,
|
|
40
|
+
referenceDate: referenceDateProp,
|
|
41
|
+
defaultCalendarMonth,
|
|
42
|
+
disableFuture,
|
|
43
|
+
disablePast,
|
|
44
|
+
disableSwitchToMonthOnDayFocus = false,
|
|
45
|
+
maxDate,
|
|
46
|
+
minDate,
|
|
47
|
+
onMonthChange,
|
|
48
|
+
reduceAnimations,
|
|
49
|
+
shouldDisableDate
|
|
50
|
+
} = params;
|
|
49
51
|
const now = useNow();
|
|
50
52
|
const utils = useUtils();
|
|
51
53
|
const reducerFn = React.useRef(createCalendarStateReducer(Boolean(reduceAnimations), disableSwitchToMonthOnDayFocus, utils)).current;
|
|
54
|
+
const referenceDate = React.useMemo(() => {
|
|
55
|
+
let externalReferenceDate = null;
|
|
56
|
+
if (referenceDateProp) {
|
|
57
|
+
externalReferenceDate = referenceDateProp;
|
|
58
|
+
} else if (defaultCalendarMonth) {
|
|
59
|
+
// For `defaultCalendarMonth`, we just want to keep the month and the year to avoid a behavior change.
|
|
60
|
+
externalReferenceDate = utils.startOfMonth(defaultCalendarMonth);
|
|
61
|
+
}
|
|
62
|
+
return singleItemValueManager.getInitialReferenceValue({
|
|
63
|
+
value,
|
|
64
|
+
utils,
|
|
65
|
+
props: params,
|
|
66
|
+
referenceDate: externalReferenceDate,
|
|
67
|
+
granularity: SECTION_TYPE_GRANULARITY.day
|
|
68
|
+
});
|
|
69
|
+
}, [] // eslint-disable-line react-hooks/exhaustive-deps
|
|
70
|
+
);
|
|
71
|
+
|
|
52
72
|
const [calendarState, dispatch] = React.useReducer(reducerFn, {
|
|
53
73
|
isMonthSwitchingAnimating: false,
|
|
54
74
|
focusedDay: value || now,
|
|
55
|
-
currentMonth: utils.startOfMonth(
|
|
75
|
+
currentMonth: utils.startOfMonth(referenceDate),
|
|
56
76
|
slideDirection: 'left'
|
|
57
77
|
});
|
|
58
78
|
const handleChangeMonth = React.useCallback(payload => {
|
|
@@ -95,6 +115,7 @@ export const useCalendarState = ({
|
|
|
95
115
|
}
|
|
96
116
|
});
|
|
97
117
|
return {
|
|
118
|
+
referenceDate,
|
|
98
119
|
calendarState,
|
|
99
120
|
changeMonth,
|
|
100
121
|
changeFocusedDay,
|
package/DateField/DateField.js
CHANGED
|
@@ -230,7 +230,7 @@ process.env.NODE_ENV !== "production" ? DateField.propTypes = {
|
|
|
230
230
|
*/
|
|
231
231
|
readOnly: PropTypes.bool,
|
|
232
232
|
/**
|
|
233
|
-
* The date used to generate a part of the
|
|
233
|
+
* The date used to generate a part of the new value that is not present in the format when both `value` and `defaultValue` are empty.
|
|
234
234
|
* For example, on time fields it will be used to determine the date to set.
|
|
235
235
|
* @default The closest valid date using the validation props, except callbacks such as `shouldDisableDate`. Value is rounded to the most granular section used.
|
|
236
236
|
*/
|
package/DatePicker/DatePicker.js
CHANGED
|
@@ -73,7 +73,7 @@ process.env.NODE_ENV !== "production" ? DatePicker.propTypes = {
|
|
|
73
73
|
*/
|
|
74
74
|
dayOfWeekFormatter: PropTypes.func,
|
|
75
75
|
/**
|
|
76
|
-
* Default calendar month displayed when `value
|
|
76
|
+
* Default calendar month displayed when `value` and `defaultValue` are empty.
|
|
77
77
|
*/
|
|
78
78
|
defaultCalendarMonth: PropTypes.any,
|
|
79
79
|
/**
|
|
@@ -8,8 +8,8 @@ import { styled, useThemeProps } from '@mui/material/styles';
|
|
|
8
8
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
9
9
|
import { PickersToolbar } from '../internals/components/PickersToolbar';
|
|
10
10
|
import { useLocaleText, useUtils } from '../internals/hooks/useUtils';
|
|
11
|
-
import { isYearOnlyView, isYearAndMonthViews } from '../internals/utils/views';
|
|
12
11
|
import { getDatePickerToolbarUtilityClass } from './datePickerToolbarClasses';
|
|
12
|
+
import { resolveDateFormat } from '../internals/utils/date-utils';
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
const useUtilityClasses = ownerState => {
|
|
15
15
|
const {
|
|
@@ -59,20 +59,11 @@ const DatePickerToolbar = /*#__PURE__*/React.forwardRef(function DatePickerToolb
|
|
|
59
59
|
if (!value) {
|
|
60
60
|
return toolbarPlaceholder;
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
if (isYearAndMonthViews(views)) {
|
|
69
|
-
return utils.format(value, 'month');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Little localization hack (Google is doing the same for android native pickers):
|
|
73
|
-
// For english localization it is convenient to include weekday into the date "Mon, Jun 1".
|
|
74
|
-
// For other locales using strings like "June 1", without weekday.
|
|
75
|
-
return /en/.test(utils.getCurrentLocaleCode()) ? utils.format(value, 'normalDateWithWeekday') : utils.format(value, 'normalDate');
|
|
62
|
+
const formatFromViews = resolveDateFormat(utils, {
|
|
63
|
+
format: toolbarFormat,
|
|
64
|
+
views
|
|
65
|
+
}, true);
|
|
66
|
+
return utils.formatByString(value, formatFromViews);
|
|
76
67
|
}, [value, toolbarFormat, toolbarPlaceholder, utils, views]);
|
|
77
68
|
const ownerState = props;
|
|
78
69
|
return /*#__PURE__*/_jsx(DatePickerToolbarRoot, _extends({
|
package/DatePicker/shared.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { DefaultizedProps } from '../internals/models/helpers';
|
|
3
3
|
import { DateCalendarSlotsComponent, DateCalendarSlotsComponentsProps, ExportedDateCalendarProps } from '../DateCalendar/DateCalendar.types';
|
|
4
|
-
import { DateValidationError, DateView
|
|
4
|
+
import { DateValidationError, DateView } from '../models';
|
|
5
5
|
import { BasePickerInputProps } from '../internals/models/props/basePickerProps';
|
|
6
6
|
import { BaseDateValidationProps, UncapitalizeObjectKeys } from '../internals';
|
|
7
7
|
import { LocalizedComponent } from '../locales/utils/pickersLocaleTextApi';
|
|
@@ -49,9 +49,5 @@ export interface BaseDatePickerProps<TDate> extends BasePickerInputProps<TDate |
|
|
|
49
49
|
viewRenderers?: Partial<PickerViewRendererLookup<TDate | null, DateView, DateViewRendererProps<TDate, DateView>, {}>>;
|
|
50
50
|
}
|
|
51
51
|
type UseDatePickerDefaultizedProps<TDate, Props extends BaseDatePickerProps<TDate>> = LocalizedComponent<TDate, Omit<DefaultizedProps<Props, 'views' | 'openTo' | keyof BaseDateValidationProps<TDate>>, 'components' | 'componentsProps'>>;
|
|
52
|
-
export declare const getDatePickerFieldFormat: (utils: MuiPickersAdapter<any>, { format, views }: {
|
|
53
|
-
format?: string | undefined;
|
|
54
|
-
views: readonly DateView[];
|
|
55
|
-
}) => string | undefined;
|
|
56
52
|
export declare function useDatePickerDefaultizedProps<TDate, Props extends BaseDatePickerProps<TDate>>(props: Props, name: string): UseDatePickerDefaultizedProps<TDate, Props>;
|
|
57
53
|
export {};
|
package/DatePicker/shared.js
CHANGED
|
@@ -2,25 +2,10 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useThemeProps } from '@mui/material/styles';
|
|
4
4
|
import { useDefaultDates, useUtils } from '../internals/hooks/useUtils';
|
|
5
|
-
import { applyDefaultViewProps
|
|
5
|
+
import { applyDefaultViewProps } from '../internals/utils/views';
|
|
6
6
|
import { applyDefaultDate } from '../internals/utils/date-utils';
|
|
7
7
|
import { DatePickerToolbar } from './DatePickerToolbar';
|
|
8
8
|
import { uncapitalizeObjectKeys } from '../internals/utils/slots-migration';
|
|
9
|
-
export const getDatePickerFieldFormat = (utils, {
|
|
10
|
-
format,
|
|
11
|
-
views
|
|
12
|
-
}) => {
|
|
13
|
-
if (format != null) {
|
|
14
|
-
return format;
|
|
15
|
-
}
|
|
16
|
-
if (isYearOnlyView(views)) {
|
|
17
|
-
return utils.formats.year;
|
|
18
|
-
}
|
|
19
|
-
if (isYearAndMonthViews(views)) {
|
|
20
|
-
return utils.formats.monthAndYear;
|
|
21
|
-
}
|
|
22
|
-
return undefined;
|
|
23
|
-
};
|
|
24
9
|
export function useDatePickerDefaultizedProps(props, name) {
|
|
25
10
|
var _themeProps$slots, _themeProps$disableFu, _themeProps$disablePa, _themeProps$slotProps;
|
|
26
11
|
const utils = useUtils();
|
|
@@ -263,7 +263,7 @@ process.env.NODE_ENV !== "production" ? DateTimeField.propTypes = {
|
|
|
263
263
|
*/
|
|
264
264
|
readOnly: PropTypes.bool,
|
|
265
265
|
/**
|
|
266
|
-
* The date used to generate a part of the
|
|
266
|
+
* The date used to generate a part of the new value that is not present in the format when both `value` and `defaultValue` are empty.
|
|
267
267
|
* For example, on time fields it will be used to determine the date to set.
|
|
268
268
|
* @default The closest valid date using the validation props, except callbacks such as `shouldDisableDate`. Value is rounded to the most granular section used.
|
|
269
269
|
*/
|
|
@@ -83,7 +83,7 @@ process.env.NODE_ENV !== "production" ? DateTimePicker.propTypes = {
|
|
|
83
83
|
*/
|
|
84
84
|
dayOfWeekFormatter: PropTypes.func,
|
|
85
85
|
/**
|
|
86
|
-
* Default calendar month displayed when `value
|
|
86
|
+
* Default calendar month displayed when `value` and `defaultValue` are empty.
|
|
87
87
|
*/
|
|
88
88
|
defaultCalendarMonth: PropTypes.any,
|
|
89
89
|
/**
|
|
@@ -3,13 +3,14 @@ import * as React from 'react';
|
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import { resolveComponentProps } from '@mui/base/utils';
|
|
5
5
|
import { singleItemValueManager } from '../internals/utils/valueManagers';
|
|
6
|
-
import {
|
|
6
|
+
import { useDatePickerDefaultizedProps } from '../DatePicker/shared';
|
|
7
7
|
import { useLocaleText, useUtils, validateDate } from '../internals';
|
|
8
8
|
import { useDesktopPicker } from '../internals/hooks/useDesktopPicker';
|
|
9
9
|
import { CalendarIcon } from '../icons';
|
|
10
10
|
import { DateField } from '../DateField';
|
|
11
11
|
import { extractValidationProps } from '../internals/utils/validation/extractValidationProps';
|
|
12
12
|
import { renderDateViewCalendar } from '../dateViewRenderers';
|
|
13
|
+
import { resolveDateFormat } from '../internals/utils/date-utils';
|
|
13
14
|
const DesktopDatePicker = /*#__PURE__*/React.forwardRef(function DesktopDatePicker(inProps, ref) {
|
|
14
15
|
var _defaultizedProps$yea, _defaultizedProps$slo2;
|
|
15
16
|
const localeText = useLocaleText();
|
|
@@ -26,7 +27,7 @@ const DesktopDatePicker = /*#__PURE__*/React.forwardRef(function DesktopDatePick
|
|
|
26
27
|
// Props with the default values specific to the desktop variant
|
|
27
28
|
const props = _extends({}, defaultizedProps, {
|
|
28
29
|
viewRenderers,
|
|
29
|
-
format:
|
|
30
|
+
format: resolveDateFormat(utils, defaultizedProps, false),
|
|
30
31
|
yearsPerRow: (_defaultizedProps$yea = defaultizedProps.yearsPerRow) != null ? _defaultizedProps$yea : 4,
|
|
31
32
|
slots: _extends({
|
|
32
33
|
openPickerIcon: CalendarIcon,
|
|
@@ -96,7 +97,7 @@ DesktopDatePicker.propTypes = {
|
|
|
96
97
|
*/
|
|
97
98
|
dayOfWeekFormatter: PropTypes.func,
|
|
98
99
|
/**
|
|
99
|
-
* Default calendar month displayed when `value
|
|
100
|
+
* Default calendar month displayed when `value` and `defaultValue` are empty.
|
|
100
101
|
*/
|
|
101
102
|
defaultCalendarMonth: PropTypes.any,
|
|
102
103
|
/**
|
|
@@ -7,13 +7,16 @@ import { DateTimeField } from '../DateTimeField';
|
|
|
7
7
|
import { useDateTimePickerDefaultizedProps } from '../DateTimePicker/shared';
|
|
8
8
|
import { renderDateViewCalendar } from '../dateViewRenderers/dateViewRenderers';
|
|
9
9
|
import { renderDesktopDateTimeView } from '../dateTimeViewRenderers';
|
|
10
|
-
import { useLocaleText,
|
|
10
|
+
import { useLocaleText, useUtils } from '../internals/hooks/useUtils';
|
|
11
|
+
import { validateDateTime } from '../internals/utils/validation/validateDateTime';
|
|
11
12
|
import { CalendarIcon } from '../icons';
|
|
12
13
|
import { useDesktopPicker } from '../internals/hooks/useDesktopPicker';
|
|
13
14
|
import { extractValidationProps } from '../internals/utils/validation/extractValidationProps';
|
|
15
|
+
import { resolveDateTimeFormat } from '../internals/utils/date-time-utils';
|
|
14
16
|
const DesktopDateTimePicker = /*#__PURE__*/React.forwardRef(function DesktopDateTimePicker(inProps, ref) {
|
|
15
17
|
var _defaultizedProps$amp, _defaultizedProps$yea, _defaultizedProps$slo2, _defaultizedProps$slo3, _defaultizedProps$slo4;
|
|
16
18
|
const localeText = useLocaleText();
|
|
19
|
+
const utils = useUtils();
|
|
17
20
|
|
|
18
21
|
// Props with the default values common to all date time pickers
|
|
19
22
|
const defaultizedProps = useDateTimePickerDefaultizedProps(inProps, 'MuiDesktopDateTimePicker');
|
|
@@ -49,6 +52,7 @@ const DesktopDateTimePicker = /*#__PURE__*/React.forwardRef(function DesktopDate
|
|
|
49
52
|
// Props with the default values specific to the desktop variant
|
|
50
53
|
const props = _extends({}, defaultizedProps, {
|
|
51
54
|
viewRenderers,
|
|
55
|
+
format: resolveDateTimeFormat(utils, defaultizedProps),
|
|
52
56
|
views: defaultizedProps.ampm ? [...defaultizedProps.views, 'meridiem'] : defaultizedProps.views,
|
|
53
57
|
yearsPerRow: (_defaultizedProps$yea = defaultizedProps.yearsPerRow) != null ? _defaultizedProps$yea : 4,
|
|
54
58
|
ampmInClock,
|
|
@@ -139,7 +143,7 @@ DesktopDateTimePicker.propTypes = {
|
|
|
139
143
|
*/
|
|
140
144
|
dayOfWeekFormatter: PropTypes.func,
|
|
141
145
|
/**
|
|
142
|
-
* Default calendar month displayed when `value
|
|
146
|
+
* Default calendar month displayed when `value` and `defaultValue` are empty.
|
|
143
147
|
*/
|
|
144
148
|
defaultCalendarMonth: PropTypes.any,
|
|
145
149
|
/**
|
|
@@ -5,14 +5,17 @@ import { resolveComponentProps } from '@mui/base/utils';
|
|
|
5
5
|
import { singleItemValueManager } from '../internals/utils/valueManagers';
|
|
6
6
|
import { TimeField } from '../TimeField';
|
|
7
7
|
import { useTimePickerDefaultizedProps } from '../TimePicker/shared';
|
|
8
|
-
import { useLocaleText,
|
|
8
|
+
import { useLocaleText, useUtils } from '../internals/hooks/useUtils';
|
|
9
|
+
import { validateTime } from '../internals/utils/validation/validateTime';
|
|
9
10
|
import { ClockIcon } from '../icons';
|
|
10
11
|
import { useDesktopPicker } from '../internals/hooks/useDesktopPicker';
|
|
11
12
|
import { extractValidationProps } from '../internals/utils/validation/extractValidationProps';
|
|
12
13
|
import { renderDigitalClockTimeView, renderMultiSectionDigitalClockTimeView } from '../timeViewRenderers';
|
|
14
|
+
import { resolveTimeFormat } from '../internals/utils/time-utils';
|
|
13
15
|
const DesktopTimePicker = /*#__PURE__*/React.forwardRef(function DesktopTimePicker(inProps, ref) {
|
|
14
16
|
var _defaultizedProps$thr, _defaultizedProps$amp, _viewRenderers$hours, _defaultizedProps$slo2, _defaultizedProps$slo3;
|
|
15
17
|
const localeText = useLocaleText();
|
|
18
|
+
const utils = useUtils();
|
|
16
19
|
|
|
17
20
|
// Props with the default values common to all time pickers
|
|
18
21
|
const defaultizedProps = useTimePickerDefaultizedProps(inProps, 'MuiDesktopTimePicker');
|
|
@@ -41,6 +44,7 @@ const DesktopTimePicker = /*#__PURE__*/React.forwardRef(function DesktopTimePick
|
|
|
41
44
|
ampmInClock,
|
|
42
45
|
timeSteps,
|
|
43
46
|
viewRenderers,
|
|
47
|
+
format: resolveTimeFormat(utils, defaultizedProps),
|
|
44
48
|
// Setting only `hours` time view in case of single column time picker
|
|
45
49
|
// Allows for easy view lifecycle management
|
|
46
50
|
views: shouldRenderTimeInASingleColumn ? ['hours'] : views,
|
|
@@ -112,6 +112,7 @@ process.env.NODE_ENV !== "production" ? LocalizationProvider.propTypes = {
|
|
|
112
112
|
keyboardDateTime: PropTypes.string,
|
|
113
113
|
keyboardDateTime12h: PropTypes.string,
|
|
114
114
|
keyboardDateTime24h: PropTypes.string,
|
|
115
|
+
meridiem: PropTypes.string,
|
|
115
116
|
minutes: PropTypes.string,
|
|
116
117
|
month: PropTypes.string,
|
|
117
118
|
monthAndDate: PropTypes.string,
|
|
@@ -3,12 +3,13 @@ import * as React from 'react';
|
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import { resolveComponentProps } from '@mui/base/utils';
|
|
5
5
|
import { useMobilePicker } from '../internals/hooks/useMobilePicker';
|
|
6
|
-
import {
|
|
6
|
+
import { useDatePickerDefaultizedProps } from '../DatePicker/shared';
|
|
7
7
|
import { useLocaleText, useUtils, validateDate } from '../internals';
|
|
8
8
|
import { DateField } from '../DateField';
|
|
9
9
|
import { extractValidationProps } from '../internals/utils/validation/extractValidationProps';
|
|
10
10
|
import { singleItemValueManager } from '../internals/utils/valueManagers';
|
|
11
11
|
import { renderDateViewCalendar } from '../dateViewRenderers';
|
|
12
|
+
import { resolveDateFormat } from '../internals/utils/date-utils';
|
|
12
13
|
const MobileDatePicker = /*#__PURE__*/React.forwardRef(function MobileDatePicker(inProps, ref) {
|
|
13
14
|
var _defaultizedProps$slo2;
|
|
14
15
|
const localeText = useLocaleText();
|
|
@@ -25,7 +26,7 @@ const MobileDatePicker = /*#__PURE__*/React.forwardRef(function MobileDatePicker
|
|
|
25
26
|
// Props with the default values specific to the mobile variant
|
|
26
27
|
const props = _extends({}, defaultizedProps, {
|
|
27
28
|
viewRenderers,
|
|
28
|
-
format:
|
|
29
|
+
format: resolveDateFormat(utils, defaultizedProps, false),
|
|
29
30
|
slots: _extends({
|
|
30
31
|
field: DateField
|
|
31
32
|
}, defaultizedProps.slots),
|
|
@@ -93,7 +94,7 @@ MobileDatePicker.propTypes = {
|
|
|
93
94
|
*/
|
|
94
95
|
dayOfWeekFormatter: PropTypes.func,
|
|
95
96
|
/**
|
|
96
|
-
* Default calendar month displayed when `value
|
|
97
|
+
* Default calendar month displayed when `value` and `defaultValue` are empty.
|
|
97
98
|
*/
|
|
98
99
|
defaultCalendarMonth: PropTypes.any,
|
|
99
100
|
/**
|
|
@@ -5,14 +5,17 @@ import { resolveComponentProps } from '@mui/base/utils';
|
|
|
5
5
|
import { singleItemValueManager } from '../internals/utils/valueManagers';
|
|
6
6
|
import { DateTimeField } from '../DateTimeField';
|
|
7
7
|
import { useDateTimePickerDefaultizedProps } from '../DateTimePicker/shared';
|
|
8
|
-
import { useLocaleText,
|
|
8
|
+
import { useLocaleText, useUtils } from '../internals/hooks/useUtils';
|
|
9
|
+
import { validateDateTime } from '../internals/utils/validation/validateDateTime';
|
|
9
10
|
import { useMobilePicker } from '../internals/hooks/useMobilePicker';
|
|
10
11
|
import { extractValidationProps } from '../internals/utils/validation/extractValidationProps';
|
|
11
12
|
import { renderDateViewCalendar } from '../dateViewRenderers';
|
|
12
13
|
import { renderTimeViewClock } from '../timeViewRenderers';
|
|
14
|
+
import { resolveDateTimeFormat } from '../internals/utils/date-time-utils';
|
|
13
15
|
const MobileDateTimePicker = /*#__PURE__*/React.forwardRef(function MobileDateTimePicker(inProps, ref) {
|
|
14
16
|
var _defaultizedProps$amp, _defaultizedProps$slo2, _defaultizedProps$slo3;
|
|
15
17
|
const localeText = useLocaleText();
|
|
18
|
+
const utils = useUtils();
|
|
16
19
|
|
|
17
20
|
// Props with the default values common to all date time pickers
|
|
18
21
|
const defaultizedProps = useDateTimePickerDefaultizedProps(inProps, 'MuiMobileDateTimePicker');
|
|
@@ -29,6 +32,7 @@ const MobileDateTimePicker = /*#__PURE__*/React.forwardRef(function MobileDateTi
|
|
|
29
32
|
// Props with the default values specific to the mobile variant
|
|
30
33
|
const props = _extends({}, defaultizedProps, {
|
|
31
34
|
viewRenderers,
|
|
35
|
+
format: resolveDateTimeFormat(utils, defaultizedProps),
|
|
32
36
|
ampmInClock,
|
|
33
37
|
slots: _extends({
|
|
34
38
|
field: DateTimeField
|
|
@@ -111,7 +115,7 @@ MobileDateTimePicker.propTypes = {
|
|
|
111
115
|
*/
|
|
112
116
|
dayOfWeekFormatter: PropTypes.func,
|
|
113
117
|
/**
|
|
114
|
-
* Default calendar month displayed when `value
|
|
118
|
+
* Default calendar month displayed when `value` and `defaultValue` are empty.
|
|
115
119
|
*/
|
|
116
120
|
defaultCalendarMonth: PropTypes.any,
|
|
117
121
|
/**
|
|
@@ -5,13 +5,16 @@ import { resolveComponentProps } from '@mui/base/utils';
|
|
|
5
5
|
import { singleItemValueManager } from '../internals/utils/valueManagers';
|
|
6
6
|
import { TimeField } from '../TimeField';
|
|
7
7
|
import { useTimePickerDefaultizedProps } from '../TimePicker/shared';
|
|
8
|
-
import { useLocaleText,
|
|
8
|
+
import { useLocaleText, useUtils } from '../internals/hooks/useUtils';
|
|
9
|
+
import { validateTime } from '../internals/utils/validation/validateTime';
|
|
9
10
|
import { useMobilePicker } from '../internals/hooks/useMobilePicker';
|
|
10
11
|
import { extractValidationProps } from '../internals/utils/validation/extractValidationProps';
|
|
11
12
|
import { renderTimeViewClock } from '../timeViewRenderers';
|
|
13
|
+
import { resolveTimeFormat } from '../internals/utils/time-utils';
|
|
12
14
|
const MobileTimePicker = /*#__PURE__*/React.forwardRef(function MobileTimePicker(inProps, ref) {
|
|
13
15
|
var _defaultizedProps$amp, _defaultizedProps$slo2;
|
|
14
16
|
const localeText = useLocaleText();
|
|
17
|
+
const utils = useUtils();
|
|
15
18
|
|
|
16
19
|
// Props with the default values common to all time pickers
|
|
17
20
|
const defaultizedProps = useTimePickerDefaultizedProps(inProps, 'MuiMobileTimePicker');
|
|
@@ -26,6 +29,7 @@ const MobileTimePicker = /*#__PURE__*/React.forwardRef(function MobileTimePicker
|
|
|
26
29
|
const props = _extends({}, defaultizedProps, {
|
|
27
30
|
ampmInClock,
|
|
28
31
|
viewRenderers,
|
|
32
|
+
format: resolveTimeFormat(utils, defaultizedProps),
|
|
29
33
|
slots: _extends({
|
|
30
34
|
field: TimeField
|
|
31
35
|
}, defaultizedProps.slots),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["className", "value", "defaultValue", "disabled", "disableFuture", "disablePast", "maxDate", "minDate", "onChange", "shouldDisableMonth", "readOnly", "disableHighlightToday", "autoFocus", "onMonthFocus", "hasFocus", "onFocusedViewChange", "monthsPerRow"];
|
|
3
|
+
const _excluded = ["className", "value", "defaultValue", "referenceDate", "disabled", "disableFuture", "disablePast", "maxDate", "minDate", "onChange", "shouldDisableMonth", "readOnly", "disableHighlightToday", "autoFocus", "onMonthFocus", "hasFocus", "onFocusedViewChange", "monthsPerRow"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import clsx from 'clsx';
|
|
@@ -11,6 +11,8 @@ import { PickersMonth } from './PickersMonth';
|
|
|
11
11
|
import { useUtils, useNow, useDefaultDates } from '../internals/hooks/useUtils';
|
|
12
12
|
import { getMonthCalendarUtilityClass } from './monthCalendarClasses';
|
|
13
13
|
import { applyDefaultDate, getMonthsInYear } from '../internals/utils/date-utils';
|
|
14
|
+
import { singleItemValueManager } from '../internals/utils/valueManagers';
|
|
15
|
+
import { SECTION_TYPE_GRANULARITY } from '../internals/utils/getDefaultReferenceDate';
|
|
14
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
17
|
const useUtilityClasses = ownerState => {
|
|
16
18
|
const {
|
|
@@ -56,6 +58,7 @@ export const MonthCalendar = /*#__PURE__*/React.forwardRef(function MonthCalenda
|
|
|
56
58
|
className,
|
|
57
59
|
value: valueProp,
|
|
58
60
|
defaultValue,
|
|
61
|
+
referenceDate: referenceDateProp,
|
|
59
62
|
disabled,
|
|
60
63
|
disableFuture,
|
|
61
64
|
disablePast,
|
|
@@ -80,8 +83,16 @@ export const MonthCalendar = /*#__PURE__*/React.forwardRef(function MonthCalenda
|
|
|
80
83
|
controlled: valueProp,
|
|
81
84
|
default: defaultValue != null ? defaultValue : null
|
|
82
85
|
});
|
|
86
|
+
const referenceDate = React.useMemo(() => singleItemValueManager.getInitialReferenceValue({
|
|
87
|
+
value,
|
|
88
|
+
utils,
|
|
89
|
+
props,
|
|
90
|
+
referenceDate: referenceDateProp,
|
|
91
|
+
granularity: SECTION_TYPE_GRANULARITY.month
|
|
92
|
+
}), [] // eslint-disable-line react-hooks/exhaustive-deps
|
|
93
|
+
);
|
|
94
|
+
|
|
83
95
|
const todayMonth = React.useMemo(() => utils.getMonth(now), [utils, now]);
|
|
84
|
-
const selectedDateOrStartOfMonth = React.useMemo(() => value != null ? value : utils.startOfMonth(now), [now, utils, value]);
|
|
85
96
|
const selectedMonth = React.useMemo(() => {
|
|
86
97
|
if (value != null) {
|
|
87
98
|
return utils.getMonth(value);
|
|
@@ -89,8 +100,8 @@ export const MonthCalendar = /*#__PURE__*/React.forwardRef(function MonthCalenda
|
|
|
89
100
|
if (disableHighlightToday) {
|
|
90
101
|
return null;
|
|
91
102
|
}
|
|
92
|
-
return utils.getMonth(
|
|
93
|
-
}, [
|
|
103
|
+
return utils.getMonth(referenceDate);
|
|
104
|
+
}, [value, utils, disableHighlightToday, referenceDate]);
|
|
94
105
|
const [focusedMonth, setFocusedMonth] = React.useState(() => selectedMonth || todayMonth);
|
|
95
106
|
const [internalHasFocus, setInternalHasFocus] = useControlled({
|
|
96
107
|
name: 'MonthCalendar',
|
|
@@ -104,30 +115,31 @@ export const MonthCalendar = /*#__PURE__*/React.forwardRef(function MonthCalenda
|
|
|
104
115
|
onFocusedViewChange(newHasFocus);
|
|
105
116
|
}
|
|
106
117
|
});
|
|
107
|
-
const isMonthDisabled = React.useCallback(
|
|
118
|
+
const isMonthDisabled = React.useCallback(dateToValidate => {
|
|
108
119
|
const firstEnabledMonth = utils.startOfMonth(disablePast && utils.isAfter(now, minDate) ? now : minDate);
|
|
109
120
|
const lastEnabledMonth = utils.startOfMonth(disableFuture && utils.isBefore(now, maxDate) ? now : maxDate);
|
|
110
|
-
|
|
121
|
+
const monthToValidate = utils.startOfMonth(dateToValidate);
|
|
122
|
+
if (utils.isBefore(monthToValidate, firstEnabledMonth)) {
|
|
111
123
|
return true;
|
|
112
124
|
}
|
|
113
|
-
if (utils.isAfter(
|
|
125
|
+
if (utils.isAfter(monthToValidate, lastEnabledMonth)) {
|
|
114
126
|
return true;
|
|
115
127
|
}
|
|
116
128
|
if (!shouldDisableMonth) {
|
|
117
129
|
return false;
|
|
118
130
|
}
|
|
119
|
-
return shouldDisableMonth(
|
|
131
|
+
return shouldDisableMonth(monthToValidate);
|
|
120
132
|
}, [disableFuture, disablePast, maxDate, minDate, now, shouldDisableMonth, utils]);
|
|
121
133
|
const handleMonthSelection = useEventCallback((event, month) => {
|
|
122
134
|
if (readOnly) {
|
|
123
135
|
return;
|
|
124
136
|
}
|
|
125
|
-
const newDate = utils.setMonth(
|
|
137
|
+
const newDate = utils.setMonth(value != null ? value : referenceDate, month);
|
|
126
138
|
setValue(newDate);
|
|
127
139
|
onChange == null ? void 0 : onChange(newDate);
|
|
128
140
|
});
|
|
129
141
|
const focusMonth = useEventCallback(month => {
|
|
130
|
-
if (!isMonthDisabled(utils.setMonth(
|
|
142
|
+
if (!isMonthDisabled(utils.setMonth(value != null ? value : referenceDate, month))) {
|
|
131
143
|
setFocusedMonth(month);
|
|
132
144
|
changeHasFocus(true);
|
|
133
145
|
if (onMonthFocus) {
|
|
@@ -175,7 +187,7 @@ export const MonthCalendar = /*#__PURE__*/React.forwardRef(function MonthCalenda
|
|
|
175
187
|
className: clsx(classes.root, className),
|
|
176
188
|
ownerState: ownerState
|
|
177
189
|
}, other, {
|
|
178
|
-
children: getMonthsInYear(utils,
|
|
190
|
+
children: getMonthsInYear(utils, value != null ? value : referenceDate).map(month => {
|
|
179
191
|
const monthNumber = utils.getMonth(month);
|
|
180
192
|
const monthText = utils.format(month, 'monthShort');
|
|
181
193
|
const isSelected = monthNumber === selectedMonth;
|
|
@@ -261,6 +273,11 @@ process.env.NODE_ENV !== "production" ? MonthCalendar.propTypes = {
|
|
|
261
273
|
* If `true` picker is readonly
|
|
262
274
|
*/
|
|
263
275
|
readOnly: PropTypes.bool,
|
|
276
|
+
/**
|
|
277
|
+
* The date used to generate the new value when both `value` and `defaultValue` are empty.
|
|
278
|
+
* @default The closest valid month using the validation props, except callbacks such as `shouldDisableDate`.
|
|
279
|
+
*/
|
|
280
|
+
referenceDate: PropTypes.any,
|
|
264
281
|
/**
|
|
265
282
|
* Disable specific month.
|
|
266
283
|
* @template TDate
|