@mui/x-date-pickers 8.0.0-alpha.5 → 8.0.0-alpha.6
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 +79 -0
- package/DatePicker/DatePickerToolbar.d.ts +1 -2
- package/DatePicker/DatePickerToolbar.js +6 -17
- package/DateTimePicker/DateTimePicker.types.d.ts +2 -2
- package/DateTimePicker/DateTimePickerTabs.d.ts +2 -5
- package/DateTimePicker/DateTimePickerTabs.js +6 -13
- package/DateTimePicker/DateTimePickerToolbar.d.ts +8 -4
- package/DateTimePicker/DateTimePickerToolbar.js +13 -24
- package/DateTimePicker/shared.d.ts +2 -2
- package/DesktopDatePicker/DesktopDatePicker.types.d.ts +2 -3
- package/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +2 -2
- package/DesktopDateTimePicker/DesktopDateTimePickerLayout.d.ts +1 -2
- package/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +1 -11
- package/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
- package/MobileDatePicker/MobileDatePicker.types.d.ts +2 -3
- package/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +4 -4
- package/MobileTimePicker/MobileTimePicker.types.d.ts +4 -4
- package/PickersActionBar/PickersActionBar.d.ts +0 -4
- package/PickersActionBar/PickersActionBar.js +12 -13
- package/PickersLayout/PickersLayout.d.ts +2 -2
- package/PickersLayout/PickersLayout.js +1 -11
- package/PickersLayout/PickersLayout.types.d.ts +12 -14
- package/PickersLayout/usePickerLayout.d.ts +2 -2
- package/PickersLayout/usePickerLayout.js +3 -18
- 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/TimePicker/TimePicker.types.d.ts +2 -2
- package/TimePicker/TimePickerToolbar.d.ts +2 -2
- package/TimePicker/TimePickerToolbar.js +6 -20
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +2 -1
- package/hooks/usePickerActionsContext.d.ts +5 -0
- package/hooks/usePickerActionsContext.js +16 -0
- package/hooks/usePickerContext.d.ts +3 -1
- package/hooks/usePickerContext.js +0 -1
- package/index.js +1 -1
- package/internals/components/PickerProvider.d.ts +11 -6
- package/internals/components/PickerProvider.js +12 -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 +3 -3
- package/internals/hooks/useDesktopPicker/useDesktopPicker.js +9 -9
- package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +5 -5
- package/internals/hooks/useMobilePicker/useMobilePicker.js +8 -7
- package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +5 -5
- package/internals/hooks/usePicker/usePicker.js +1 -3
- package/internals/hooks/usePicker/usePicker.types.d.ts +2 -2
- package/internals/hooks/usePicker/usePickerProvider.js +5 -4
- package/internals/hooks/usePicker/usePickerValue.js +46 -64
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +38 -17
- package/internals/hooks/usePicker/usePickerViews.d.ts +15 -4
- package/internals/hooks/usePicker/usePickerViews.js +9 -7
- package/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +4 -4
- package/internals/index.d.ts +4 -4
- package/internals/index.js +1 -1
- package/internals/models/props/tabs.d.ts +0 -13
- package/internals/models/props/toolbar.d.ts +1 -16
- package/modern/DatePicker/DatePickerToolbar.js +6 -17
- package/modern/DateTimePicker/DateTimePickerTabs.js +6 -13
- package/modern/DateTimePicker/DateTimePickerToolbar.js +13 -24
- package/modern/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +1 -11
- package/modern/PickersActionBar/PickersActionBar.js +12 -13
- package/modern/PickersLayout/PickersLayout.js +1 -11
- package/modern/PickersLayout/usePickerLayout.js +3 -18
- package/modern/TimePicker/TimePickerToolbar.js +6 -20
- package/modern/hooks/index.js +2 -1
- package/modern/hooks/usePickerActionsContext.js +16 -0
- package/modern/hooks/usePickerContext.js +0 -1
- package/modern/index.js +1 -1
- package/modern/internals/components/PickerProvider.js +12 -6
- package/modern/internals/components/PickersModalDialog.js +9 -3
- package/modern/internals/components/PickersPopper.js +11 -6
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +9 -9
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +8 -7
- package/modern/internals/hooks/usePicker/usePicker.js +1 -3
- package/modern/internals/hooks/usePicker/usePickerProvider.js +5 -4
- package/modern/internals/hooks/usePicker/usePickerValue.js +46 -64
- package/modern/internals/hooks/usePicker/usePickerViews.js +9 -7
- package/modern/internals/index.js +1 -1
- package/node/DatePicker/DatePickerToolbar.js +6 -17
- package/node/DateTimePicker/DateTimePickerTabs.js +6 -13
- package/node/DateTimePicker/DateTimePickerToolbar.js +14 -25
- package/node/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +1 -11
- package/node/PickersActionBar/PickersActionBar.js +12 -13
- package/node/PickersLayout/PickersLayout.js +1 -11
- package/node/PickersLayout/usePickerLayout.js +3 -18
- package/node/TimePicker/TimePickerToolbar.js +6 -20
- package/node/hooks/index.js +8 -1
- package/node/hooks/usePickerActionsContext.js +22 -0
- package/node/index.js +1 -1
- package/node/internals/components/PickerProvider.js +13 -7
- package/node/internals/components/PickersModalDialog.js +9 -3
- package/node/internals/components/PickersPopper.js +11 -6
- package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +9 -9
- package/node/internals/hooks/useMobilePicker/useMobilePicker.js +8 -7
- package/node/internals/hooks/usePicker/usePicker.js +1 -3
- package/node/internals/hooks/usePicker/usePickerProvider.js +5 -4
- package/node/internals/hooks/usePicker/usePickerValue.js +46 -64
- package/node/internals/hooks/usePicker/usePickerViews.js +9 -7
- package/node/internals/index.js +2 -2
- package/package.json +2 -2
- package/themeAugmentation/props.d.ts +2 -3
|
@@ -158,16 +158,8 @@ process.env.NODE_ENV !== "production" ? PickersLayout.propTypes = {
|
|
|
158
158
|
classes: _propTypes.default.object,
|
|
159
159
|
className: _propTypes.default.string,
|
|
160
160
|
isValid: _propTypes.default.func.isRequired,
|
|
161
|
-
onAccept: _propTypes.default.func.isRequired,
|
|
162
|
-
onCancel: _propTypes.default.func.isRequired,
|
|
163
161
|
onChange: _propTypes.default.func.isRequired,
|
|
164
|
-
onClear: _propTypes.default.func.isRequired,
|
|
165
|
-
onClose: _propTypes.default.func.isRequired,
|
|
166
|
-
onDismiss: _propTypes.default.func.isRequired,
|
|
167
|
-
onOpen: _propTypes.default.func.isRequired,
|
|
168
162
|
onSelectShortcut: _propTypes.default.func.isRequired,
|
|
169
|
-
onSetToday: _propTypes.default.func.isRequired,
|
|
170
|
-
onViewChange: _propTypes.default.func.isRequired,
|
|
171
163
|
/**
|
|
172
164
|
* The props used for each component slot.
|
|
173
165
|
* @default {}
|
|
@@ -182,7 +174,5 @@ process.env.NODE_ENV !== "production" ? PickersLayout.propTypes = {
|
|
|
182
174
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
183
175
|
*/
|
|
184
176
|
sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
|
|
185
|
-
value: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.object), _propTypes.default.object])
|
|
186
|
-
view: _propTypes.default.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']),
|
|
187
|
-
views: _propTypes.default.arrayOf(_propTypes.default.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']).isRequired).isRequired
|
|
177
|
+
value: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.object), _propTypes.default.object])
|
|
188
178
|
} : void 0;
|
|
@@ -42,17 +42,11 @@ const usePickerLayout = props => {
|
|
|
42
42
|
} = (0, _usePickerPrivateContext.usePickerPrivateContext)();
|
|
43
43
|
const {
|
|
44
44
|
variant,
|
|
45
|
-
orientation
|
|
45
|
+
orientation,
|
|
46
|
+
view
|
|
46
47
|
} = (0, _hooks.usePickerContext)();
|
|
47
48
|
const isRtl = (0, _RtlProvider.useRtl)();
|
|
48
49
|
const {
|
|
49
|
-
onAccept,
|
|
50
|
-
onClear,
|
|
51
|
-
onCancel,
|
|
52
|
-
onSetToday,
|
|
53
|
-
view,
|
|
54
|
-
views,
|
|
55
|
-
onViewChange,
|
|
56
50
|
value,
|
|
57
51
|
onChange,
|
|
58
52
|
onSelectShortcut,
|
|
@@ -77,10 +71,6 @@ const usePickerLayout = props => {
|
|
|
77
71
|
elementType: ActionBar,
|
|
78
72
|
externalSlotProps: slotProps?.actionBar,
|
|
79
73
|
additionalProps: {
|
|
80
|
-
onAccept,
|
|
81
|
-
onClear,
|
|
82
|
-
onCancel,
|
|
83
|
-
onSetToday,
|
|
84
74
|
actions: variant === 'desktop' ? [] : ['cancel', 'accept']
|
|
85
75
|
},
|
|
86
76
|
className: classes.actionBar,
|
|
@@ -97,10 +87,7 @@ const usePickerLayout = props => {
|
|
|
97
87
|
isLandscape: orientation === 'landscape',
|
|
98
88
|
// Will be removed in a follow up PR?
|
|
99
89
|
onChange,
|
|
100
|
-
value
|
|
101
|
-
view,
|
|
102
|
-
onViewChange,
|
|
103
|
-
views
|
|
90
|
+
value
|
|
104
91
|
},
|
|
105
92
|
className: classes.toolbar,
|
|
106
93
|
ownerState
|
|
@@ -113,8 +100,6 @@ const usePickerLayout = props => {
|
|
|
113
100
|
// Tabs
|
|
114
101
|
const Tabs = slots?.tabs;
|
|
115
102
|
const tabs = view && Tabs ? /*#__PURE__*/(0, _jsxRuntime.jsx)(Tabs, (0, _extends2.default)({
|
|
116
|
-
view: view,
|
|
117
|
-
onViewChange: onViewChange,
|
|
118
103
|
className: classes.tabs
|
|
119
104
|
}, slotProps?.tabs)) : null;
|
|
120
105
|
|
|
@@ -26,7 +26,7 @@ var _dateUtils = require("../internals/utils/date-utils");
|
|
|
26
26
|
var _hooks = require("../hooks");
|
|
27
27
|
var _useToolbarOwnerState = require("../internals/hooks/useToolbarOwnerState");
|
|
28
28
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
29
|
-
const _excluded = ["ampm", "ampmInClock", "value", "isLandscape", "onChange", "
|
|
29
|
+
const _excluded = ["ampm", "ampmInClock", "value", "isLandscape", "onChange", "className", "classes"];
|
|
30
30
|
const useUtilityClasses = (classes, ownerState) => {
|
|
31
31
|
const {
|
|
32
32
|
pickerOrientation,
|
|
@@ -132,9 +132,6 @@ function TimePickerToolbar(inProps) {
|
|
|
132
132
|
value,
|
|
133
133
|
isLandscape,
|
|
134
134
|
onChange,
|
|
135
|
-
view,
|
|
136
|
-
onViewChange,
|
|
137
|
-
views,
|
|
138
135
|
className,
|
|
139
136
|
classes: classesProp
|
|
140
137
|
} = props,
|
|
@@ -145,7 +142,10 @@ function TimePickerToolbar(inProps) {
|
|
|
145
142
|
const classes = useUtilityClasses(classesProp, ownerState);
|
|
146
143
|
const {
|
|
147
144
|
disabled,
|
|
148
|
-
readOnly
|
|
145
|
+
readOnly,
|
|
146
|
+
view,
|
|
147
|
+
onViewChange,
|
|
148
|
+
views
|
|
149
149
|
} = (0, _hooks.usePickerContext)();
|
|
150
150
|
const showAmPmControl = Boolean(ampm && !ampmInClock && views.includes('hours'));
|
|
151
151
|
const {
|
|
@@ -230,12 +230,6 @@ process.env.NODE_ENV !== "production" ? TimePickerToolbar.propTypes = {
|
|
|
230
230
|
hidden: _propTypes.default.bool,
|
|
231
231
|
isLandscape: _propTypes.default.bool.isRequired,
|
|
232
232
|
onChange: _propTypes.default.func.isRequired,
|
|
233
|
-
/**
|
|
234
|
-
* Callback called when a toolbar is clicked
|
|
235
|
-
* @template TView
|
|
236
|
-
* @param {TView} view The view to open
|
|
237
|
-
*/
|
|
238
|
-
onViewChange: _propTypes.default.func.isRequired,
|
|
239
233
|
/**
|
|
240
234
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
241
235
|
*/
|
|
@@ -250,13 +244,5 @@ process.env.NODE_ENV !== "production" ? TimePickerToolbar.propTypes = {
|
|
|
250
244
|
* @default "––"
|
|
251
245
|
*/
|
|
252
246
|
toolbarPlaceholder: _propTypes.default.node,
|
|
253
|
-
value: _propTypes.default.object
|
|
254
|
-
/**
|
|
255
|
-
* Currently visible picker view.
|
|
256
|
-
*/
|
|
257
|
-
view: _propTypes.default.oneOf(['hours', 'meridiem', 'minutes', 'seconds']).isRequired,
|
|
258
|
-
/**
|
|
259
|
-
* Available views.
|
|
260
|
-
*/
|
|
261
|
-
views: _propTypes.default.arrayOf(_propTypes.default.oneOf(['hours', 'meridiem', 'minutes', 'seconds']).isRequired).isRequired
|
|
247
|
+
value: _propTypes.default.object
|
|
262
248
|
} : void 0;
|
package/node/hooks/index.js
CHANGED
|
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "useParsedFormat", {
|
|
|
15
15
|
return _useParsedFormat.useParsedFormat;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "usePickerActionsContext", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _usePickerActionsContext.usePickerActionsContext;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
Object.defineProperty(exports, "usePickerContext", {
|
|
19
25
|
enumerable: true,
|
|
20
26
|
get: function () {
|
|
@@ -37,4 +43,5 @@ var _useClearableField = require("./useClearableField");
|
|
|
37
43
|
var _usePickerTranslations = require("./usePickerTranslations");
|
|
38
44
|
var _useSplitFieldProps = require("./useSplitFieldProps");
|
|
39
45
|
var _useParsedFormat = require("./useParsedFormat");
|
|
40
|
-
var _usePickerContext = require("./usePickerContext");
|
|
46
|
+
var _usePickerContext = require("./usePickerContext");
|
|
47
|
+
var _usePickerActionsContext = require("./usePickerActionsContext");
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.usePickerActionsContext = void 0;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _PickerProvider = require("../internals/components/PickerProvider");
|
|
11
|
+
/**
|
|
12
|
+
* Returns a subset of the context passed by the picker wrapping the current component.
|
|
13
|
+
* It only contains the actions and never causes a re-render of the component using it.
|
|
14
|
+
*/
|
|
15
|
+
const usePickerActionsContext = () => {
|
|
16
|
+
const value = React.useContext(_PickerProvider.PickerActionsContext);
|
|
17
|
+
if (value == null) {
|
|
18
|
+
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'));
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
22
|
+
exports.usePickerActionsContext = usePickerActionsContext;
|
package/node/index.js
CHANGED
|
@@ -4,12 +4,13 @@ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWild
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.PickerPrivateContext = exports.PickerContext = void 0;
|
|
7
|
+
exports.PickerPrivateContext = exports.PickerContext = exports.PickerActionsContext = void 0;
|
|
8
8
|
exports.PickerProvider = PickerProvider;
|
|
9
9
|
var React = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _LocalizationProvider = require("../../LocalizationProvider");
|
|
11
11
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
12
|
const PickerContext = exports.PickerContext = /*#__PURE__*/React.createContext(null);
|
|
13
|
+
const PickerActionsContext = exports.PickerActionsContext = /*#__PURE__*/React.createContext(null);
|
|
13
14
|
const PickerPrivateContext = exports.PickerPrivateContext = /*#__PURE__*/React.createContext({
|
|
14
15
|
ownerState: {
|
|
15
16
|
isPickerDisabled: false,
|
|
@@ -18,7 +19,8 @@ const PickerPrivateContext = exports.PickerPrivateContext = /*#__PURE__*/React.c
|
|
|
18
19
|
isPickerOpen: false,
|
|
19
20
|
pickerVariant: 'desktop',
|
|
20
21
|
pickerOrientation: 'portrait'
|
|
21
|
-
}
|
|
22
|
+
},
|
|
23
|
+
dismissViews: () => {}
|
|
22
24
|
});
|
|
23
25
|
|
|
24
26
|
/**
|
|
@@ -31,17 +33,21 @@ const PickerPrivateContext = exports.PickerPrivateContext = /*#__PURE__*/React.c
|
|
|
31
33
|
function PickerProvider(props) {
|
|
32
34
|
const {
|
|
33
35
|
contextValue,
|
|
36
|
+
actionsContextValue,
|
|
34
37
|
privateContextValue,
|
|
35
38
|
localeText,
|
|
36
39
|
children
|
|
37
40
|
} = props;
|
|
38
41
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(PickerContext.Provider, {
|
|
39
42
|
value: contextValue,
|
|
40
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
41
|
-
value:
|
|
42
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
43
|
-
|
|
44
|
-
children:
|
|
43
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(PickerActionsContext.Provider, {
|
|
44
|
+
value: actionsContextValue,
|
|
45
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(PickerPrivateContext.Provider, {
|
|
46
|
+
value: privateContextValue,
|
|
47
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_LocalizationProvider.LocalizationProvider, {
|
|
48
|
+
localeText: localeText,
|
|
49
|
+
children: children
|
|
50
|
+
})
|
|
45
51
|
})
|
|
46
52
|
})
|
|
47
53
|
});
|
|
@@ -13,6 +13,8 @@ var _Fade = _interopRequireDefault(require("@mui/material/Fade"));
|
|
|
13
13
|
var _Dialog = _interopRequireWildcard(require("@mui/material/Dialog"));
|
|
14
14
|
var _styles = require("@mui/material/styles");
|
|
15
15
|
var _dimensions = require("../constants/dimensions");
|
|
16
|
+
var _hooks = require("../../hooks");
|
|
17
|
+
var _usePickerPrivateContext = require("../hooks/usePickerPrivateContext");
|
|
16
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
19
|
const PickersModalDialogRoot = (0, _styles.styled)(_Dialog.default)({
|
|
18
20
|
[`& .${_Dialog.dialogClasses.container}`]: {
|
|
@@ -31,16 +33,20 @@ const PickersModalDialogContent = (0, _styles.styled)(_DialogContent.default)({
|
|
|
31
33
|
function PickersModalDialog(props) {
|
|
32
34
|
const {
|
|
33
35
|
children,
|
|
34
|
-
onDismiss,
|
|
35
|
-
open,
|
|
36
36
|
slots,
|
|
37
37
|
slotProps
|
|
38
38
|
} = props;
|
|
39
|
+
const {
|
|
40
|
+
open
|
|
41
|
+
} = (0, _hooks.usePickerContext)();
|
|
42
|
+
const {
|
|
43
|
+
dismissViews
|
|
44
|
+
} = (0, _usePickerPrivateContext.usePickerPrivateContext)();
|
|
39
45
|
const Dialog = slots?.dialog ?? PickersModalDialogRoot;
|
|
40
46
|
const Transition = slots?.mobileTransition ?? _Fade.default;
|
|
41
47
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Dialog, (0, _extends2.default)({
|
|
42
48
|
open: open,
|
|
43
|
-
onClose:
|
|
49
|
+
onClose: dismissViews
|
|
44
50
|
}, slotProps?.dialog, {
|
|
45
51
|
TransitionComponent: Transition,
|
|
46
52
|
TransitionProps: slotProps?.mobileTransition,
|
|
@@ -21,6 +21,7 @@ var _pickersPopperClasses = require("./pickersPopperClasses");
|
|
|
21
21
|
var _utils2 = require("../utils/utils");
|
|
22
22
|
var _useDefaultReduceAnimations = require("../hooks/useDefaultReduceAnimations");
|
|
23
23
|
var _usePickerPrivateContext = require("../hooks/usePickerPrivateContext");
|
|
24
|
+
var _hooks = require("../../hooks");
|
|
24
25
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
25
26
|
const _excluded = ["PaperComponent", "ownerState", "children", "paperSlotProps", "paperClasses", "onPaperClick", "onPaperTouchStart"];
|
|
26
27
|
const useUtilityClasses = classes => {
|
|
@@ -218,8 +219,6 @@ function PickersPopper(inProps) {
|
|
|
218
219
|
containerRef = null,
|
|
219
220
|
shouldRestoreFocus,
|
|
220
221
|
onBlur,
|
|
221
|
-
onDismiss,
|
|
222
|
-
open,
|
|
223
222
|
role,
|
|
224
223
|
placement = 'bottom',
|
|
225
224
|
slots,
|
|
@@ -227,17 +226,23 @@ function PickersPopper(inProps) {
|
|
|
227
226
|
reduceAnimations: inReduceAnimations,
|
|
228
227
|
classes: classesProp
|
|
229
228
|
} = props;
|
|
229
|
+
const {
|
|
230
|
+
open
|
|
231
|
+
} = (0, _hooks.usePickerContext)();
|
|
232
|
+
const {
|
|
233
|
+
dismissViews
|
|
234
|
+
} = (0, _usePickerPrivateContext.usePickerPrivateContext)();
|
|
230
235
|
React.useEffect(() => {
|
|
231
236
|
function handleKeyDown(nativeEvent) {
|
|
232
237
|
if (open && nativeEvent.key === 'Escape') {
|
|
233
|
-
|
|
238
|
+
dismissViews();
|
|
234
239
|
}
|
|
235
240
|
}
|
|
236
241
|
document.addEventListener('keydown', handleKeyDown);
|
|
237
242
|
return () => {
|
|
238
243
|
document.removeEventListener('keydown', handleKeyDown);
|
|
239
244
|
};
|
|
240
|
-
}, [
|
|
245
|
+
}, [dismissViews, open]);
|
|
241
246
|
const lastFocusedElementRef = React.useRef(null);
|
|
242
247
|
React.useEffect(() => {
|
|
243
248
|
if (role === 'tooltip' || shouldRestoreFocus && !shouldRestoreFocus()) {
|
|
@@ -255,7 +260,7 @@ function PickersPopper(inProps) {
|
|
|
255
260
|
});
|
|
256
261
|
}
|
|
257
262
|
}, [open, role, shouldRestoreFocus]);
|
|
258
|
-
const [clickAwayRef, onPaperClick, onPaperTouchStart] = useClickAwayListener(open, onBlur ??
|
|
263
|
+
const [clickAwayRef, onPaperClick, onPaperTouchStart] = useClickAwayListener(open, onBlur ?? dismissViews);
|
|
259
264
|
const paperRef = React.useRef(null);
|
|
260
265
|
const handleRef = (0, _utils.unstable_useForkRef)(paperRef, containerRef);
|
|
261
266
|
const handlePaperRef = (0, _utils.unstable_useForkRef)(handleRef, clickAwayRef);
|
|
@@ -272,7 +277,7 @@ function PickersPopper(inProps) {
|
|
|
272
277
|
if (event.key === 'Escape') {
|
|
273
278
|
// stop the propagation to avoid closing parent modal
|
|
274
279
|
event.stopPropagation();
|
|
275
|
-
|
|
280
|
+
dismissViews();
|
|
276
281
|
}
|
|
277
282
|
};
|
|
278
283
|
const Transition = slots?.desktopTransition ?? reduceAnimations ? _Fade.default : _Grow.default;
|
|
@@ -59,8 +59,6 @@ const useDesktopPicker = _ref => {
|
|
|
59
59
|
const labelId = (0, _useId.default)();
|
|
60
60
|
const isToolbarHidden = innerSlotProps?.toolbar?.hidden ?? false;
|
|
61
61
|
const {
|
|
62
|
-
open,
|
|
63
|
-
actions,
|
|
64
62
|
hasUIView,
|
|
65
63
|
layoutProps,
|
|
66
64
|
providerProps,
|
|
@@ -92,7 +90,11 @@ const useDesktopPicker = _ref => {
|
|
|
92
90
|
externalSlotProps: innerSlotProps?.openPickerButton,
|
|
93
91
|
additionalProps: {
|
|
94
92
|
disabled: disabled || readOnly,
|
|
95
|
-
|
|
93
|
+
// This direct access to `providerProps` will go away in https://github.com/mui/mui-x/pull/15671
|
|
94
|
+
onClick: event => {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
providerProps.contextValue.setOpen(prevOpen => !prevOpen);
|
|
97
|
+
},
|
|
96
98
|
'aria-label': getOpenDialogAriaText(pickerFieldProps.value),
|
|
97
99
|
edge: inputAdornmentProps.position
|
|
98
100
|
},
|
|
@@ -128,7 +130,7 @@ const useDesktopPicker = _ref => {
|
|
|
128
130
|
sx,
|
|
129
131
|
label,
|
|
130
132
|
name,
|
|
131
|
-
focused: open ? true : undefined
|
|
133
|
+
focused: providerProps.contextValue.open ? true : undefined
|
|
132
134
|
}, isToolbarHidden && {
|
|
133
135
|
id: labelId
|
|
134
136
|
}, !!inputRef && {
|
|
@@ -177,12 +179,10 @@ const useDesktopPicker = _ref => {
|
|
|
177
179
|
slots: slotsForField,
|
|
178
180
|
slotProps: slotProps,
|
|
179
181
|
unstableFieldRef: handleFieldRef
|
|
180
|
-
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(_PickersPopper.PickersPopper,
|
|
182
|
+
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(_PickersPopper.PickersPopper, {
|
|
181
183
|
role: "dialog",
|
|
182
184
|
placement: "bottom-start",
|
|
183
|
-
anchorEl: containerRef.current
|
|
184
|
-
}, actions, {
|
|
185
|
-
open: open,
|
|
185
|
+
anchorEl: containerRef.current,
|
|
186
186
|
slots: slots,
|
|
187
187
|
slotProps: slotProps,
|
|
188
188
|
shouldRestoreFocus: shouldRestoreFocus,
|
|
@@ -192,7 +192,7 @@ const useDesktopPicker = _ref => {
|
|
|
192
192
|
slotProps: slotProps,
|
|
193
193
|
children: renderCurrentView()
|
|
194
194
|
}))
|
|
195
|
-
})
|
|
195
|
+
})]
|
|
196
196
|
}));
|
|
197
197
|
return {
|
|
198
198
|
renderPicker
|
|
@@ -53,8 +53,6 @@ const useMobilePicker = _ref => {
|
|
|
53
53
|
const labelId = (0, _useId.default)();
|
|
54
54
|
const isToolbarHidden = innerSlotProps?.toolbar?.hidden ?? false;
|
|
55
55
|
const {
|
|
56
|
-
open,
|
|
57
|
-
actions,
|
|
58
56
|
layoutProps,
|
|
59
57
|
providerProps,
|
|
60
58
|
renderCurrentView,
|
|
@@ -93,8 +91,12 @@ const useMobilePicker = _ref => {
|
|
|
93
91
|
}, isToolbarHidden && {
|
|
94
92
|
id: labelId
|
|
95
93
|
}, !(disabled || readOnly) && {
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
// These direct access to `providerProps` will go away in https://github.com/mui/mui-x/pull/15671
|
|
95
|
+
onClick: event => {
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
providerProps.contextValue.setOpen(true);
|
|
98
|
+
},
|
|
99
|
+
onKeyDown: (0, _utils.onSpaceOrEnter)(() => providerProps.contextValue.setOpen(true))
|
|
98
100
|
}, !!inputRef && {
|
|
99
101
|
inputRef
|
|
100
102
|
}),
|
|
@@ -131,8 +133,7 @@ const useMobilePicker = _ref => {
|
|
|
131
133
|
slots: slotsForField,
|
|
132
134
|
slotProps: slotProps,
|
|
133
135
|
unstableFieldRef: handleFieldRef
|
|
134
|
-
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(_PickersModalDialog.PickersModalDialog,
|
|
135
|
-
open: open,
|
|
136
|
+
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(_PickersModalDialog.PickersModalDialog, {
|
|
136
137
|
slots: slots,
|
|
137
138
|
slotProps: slotProps,
|
|
138
139
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Layout, (0, _extends2.default)({}, layoutProps, slotProps?.layout, {
|
|
@@ -140,7 +141,7 @@ const useMobilePicker = _ref => {
|
|
|
140
141
|
slotProps: slotProps,
|
|
141
142
|
children: renderCurrentView()
|
|
142
143
|
}))
|
|
143
|
-
})
|
|
144
|
+
})]
|
|
144
145
|
}));
|
|
145
146
|
return {
|
|
146
147
|
renderPicker
|
|
@@ -52,15 +52,13 @@ const usePicker = ({
|
|
|
52
52
|
});
|
|
53
53
|
return {
|
|
54
54
|
// Picker value
|
|
55
|
-
open: pickerValueResponse.open,
|
|
56
|
-
actions: pickerValueResponse.actions,
|
|
57
55
|
fieldProps: pickerValueResponse.fieldProps,
|
|
58
56
|
// Picker views
|
|
59
57
|
renderCurrentView: pickerViewsResponse.renderCurrentView,
|
|
60
58
|
hasUIView: pickerViewsResponse.provider.hasUIView,
|
|
61
59
|
shouldRestoreFocus: pickerViewsResponse.shouldRestoreFocus,
|
|
62
60
|
// Picker layout
|
|
63
|
-
layoutProps: (0, _extends2.default)({},
|
|
61
|
+
layoutProps: (0, _extends2.default)({}, pickerValueResponse.layoutProps),
|
|
64
62
|
// Picker provider
|
|
65
63
|
providerProps,
|
|
66
64
|
// Picker owner state
|
|
@@ -63,18 +63,19 @@ function usePickerProvider(parameters) {
|
|
|
63
63
|
pickerOrientation: orientation,
|
|
64
64
|
pickerVariant: variant
|
|
65
65
|
}), [utils, valueManager, paramsFromUsePickerValue.value, paramsFromUsePickerValue.contextValue.open, orientation, variant, props.disabled, props.readOnly]);
|
|
66
|
-
const contextValue = React.useMemo(() => (0, _extends2.default)({}, paramsFromUsePickerValue.contextValue, {
|
|
66
|
+
const contextValue = React.useMemo(() => (0, _extends2.default)({}, paramsFromUsePickerValue.contextValue, paramsFromUsePickerViews.contextValue, {
|
|
67
67
|
disabled: props.disabled ?? false,
|
|
68
68
|
readOnly: props.readOnly ?? false,
|
|
69
69
|
variant,
|
|
70
70
|
orientation
|
|
71
|
-
}), [paramsFromUsePickerValue.contextValue, variant, orientation, props.disabled, props.readOnly]);
|
|
72
|
-
const privateContextValue = React.useMemo(() => ({
|
|
71
|
+
}), [paramsFromUsePickerValue.contextValue, paramsFromUsePickerViews.contextValue, variant, orientation, props.disabled, props.readOnly]);
|
|
72
|
+
const privateContextValue = React.useMemo(() => (0, _extends2.default)({}, paramsFromUsePickerValue.privateContextValue, {
|
|
73
73
|
ownerState
|
|
74
|
-
}), [ownerState]);
|
|
74
|
+
}), [paramsFromUsePickerValue, ownerState]);
|
|
75
75
|
return {
|
|
76
76
|
localeText,
|
|
77
77
|
contextValue,
|
|
78
|
+
actionsContextValue: paramsFromUsePickerValue.actionsContextValue,
|
|
78
79
|
privateContextValue
|
|
79
80
|
};
|
|
80
81
|
}
|
|
@@ -259,49 +259,6 @@ const usePickerValue = ({
|
|
|
259
259
|
hasBeenModifiedSinceMount: true
|
|
260
260
|
}));
|
|
261
261
|
}
|
|
262
|
-
const handleClear = (0, _useEventCallback.default)(() => {
|
|
263
|
-
updateDate({
|
|
264
|
-
value: valueManager.emptyValue,
|
|
265
|
-
name: 'setValueFromAction',
|
|
266
|
-
pickerAction: 'clear'
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
const handleAccept = (0, _useEventCallback.default)(() => {
|
|
270
|
-
updateDate({
|
|
271
|
-
value: dateState.lastPublishedValue,
|
|
272
|
-
name: 'setValueFromAction',
|
|
273
|
-
pickerAction: 'accept'
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
const handleDismiss = (0, _useEventCallback.default)(() => {
|
|
277
|
-
updateDate({
|
|
278
|
-
value: dateState.lastPublishedValue,
|
|
279
|
-
name: 'setValueFromAction',
|
|
280
|
-
pickerAction: 'dismiss'
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
const handleCancel = (0, _useEventCallback.default)(() => {
|
|
284
|
-
updateDate({
|
|
285
|
-
value: dateState.lastCommittedValue,
|
|
286
|
-
name: 'setValueFromAction',
|
|
287
|
-
pickerAction: 'cancel'
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
const handleSetToday = (0, _useEventCallback.default)(() => {
|
|
291
|
-
updateDate({
|
|
292
|
-
value: valueManager.getTodayValue(utils, timezone, valueType),
|
|
293
|
-
name: 'setValueFromAction',
|
|
294
|
-
pickerAction: 'today'
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
const handleOpen = (0, _useEventCallback.default)(event => {
|
|
298
|
-
event.preventDefault();
|
|
299
|
-
setOpen(true);
|
|
300
|
-
});
|
|
301
|
-
const handleClose = (0, _useEventCallback.default)(event => {
|
|
302
|
-
event?.preventDefault();
|
|
303
|
-
setOpen(false);
|
|
304
|
-
});
|
|
305
262
|
const handleChange = (0, _useEventCallback.default)((newValue, selectionState = 'partial') => updateDate({
|
|
306
263
|
name: 'setValueFromView',
|
|
307
264
|
value: newValue,
|
|
@@ -318,15 +275,6 @@ const usePickerValue = ({
|
|
|
318
275
|
value: newValue,
|
|
319
276
|
context
|
|
320
277
|
}));
|
|
321
|
-
const actions = {
|
|
322
|
-
onClear: handleClear,
|
|
323
|
-
onAccept: handleAccept,
|
|
324
|
-
onDismiss: handleDismiss,
|
|
325
|
-
onCancel: handleCancel,
|
|
326
|
-
onSetToday: handleSetToday,
|
|
327
|
-
onOpen: handleOpen,
|
|
328
|
-
onClose: handleClose
|
|
329
|
-
};
|
|
330
278
|
const fieldResponse = {
|
|
331
279
|
value: dateState.draft,
|
|
332
280
|
onChange: handleChangeFromField
|
|
@@ -335,8 +283,8 @@ const usePickerValue = ({
|
|
|
335
283
|
const viewResponse = {
|
|
336
284
|
value: valueWithoutError,
|
|
337
285
|
onChange: handleChange,
|
|
338
|
-
|
|
339
|
-
|
|
286
|
+
open,
|
|
287
|
+
setOpen
|
|
340
288
|
};
|
|
341
289
|
const isValid = testedValue => {
|
|
342
290
|
const error = validator({
|
|
@@ -347,28 +295,62 @@ const usePickerValue = ({
|
|
|
347
295
|
});
|
|
348
296
|
return !valueManager.hasError(error);
|
|
349
297
|
};
|
|
350
|
-
const layoutResponse =
|
|
298
|
+
const layoutResponse = {
|
|
351
299
|
value: valueWithoutError,
|
|
352
300
|
onChange: handleChange,
|
|
353
301
|
onSelectShortcut: handleSelectShortcut,
|
|
354
302
|
isValid
|
|
303
|
+
};
|
|
304
|
+
const clearValue = (0, _useEventCallback.default)(() => updateDate({
|
|
305
|
+
value: valueManager.emptyValue,
|
|
306
|
+
name: 'setValueFromAction',
|
|
307
|
+
pickerAction: 'clear'
|
|
308
|
+
}));
|
|
309
|
+
const setValueToToday = (0, _useEventCallback.default)(() => updateDate({
|
|
310
|
+
value: valueManager.getTodayValue(utils, timezone, valueType),
|
|
311
|
+
name: 'setValueFromAction',
|
|
312
|
+
pickerAction: 'today'
|
|
313
|
+
}));
|
|
314
|
+
const acceptValueChanges = (0, _useEventCallback.default)(() => updateDate({
|
|
315
|
+
value: dateState.lastPublishedValue,
|
|
316
|
+
name: 'setValueFromAction',
|
|
317
|
+
pickerAction: 'accept'
|
|
318
|
+
}));
|
|
319
|
+
const cancelValueChanges = (0, _useEventCallback.default)(() => updateDate({
|
|
320
|
+
value: dateState.lastCommittedValue,
|
|
321
|
+
name: 'setValueFromAction',
|
|
322
|
+
pickerAction: 'cancel'
|
|
323
|
+
}));
|
|
324
|
+
const dismissViews = (0, _useEventCallback.default)(() => {
|
|
325
|
+
updateDate({
|
|
326
|
+
value: dateState.lastPublishedValue,
|
|
327
|
+
name: 'setValueFromAction',
|
|
328
|
+
pickerAction: 'dismiss'
|
|
329
|
+
});
|
|
355
330
|
});
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
331
|
+
const actionsContextValue = React.useMemo(() => ({
|
|
332
|
+
setOpen,
|
|
333
|
+
clearValue,
|
|
334
|
+
setValueToToday,
|
|
335
|
+
acceptValueChanges,
|
|
336
|
+
cancelValueChanges
|
|
337
|
+
}), [setOpen, clearValue, setValueToToday, acceptValueChanges, cancelValueChanges]);
|
|
338
|
+
const contextValue = React.useMemo(() => (0, _extends2.default)({}, actionsContextValue, {
|
|
339
|
+
open
|
|
340
|
+
}), [actionsContextValue, open]);
|
|
341
|
+
const privateContextValue = React.useMemo(() => ({
|
|
342
|
+
dismissViews
|
|
343
|
+
}), [dismissViews]);
|
|
362
344
|
const providerParams = {
|
|
363
345
|
value: valueWithoutError,
|
|
364
|
-
contextValue
|
|
346
|
+
contextValue,
|
|
347
|
+
actionsContextValue,
|
|
348
|
+
privateContextValue
|
|
365
349
|
};
|
|
366
350
|
return {
|
|
367
|
-
open,
|
|
368
351
|
fieldProps: fieldResponse,
|
|
369
352
|
viewProps: viewResponse,
|
|
370
353
|
layoutProps: layoutResponse,
|
|
371
|
-
actions,
|
|
372
354
|
provider: providerParams
|
|
373
355
|
};
|
|
374
356
|
};
|
|
@@ -38,8 +38,9 @@ const usePickerViews = ({
|
|
|
38
38
|
}) => {
|
|
39
39
|
const {
|
|
40
40
|
onChange,
|
|
41
|
+
value,
|
|
41
42
|
open,
|
|
42
|
-
|
|
43
|
+
setOpen
|
|
43
44
|
} = propsFromPickerValue;
|
|
44
45
|
const {
|
|
45
46
|
view: inView,
|
|
@@ -99,7 +100,7 @@ const usePickerViews = ({
|
|
|
99
100
|
(0, _useEnhancedEffect.default)(() => {
|
|
100
101
|
// Handle case of `DateTimePicker` without time renderers
|
|
101
102
|
if (currentViewMode === 'field' && open) {
|
|
102
|
-
|
|
103
|
+
setOpen(false);
|
|
103
104
|
setTimeout(() => {
|
|
104
105
|
fieldRef?.current?.setSelectedSections(view);
|
|
105
106
|
// focusing the input before the range selection is done
|
|
@@ -130,18 +131,18 @@ const usePickerViews = ({
|
|
|
130
131
|
setFocusedView(newView, true);
|
|
131
132
|
}, [open]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
132
133
|
|
|
133
|
-
const
|
|
134
|
+
const contextValue = React.useMemo(() => ({
|
|
134
135
|
views,
|
|
135
136
|
view: popperView,
|
|
136
137
|
onViewChange: setView
|
|
137
|
-
};
|
|
138
|
+
}), [views, popperView, setView]);
|
|
138
139
|
const providerParams = {
|
|
139
140
|
hasUIView,
|
|
140
|
-
views
|
|
141
|
+
views,
|
|
142
|
+
contextValue
|
|
141
143
|
};
|
|
142
144
|
return {
|
|
143
145
|
shouldRestoreFocus,
|
|
144
|
-
layoutProps,
|
|
145
146
|
provider: providerParams,
|
|
146
147
|
renderCurrentView: () => {
|
|
147
148
|
if (popperView == null) {
|
|
@@ -151,9 +152,10 @@ const usePickerViews = ({
|
|
|
151
152
|
if (renderer == null) {
|
|
152
153
|
return null;
|
|
153
154
|
}
|
|
154
|
-
const rendererProps = (0, _extends2.default)({}, propsToForwardToView, additionalViewProps,
|
|
155
|
+
const rendererProps = (0, _extends2.default)({}, propsToForwardToView, additionalViewProps, {
|
|
155
156
|
views,
|
|
156
157
|
timezone,
|
|
158
|
+
value,
|
|
157
159
|
onChange: setValueAndGoToNextView,
|
|
158
160
|
view: popperView,
|
|
159
161
|
onViewChange: setView,
|