@mui/x-date-pickers 8.0.0-alpha.5 → 8.0.0-alpha.7
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.d.ts +2 -4
- package/AdapterDateFns/AdapterDateFns.js +49 -47
- package/AdapterDateFnsBase/AdapterDateFnsBase.d.ts +1 -1
- package/AdapterDateFnsJalali/AdapterDateFnsJalali.d.ts +2 -4
- package/AdapterDateFnsJalali/AdapterDateFnsJalali.js +48 -46
- package/{AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.d.ts → AdapterDateFnsJalaliV2/AdapterDateFnsJalaliV2.d.ts} +2 -2
- package/{AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js → AdapterDateFnsJalaliV2/AdapterDateFnsJalaliV2.js} +45 -52
- package/AdapterDateFnsJalaliV2/index.d.ts +1 -0
- package/AdapterDateFnsJalaliV2/index.js +1 -0
- package/{AdapterDateFnsJalaliV3 → AdapterDateFnsJalaliV2}/package.json +1 -1
- package/{AdapterDateFnsV3/AdapterDateFnsV3.d.ts → AdapterDateFnsV2/AdapterDateFnsV2.d.ts} +2 -2
- package/{AdapterDateFnsV3/AdapterDateFnsV3.js → AdapterDateFnsV2/AdapterDateFnsV2.js} +46 -54
- package/AdapterDateFnsV2/index.d.ts +1 -0
- package/AdapterDateFnsV2/index.js +1 -0
- package/{AdapterDateFnsV3 → AdapterDateFnsV2}/package.json +1 -1
- package/AdapterDayjs/AdapterDayjs.d.ts +1 -1
- package/AdapterLuxon/AdapterLuxon.d.ts +1 -1
- package/AdapterMoment/AdapterMoment.d.ts +1 -1
- package/CHANGELOG.md +206 -1
- package/DateCalendar/DateCalendar.js +1 -1
- package/DateCalendar/PickersFadeTransitionGroup.d.ts +1 -1
- package/DateCalendar/PickersSlideTransition.d.ts +1 -1
- package/DateField/useDateField.d.ts +1 -1
- package/DateField/useDateField.js +13 -11
- package/DatePicker/DatePicker.js +1 -1
- package/DatePicker/DatePicker.types.d.ts +5 -0
- package/DatePicker/DatePickerToolbar.d.ts +1 -3
- package/DatePicker/DatePickerToolbar.js +10 -25
- package/DatePicker/shared.d.ts +1 -1
- package/DateTimeField/useDateTimeField.d.ts +1 -1
- package/DateTimeField/useDateTimeField.js +13 -11
- package/DateTimePicker/DateTimePicker.js +2 -2
- package/DateTimePicker/DateTimePicker.types.d.ts +2 -2
- package/DateTimePicker/DateTimePickerTabs.d.ts +2 -5
- package/DateTimePicker/DateTimePickerTabs.js +7 -14
- package/DateTimePicker/DateTimePickerToolbar.d.ts +12 -4
- package/DateTimePicker/DateTimePickerToolbar.js +42 -48
- package/DateTimePicker/shared.d.ts +3 -3
- package/DesktopDatePicker/DesktopDatePicker.js +9 -3
- package/DesktopDatePicker/DesktopDatePicker.types.d.ts +7 -3
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -10
- package/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +2 -2
- package/DesktopDateTimePicker/DesktopDateTimePickerLayout.d.ts +1 -2
- package/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +1 -15
- package/DesktopTimePicker/DesktopTimePicker.js +3 -7
- package/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
- package/MobileDatePicker/MobileDatePicker.js +2 -2
- package/MobileDatePicker/MobileDatePicker.types.d.ts +2 -3
- package/MobileDateTimePicker/MobileDateTimePicker.js +2 -2
- package/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +4 -4
- package/MobileTimePicker/MobileTimePicker.js +2 -2
- package/MobileTimePicker/MobileTimePicker.types.d.ts +4 -4
- package/PickersActionBar/PickersActionBar.d.ts +6 -7
- package/PickersActionBar/PickersActionBar.js +18 -16
- package/PickersLayout/PickersLayout.d.ts +2 -2
- package/PickersLayout/PickersLayout.js +1 -15
- package/PickersLayout/PickersLayout.types.d.ts +12 -15
- package/PickersLayout/usePickerLayout.d.ts +2 -2
- package/PickersLayout/usePickerLayout.js +13 -47
- package/PickersShortcuts/PickersShortcuts.d.ts +2 -5
- package/PickersShortcuts/PickersShortcuts.js +13 -10
- package/PickersShortcuts/index.d.ts +1 -1
- package/PickersTextField/PickersInputBase/PickersInputBase.js +7 -0
- package/PickersTextField/PickersTextField.js +1 -1
- package/StaticDatePicker/StaticDatePicker.types.d.ts +2 -3
- package/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +2 -2
- package/StaticTimePicker/StaticTimePicker.types.d.ts +2 -2
- package/TimeField/useTimeField.d.ts +1 -1
- package/TimeField/useTimeField.js +13 -11
- package/TimePicker/TimePicker.js +2 -2
- package/TimePicker/TimePicker.types.d.ts +2 -2
- package/TimePicker/TimePickerToolbar.d.ts +1 -2
- package/TimePicker/TimePickerToolbar.js +23 -35
- package/TimePicker/shared.d.ts +1 -1
- package/hooks/index.d.ts +2 -0
- package/hooks/index.js +3 -1
- package/hooks/useIsValidValue.d.ts +7 -0
- package/hooks/useIsValidValue.js +11 -0
- package/hooks/usePickerActionsContext.d.ts +7 -0
- package/hooks/usePickerActionsContext.js +15 -0
- package/hooks/usePickerContext.d.ts +3 -1
- package/hooks/usePickerContext.js +1 -2
- package/index.d.ts +1 -0
- package/index.js +3 -2
- package/internals/components/PickerProvider.d.ts +14 -8
- package/internals/components/PickerProvider.js +17 -6
- package/internals/components/PickersModalDialog.d.ts +1 -3
- package/internals/components/PickersModalDialog.js +9 -3
- package/internals/components/PickersPopper.d.ts +1 -3
- package/internals/components/PickersPopper.js +11 -6
- package/internals/components/PickersToolbar.d.ts +2 -3
- package/internals/components/PickersToolbar.js +1 -1
- package/internals/hooks/date-helpers-hooks.js +4 -3
- package/internals/hooks/useDesktopPicker/useDesktopPicker.js +10 -12
- package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +7 -7
- package/internals/hooks/useField/buildSectionsFromFormat.js +1 -1
- package/internals/hooks/useField/index.d.ts +1 -1
- package/internals/hooks/useField/index.js +1 -1
- package/internals/hooks/useField/useField.d.ts +10 -1
- package/internals/hooks/useField/useField.js +17 -1
- package/internals/hooks/useField/useField.utils.js +2 -2
- package/internals/hooks/useField/useFieldState.js +2 -2
- package/internals/hooks/useField/useFieldV6TextField.js +2 -2
- package/internals/hooks/useMobilePicker/useMobilePicker.js +9 -10
- package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +7 -7
- package/internals/hooks/useOpenState.js +3 -2
- package/internals/hooks/usePicker/usePicker.d.ts +1 -1
- package/internals/hooks/usePicker/usePicker.js +0 -8
- package/internals/hooks/usePicker/usePicker.types.d.ts +6 -7
- package/internals/hooks/usePicker/usePickerProvider.d.ts +5 -5
- package/internals/hooks/usePicker/usePickerProvider.js +8 -5
- package/internals/hooks/usePicker/usePickerValue.d.ts +1 -1
- package/internals/hooks/usePicker/usePickerValue.js +82 -217
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +82 -67
- package/internals/hooks/usePicker/usePickerViews.d.ts +35 -20
- package/internals/hooks/usePicker/usePickerViews.js +22 -14
- package/internals/hooks/useStaticPicker/useStaticPicker.js +1 -4
- package/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +6 -6
- package/internals/hooks/useUtils.js +1 -1
- package/internals/index.d.ts +9 -7
- package/internals/index.js +5 -3
- package/internals/models/index.d.ts +1 -0
- package/internals/models/index.js +2 -1
- package/internals/models/manager.d.ts +12 -0
- package/internals/models/manager.js +1 -0
- package/internals/models/props/basePickerProps.d.ts +2 -2
- package/internals/models/props/tabs.d.ts +0 -13
- package/internals/models/props/toolbar.d.ts +1 -20
- package/internals/utils/date-utils.js +1 -1
- package/internals/utils/valueManagers.js +4 -4
- package/locales/index.d.ts +1 -0
- package/locales/index.js +1 -0
- package/locales/nbNO.js +15 -19
- package/locales/utils/getPickersLocalization.js +1 -1
- package/locales/zhTW.d.ts +80 -0
- package/locales/zhTW.js +73 -0
- package/managers/index.d.ts +6 -0
- package/managers/index.js +3 -0
- package/managers/package.json +6 -0
- package/managers/useDateManager.d.ts +27 -0
- package/managers/useDateManager.js +47 -0
- package/managers/useDateTimeManager.d.ts +28 -0
- package/managers/useDateTimeManager.js +52 -0
- package/managers/useTimeManager.d.ts +28 -0
- package/managers/useTimeManager.js +43 -0
- package/models/adapters.d.ts +1 -1
- package/models/index.d.ts +1 -0
- package/models/index.js +1 -0
- package/models/manager.d.ts +78 -0
- package/models/manager.js +1 -0
- package/models/pickers.d.ts +7 -0
- package/modern/AdapterDateFns/AdapterDateFns.js +49 -47
- package/modern/AdapterDateFnsJalali/AdapterDateFnsJalali.js +48 -46
- package/modern/{AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js → AdapterDateFnsJalaliV2/AdapterDateFnsJalaliV2.js} +45 -52
- package/modern/AdapterDateFnsJalaliV2/index.js +1 -0
- package/modern/{AdapterDateFnsV3/AdapterDateFnsV3.js → AdapterDateFnsV2/AdapterDateFnsV2.js} +46 -54
- package/modern/AdapterDateFnsV2/index.js +1 -0
- package/modern/DateCalendar/DateCalendar.js +1 -1
- package/modern/DateField/useDateField.js +13 -11
- package/modern/DatePicker/DatePicker.js +1 -1
- package/modern/DatePicker/DatePickerToolbar.js +10 -25
- package/modern/DateTimeField/useDateTimeField.js +13 -11
- package/modern/DateTimePicker/DateTimePicker.js +2 -2
- package/modern/DateTimePicker/DateTimePickerTabs.js +7 -14
- package/modern/DateTimePicker/DateTimePickerToolbar.js +42 -48
- package/modern/DesktopDatePicker/DesktopDatePicker.js +9 -3
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -10
- package/modern/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +1 -15
- package/modern/DesktopTimePicker/DesktopTimePicker.js +3 -7
- package/modern/MobileDatePicker/MobileDatePicker.js +2 -2
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +2 -2
- package/modern/MobileTimePicker/MobileTimePicker.js +2 -2
- package/modern/PickersActionBar/PickersActionBar.js +18 -16
- package/modern/PickersLayout/PickersLayout.js +1 -15
- package/modern/PickersLayout/usePickerLayout.js +13 -47
- package/modern/PickersShortcuts/PickersShortcuts.js +13 -10
- package/modern/PickersTextField/PickersInputBase/PickersInputBase.js +7 -0
- package/modern/PickersTextField/PickersTextField.js +1 -1
- package/modern/TimeField/useTimeField.js +13 -11
- package/modern/TimePicker/TimePicker.js +2 -2
- package/modern/TimePicker/TimePickerToolbar.js +23 -35
- package/modern/hooks/index.js +3 -1
- package/modern/hooks/useIsValidValue.js +11 -0
- package/modern/hooks/usePickerActionsContext.js +15 -0
- package/modern/hooks/usePickerContext.js +1 -2
- package/modern/index.js +3 -2
- package/modern/internals/components/PickerProvider.js +17 -6
- package/modern/internals/components/PickersModalDialog.js +9 -3
- package/modern/internals/components/PickersPopper.js +11 -6
- package/modern/internals/components/PickersToolbar.js +1 -1
- package/modern/internals/hooks/date-helpers-hooks.js +4 -3
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +10 -12
- package/modern/internals/hooks/useField/buildSectionsFromFormat.js +1 -1
- package/modern/internals/hooks/useField/index.js +1 -1
- package/modern/internals/hooks/useField/useField.js +17 -1
- package/modern/internals/hooks/useField/useField.utils.js +2 -2
- package/modern/internals/hooks/useField/useFieldState.js +2 -2
- package/modern/internals/hooks/useField/useFieldV6TextField.js +2 -2
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +9 -10
- package/modern/internals/hooks/useOpenState.js +3 -2
- package/modern/internals/hooks/usePicker/usePicker.js +0 -8
- package/modern/internals/hooks/usePicker/usePickerProvider.js +8 -5
- package/modern/internals/hooks/usePicker/usePickerValue.js +82 -217
- package/modern/internals/hooks/usePicker/usePickerViews.js +22 -14
- package/modern/internals/hooks/useStaticPicker/useStaticPicker.js +1 -4
- package/modern/internals/hooks/useUtils.js +1 -1
- package/modern/internals/index.js +5 -3
- package/modern/internals/models/index.js +2 -1
- package/modern/internals/models/manager.js +1 -0
- package/modern/internals/utils/date-utils.js +1 -1
- package/modern/internals/utils/valueManagers.js +4 -4
- package/modern/locales/index.js +1 -0
- package/modern/locales/nbNO.js +15 -19
- package/modern/locales/utils/getPickersLocalization.js +1 -1
- package/modern/locales/zhTW.js +73 -0
- package/modern/managers/index.js +3 -0
- package/modern/managers/useDateManager.js +47 -0
- package/modern/managers/useDateTimeManager.js +52 -0
- package/modern/managers/useTimeManager.js +43 -0
- package/modern/models/index.js +1 -0
- package/modern/models/manager.js +1 -0
- package/node/AdapterDateFns/AdapterDateFns.js +97 -97
- package/node/AdapterDateFnsJalali/AdapterDateFnsJalali.js +97 -96
- package/node/{AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js → AdapterDateFnsJalaliV2/AdapterDateFnsJalaliV2.js} +94 -101
- package/node/{AdapterDateFnsJalaliV3 → AdapterDateFnsJalaliV2}/index.js +1 -1
- package/node/AdapterDateFnsV2/AdapterDateFnsV2.js +291 -0
- package/node/{AdapterDateFnsV3 → AdapterDateFnsV2}/index.js +1 -1
- package/node/DateCalendar/DateCalendar.js +1 -1
- package/node/DateField/useDateField.js +12 -10
- package/node/DatePicker/DatePicker.js +1 -1
- package/node/DatePicker/DatePickerToolbar.js +10 -25
- package/node/DateTimeField/useDateTimeField.js +12 -10
- package/node/DateTimePicker/DateTimePicker.js +2 -2
- package/node/DateTimePicker/DateTimePickerTabs.js +7 -14
- package/node/DateTimePicker/DateTimePickerToolbar.js +43 -49
- package/node/DesktopDatePicker/DesktopDatePicker.js +9 -3
- package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -10
- package/node/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +1 -15
- package/node/DesktopTimePicker/DesktopTimePicker.js +3 -7
- package/node/MobileDatePicker/MobileDatePicker.js +2 -2
- package/node/MobileDateTimePicker/MobileDateTimePicker.js +2 -2
- package/node/MobileTimePicker/MobileTimePicker.js +2 -2
- package/node/PickersActionBar/PickersActionBar.js +20 -18
- package/node/PickersLayout/PickersLayout.js +1 -15
- package/node/PickersLayout/usePickerLayout.js +17 -51
- package/node/PickersShortcuts/PickersShortcuts.js +13 -10
- package/node/PickersTextField/PickersInputBase/PickersInputBase.js +7 -0
- package/node/PickersTextField/PickersTextField.js +1 -1
- package/node/TimeField/useTimeField.js +12 -10
- package/node/TimePicker/TimePicker.js +2 -2
- package/node/TimePicker/TimePickerToolbar.js +23 -35
- package/node/hooks/index.js +15 -1
- package/node/hooks/useIsValidValue.js +18 -0
- package/node/hooks/usePickerActionsContext.js +22 -0
- package/node/hooks/usePickerContext.js +1 -1
- package/node/index.js +13 -1
- package/node/internals/components/PickerProvider.js +18 -7
- package/node/internals/components/PickersModalDialog.js +9 -3
- package/node/internals/components/PickersPopper.js +11 -6
- package/node/internals/components/PickersToolbar.js +1 -1
- package/node/internals/hooks/date-helpers-hooks.js +4 -3
- package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +10 -12
- package/node/internals/hooks/useField/buildSectionsFromFormat.js +1 -1
- package/node/internals/hooks/useField/index.js +6 -0
- package/node/internals/hooks/useField/useField.js +18 -1
- package/node/internals/hooks/useField/useField.utils.js +2 -2
- package/node/internals/hooks/useField/useFieldState.js +2 -2
- package/node/internals/hooks/useField/useFieldV6TextField.js +2 -2
- package/node/internals/hooks/useMobilePicker/useMobilePicker.js +9 -10
- package/node/internals/hooks/useOpenState.js +4 -2
- package/node/internals/hooks/usePicker/usePicker.js +0 -9
- package/node/internals/hooks/usePicker/usePickerProvider.js +8 -5
- package/node/internals/hooks/usePicker/usePickerValue.js +82 -217
- package/node/internals/hooks/usePicker/usePickerViews.js +22 -15
- package/node/internals/hooks/useStaticPicker/useStaticPicker.js +1 -4
- package/node/internals/hooks/useUtils.js +1 -1
- package/node/internals/index.js +28 -20
- package/node/internals/models/index.js +11 -0
- package/node/internals/models/manager.js +5 -0
- package/node/internals/utils/date-utils.js +1 -1
- package/node/internals/utils/valueManagers.js +4 -4
- package/node/locales/index.js +11 -0
- package/node/locales/nbNO.js +15 -19
- package/node/locales/utils/getPickersLocalization.js +1 -1
- package/node/locales/zhTW.js +79 -0
- package/node/managers/index.js +26 -0
- package/node/managers/useDateManager.js +55 -0
- package/node/managers/useDateTimeManager.js +60 -0
- package/node/managers/useTimeManager.js +51 -0
- package/node/models/index.js +11 -0
- package/node/models/manager.js +5 -0
- package/package.json +3 -3
- package/themeAugmentation/props.d.ts +2 -3
- package/validation/extractValidationProps.d.ts +1 -1
- package/AdapterDateFnsJalaliV3/index.d.ts +0 -1
- package/AdapterDateFnsJalaliV3/index.js +0 -1
- package/AdapterDateFnsV3/index.d.ts +0 -1
- package/AdapterDateFnsV3/index.js +0 -1
- package/internals/hooks/defaultizedFieldProps.d.ts +0 -18
- package/internals/hooks/defaultizedFieldProps.js +0 -40
- package/modern/AdapterDateFnsJalaliV3/index.js +0 -1
- package/modern/AdapterDateFnsV3/index.js +0 -1
- package/modern/internals/hooks/defaultizedFieldProps.js +0 -40
- package/node/AdapterDateFnsV3/AdapterDateFnsV3.js +0 -299
- package/node/internals/hooks/defaultizedFieldProps.js +0 -50
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
|
-
const _excluded = ["items", "changeImportance"
|
|
5
|
+
const _excluded = ["items", "changeImportance"],
|
|
6
6
|
_excluded2 = ["getValue"];
|
|
7
7
|
import * as React from 'react';
|
|
8
8
|
import { styled } from '@mui/material/styles';
|
|
@@ -11,6 +11,7 @@ import List from '@mui/material/List';
|
|
|
11
11
|
import ListItem from '@mui/material/ListItem';
|
|
12
12
|
import Chip from '@mui/material/Chip';
|
|
13
13
|
import { VIEW_HEIGHT } from "../internals/constants/dimensions.js";
|
|
14
|
+
import { useIsValidValue, usePickerActionsContext } from "../hooks/index.js";
|
|
14
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
16
|
const PickersShortcutsRoot = styled(List, {
|
|
16
17
|
name: 'MuiPickersLayout',
|
|
@@ -30,11 +31,13 @@ const PickersShortcutsRoot = styled(List, {
|
|
|
30
31
|
function PickersShortcuts(props) {
|
|
31
32
|
const {
|
|
32
33
|
items,
|
|
33
|
-
changeImportance = 'accept'
|
|
34
|
-
onChange,
|
|
35
|
-
isValid
|
|
34
|
+
changeImportance = 'accept'
|
|
36
35
|
} = props,
|
|
37
36
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
37
|
+
const {
|
|
38
|
+
setValue
|
|
39
|
+
} = usePickerActionsContext();
|
|
40
|
+
const isValidValue = useIsValidValue();
|
|
38
41
|
if (items == null || items.length === 0) {
|
|
39
42
|
return null;
|
|
40
43
|
}
|
|
@@ -44,14 +47,17 @@ function PickersShortcuts(props) {
|
|
|
44
47
|
} = _ref,
|
|
45
48
|
item = _objectWithoutPropertiesLoose(_ref, _excluded2);
|
|
46
49
|
const newValue = getValue({
|
|
47
|
-
isValid
|
|
50
|
+
isValid: isValidValue
|
|
48
51
|
});
|
|
49
52
|
return _extends({}, item, {
|
|
50
53
|
label: item.label,
|
|
51
54
|
onClick: () => {
|
|
52
|
-
|
|
55
|
+
setValue(newValue, {
|
|
56
|
+
changeImportance,
|
|
57
|
+
shortcut: item
|
|
58
|
+
});
|
|
53
59
|
},
|
|
54
|
-
disabled: !
|
|
60
|
+
disabled: !isValidValue(newValue)
|
|
55
61
|
});
|
|
56
62
|
});
|
|
57
63
|
return /*#__PURE__*/_jsx(PickersShortcutsRoot, _extends({
|
|
@@ -95,8 +101,6 @@ process.env.NODE_ENV !== "production" ? PickersShortcuts.propTypes = {
|
|
|
95
101
|
* @default false
|
|
96
102
|
*/
|
|
97
103
|
disablePadding: PropTypes.bool,
|
|
98
|
-
isLandscape: PropTypes.bool.isRequired,
|
|
99
|
-
isValid: PropTypes.func.isRequired,
|
|
100
104
|
/**
|
|
101
105
|
* Ordered array of shortcuts to display.
|
|
102
106
|
* If empty, does not display the shortcuts.
|
|
@@ -107,7 +111,6 @@ process.env.NODE_ENV !== "production" ? PickersShortcuts.propTypes = {
|
|
|
107
111
|
id: PropTypes.string,
|
|
108
112
|
label: PropTypes.string.isRequired
|
|
109
113
|
})),
|
|
110
|
-
onChange: PropTypes.func.isRequired,
|
|
111
114
|
style: PropTypes.object,
|
|
112
115
|
/**
|
|
113
116
|
* The content of the subheader, normally `ListSubheader`.
|
|
@@ -213,6 +213,9 @@ const PickersInputBase = /*#__PURE__*/React.forwardRef(function PickersInputBase
|
|
|
213
213
|
muiFormControl.onFocus?.(event);
|
|
214
214
|
onFocus?.(event);
|
|
215
215
|
};
|
|
216
|
+
const handleHiddenInputFocus = event => {
|
|
217
|
+
handleInputFocus(event);
|
|
218
|
+
};
|
|
216
219
|
const handleInputBlur = event => {
|
|
217
220
|
muiFormControl.onBlur?.(event);
|
|
218
221
|
onBlur?.(event);
|
|
@@ -288,6 +291,10 @@ const PickersInputBase = /*#__PURE__*/React.forwardRef(function PickersInputBase
|
|
|
288
291
|
readOnly: readOnly,
|
|
289
292
|
required: muiFormControl.required,
|
|
290
293
|
disabled: muiFormControl.disabled
|
|
294
|
+
// Hidden input element cannot be focused, trigger the root focus instead
|
|
295
|
+
// This allows to maintain the ability to do `inputRef.current.focus()` to focus the field
|
|
296
|
+
,
|
|
297
|
+
onFocus: handleHiddenInputFocus
|
|
291
298
|
}, inputProps, {
|
|
292
299
|
ref: handleInputRef
|
|
293
300
|
}))]
|
|
@@ -125,7 +125,7 @@ const PickersTextField = /*#__PURE__*/React.forwardRef(function PickersTextField
|
|
|
125
125
|
required: required,
|
|
126
126
|
ownerState: ownerState
|
|
127
127
|
}, other, {
|
|
128
|
-
children: [/*#__PURE__*/_jsx(InputLabel, _extends({
|
|
128
|
+
children: [label != null && label !== '' && /*#__PURE__*/_jsx(InputLabel, _extends({
|
|
129
129
|
htmlFor: id,
|
|
130
130
|
id: inputLabelId
|
|
131
131
|
}, InputLabelProps, {
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { useField } from "../internals/hooks/useField/index.js";
|
|
5
|
-
import { validateTime } from "../validation/index.js";
|
|
3
|
+
import { useField, useFieldInternalPropsWithDefaults } from "../internals/hooks/useField/index.js";
|
|
6
4
|
import { useSplitFieldProps } from "../hooks/index.js";
|
|
7
|
-
import {
|
|
8
|
-
export const useTimeField =
|
|
9
|
-
const
|
|
5
|
+
import { useTimeManager } from "../managers/index.js";
|
|
6
|
+
export const useTimeField = props => {
|
|
7
|
+
const manager = useTimeManager(props);
|
|
10
8
|
const {
|
|
11
9
|
forwardedProps,
|
|
12
10
|
internalProps
|
|
13
11
|
} = useSplitFieldProps(props, 'time');
|
|
12
|
+
const internalPropsWithDefaults = useFieldInternalPropsWithDefaults({
|
|
13
|
+
manager,
|
|
14
|
+
internalProps
|
|
15
|
+
});
|
|
14
16
|
return useField({
|
|
15
17
|
forwardedProps,
|
|
16
|
-
internalProps,
|
|
17
|
-
valueManager:
|
|
18
|
-
fieldValueManager:
|
|
19
|
-
validator:
|
|
20
|
-
valueType:
|
|
18
|
+
internalProps: internalPropsWithDefaults,
|
|
19
|
+
valueManager: manager.internal_valueManager,
|
|
20
|
+
fieldValueManager: manager.internal_fieldValueManager,
|
|
21
|
+
validator: manager.validator,
|
|
22
|
+
valueType: manager.valueType
|
|
21
23
|
});
|
|
22
24
|
};
|
|
@@ -69,8 +69,8 @@ process.env.NODE_ENV !== "production" ? TimePicker.propTypes = {
|
|
|
69
69
|
autoFocus: PropTypes.bool,
|
|
70
70
|
className: PropTypes.string,
|
|
71
71
|
/**
|
|
72
|
-
* If `true`, the
|
|
73
|
-
* @default
|
|
72
|
+
* If `true`, the Picker will close after submitting the full date.
|
|
73
|
+
* @default false
|
|
74
74
|
*/
|
|
75
75
|
closeOnSelect: PropTypes.bool,
|
|
76
76
|
/**
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
|
-
const _excluded = ["ampm", "ampmInClock", "
|
|
5
|
+
const _excluded = ["ampm", "ampmInClock", "className", "classes"];
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import clsx from 'clsx';
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
@@ -122,12 +122,6 @@ function TimePickerToolbar(inProps) {
|
|
|
122
122
|
const {
|
|
123
123
|
ampm,
|
|
124
124
|
ampmInClock,
|
|
125
|
-
value,
|
|
126
|
-
isLandscape,
|
|
127
|
-
onChange,
|
|
128
|
-
view,
|
|
129
|
-
onViewChange,
|
|
130
|
-
views,
|
|
131
125
|
className,
|
|
132
126
|
classes: classesProp
|
|
133
127
|
} = props,
|
|
@@ -137,15 +131,27 @@ function TimePickerToolbar(inProps) {
|
|
|
137
131
|
const ownerState = useToolbarOwnerState();
|
|
138
132
|
const classes = useUtilityClasses(classesProp, ownerState);
|
|
139
133
|
const {
|
|
134
|
+
value,
|
|
135
|
+
setValue,
|
|
140
136
|
disabled,
|
|
141
|
-
readOnly
|
|
137
|
+
readOnly,
|
|
138
|
+
view,
|
|
139
|
+
setView,
|
|
140
|
+
views
|
|
142
141
|
} = usePickerContext();
|
|
143
142
|
const showAmPmControl = Boolean(ampm && !ampmInClock && views.includes('hours'));
|
|
144
143
|
const {
|
|
145
144
|
meridiemMode,
|
|
146
145
|
handleMeridiemChange
|
|
147
|
-
} = useMeridiemMode(value, ampm,
|
|
148
|
-
|
|
146
|
+
} = useMeridiemMode(value, ampm, newValue => setValue(newValue, {
|
|
147
|
+
changeImportance: 'set'
|
|
148
|
+
}));
|
|
149
|
+
const formatSection = format => {
|
|
150
|
+
if (!utils.isValid(value)) {
|
|
151
|
+
return '--';
|
|
152
|
+
}
|
|
153
|
+
return utils.format(value, format);
|
|
154
|
+
};
|
|
149
155
|
const separator = /*#__PURE__*/_jsx(TimePickerToolbarSeparator, {
|
|
150
156
|
tabIndex: -1,
|
|
151
157
|
value: ":",
|
|
@@ -156,7 +162,6 @@ function TimePickerToolbar(inProps) {
|
|
|
156
162
|
return /*#__PURE__*/_jsxs(TimePickerToolbarRoot, _extends({
|
|
157
163
|
landscapeDirection: "row",
|
|
158
164
|
toolbarTitle: translations.timePickerToolbarTitle,
|
|
159
|
-
isLandscape: isLandscape,
|
|
160
165
|
ownerState: ownerState,
|
|
161
166
|
className: clsx(classes.root, className)
|
|
162
167
|
}, other, {
|
|
@@ -166,20 +171,20 @@ function TimePickerToolbar(inProps) {
|
|
|
166
171
|
children: [arrayIncludes(views, 'hours') && /*#__PURE__*/_jsx(PickersToolbarButton, {
|
|
167
172
|
tabIndex: -1,
|
|
168
173
|
variant: "h3",
|
|
169
|
-
onClick: () =>
|
|
174
|
+
onClick: () => setView('hours'),
|
|
170
175
|
selected: view === 'hours',
|
|
171
|
-
value:
|
|
176
|
+
value: formatSection(ampm ? 'hours12h' : 'hours24h')
|
|
172
177
|
}), arrayIncludes(views, ['hours', 'minutes']) && separator, arrayIncludes(views, 'minutes') && /*#__PURE__*/_jsx(PickersToolbarButton, {
|
|
173
178
|
tabIndex: -1,
|
|
174
179
|
variant: "h3",
|
|
175
|
-
onClick: () =>
|
|
180
|
+
onClick: () => setView('minutes'),
|
|
176
181
|
selected: view === 'minutes',
|
|
177
|
-
value:
|
|
182
|
+
value: formatSection('minutes')
|
|
178
183
|
}), arrayIncludes(views, ['minutes', 'seconds']) && separator, arrayIncludes(views, 'seconds') && /*#__PURE__*/_jsx(PickersToolbarButton, {
|
|
179
184
|
variant: "h3",
|
|
180
|
-
onClick: () =>
|
|
185
|
+
onClick: () => setView('seconds'),
|
|
181
186
|
selected: view === 'seconds',
|
|
182
|
-
value:
|
|
187
|
+
value: formatSection('seconds')
|
|
183
188
|
})]
|
|
184
189
|
}), showAmPmControl && /*#__PURE__*/_jsxs(TimePickerToolbarAmPmSelection, {
|
|
185
190
|
className: classes.ampmSelection,
|
|
@@ -221,14 +226,6 @@ process.env.NODE_ENV !== "production" ? TimePickerToolbar.propTypes = {
|
|
|
221
226
|
* @default `true` for Desktop, `false` for Mobile.
|
|
222
227
|
*/
|
|
223
228
|
hidden: PropTypes.bool,
|
|
224
|
-
isLandscape: PropTypes.bool.isRequired,
|
|
225
|
-
onChange: PropTypes.func.isRequired,
|
|
226
|
-
/**
|
|
227
|
-
* Callback called when a toolbar is clicked
|
|
228
|
-
* @template TView
|
|
229
|
-
* @param {TView} view The view to open
|
|
230
|
-
*/
|
|
231
|
-
onViewChange: PropTypes.func.isRequired,
|
|
232
229
|
/**
|
|
233
230
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
234
231
|
*/
|
|
@@ -242,15 +239,6 @@ process.env.NODE_ENV !== "production" ? TimePickerToolbar.propTypes = {
|
|
|
242
239
|
* Toolbar value placeholder—it is displayed when the value is empty.
|
|
243
240
|
* @default "––"
|
|
244
241
|
*/
|
|
245
|
-
toolbarPlaceholder: PropTypes.node
|
|
246
|
-
value: PropTypes.object,
|
|
247
|
-
/**
|
|
248
|
-
* Currently visible picker view.
|
|
249
|
-
*/
|
|
250
|
-
view: PropTypes.oneOf(['hours', 'meridiem', 'minutes', 'seconds']).isRequired,
|
|
251
|
-
/**
|
|
252
|
-
* Available views.
|
|
253
|
-
*/
|
|
254
|
-
views: PropTypes.arrayOf(PropTypes.oneOf(['hours', 'meridiem', 'minutes', 'seconds']).isRequired).isRequired
|
|
242
|
+
toolbarPlaceholder: PropTypes.node
|
|
255
243
|
} : void 0;
|
|
256
244
|
export { TimePickerToolbar };
|
package/modern/hooks/index.js
CHANGED
|
@@ -2,4 +2,6 @@ export { useClearableField } from "./useClearableField.js";
|
|
|
2
2
|
export { usePickerTranslations } from "./usePickerTranslations.js";
|
|
3
3
|
export { useSplitFieldProps } from "./useSplitFieldProps.js";
|
|
4
4
|
export { useParsedFormat } from "./useParsedFormat.js";
|
|
5
|
-
export { usePickerContext } from "./usePickerContext.js";
|
|
5
|
+
export { usePickerContext } from "./usePickerContext.js";
|
|
6
|
+
export { usePickerActionsContext } from "./usePickerActionsContext.js";
|
|
7
|
+
export { useIsValidValue } from "./useIsValidValue.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
export const IsValidValueContext = /*#__PURE__*/React.createContext(() => true);
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns a function to check if a value is valid according to the validation props passed to the parent picker.
|
|
8
|
+
*/
|
|
9
|
+
export function useIsValidValue() {
|
|
10
|
+
return React.useContext(IsValidValueContext);
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { PickerActionsContext } from "../internals/components/PickerProvider.js";
|
|
5
|
+
/**
|
|
6
|
+
* Returns a subset of the context passed by the picker wrapping the current component.
|
|
7
|
+
* It only contains the actions and never causes a re-render of the component using it.
|
|
8
|
+
*/
|
|
9
|
+
export const usePickerActionsContext = () => {
|
|
10
|
+
const value = React.useContext(PickerActionsContext);
|
|
11
|
+
if (value == null) {
|
|
12
|
+
throw new Error(['MUI X: The `usePickerActionsContext` can only be called in fields that are used as a slot of a picker component'].join('\n'));
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
};
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { PickerContext } from "../internals/components/PickerProvider.js";
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Returns the context passed by the picker that wraps the current component.
|
|
8
7
|
*/
|
|
9
8
|
export const usePickerContext = () => {
|
|
10
9
|
const value = React.useContext(PickerContext);
|
|
11
10
|
if (value == null) {
|
|
12
|
-
throw new Error(
|
|
11
|
+
throw new Error('MUI X: The `usePickerContext` hook can only be called inside the context of a picker component');
|
|
13
12
|
}
|
|
14
13
|
return value;
|
|
15
14
|
};
|
package/modern/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/x-date-pickers v8.0.0-alpha.
|
|
2
|
+
* @mui/x-date-pickers v8.0.0-alpha.7
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -57,4 +57,5 @@ export { DEFAULT_DESKTOP_MODE_MEDIA_QUERY } from "./internals/utils/utils.js";
|
|
|
57
57
|
export * from "./models/index.js";
|
|
58
58
|
export * from "./icons/index.js";
|
|
59
59
|
export * from "./hooks/index.js";
|
|
60
|
-
export * from "./validation/index.js";
|
|
60
|
+
export * from "./validation/index.js";
|
|
61
|
+
export * from "./managers/index.js";
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { LocalizationProvider } from "../../LocalizationProvider/index.js";
|
|
3
|
+
import { IsValidValueContext } from "../../hooks/useIsValidValue.js";
|
|
3
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
5
|
export const PickerContext = /*#__PURE__*/React.createContext(null);
|
|
6
|
+
export const PickerActionsContext = /*#__PURE__*/React.createContext(null);
|
|
5
7
|
export const PickerPrivateContext = /*#__PURE__*/React.createContext({
|
|
6
8
|
ownerState: {
|
|
7
9
|
isPickerDisabled: false,
|
|
@@ -10,7 +12,8 @@ export const PickerPrivateContext = /*#__PURE__*/React.createContext({
|
|
|
10
12
|
isPickerOpen: false,
|
|
11
13
|
pickerVariant: 'desktop',
|
|
12
14
|
pickerOrientation: 'portrait'
|
|
13
|
-
}
|
|
15
|
+
},
|
|
16
|
+
dismissViews: () => {}
|
|
14
17
|
});
|
|
15
18
|
|
|
16
19
|
/**
|
|
@@ -23,17 +26,25 @@ export const PickerPrivateContext = /*#__PURE__*/React.createContext({
|
|
|
23
26
|
export function PickerProvider(props) {
|
|
24
27
|
const {
|
|
25
28
|
contextValue,
|
|
29
|
+
actionsContextValue,
|
|
26
30
|
privateContextValue,
|
|
31
|
+
isValidContextValue,
|
|
27
32
|
localeText,
|
|
28
33
|
children
|
|
29
34
|
} = props;
|
|
30
35
|
return /*#__PURE__*/_jsx(PickerContext.Provider, {
|
|
31
36
|
value: contextValue,
|
|
32
|
-
children: /*#__PURE__*/_jsx(
|
|
33
|
-
value:
|
|
34
|
-
children: /*#__PURE__*/_jsx(
|
|
35
|
-
|
|
36
|
-
children:
|
|
37
|
+
children: /*#__PURE__*/_jsx(PickerActionsContext.Provider, {
|
|
38
|
+
value: actionsContextValue,
|
|
39
|
+
children: /*#__PURE__*/_jsx(PickerPrivateContext.Provider, {
|
|
40
|
+
value: privateContextValue,
|
|
41
|
+
children: /*#__PURE__*/_jsx(IsValidValueContext.Provider, {
|
|
42
|
+
value: isValidContextValue,
|
|
43
|
+
children: /*#__PURE__*/_jsx(LocalizationProvider, {
|
|
44
|
+
localeText: localeText,
|
|
45
|
+
children: children
|
|
46
|
+
})
|
|
47
|
+
})
|
|
37
48
|
})
|
|
38
49
|
})
|
|
39
50
|
});
|
|
@@ -5,6 +5,8 @@ import Fade from '@mui/material/Fade';
|
|
|
5
5
|
import MuiDialog, { dialogClasses } from '@mui/material/Dialog';
|
|
6
6
|
import { styled } from '@mui/material/styles';
|
|
7
7
|
import { DIALOG_WIDTH } from "../constants/dimensions.js";
|
|
8
|
+
import { usePickerContext } from "../../hooks/index.js";
|
|
9
|
+
import { usePickerPrivateContext } from "../hooks/usePickerPrivateContext.js";
|
|
8
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
11
|
const PickersModalDialogRoot = styled(MuiDialog)({
|
|
10
12
|
[`& .${dialogClasses.container}`]: {
|
|
@@ -23,16 +25,20 @@ const PickersModalDialogContent = styled(DialogContent)({
|
|
|
23
25
|
export function PickersModalDialog(props) {
|
|
24
26
|
const {
|
|
25
27
|
children,
|
|
26
|
-
onDismiss,
|
|
27
|
-
open,
|
|
28
28
|
slots,
|
|
29
29
|
slotProps
|
|
30
30
|
} = props;
|
|
31
|
+
const {
|
|
32
|
+
open
|
|
33
|
+
} = usePickerContext();
|
|
34
|
+
const {
|
|
35
|
+
dismissViews
|
|
36
|
+
} = usePickerPrivateContext();
|
|
31
37
|
const Dialog = slots?.dialog ?? PickersModalDialogRoot;
|
|
32
38
|
const Transition = slots?.mobileTransition ?? Fade;
|
|
33
39
|
return /*#__PURE__*/_jsx(Dialog, _extends({
|
|
34
40
|
open: open,
|
|
35
|
-
onClose:
|
|
41
|
+
onClose: dismissViews
|
|
36
42
|
}, slotProps?.dialog, {
|
|
37
43
|
TransitionComponent: Transition,
|
|
38
44
|
TransitionProps: slotProps?.mobileTransition,
|
|
@@ -14,6 +14,7 @@ import { getPickersPopperUtilityClass } from "./pickersPopperClasses.js";
|
|
|
14
14
|
import { getActiveElement } from "../utils/utils.js";
|
|
15
15
|
import { useDefaultReduceAnimations } from "../hooks/useDefaultReduceAnimations.js";
|
|
16
16
|
import { usePickerPrivateContext } from "../hooks/usePickerPrivateContext.js";
|
|
17
|
+
import { usePickerContext } from "../../hooks/index.js";
|
|
17
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
19
|
const useUtilityClasses = classes => {
|
|
19
20
|
const slots = {
|
|
@@ -210,8 +211,6 @@ export function PickersPopper(inProps) {
|
|
|
210
211
|
containerRef = null,
|
|
211
212
|
shouldRestoreFocus,
|
|
212
213
|
onBlur,
|
|
213
|
-
onDismiss,
|
|
214
|
-
open,
|
|
215
214
|
role,
|
|
216
215
|
placement = 'bottom',
|
|
217
216
|
slots,
|
|
@@ -219,17 +218,23 @@ export function PickersPopper(inProps) {
|
|
|
219
218
|
reduceAnimations: inReduceAnimations,
|
|
220
219
|
classes: classesProp
|
|
221
220
|
} = props;
|
|
221
|
+
const {
|
|
222
|
+
open
|
|
223
|
+
} = usePickerContext();
|
|
224
|
+
const {
|
|
225
|
+
dismissViews
|
|
226
|
+
} = usePickerPrivateContext();
|
|
222
227
|
React.useEffect(() => {
|
|
223
228
|
function handleKeyDown(nativeEvent) {
|
|
224
229
|
if (open && nativeEvent.key === 'Escape') {
|
|
225
|
-
|
|
230
|
+
dismissViews();
|
|
226
231
|
}
|
|
227
232
|
}
|
|
228
233
|
document.addEventListener('keydown', handleKeyDown);
|
|
229
234
|
return () => {
|
|
230
235
|
document.removeEventListener('keydown', handleKeyDown);
|
|
231
236
|
};
|
|
232
|
-
}, [
|
|
237
|
+
}, [dismissViews, open]);
|
|
233
238
|
const lastFocusedElementRef = React.useRef(null);
|
|
234
239
|
React.useEffect(() => {
|
|
235
240
|
if (role === 'tooltip' || shouldRestoreFocus && !shouldRestoreFocus()) {
|
|
@@ -247,7 +252,7 @@ export function PickersPopper(inProps) {
|
|
|
247
252
|
});
|
|
248
253
|
}
|
|
249
254
|
}, [open, role, shouldRestoreFocus]);
|
|
250
|
-
const [clickAwayRef, onPaperClick, onPaperTouchStart] = useClickAwayListener(open, onBlur ??
|
|
255
|
+
const [clickAwayRef, onPaperClick, onPaperTouchStart] = useClickAwayListener(open, onBlur ?? dismissViews);
|
|
251
256
|
const paperRef = React.useRef(null);
|
|
252
257
|
const handleRef = useForkRef(paperRef, containerRef);
|
|
253
258
|
const handlePaperRef = useForkRef(handleRef, clickAwayRef);
|
|
@@ -264,7 +269,7 @@ export function PickersPopper(inProps) {
|
|
|
264
269
|
if (event.key === 'Escape') {
|
|
265
270
|
// stop the propagation to avoid closing parent modal
|
|
266
271
|
event.stopPropagation();
|
|
267
|
-
|
|
272
|
+
dismissViews();
|
|
268
273
|
}
|
|
269
274
|
};
|
|
270
275
|
const Transition = slots?.desktopTransition ?? reduceAnimations ? Fade : Grow;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["children", "className", "classes", "toolbarTitle", "hidden", "titleId", "
|
|
3
|
+
const _excluded = ["children", "className", "classes", "toolbarTitle", "hidden", "titleId", "classes", "landscapeDirection"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import clsx from 'clsx';
|
|
6
6
|
import Typography from '@mui/material/Typography';
|
|
@@ -27,11 +27,12 @@ export function usePreviousMonthDisabled(month, {
|
|
|
27
27
|
}
|
|
28
28
|
export function useMeridiemMode(date, ampm, onChange, selectionState) {
|
|
29
29
|
const utils = useUtils();
|
|
30
|
-
const
|
|
30
|
+
const cleanDate = React.useMemo(() => !utils.isValid(date) ? null : date, [utils, date]);
|
|
31
|
+
const meridiemMode = getMeridiem(cleanDate, utils);
|
|
31
32
|
const handleMeridiemChange = React.useCallback(mode => {
|
|
32
|
-
const timeWithMeridiem =
|
|
33
|
+
const timeWithMeridiem = cleanDate == null ? null : convertToMeridiem(cleanDate, mode, Boolean(ampm), utils);
|
|
33
34
|
onChange(timeWithMeridiem, selectionState ?? 'partial');
|
|
34
|
-
}, [ampm,
|
|
35
|
+
}, [ampm, cleanDate, onChange, selectionState, utils]);
|
|
35
36
|
return {
|
|
36
37
|
meridiemMode,
|
|
37
38
|
handleMeridiemChange
|
|
@@ -52,10 +52,7 @@ export const useDesktopPicker = _ref => {
|
|
|
52
52
|
const labelId = useId();
|
|
53
53
|
const isToolbarHidden = innerSlotProps?.toolbar?.hidden ?? false;
|
|
54
54
|
const {
|
|
55
|
-
open,
|
|
56
|
-
actions,
|
|
57
55
|
hasUIView,
|
|
58
|
-
layoutProps,
|
|
59
56
|
providerProps,
|
|
60
57
|
renderCurrentView,
|
|
61
58
|
shouldRestoreFocus,
|
|
@@ -66,7 +63,6 @@ export const useDesktopPicker = _ref => {
|
|
|
66
63
|
fieldRef,
|
|
67
64
|
localeText,
|
|
68
65
|
autoFocusView: true,
|
|
69
|
-
additionalViewProps: {},
|
|
70
66
|
variant: 'desktop'
|
|
71
67
|
}));
|
|
72
68
|
const InputAdornment = slots.inputAdornment ?? MuiInputAdornment;
|
|
@@ -85,7 +81,11 @@ export const useDesktopPicker = _ref => {
|
|
|
85
81
|
externalSlotProps: innerSlotProps?.openPickerButton,
|
|
86
82
|
additionalProps: {
|
|
87
83
|
disabled: disabled || readOnly,
|
|
88
|
-
|
|
84
|
+
// This direct access to `providerProps` will go away in https://github.com/mui/mui-x/pull/15671
|
|
85
|
+
onClick: event => {
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
providerProps.contextValue.setOpen(prevOpen => !prevOpen);
|
|
88
|
+
},
|
|
89
89
|
'aria-label': getOpenDialogAriaText(pickerFieldProps.value),
|
|
90
90
|
edge: inputAdornmentProps.position
|
|
91
91
|
},
|
|
@@ -121,7 +121,7 @@ export const useDesktopPicker = _ref => {
|
|
|
121
121
|
sx,
|
|
122
122
|
label,
|
|
123
123
|
name,
|
|
124
|
-
focused: open ? true : undefined
|
|
124
|
+
focused: providerProps.contextValue.open ? true : undefined
|
|
125
125
|
}, isToolbarHidden && {
|
|
126
126
|
id: labelId
|
|
127
127
|
}, !!inputRef && {
|
|
@@ -170,22 +170,20 @@ export const useDesktopPicker = _ref => {
|
|
|
170
170
|
slots: slotsForField,
|
|
171
171
|
slotProps: slotProps,
|
|
172
172
|
unstableFieldRef: handleFieldRef
|
|
173
|
-
})), /*#__PURE__*/_jsx(PickersPopper,
|
|
173
|
+
})), /*#__PURE__*/_jsx(PickersPopper, {
|
|
174
174
|
role: "dialog",
|
|
175
175
|
placement: "bottom-start",
|
|
176
|
-
anchorEl: containerRef.current
|
|
177
|
-
}, actions, {
|
|
178
|
-
open: open,
|
|
176
|
+
anchorEl: containerRef.current,
|
|
179
177
|
slots: slots,
|
|
180
178
|
slotProps: slotProps,
|
|
181
179
|
shouldRestoreFocus: shouldRestoreFocus,
|
|
182
180
|
reduceAnimations: reduceAnimations,
|
|
183
|
-
children: /*#__PURE__*/_jsx(Layout, _extends({},
|
|
181
|
+
children: /*#__PURE__*/_jsx(Layout, _extends({}, slotProps?.layout, {
|
|
184
182
|
slots: slots,
|
|
185
183
|
slotProps: slotProps,
|
|
186
184
|
children: renderCurrentView()
|
|
187
185
|
}))
|
|
188
|
-
})
|
|
186
|
+
})]
|
|
189
187
|
}));
|
|
190
188
|
return {
|
|
191
189
|
renderPicker
|
|
@@ -113,7 +113,7 @@ const createSection = ({
|
|
|
113
113
|
const sectionConfig = getDateSectionConfigFromFormatToken(utils, token);
|
|
114
114
|
const hasLeadingZerosInFormat = doesSectionFormatHaveLeadingZeros(utils, sectionConfig.contentType, sectionConfig.type, token);
|
|
115
115
|
const hasLeadingZerosInInput = shouldRespectLeadingZeros ? hasLeadingZerosInFormat : sectionConfig.contentType === 'digit';
|
|
116
|
-
const isValidDate =
|
|
116
|
+
const isValidDate = utils.isValid(date);
|
|
117
117
|
let sectionValue = isValidDate ? utils.formatByString(date, token) : '';
|
|
118
118
|
let maxLength = null;
|
|
119
119
|
if (hasLeadingZerosInInput) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { useField } from "./useField.js";
|
|
1
|
+
export { useField, useFieldInternalPropsWithDefaults } from "./useField.js";
|
|
2
2
|
export { createDateStrForV7HiddenInputFromSections, createDateStrForV6InputFromSections } from "./useField.utils.js";
|
|
@@ -4,12 +4,28 @@ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
|
4
4
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
5
5
|
import { useRtl } from '@mui/system/RtlProvider';
|
|
6
6
|
import { useValidation } from "../../../validation/index.js";
|
|
7
|
-
import { useUtils } from "../useUtils.js";
|
|
7
|
+
import { useLocalizationContext, useUtils } from "../useUtils.js";
|
|
8
8
|
import { adjustSectionValue, getSectionOrder } from "./useField.utils.js";
|
|
9
9
|
import { useFieldState } from "./useFieldState.js";
|
|
10
10
|
import { useFieldCharacterEditing } from "./useFieldCharacterEditing.js";
|
|
11
11
|
import { useFieldV7TextField } from "./useFieldV7TextField.js";
|
|
12
12
|
import { useFieldV6TextField } from "./useFieldV6TextField.js";
|
|
13
|
+
/**
|
|
14
|
+
* Applies the default values to the field internal props.
|
|
15
|
+
* This is a temporary hook that will be removed during a follow up when `useField` will receive the internal props without the defaults.
|
|
16
|
+
* It is only here to allow the migration to be done in smaller steps.
|
|
17
|
+
*/
|
|
18
|
+
export const useFieldInternalPropsWithDefaults = ({
|
|
19
|
+
manager,
|
|
20
|
+
internalProps
|
|
21
|
+
}) => {
|
|
22
|
+
const localizationContext = useLocalizationContext();
|
|
23
|
+
return React.useMemo(() => {
|
|
24
|
+
return manager.internal_applyDefaultsToFieldInternalProps(_extends({}, localizationContext, {
|
|
25
|
+
internalProps
|
|
26
|
+
}));
|
|
27
|
+
}, [manager, internalProps, localizationContext]);
|
|
28
|
+
};
|
|
13
29
|
export const useField = params => {
|
|
14
30
|
const utils = useUtils();
|
|
15
31
|
const {
|
|
@@ -361,7 +361,7 @@ export const getSectionsBoundaries = (utils, localizedDigits, timezone) => {
|
|
|
361
361
|
currentDate
|
|
362
362
|
}) => ({
|
|
363
363
|
minimum: 1,
|
|
364
|
-
maximum:
|
|
364
|
+
maximum: utils.isValid(currentDate) ? utils.getDaysInMonth(currentDate) : maxDaysInMonth,
|
|
365
365
|
longestMonth: longestMonth
|
|
366
366
|
}),
|
|
367
367
|
weekDay: ({
|
|
@@ -509,7 +509,7 @@ export const mergeDateIntoReferenceDate = (utils, dateToTransferFrom, sections,
|
|
|
509
509
|
}, referenceDate);
|
|
510
510
|
export const isAndroid = () => navigator.userAgent.toLowerCase().includes('android');
|
|
511
511
|
|
|
512
|
-
// TODO
|
|
512
|
+
// TODO v9: Remove
|
|
513
513
|
export const getSectionOrder = (sections, shouldApplyRTL) => {
|
|
514
514
|
const neighbors = {};
|
|
515
515
|
if (!shouldApplyRTL) {
|