@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
3
|
-
import { useUtils } from "../useUtils.js";
|
|
4
3
|
import { changeSectionValueFormat, cleanDigitSectionValue, doesSectionFormatHaveLeadingZeros, getDateSectionConfigFromFormatToken, getDaysInWeekStr, getLetterEditingOptions, applyLocalizedDigits, removeLocalizedDigits, isStringNumber } from "./useField.utils.js";
|
|
4
|
+
import { usePickerAdapter } from "../../../hooks/usePickerAdapter.js";
|
|
5
5
|
const isQueryResponseWithoutValue = response => response.saveQuery != null;
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -24,7 +24,7 @@ export const useFieldCharacterEditing = ({
|
|
|
24
24
|
updateSectionValue
|
|
25
25
|
}
|
|
26
26
|
}) => {
|
|
27
|
-
const
|
|
27
|
+
const adapter = usePickerAdapter();
|
|
28
28
|
const applyQuery = ({
|
|
29
29
|
keyPressed,
|
|
30
30
|
sectionIndex
|
|
@@ -75,7 +75,7 @@ export const useFieldCharacterEditing = ({
|
|
|
75
75
|
};
|
|
76
76
|
};
|
|
77
77
|
const testQueryOnFormatAndFallbackFormat = (queryValue, activeSection, fallbackFormat, formatFallbackValue) => {
|
|
78
|
-
const getOptions = format => getLetterEditingOptions(
|
|
78
|
+
const getOptions = format => getLetterEditingOptions(adapter, timezone, activeSection.type, format);
|
|
79
79
|
if (activeSection.contentType === 'letter') {
|
|
80
80
|
return findMatchingOptions(activeSection.format, getOptions(activeSection.format), queryValue);
|
|
81
81
|
}
|
|
@@ -83,7 +83,7 @@ export const useFieldCharacterEditing = ({
|
|
|
83
83
|
// When editing a digit-format month / weekDay and the user presses a letter,
|
|
84
84
|
// We can support the letter editing by using the letter-format month / weekDay and re-formatting the result.
|
|
85
85
|
// We just have to make sure that the default month / weekDay format is a letter format,
|
|
86
|
-
if (fallbackFormat && formatFallbackValue != null && getDateSectionConfigFromFormatToken(
|
|
86
|
+
if (fallbackFormat && formatFallbackValue != null && getDateSectionConfigFromFormatToken(adapter, fallbackFormat).contentType === 'letter') {
|
|
87
87
|
const fallbackOptions = getOptions(fallbackFormat);
|
|
88
88
|
const response = findMatchingOptions(fallbackFormat, fallbackOptions, queryValue);
|
|
89
89
|
if (isQueryResponseWithoutValue(response)) {
|
|
@@ -103,13 +103,13 @@ export const useFieldCharacterEditing = ({
|
|
|
103
103
|
switch (activeSection.type) {
|
|
104
104
|
case 'month':
|
|
105
105
|
{
|
|
106
|
-
const formatFallbackValue = fallbackValue => changeSectionValueFormat(
|
|
107
|
-
return testQueryOnFormatAndFallbackFormat(queryValue, activeSection,
|
|
106
|
+
const formatFallbackValue = fallbackValue => changeSectionValueFormat(adapter, fallbackValue, adapter.formats.month, activeSection.format);
|
|
107
|
+
return testQueryOnFormatAndFallbackFormat(queryValue, activeSection, adapter.formats.month, formatFallbackValue);
|
|
108
108
|
}
|
|
109
109
|
case 'weekDay':
|
|
110
110
|
{
|
|
111
111
|
const formatFallbackValue = (fallbackValue, fallbackOptions) => fallbackOptions.indexOf(fallbackValue).toString();
|
|
112
|
-
return testQueryOnFormatAndFallbackFormat(queryValue, activeSection,
|
|
112
|
+
return testQueryOnFormatAndFallbackFormat(queryValue, activeSection, adapter.formats.weekday, formatFallbackValue);
|
|
113
113
|
}
|
|
114
114
|
case 'meridiem':
|
|
115
115
|
{
|
|
@@ -153,7 +153,7 @@ export const useFieldCharacterEditing = ({
|
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
155
|
const shouldGoToNextSection = queryValueNumber * 10 > sectionBoundaries.maximum || cleanQueryValue.length === sectionBoundaries.maximum.toString().length;
|
|
156
|
-
const newSectionValue = cleanDigitSectionValue(
|
|
156
|
+
const newSectionValue = cleanDigitSectionValue(adapter, queryValueNumber, sectionBoundaries, localizedDigits, section);
|
|
157
157
|
return {
|
|
158
158
|
sectionValue: newSectionValue,
|
|
159
159
|
shouldGoToNextSection
|
|
@@ -171,7 +171,7 @@ export const useFieldCharacterEditing = ({
|
|
|
171
171
|
// When editing a letter-format month and the user presses a digit,
|
|
172
172
|
// We can support the numeric editing by using the digit-format month and re-formatting the result.
|
|
173
173
|
if (activeSection.type === 'month') {
|
|
174
|
-
const hasLeadingZerosInFormat = doesSectionFormatHaveLeadingZeros(
|
|
174
|
+
const hasLeadingZerosInFormat = doesSectionFormatHaveLeadingZeros(adapter, 'digit', 'month', 'MM');
|
|
175
175
|
const response = getNewSectionValue({
|
|
176
176
|
queryValue,
|
|
177
177
|
skipIfBelowMinimum: true,
|
|
@@ -187,7 +187,7 @@ export const useFieldCharacterEditing = ({
|
|
|
187
187
|
if (isQueryResponseWithoutValue(response)) {
|
|
188
188
|
return response;
|
|
189
189
|
}
|
|
190
|
-
const formattedValue = changeSectionValueFormat(
|
|
190
|
+
const formattedValue = changeSectionValueFormat(adapter, response.sectionValue, 'MM', activeSection.format);
|
|
191
191
|
return _extends({}, response, {
|
|
192
192
|
sectionValue: formattedValue
|
|
193
193
|
});
|
|
@@ -204,7 +204,7 @@ export const useFieldCharacterEditing = ({
|
|
|
204
204
|
if (isQueryResponseWithoutValue(response)) {
|
|
205
205
|
return response;
|
|
206
206
|
}
|
|
207
|
-
const formattedValue = getDaysInWeekStr(
|
|
207
|
+
const formattedValue = getDaysInWeekStr(adapter, activeSection.format)[Number(response.sectionValue) - 1];
|
|
208
208
|
return _extends({}, response, {
|
|
209
209
|
sectionValue: formattedValue
|
|
210
210
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
2
|
-
import { useUtils } from "../useUtils.js";
|
|
3
2
|
import { cleanDigitSectionValue, getLetterEditingOptions, removeLocalizedDigits } from "./useField.utils.js";
|
|
3
|
+
import { usePickerAdapter } from "../../../hooks/usePickerAdapter.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Returns the `onKeyDown` handler to pass to the root element of the field.
|
|
7
7
|
*/
|
|
8
8
|
export function useFieldRootHandleKeyDown(parameters) {
|
|
9
|
-
const
|
|
9
|
+
const adapter = usePickerAdapter();
|
|
10
10
|
const {
|
|
11
11
|
manager: {
|
|
12
12
|
internal_fieldValueManager: fieldValueManager
|
|
@@ -112,7 +112,7 @@ export function useFieldRootHandleKeyDown(parameters) {
|
|
|
112
112
|
setSelectedSections(activeSectionIndex);
|
|
113
113
|
}
|
|
114
114
|
const activeSection = state.sections[activeSectionIndex];
|
|
115
|
-
const newSectionValue = adjustSectionValue(
|
|
115
|
+
const newSectionValue = adjustSectionValue(adapter, timezone, activeSection, event.key, sectionsValueBoundaries, localizedDigits, fieldValueManager.getDateFromSection(value, activeSection), {
|
|
116
116
|
minutesStep
|
|
117
117
|
});
|
|
118
118
|
updateSectionValue({
|
|
@@ -139,7 +139,7 @@ function getDeltaFromKeyCode(keyCode) {
|
|
|
139
139
|
return 0;
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
function adjustSectionValue(
|
|
142
|
+
function adjustSectionValue(adapter, timezone, section, keyCode, sectionsValueBoundaries, localizedDigits, activeDate, stepsAttributes) {
|
|
143
143
|
const delta = getDeltaFromKeyCode(keyCode);
|
|
144
144
|
const isStart = keyCode === 'Home';
|
|
145
145
|
const isEnd = keyCode === 'End';
|
|
@@ -150,12 +150,12 @@ function adjustSectionValue(utils, timezone, section, keyCode, sectionsValueBoun
|
|
|
150
150
|
format: section.format,
|
|
151
151
|
contentType: section.contentType
|
|
152
152
|
});
|
|
153
|
-
const getCleanValue = value => cleanDigitSectionValue(
|
|
153
|
+
const getCleanValue = value => cleanDigitSectionValue(adapter, value, sectionBoundaries, localizedDigits, section);
|
|
154
154
|
const step = section.type === 'minutes' && stepsAttributes?.minutesStep ? stepsAttributes.minutesStep : 1;
|
|
155
155
|
let newSectionValueNumber;
|
|
156
156
|
if (shouldSetAbsolute) {
|
|
157
157
|
if (section.type === 'year' && !isEnd && !isStart) {
|
|
158
|
-
return
|
|
158
|
+
return adapter.formatByString(adapter.date(undefined, timezone), section.format);
|
|
159
159
|
}
|
|
160
160
|
if (delta > 0 || isStart) {
|
|
161
161
|
newSectionValueNumber = sectionBoundaries.minimum;
|
|
@@ -183,7 +183,7 @@ function adjustSectionValue(utils, timezone, section, keyCode, sectionsValueBoun
|
|
|
183
183
|
return getCleanValue(newSectionValueNumber);
|
|
184
184
|
};
|
|
185
185
|
const adjustLetterSection = () => {
|
|
186
|
-
const options = getLetterEditingOptions(
|
|
186
|
+
const options = getLetterEditingOptions(adapter, timezone, section.type, section.format);
|
|
187
187
|
if (options.length === 0) {
|
|
188
188
|
return section.value;
|
|
189
189
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
3
3
|
import useId from '@mui/utils/useId';
|
|
4
|
-
import {
|
|
5
|
-
import { usePickerTranslations } from "../../../hooks/index.js";
|
|
4
|
+
import { usePickerAdapter, usePickerTranslations } from "../../../hooks/index.js";
|
|
6
5
|
import { syncSelectionToDOM } from "./syncSelectionToDOM.js";
|
|
7
6
|
/**
|
|
8
7
|
* Generate the props to pass to the content element of each section of the field.
|
|
@@ -12,7 +11,7 @@ import { syncSelectionToDOM } from "./syncSelectionToDOM.js";
|
|
|
12
11
|
* @returns {UseFieldRootPropsReturnValue} The props to forward to the content element of each section of the field.
|
|
13
12
|
*/
|
|
14
13
|
export function useFieldSectionContentProps(parameters) {
|
|
15
|
-
const
|
|
14
|
+
const adapter = usePickerAdapter();
|
|
16
15
|
const translations = usePickerTranslations();
|
|
17
16
|
const id = useId();
|
|
18
17
|
const {
|
|
@@ -150,10 +149,10 @@ export function useFieldSectionContentProps(parameters) {
|
|
|
150
149
|
// Aria attributes
|
|
151
150
|
'aria-labelledby': `${id}-${section.type}`,
|
|
152
151
|
'aria-readonly': readOnly,
|
|
153
|
-
'aria-valuenow': getSectionValueNow(section,
|
|
152
|
+
'aria-valuenow': getSectionValueNow(section, adapter),
|
|
154
153
|
'aria-valuemin': sectionBoundaries.minimum,
|
|
155
154
|
'aria-valuemax': sectionBoundaries.maximum,
|
|
156
|
-
'aria-valuetext': section.value ? getSectionValueText(section,
|
|
155
|
+
'aria-valuetext': section.value ? getSectionValueText(section, adapter) : translations.empty,
|
|
157
156
|
'aria-label': translations[section.type],
|
|
158
157
|
'aria-disabled': disabled,
|
|
159
158
|
// Other
|
|
@@ -168,9 +167,9 @@ export function useFieldSectionContentProps(parameters) {
|
|
|
168
167
|
children: section.value || section.placeholder,
|
|
169
168
|
inputMode: section.contentType === 'letter' ? 'text' : 'numeric'
|
|
170
169
|
};
|
|
171
|
-
}, [sectionsValueBoundaries, id, isContainerEditable, disabled, readOnly, isEditable, translations,
|
|
170
|
+
}, [sectionsValueBoundaries, id, isContainerEditable, disabled, readOnly, isEditable, translations, adapter, handleInput, handlePaste, handleMouseUp, handleDragOver, createFocusHandler, fieldValueManager, value]);
|
|
172
171
|
}
|
|
173
|
-
function getSectionValueText(section,
|
|
172
|
+
function getSectionValueText(section, adapter) {
|
|
174
173
|
if (!section.value) {
|
|
175
174
|
return undefined;
|
|
176
175
|
}
|
|
@@ -178,13 +177,13 @@ function getSectionValueText(section, utils) {
|
|
|
178
177
|
case 'month':
|
|
179
178
|
{
|
|
180
179
|
if (section.contentType === 'digit') {
|
|
181
|
-
return
|
|
180
|
+
return adapter.format(adapter.setMonth(adapter.date(), Number(section.value) - 1), 'month');
|
|
182
181
|
}
|
|
183
|
-
const parsedDate =
|
|
184
|
-
return parsedDate ?
|
|
182
|
+
const parsedDate = adapter.parse(section.value, section.format);
|
|
183
|
+
return parsedDate ? adapter.format(parsedDate, 'month') : undefined;
|
|
185
184
|
}
|
|
186
185
|
case 'day':
|
|
187
|
-
return section.contentType === 'digit' ?
|
|
186
|
+
return section.contentType === 'digit' ? adapter.format(adapter.setDate(adapter.startOfYear(adapter.date()), Number(section.value)), 'dayOfMonthFull') : section.value;
|
|
188
187
|
case 'weekDay':
|
|
189
188
|
// TODO: improve by providing the label of the week day
|
|
190
189
|
return undefined;
|
|
@@ -192,7 +191,7 @@ function getSectionValueText(section, utils) {
|
|
|
192
191
|
return undefined;
|
|
193
192
|
}
|
|
194
193
|
}
|
|
195
|
-
function getSectionValueNow(section,
|
|
194
|
+
function getSectionValueNow(section, adapter) {
|
|
196
195
|
if (!section.value) {
|
|
197
196
|
return undefined;
|
|
198
197
|
}
|
|
@@ -207,9 +206,9 @@ function getSectionValueNow(section, utils) {
|
|
|
207
206
|
}
|
|
208
207
|
case 'meridiem':
|
|
209
208
|
{
|
|
210
|
-
const parsedDate =
|
|
209
|
+
const parsedDate = adapter.parse(`01:00 ${section.value}`, `${adapter.formats.hours12h}:${adapter.formats.minutes} ${section.format}`);
|
|
211
210
|
if (parsedDate) {
|
|
212
|
-
return
|
|
211
|
+
return adapter.getHours(parsedDate) >= 12 ? 1 : 0;
|
|
213
212
|
}
|
|
214
213
|
return undefined;
|
|
215
214
|
}
|
|
@@ -220,8 +219,8 @@ function getSectionValueNow(section, utils) {
|
|
|
220
219
|
if (section.contentType === 'digit') {
|
|
221
220
|
return Number(section.value);
|
|
222
221
|
}
|
|
223
|
-
const parsedDate =
|
|
224
|
-
return parsedDate ?
|
|
222
|
+
const parsedDate = adapter.parse(section.value, section.format);
|
|
223
|
+
return parsedDate ? adapter.getMonth(parsedDate) + 1 : undefined;
|
|
225
224
|
}
|
|
226
225
|
default:
|
|
227
226
|
return section.contentType !== 'letter' ? Number(section.value) : undefined;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
1
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
4
|
import * as React from 'react';
|
|
3
5
|
import useControlled from '@mui/utils/useControlled';
|
|
4
6
|
import useTimeout from '@mui/utils/useTimeout';
|
|
5
7
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
6
8
|
import { useRtl } from '@mui/system/RtlProvider';
|
|
7
|
-
import { usePickerTranslations } from "../../../hooks/
|
|
8
|
-
import { useUtils, useLocalizationContext } from "../useUtils.js";
|
|
9
|
+
import { usePickerAdapter, usePickerTranslations } from "../../../hooks/index.js";
|
|
9
10
|
import { mergeDateIntoReferenceDate, getSectionsBoundaries, validateSections, getDateFromDateSections, parseSelectedSections, getLocalizedDigits, getSectionOrder } from "./useField.utils.js";
|
|
10
11
|
import { buildSectionsFromFormat } from "./buildSectionsFromFormat.js";
|
|
11
12
|
import { useValidation } from "../../../validation/index.js";
|
|
@@ -13,9 +14,8 @@ import { useControlledValue } from "../useControlledValue.js";
|
|
|
13
14
|
import { getSectionTypeGranularity } from "../../utils/getDefaultReferenceDate.js";
|
|
14
15
|
const QUERY_LIFE_DURATION_MS = 5000;
|
|
15
16
|
export const useFieldState = parameters => {
|
|
16
|
-
const
|
|
17
|
+
const adapter = usePickerAdapter();
|
|
17
18
|
const translations = usePickerTranslations();
|
|
18
|
-
const adapter = useLocalizationContext();
|
|
19
19
|
const isRtl = useRtl();
|
|
20
20
|
const {
|
|
21
21
|
manager: {
|
|
@@ -76,10 +76,10 @@ export const useFieldState = parameters => {
|
|
|
76
76
|
}
|
|
77
77
|
return hasValidationError;
|
|
78
78
|
}, [hasValidationError, errorProp]);
|
|
79
|
-
const localizedDigits = React.useMemo(() => getLocalizedDigits(
|
|
80
|
-
const sectionsValueBoundaries = React.useMemo(() => getSectionsBoundaries(
|
|
79
|
+
const localizedDigits = React.useMemo(() => getLocalizedDigits(adapter), [adapter]);
|
|
80
|
+
const sectionsValueBoundaries = React.useMemo(() => getSectionsBoundaries(adapter, localizedDigits, timezone), [adapter, localizedDigits, timezone]);
|
|
81
81
|
const getSectionsFromValue = React.useCallback(valueToAnalyze => fieldValueManager.getSectionsFromValue(valueToAnalyze, date => buildSectionsFromFormat({
|
|
82
|
-
|
|
82
|
+
adapter,
|
|
83
83
|
localeText: translations,
|
|
84
84
|
localizedDigits,
|
|
85
85
|
format,
|
|
@@ -88,7 +88,7 @@ export const useFieldState = parameters => {
|
|
|
88
88
|
shouldRespectLeadingZeros,
|
|
89
89
|
enableAccessibleFieldDOMStructure,
|
|
90
90
|
isRtl
|
|
91
|
-
})), [fieldValueManager, format, translations, localizedDigits, isRtl, shouldRespectLeadingZeros,
|
|
91
|
+
})), [fieldValueManager, format, translations, localizedDigits, isRtl, shouldRespectLeadingZeros, adapter, formatDensity, enableAccessibleFieldDOMStructure]);
|
|
92
92
|
const [state, setState] = React.useState(() => {
|
|
93
93
|
const sections = getSectionsFromValue(value);
|
|
94
94
|
validateSections(sections, valueType);
|
|
@@ -98,7 +98,7 @@ export const useFieldState = parameters => {
|
|
|
98
98
|
lastSectionsDependencies: {
|
|
99
99
|
format,
|
|
100
100
|
isRtl,
|
|
101
|
-
locale:
|
|
101
|
+
locale: adapter.locale
|
|
102
102
|
},
|
|
103
103
|
tempValueStrAndroid: null,
|
|
104
104
|
characterQuery: null
|
|
@@ -107,7 +107,7 @@ export const useFieldState = parameters => {
|
|
|
107
107
|
const referenceValue = valueManager.getInitialReferenceValue({
|
|
108
108
|
referenceDate: referenceDateProp,
|
|
109
109
|
value,
|
|
110
|
-
|
|
110
|
+
adapter,
|
|
111
111
|
props: internalPropsWithDefaults,
|
|
112
112
|
granularity,
|
|
113
113
|
timezone
|
|
@@ -164,7 +164,7 @@ export const useFieldState = parameters => {
|
|
|
164
164
|
});
|
|
165
165
|
};
|
|
166
166
|
const clearValue = () => {
|
|
167
|
-
if (valueManager.areValuesEqual(
|
|
167
|
+
if (valueManager.areValuesEqual(adapter, value, valueManager.emptyValue)) {
|
|
168
168
|
setState(prevState => _extends({}, prevState, {
|
|
169
169
|
sections: prevState.sections.map(section => _extends({}, section, {
|
|
170
170
|
value: ''
|
|
@@ -203,12 +203,12 @@ export const useFieldState = parameters => {
|
|
|
203
203
|
};
|
|
204
204
|
const updateValueFromValueStr = valueStr => {
|
|
205
205
|
const parseDateStr = (dateStr, referenceDate) => {
|
|
206
|
-
const date =
|
|
207
|
-
if (!
|
|
206
|
+
const date = adapter.parse(dateStr, format);
|
|
207
|
+
if (!adapter.isValid(date)) {
|
|
208
208
|
return null;
|
|
209
209
|
}
|
|
210
210
|
const sections = buildSectionsFromFormat({
|
|
211
|
-
|
|
211
|
+
adapter,
|
|
212
212
|
localeText: translations,
|
|
213
213
|
localizedDigits,
|
|
214
214
|
format,
|
|
@@ -218,7 +218,7 @@ export const useFieldState = parameters => {
|
|
|
218
218
|
enableAccessibleFieldDOMStructure,
|
|
219
219
|
isRtl
|
|
220
220
|
});
|
|
221
|
-
return mergeDateIntoReferenceDate(
|
|
221
|
+
return mergeDateIntoReferenceDate(adapter, date, sections, referenceDate, false);
|
|
222
222
|
};
|
|
223
223
|
const newValue = fieldValueManager.parseValueStr(valueStr, state.referenceValue, parseDateStr);
|
|
224
224
|
publishValue(newValue);
|
|
@@ -245,15 +245,15 @@ export const useFieldState = parameters => {
|
|
|
245
245
|
*/
|
|
246
246
|
const newSections = setSectionValue(activeSectionIndex, newSectionValue);
|
|
247
247
|
const newActiveDateSections = fieldValueManager.getDateSectionsFromValue(newSections, section);
|
|
248
|
-
const newActiveDate = getDateFromDateSections(
|
|
248
|
+
const newActiveDate = getDateFromDateSections(adapter, newActiveDateSections, localizedDigits);
|
|
249
249
|
|
|
250
250
|
/**
|
|
251
251
|
* If the new date is valid,
|
|
252
252
|
* Then we merge the value of the modified sections into the reference date.
|
|
253
253
|
* This makes sure that we don't lose some information of the initial date (like the time on a date field).
|
|
254
254
|
*/
|
|
255
|
-
if (
|
|
256
|
-
const mergedDate = mergeDateIntoReferenceDate(
|
|
255
|
+
if (adapter.isValid(newActiveDate)) {
|
|
256
|
+
const mergedDate = mergeDateIntoReferenceDate(adapter, newActiveDate, newActiveDateSections, fieldValueManager.getDateFromSection(state.referenceValue, section), true);
|
|
257
257
|
if (activeDate == null) {
|
|
258
258
|
cleanActiveDateSectionsIfValueNullTimeout.start(0, () => {
|
|
259
259
|
if (valueRef.current === value) {
|
|
@@ -271,7 +271,7 @@ export const useFieldState = parameters => {
|
|
|
271
271
|
* If all the sections are filled but the date is invalid and the previous date is valid or null,
|
|
272
272
|
* Then we publish an invalid date.
|
|
273
273
|
*/
|
|
274
|
-
if (newActiveDateSections.every(sectionBis => sectionBis.value !== '') && (activeDate == null ||
|
|
274
|
+
if (newActiveDateSections.every(sectionBis => sectionBis.value !== '') && (activeDate == null || adapter.isValid(activeDate))) {
|
|
275
275
|
setSectionUpdateToApplyOnNextInvalidDate(newSectionValue);
|
|
276
276
|
return publishValue(fieldValueManager.updateDateInValue(value, section, newActiveDate));
|
|
277
277
|
}
|
|
@@ -306,7 +306,7 @@ export const useFieldState = parameters => {
|
|
|
306
306
|
// If `prop.value` changes, we update the state to reflect the new value
|
|
307
307
|
if (value !== state.lastExternalValue) {
|
|
308
308
|
let sections;
|
|
309
|
-
if (sectionToUpdateOnNextInvalidDateRef.current != null && !
|
|
309
|
+
if (sectionToUpdateOnNextInvalidDateRef.current != null && !adapter.isValid(fieldValueManager.getDateFromSection(value, state.sections[sectionToUpdateOnNextInvalidDateRef.current.sectionIndex]))) {
|
|
310
310
|
sections = setSectionValue(sectionToUpdateOnNextInvalidDateRef.current.sectionIndex, sectionToUpdateOnNextInvalidDateRef.current.value);
|
|
311
311
|
} else {
|
|
312
312
|
sections = getSectionsFromValue(value);
|
|
@@ -317,20 +317,20 @@ export const useFieldState = parameters => {
|
|
|
317
317
|
sectionsDependencies: {
|
|
318
318
|
format,
|
|
319
319
|
isRtl,
|
|
320
|
-
locale:
|
|
320
|
+
locale: adapter.locale
|
|
321
321
|
},
|
|
322
|
-
referenceValue: fieldValueManager.updateReferenceValue(
|
|
322
|
+
referenceValue: fieldValueManager.updateReferenceValue(adapter, value, prevState.referenceValue),
|
|
323
323
|
tempValueStrAndroid: null
|
|
324
324
|
}));
|
|
325
325
|
}
|
|
326
|
-
if (isRtl !== state.lastSectionsDependencies.isRtl || format !== state.lastSectionsDependencies.format ||
|
|
326
|
+
if (isRtl !== state.lastSectionsDependencies.isRtl || format !== state.lastSectionsDependencies.format || adapter.locale !== state.lastSectionsDependencies.locale) {
|
|
327
327
|
const sections = getSectionsFromValue(value);
|
|
328
328
|
validateSections(sections, valueType);
|
|
329
329
|
setState(prevState => _extends({}, prevState, {
|
|
330
330
|
lastSectionsDependencies: {
|
|
331
331
|
format,
|
|
332
332
|
isRtl,
|
|
333
|
-
locale:
|
|
333
|
+
locale: adapter.locale
|
|
334
334
|
},
|
|
335
335
|
sections,
|
|
336
336
|
tempValueStrAndroid: null,
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
1
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
4
|
import * as React from 'react';
|
|
3
5
|
import { warnOnce } from '@mui/x-internals/warning';
|
|
4
6
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
5
7
|
import { useControlledValue } from "../../useControlledValue.js";
|
|
6
|
-
import {
|
|
8
|
+
import { usePickerAdapter } from "../../../../hooks/usePickerAdapter.js";
|
|
7
9
|
import { useValidation } from "../../../../validation/index.js";
|
|
8
10
|
export function useValueAndOpenStates(parameters) {
|
|
9
11
|
const {
|
|
@@ -32,7 +34,7 @@ export function useValueAndOpenStates(parameters) {
|
|
|
32
34
|
const {
|
|
33
35
|
current: isOpenControlled
|
|
34
36
|
} = React.useRef(openProp !== undefined);
|
|
35
|
-
const
|
|
37
|
+
const adapter = usePickerAdapter();
|
|
36
38
|
if (process.env.NODE_ENV !== 'production') {
|
|
37
39
|
if (props.renderInput != null) {
|
|
38
40
|
warnOnce(['MUI X: The `renderInput` prop has been removed in version 6.0 of the Date and Time Pickers.', 'You can replace it with the `textField` component slot in most cases.', 'For more information, please have a look at the migration guide (https://mui.com/x/migration/migration-pickers-v5/#input-renderer-required-in-v5).']);
|
|
@@ -113,13 +115,13 @@ export function useValueAndOpenStates(parameters) {
|
|
|
113
115
|
shouldFireOnChange = true;
|
|
114
116
|
shouldFireOnAccept = changeImportance === 'accept';
|
|
115
117
|
} else {
|
|
116
|
-
shouldFireOnChange = !valueManager.areValuesEqual(
|
|
117
|
-
shouldFireOnAccept = changeImportance === 'accept' && !valueManager.areValuesEqual(
|
|
118
|
+
shouldFireOnChange = !valueManager.areValuesEqual(adapter, newValue, value);
|
|
119
|
+
shouldFireOnAccept = changeImportance === 'accept' && !valueManager.areValuesEqual(adapter, newValue, state.lastCommittedValue);
|
|
118
120
|
}
|
|
119
121
|
setState(prevState => _extends({}, prevState, {
|
|
120
122
|
// We reset the shallow value whenever we fire onChange.
|
|
121
123
|
clockShallowValue: shouldFireOnChange ? undefined : prevState.clockShallowValue,
|
|
122
|
-
lastCommittedValue: shouldFireOnAccept ?
|
|
124
|
+
lastCommittedValue: shouldFireOnAccept ? newValue : prevState.lastCommittedValue,
|
|
123
125
|
hasBeenModifiedSinceMount: true
|
|
124
126
|
}));
|
|
125
127
|
let cachedContext = null;
|
|
@@ -179,7 +181,7 @@ export function useValueAndOpenStates(parameters) {
|
|
|
179
181
|
}));
|
|
180
182
|
}
|
|
181
183
|
}, [isOpenControlled, openProp]);
|
|
182
|
-
const viewValue = React.useMemo(() => valueManager.cleanValue(
|
|
184
|
+
const viewValue = React.useMemo(() => valueManager.cleanValue(adapter, state.clockShallowValue === undefined ? value : state.clockShallowValue), [adapter, valueManager, state.clockShallowValue, value]);
|
|
183
185
|
return {
|
|
184
186
|
timezone,
|
|
185
187
|
state,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
1
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
4
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
5
|
const _excluded = ["className", "sx"];
|
|
@@ -6,7 +8,7 @@ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
|
6
8
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
7
9
|
import useForkRef from '@mui/utils/useForkRef';
|
|
8
10
|
import useId from '@mui/utils/useId';
|
|
9
|
-
import {
|
|
11
|
+
import { usePickerAdapter } from "../../../hooks/usePickerAdapter.js";
|
|
10
12
|
import { useReduceAnimations } from "../useReduceAnimations.js";
|
|
11
13
|
import { isTimeView } from "../../utils/time-utils.js";
|
|
12
14
|
import { useViews } from "../useViews.js";
|
|
@@ -62,8 +64,7 @@ export const usePicker = ({
|
|
|
62
64
|
* TODO: Improve how we generate the aria-label and aria-labelledby attributes.
|
|
63
65
|
*/
|
|
64
66
|
const labelId = useId();
|
|
65
|
-
const
|
|
66
|
-
const adapter = useLocalizationContext();
|
|
67
|
+
const adapter = usePickerAdapter();
|
|
67
68
|
const reduceAnimations = useReduceAnimations(reduceAnimationsProp);
|
|
68
69
|
const orientation = useOrientation(views, orientationProp);
|
|
69
70
|
const {
|
|
@@ -111,7 +112,7 @@ export const usePicker = ({
|
|
|
111
112
|
getStepNavigation
|
|
112
113
|
});
|
|
113
114
|
const clearValue = useEventCallback(() => setValue(valueManager.emptyValue));
|
|
114
|
-
const setValueToToday = useEventCallback(() => setValue(valueManager.getTodayValue(
|
|
115
|
+
const setValueToToday = useEventCallback(() => setValue(valueManager.getTodayValue(adapter, timezone, valueType)));
|
|
115
116
|
const acceptValueChanges = useEventCallback(() => setValue(value));
|
|
116
117
|
const cancelValueChanges = useEventCallback(() => setValue(state.lastCommittedValue, {
|
|
117
118
|
skipPublicationIfPristine: true
|
|
@@ -181,13 +182,13 @@ export const usePicker = ({
|
|
|
181
182
|
}, [state.open]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
182
183
|
|
|
183
184
|
const ownerState = React.useMemo(() => ({
|
|
184
|
-
isPickerValueEmpty: valueManager.areValuesEqual(
|
|
185
|
+
isPickerValueEmpty: valueManager.areValuesEqual(adapter, value, valueManager.emptyValue),
|
|
185
186
|
isPickerOpen: state.open,
|
|
186
187
|
isPickerDisabled: props.disabled ?? false,
|
|
187
188
|
isPickerReadOnly: props.readOnly ?? false,
|
|
188
189
|
pickerOrientation: orientation,
|
|
189
190
|
pickerVariant: variant
|
|
190
|
-
}), [
|
|
191
|
+
}), [adapter, valueManager, value, state.open, orientation, variant, props.disabled, props.readOnly]);
|
|
191
192
|
const triggerStatus = React.useMemo(() => {
|
|
192
193
|
if (disableOpenPicker || !hasUIView) {
|
|
193
194
|
return 'hidden';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SxProps } from '@mui/system';
|
|
2
2
|
import { Theme } from '@mui/material/styles';
|
|
3
3
|
import { InferError, OnErrorProps, PickerChangeHandlerContext, PickerOwnerState, PickerValidDate, PickerValueType, TimezoneProps } from "../../../models/index.js";
|
|
4
|
-
import { DateOrTimeViewWithMeridiem, FormProps, PickerOrientation, PickerValidValue, PickerValueManager, PickerVariant } from "../../models/index.js";
|
|
4
|
+
import { DateOrTimeViewWithMeridiem, FormProps, PickerOrientation, PickerRangeValue, PickerValidValue, PickerValueManager, PickerVariant } from "../../models/index.js";
|
|
5
5
|
import { Validator } from "../../../validation/index.js";
|
|
6
6
|
import { UseViewsOptions } from "../useViews.js";
|
|
7
7
|
import { PickerProviderProps } from "../../components/PickerProvider.js";
|
|
@@ -48,7 +48,7 @@ export interface UsePickerBaseProps<TValue extends PickerValidValue, TView exten
|
|
|
48
48
|
* The date used to generate the new value when both `value` and `defaultValue` are empty.
|
|
49
49
|
* @default The closest valid date-time using the validation props, except callbacks like `shouldDisable<...>`.
|
|
50
50
|
*/
|
|
51
|
-
referenceDate?: PickerValidDate;
|
|
51
|
+
referenceDate?: TValue extends PickerRangeValue ? TValue | PickerValidDate : PickerValidDate;
|
|
52
52
|
/**
|
|
53
53
|
* Force rendering in particular orientation.
|
|
54
54
|
*/
|
|
@@ -108,7 +108,7 @@ export interface UsePickerNonStaticProps extends Omit<PickerFieldPrivateContextV
|
|
|
108
108
|
name?: string;
|
|
109
109
|
}
|
|
110
110
|
export interface UsePickerProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError, TExternalProps extends UsePickerProps<TValue, TView, TError, any>> extends UsePickerBaseProps<TValue, TView, TError, TExternalProps>, UsePickerNonStaticProps {
|
|
111
|
-
referenceDate?: PickerValidDate;
|
|
111
|
+
referenceDate?: TValue extends PickerRangeValue ? TValue | PickerValidDate : PickerValidDate;
|
|
112
112
|
className?: string;
|
|
113
113
|
sx?: SxProps<Theme>;
|
|
114
114
|
}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import { MuiPickersAdapterContextValue } from "../../LocalizationProvider/LocalizationProvider.js";
|
|
2
|
-
import { PickersLocaleText } from "../../locales/utils/pickersLocaleTextApi.js";
|
|
3
1
|
import { PickersTimezone, PickerValidDate } from "../../models/index.js";
|
|
4
|
-
export declare const useLocalizationContext: () => UseLocalizationContextReturnValue;
|
|
5
|
-
export declare const useUtils: () => import("@mui/x-date-pickers/models").MuiPickersAdapter<any>;
|
|
6
2
|
export declare const useDefaultDates: () => {
|
|
7
3
|
minDate: PickerValidDate;
|
|
8
4
|
maxDate: PickerValidDate;
|
|
9
5
|
};
|
|
10
|
-
export declare const useNow: (timezone: PickersTimezone) => PickerValidDate;
|
|
11
|
-
export interface UseLocalizationContextReturnValue extends Omit<MuiPickersAdapterContextValue, 'localeText'> {
|
|
12
|
-
localeText: PickersLocaleText;
|
|
13
|
-
}
|
|
6
|
+
export declare const useNow: (timezone: PickersTimezone) => PickerValidDate;
|
|
@@ -1,27 +1,11 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
1
|
import * as React from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import { DEFAULT_LOCALE } from "../../locales/enUS.js";
|
|
5
|
-
export const useLocalizationContext = () => {
|
|
6
|
-
const localization = React.useContext(MuiPickersAdapterContext);
|
|
7
|
-
if (localization === null) {
|
|
8
|
-
throw new Error(['MUI X: Can not find the date and time pickers localization context.', 'It looks like you forgot to wrap your component in LocalizationProvider.', 'This can also happen if you are bundling multiple versions of the `@mui/x-date-pickers` package'].join('\n'));
|
|
9
|
-
}
|
|
10
|
-
if (localization.utils === null) {
|
|
11
|
-
throw new Error(['MUI X: Can not find the date and time pickers adapter from its localization context.', 'It looks like you forgot to pass a `dateAdapter` to your LocalizationProvider.'].join('\n'));
|
|
12
|
-
}
|
|
13
|
-
const localeText = React.useMemo(() => _extends({}, DEFAULT_LOCALE, localization.localeText), [localization.localeText]);
|
|
14
|
-
return React.useMemo(() => _extends({}, localization, {
|
|
15
|
-
localeText
|
|
16
|
-
}), [localization, localeText]);
|
|
17
|
-
};
|
|
18
|
-
export const useUtils = () => useLocalizationContext().utils;
|
|
2
|
+
import { useLocalizationContext, usePickerAdapter } from "../../hooks/usePickerAdapter.js";
|
|
19
3
|
export const useDefaultDates = () => useLocalizationContext().defaultDates;
|
|
20
4
|
export const useNow = timezone => {
|
|
21
|
-
const
|
|
5
|
+
const adapter = usePickerAdapter();
|
|
22
6
|
const now = React.useRef(undefined);
|
|
23
7
|
if (now.current === undefined) {
|
|
24
|
-
now.current =
|
|
8
|
+
now.current = adapter.date(undefined, timezone);
|
|
25
9
|
}
|
|
26
10
|
return now.current;
|
|
27
11
|
};
|
package/esm/internals/index.d.ts
CHANGED
|
@@ -39,7 +39,8 @@ export { useStaticPicker } from "./hooks/useStaticPicker/index.js";
|
|
|
39
39
|
export type { StaticOnlyPickerProps, UseStaticPickerSlots, UseStaticPickerSlotProps } from "./hooks/useStaticPicker/index.js";
|
|
40
40
|
export { useToolbarOwnerState } from "./hooks/useToolbarOwnerState.js";
|
|
41
41
|
export type { PickerToolbarOwnerState } from "./hooks/useToolbarOwnerState.js";
|
|
42
|
-
export {
|
|
42
|
+
export { useDefaultDates, useNow } from "./hooks/useUtils.js";
|
|
43
|
+
export { useLocalizationContext } from "../hooks/usePickerAdapter.js";
|
|
43
44
|
export type { ExportedUseViewsOptions, UseViewsOptions } from "./hooks/useViews.js";
|
|
44
45
|
export { useViews } from "./hooks/useViews.js";
|
|
45
46
|
export { usePreviousMonthDisabled, useNextMonthDisabled } from "./hooks/date-helpers-hooks.js";
|
package/esm/internals/index.js
CHANGED
|
@@ -21,7 +21,8 @@ export { usePicker } from "./hooks/usePicker/index.js";
|
|
|
21
21
|
export { usePickerPrivateContext } from "./hooks/usePickerPrivateContext.js";
|
|
22
22
|
export { useStaticPicker } from "./hooks/useStaticPicker/index.js";
|
|
23
23
|
export { useToolbarOwnerState } from "./hooks/useToolbarOwnerState.js";
|
|
24
|
-
export {
|
|
24
|
+
export { useDefaultDates, useNow } from "./hooks/useUtils.js";
|
|
25
|
+
export { useLocalizationContext } from "../hooks/usePickerAdapter.js";
|
|
25
26
|
export { useViews } from "./hooks/useViews.js";
|
|
26
27
|
export { usePreviousMonthDisabled, useNextMonthDisabled } from "./hooks/date-helpers-hooks.js";
|
|
27
28
|
export { createStepNavigation } from "./utils/createStepNavigation.js";
|