@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
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { SxProps } from '@mui/system';
|
|
3
3
|
import { Theme } from '@mui/material/styles';
|
|
4
|
-
import { DateOrTimeViewWithMeridiem } from '../common';
|
|
5
4
|
import { PickerValidValue } from '../value';
|
|
6
|
-
export interface BaseToolbarProps<TValue extends PickerValidValue
|
|
5
|
+
export interface BaseToolbarProps<TValue extends PickerValidValue> extends ExportedBaseToolbarProps {
|
|
7
6
|
isLandscape: boolean;
|
|
8
7
|
onChange: (newValue: TValue) => void;
|
|
9
8
|
value: TValue;
|
|
10
|
-
/**
|
|
11
|
-
* Currently visible picker view.
|
|
12
|
-
*/
|
|
13
|
-
view: TView;
|
|
14
|
-
/**
|
|
15
|
-
* Callback called when a toolbar is clicked
|
|
16
|
-
* @template TView
|
|
17
|
-
* @param {TView} view The view to open
|
|
18
|
-
*/
|
|
19
|
-
onViewChange: (view: TView) => void;
|
|
20
|
-
/**
|
|
21
|
-
* Available views.
|
|
22
|
-
*/
|
|
23
|
-
views: readonly TView[];
|
|
24
9
|
titleId?: string;
|
|
25
10
|
}
|
|
26
11
|
export interface ExportedBaseToolbarProps {
|
|
@@ -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 = ["value", "isLandscape", "onChange", "toolbarFormat", "toolbarPlaceholder", "
|
|
5
|
+
const _excluded = ["value", "isLandscape", "onChange", "toolbarFormat", "toolbarPlaceholder", "className", "classes"];
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import clsx from 'clsx';
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
@@ -15,6 +15,7 @@ import { useUtils } from "../internals/hooks/useUtils.js";
|
|
|
15
15
|
import { getDatePickerToolbarUtilityClass } from "./datePickerToolbarClasses.js";
|
|
16
16
|
import { resolveDateFormat } from "../internals/utils/date-utils.js";
|
|
17
17
|
import { useToolbarOwnerState } from "../internals/hooks/useToolbarOwnerState.js";
|
|
18
|
+
import { usePickerContext } from "../hooks/index.js";
|
|
18
19
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
20
|
const useUtilityClasses = classes => {
|
|
20
21
|
const slots = {
|
|
@@ -62,12 +63,14 @@ export const DatePickerToolbar = /*#__PURE__*/React.forwardRef(function DatePick
|
|
|
62
63
|
isLandscape,
|
|
63
64
|
toolbarFormat,
|
|
64
65
|
toolbarPlaceholder = '––',
|
|
65
|
-
views,
|
|
66
66
|
className,
|
|
67
67
|
classes: classesProp
|
|
68
68
|
} = props,
|
|
69
69
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
70
70
|
const utils = useUtils();
|
|
71
|
+
const {
|
|
72
|
+
views
|
|
73
|
+
} = usePickerContext();
|
|
71
74
|
const translations = usePickerTranslations();
|
|
72
75
|
const ownerState = useToolbarOwnerState();
|
|
73
76
|
const classes = useUtilityClasses(classesProp);
|
|
@@ -113,12 +116,6 @@ process.env.NODE_ENV !== "production" ? DatePickerToolbar.propTypes = {
|
|
|
113
116
|
hidden: PropTypes.bool,
|
|
114
117
|
isLandscape: PropTypes.bool.isRequired,
|
|
115
118
|
onChange: PropTypes.func.isRequired,
|
|
116
|
-
/**
|
|
117
|
-
* Callback called when a toolbar is clicked
|
|
118
|
-
* @template TView
|
|
119
|
-
* @param {TView} view The view to open
|
|
120
|
-
*/
|
|
121
|
-
onViewChange: PropTypes.func.isRequired,
|
|
122
119
|
/**
|
|
123
120
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
124
121
|
*/
|
|
@@ -133,13 +130,5 @@ process.env.NODE_ENV !== "production" ? DatePickerToolbar.propTypes = {
|
|
|
133
130
|
* @default "––"
|
|
134
131
|
*/
|
|
135
132
|
toolbarPlaceholder: PropTypes.node,
|
|
136
|
-
value: PropTypes.object
|
|
137
|
-
/**
|
|
138
|
-
* Currently visible picker view.
|
|
139
|
-
*/
|
|
140
|
-
view: PropTypes.oneOf(['day', 'month', 'year']).isRequired,
|
|
141
|
-
/**
|
|
142
|
-
* Available views.
|
|
143
|
-
*/
|
|
144
|
-
views: PropTypes.arrayOf(PropTypes.oneOf(['day', 'month', 'year']).isRequired).isRequired
|
|
133
|
+
value: PropTypes.object
|
|
145
134
|
} : void 0;
|
|
@@ -12,6 +12,7 @@ import { usePickerTranslations } from "../hooks/usePickerTranslations.js";
|
|
|
12
12
|
import { getDateTimePickerTabsUtilityClass } from "./dateTimePickerTabsClasses.js";
|
|
13
13
|
import { isDatePickerView } from "../internals/utils/date-utils.js";
|
|
14
14
|
import { usePickerPrivateContext } from "../internals/hooks/usePickerPrivateContext.js";
|
|
15
|
+
import { usePickerContext } from "../hooks/index.js";
|
|
15
16
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
17
|
const viewToTab = view => {
|
|
17
18
|
if (isDatePickerView(view)) {
|
|
@@ -65,9 +66,7 @@ const DateTimePickerTabs = function DateTimePickerTabs(inProps) {
|
|
|
65
66
|
});
|
|
66
67
|
const {
|
|
67
68
|
dateIcon = /*#__PURE__*/_jsx(DateRangeIcon, {}),
|
|
68
|
-
onViewChange,
|
|
69
69
|
timeIcon = /*#__PURE__*/_jsx(TimeIcon, {}),
|
|
70
|
-
view,
|
|
71
70
|
hidden = typeof window === 'undefined' || window.innerHeight < 667,
|
|
72
71
|
className,
|
|
73
72
|
classes: classesProp,
|
|
@@ -77,6 +76,10 @@ const DateTimePickerTabs = function DateTimePickerTabs(inProps) {
|
|
|
77
76
|
const {
|
|
78
77
|
ownerState
|
|
79
78
|
} = usePickerPrivateContext();
|
|
79
|
+
const {
|
|
80
|
+
view,
|
|
81
|
+
onViewChange
|
|
82
|
+
} = usePickerContext();
|
|
80
83
|
const classes = useUtilityClasses(classesProp);
|
|
81
84
|
const handleChange = (event, value) => {
|
|
82
85
|
onViewChange(tabToView(value));
|
|
@@ -126,12 +129,6 @@ process.env.NODE_ENV !== "production" ? DateTimePickerTabs.propTypes = {
|
|
|
126
129
|
* @default `window.innerHeight < 667` for `DesktopDateTimePicker` and `MobileDateTimePicker`, `displayStaticWrapperAs === 'desktop'` for `StaticDateTimePicker`
|
|
127
130
|
*/
|
|
128
131
|
hidden: PropTypes.bool,
|
|
129
|
-
/**
|
|
130
|
-
* Callback called when a tab is clicked.
|
|
131
|
-
* @template TView
|
|
132
|
-
* @param {TView} view The view to open
|
|
133
|
-
*/
|
|
134
|
-
onViewChange: PropTypes.func.isRequired,
|
|
135
132
|
/**
|
|
136
133
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
137
134
|
*/
|
|
@@ -140,10 +137,6 @@ process.env.NODE_ENV !== "production" ? DateTimePickerTabs.propTypes = {
|
|
|
140
137
|
* Time tab icon.
|
|
141
138
|
* @default Time
|
|
142
139
|
*/
|
|
143
|
-
timeIcon: PropTypes.node
|
|
144
|
-
/**
|
|
145
|
-
* Currently visible picker view.
|
|
146
|
-
*/
|
|
147
|
-
view: PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']).isRequired
|
|
140
|
+
timeIcon: PropTypes.node
|
|
148
141
|
} : void 0;
|
|
149
142
|
export { DateTimePickerTabs };
|
|
@@ -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", "value", "onChange", "
|
|
5
|
+
const _excluded = ["ampm", "ampmInClock", "value", "onChange", "isLandscape", "toolbarFormat", "toolbarPlaceholder", "toolbarTitle", "className", "classes"];
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import clsx from 'clsx';
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
@@ -206,10 +206,11 @@ const DateTimePickerToolbarAmPmSelection = styled('div', {
|
|
|
206
206
|
});
|
|
207
207
|
|
|
208
208
|
/**
|
|
209
|
-
* If
|
|
209
|
+
* If `forceDesktopVariant` is set to `true`, the toolbar will always be rendered in the desktop mode.
|
|
210
|
+
* If `onViewChange` is defined, the toolbar will call it instead of calling the default handler from `usePickerContext`.
|
|
210
211
|
* This is used by the Date Time Range Picker Toolbar.
|
|
211
212
|
*/
|
|
212
|
-
export const
|
|
213
|
+
export const DateTimePickerToolbarOverrideContext = /*#__PURE__*/React.createContext(null);
|
|
213
214
|
|
|
214
215
|
/**
|
|
215
216
|
* Demos:
|
|
@@ -231,12 +232,9 @@ function DateTimePickerToolbar(inProps) {
|
|
|
231
232
|
ampmInClock,
|
|
232
233
|
value,
|
|
233
234
|
onChange,
|
|
234
|
-
view,
|
|
235
235
|
isLandscape,
|
|
236
|
-
onViewChange,
|
|
237
236
|
toolbarFormat,
|
|
238
237
|
toolbarPlaceholder = '––',
|
|
239
|
-
views,
|
|
240
238
|
toolbarTitle: inToolbarTitle,
|
|
241
239
|
className,
|
|
242
240
|
classes: classesProp
|
|
@@ -245,7 +243,10 @@ function DateTimePickerToolbar(inProps) {
|
|
|
245
243
|
const {
|
|
246
244
|
disabled,
|
|
247
245
|
readOnly,
|
|
248
|
-
variant
|
|
246
|
+
variant,
|
|
247
|
+
view: viewCtx,
|
|
248
|
+
onViewChange: onViewChangeCtx,
|
|
249
|
+
views
|
|
249
250
|
} = usePickerContext();
|
|
250
251
|
const ownerState = useToolbarOwnerState();
|
|
251
252
|
const classes = useUtilityClasses(classesProp, ownerState);
|
|
@@ -255,11 +256,13 @@ function DateTimePickerToolbar(inProps) {
|
|
|
255
256
|
handleMeridiemChange
|
|
256
257
|
} = useMeridiemMode(value, ampm, onChange);
|
|
257
258
|
const translations = usePickerTranslations();
|
|
258
|
-
const
|
|
259
|
-
const toolbarVariant = forceDesktopVariant ? 'desktop' : variant;
|
|
259
|
+
const overrides = React.useContext(DateTimePickerToolbarOverrideContext);
|
|
260
|
+
const toolbarVariant = overrides?.forceDesktopVariant ? 'desktop' : variant;
|
|
260
261
|
const isDesktop = toolbarVariant === 'desktop';
|
|
261
262
|
const showAmPmControl = Boolean(ampm && !ampmInClock);
|
|
262
263
|
const toolbarTitle = inToolbarTitle ?? translations.dateTimePickerToolbarTitle;
|
|
264
|
+
const view = overrides ? overrides.view : viewCtx;
|
|
265
|
+
const onViewChange = overrides ? overrides.onViewChange : onViewChangeCtx;
|
|
263
266
|
const formatHours = time => ampm ? utils.format(time, 'hours12h') : utils.format(time, 'hours24h');
|
|
264
267
|
const dateText = React.useMemo(() => {
|
|
265
268
|
if (!value) {
|
|
@@ -384,12 +387,6 @@ process.env.NODE_ENV !== "production" ? DateTimePickerToolbar.propTypes = {
|
|
|
384
387
|
hidden: PropTypes.bool,
|
|
385
388
|
isLandscape: PropTypes.bool.isRequired,
|
|
386
389
|
onChange: PropTypes.func.isRequired,
|
|
387
|
-
/**
|
|
388
|
-
* Callback called when a toolbar is clicked
|
|
389
|
-
* @template TView
|
|
390
|
-
* @param {TView} view The view to open
|
|
391
|
-
*/
|
|
392
|
-
onViewChange: PropTypes.func.isRequired,
|
|
393
390
|
/**
|
|
394
391
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
395
392
|
*/
|
|
@@ -408,14 +405,6 @@ process.env.NODE_ENV !== "production" ? DateTimePickerToolbar.propTypes = {
|
|
|
408
405
|
* If provided, it will be used instead of `dateTimePickerToolbarTitle` from localization.
|
|
409
406
|
*/
|
|
410
407
|
toolbarTitle: PropTypes.node,
|
|
411
|
-
value: PropTypes.object
|
|
412
|
-
/**
|
|
413
|
-
* Currently visible picker view.
|
|
414
|
-
*/
|
|
415
|
-
view: PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']),
|
|
416
|
-
/**
|
|
417
|
-
* Available views.
|
|
418
|
-
*/
|
|
419
|
-
views: PropTypes.arrayOf(PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']).isRequired).isRequired
|
|
408
|
+
value: PropTypes.object
|
|
420
409
|
} : void 0;
|
|
421
410
|
export { DateTimePickerToolbar };
|
|
@@ -66,16 +66,8 @@ process.env.NODE_ENV !== "production" ? DesktopDateTimePickerLayout.propTypes =
|
|
|
66
66
|
classes: PropTypes.object,
|
|
67
67
|
className: PropTypes.string,
|
|
68
68
|
isValid: PropTypes.func.isRequired,
|
|
69
|
-
onAccept: PropTypes.func.isRequired,
|
|
70
|
-
onCancel: PropTypes.func.isRequired,
|
|
71
69
|
onChange: PropTypes.func.isRequired,
|
|
72
|
-
onClear: PropTypes.func.isRequired,
|
|
73
|
-
onClose: PropTypes.func.isRequired,
|
|
74
|
-
onDismiss: PropTypes.func.isRequired,
|
|
75
|
-
onOpen: PropTypes.func.isRequired,
|
|
76
70
|
onSelectShortcut: PropTypes.func.isRequired,
|
|
77
|
-
onSetToday: PropTypes.func.isRequired,
|
|
78
|
-
onViewChange: PropTypes.func.isRequired,
|
|
79
71
|
/**
|
|
80
72
|
* The props used for each component slot.
|
|
81
73
|
* @default {}
|
|
@@ -90,8 +82,6 @@ process.env.NODE_ENV !== "production" ? DesktopDateTimePickerLayout.propTypes =
|
|
|
90
82
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
91
83
|
*/
|
|
92
84
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
93
|
-
value: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object])
|
|
94
|
-
view: PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']),
|
|
95
|
-
views: PropTypes.arrayOf(PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']).isRequired).isRequired
|
|
85
|
+
value: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object])
|
|
96
86
|
} : void 0;
|
|
97
87
|
export { DesktopDateTimePickerLayout };
|
|
@@ -2,13 +2,14 @@
|
|
|
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 = ["
|
|
5
|
+
const _excluded = ["actions"];
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import { styled } from '@mui/material/styles';
|
|
9
9
|
import Button from '@mui/material/Button';
|
|
10
10
|
import DialogActions from '@mui/material/DialogActions';
|
|
11
11
|
import { usePickerTranslations } from "../hooks/usePickerTranslations.js";
|
|
12
|
+
import { usePickerActionsContext } from "../hooks/index.js";
|
|
12
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
14
|
const PickersActionBarRoot = styled(DialogActions, {
|
|
14
15
|
name: 'MuiPickersLayout',
|
|
@@ -28,14 +29,16 @@ const PickersActionBarRoot = styled(DialogActions, {
|
|
|
28
29
|
*/
|
|
29
30
|
function PickersActionBar(props) {
|
|
30
31
|
const {
|
|
31
|
-
onAccept,
|
|
32
|
-
onClear,
|
|
33
|
-
onCancel,
|
|
34
|
-
onSetToday,
|
|
35
32
|
actions
|
|
36
33
|
} = props,
|
|
37
34
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
38
35
|
const translations = usePickerTranslations();
|
|
36
|
+
const {
|
|
37
|
+
clearValue,
|
|
38
|
+
setValueToToday,
|
|
39
|
+
acceptValueChanges,
|
|
40
|
+
cancelValueChanges
|
|
41
|
+
} = usePickerActionsContext();
|
|
39
42
|
if (actions == null || actions.length === 0) {
|
|
40
43
|
return null;
|
|
41
44
|
}
|
|
@@ -43,22 +46,22 @@ function PickersActionBar(props) {
|
|
|
43
46
|
switch (actionType) {
|
|
44
47
|
case 'clear':
|
|
45
48
|
return /*#__PURE__*/_jsx(Button, {
|
|
46
|
-
onClick:
|
|
49
|
+
onClick: clearValue,
|
|
47
50
|
children: translations.clearButtonLabel
|
|
48
51
|
}, actionType);
|
|
49
52
|
case 'cancel':
|
|
50
53
|
return /*#__PURE__*/_jsx(Button, {
|
|
51
|
-
onClick:
|
|
54
|
+
onClick: cancelValueChanges,
|
|
52
55
|
children: translations.cancelButtonLabel
|
|
53
56
|
}, actionType);
|
|
54
57
|
case 'accept':
|
|
55
58
|
return /*#__PURE__*/_jsx(Button, {
|
|
56
|
-
onClick:
|
|
59
|
+
onClick: acceptValueChanges,
|
|
57
60
|
children: translations.okButtonLabel
|
|
58
61
|
}, actionType);
|
|
59
62
|
case 'today':
|
|
60
63
|
return /*#__PURE__*/_jsx(Button, {
|
|
61
|
-
onClick:
|
|
64
|
+
onClick: setValueToToday,
|
|
62
65
|
children: translations.todayButtonLabel
|
|
63
66
|
}, actionType);
|
|
64
67
|
default:
|
|
@@ -85,10 +88,6 @@ process.env.NODE_ENV !== "production" ? PickersActionBar.propTypes = {
|
|
|
85
88
|
* @default false
|
|
86
89
|
*/
|
|
87
90
|
disableSpacing: PropTypes.bool,
|
|
88
|
-
onAccept: PropTypes.func.isRequired,
|
|
89
|
-
onCancel: PropTypes.func.isRequired,
|
|
90
|
-
onClear: PropTypes.func.isRequired,
|
|
91
|
-
onSetToday: PropTypes.func.isRequired,
|
|
92
91
|
/**
|
|
93
92
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
94
93
|
*/
|
|
@@ -151,16 +151,8 @@ process.env.NODE_ENV !== "production" ? PickersLayout.propTypes = {
|
|
|
151
151
|
classes: PropTypes.object,
|
|
152
152
|
className: PropTypes.string,
|
|
153
153
|
isValid: PropTypes.func.isRequired,
|
|
154
|
-
onAccept: PropTypes.func.isRequired,
|
|
155
|
-
onCancel: PropTypes.func.isRequired,
|
|
156
154
|
onChange: PropTypes.func.isRequired,
|
|
157
|
-
onClear: PropTypes.func.isRequired,
|
|
158
|
-
onClose: PropTypes.func.isRequired,
|
|
159
|
-
onDismiss: PropTypes.func.isRequired,
|
|
160
|
-
onOpen: PropTypes.func.isRequired,
|
|
161
155
|
onSelectShortcut: PropTypes.func.isRequired,
|
|
162
|
-
onSetToday: PropTypes.func.isRequired,
|
|
163
|
-
onViewChange: PropTypes.func.isRequired,
|
|
164
156
|
/**
|
|
165
157
|
* The props used for each component slot.
|
|
166
158
|
* @default {}
|
|
@@ -175,8 +167,6 @@ process.env.NODE_ENV !== "production" ? PickersLayout.propTypes = {
|
|
|
175
167
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
176
168
|
*/
|
|
177
169
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
178
|
-
value: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object])
|
|
179
|
-
view: PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']),
|
|
180
|
-
views: PropTypes.arrayOf(PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']).isRequired).isRequired
|
|
170
|
+
value: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object])
|
|
181
171
|
} : void 0;
|
|
182
172
|
export { PickersLayout };
|
|
@@ -35,17 +35,11 @@ const usePickerLayout = props => {
|
|
|
35
35
|
} = usePickerPrivateContext();
|
|
36
36
|
const {
|
|
37
37
|
variant,
|
|
38
|
-
orientation
|
|
38
|
+
orientation,
|
|
39
|
+
view
|
|
39
40
|
} = usePickerContext();
|
|
40
41
|
const isRtl = useRtl();
|
|
41
42
|
const {
|
|
42
|
-
onAccept,
|
|
43
|
-
onClear,
|
|
44
|
-
onCancel,
|
|
45
|
-
onSetToday,
|
|
46
|
-
view,
|
|
47
|
-
views,
|
|
48
|
-
onViewChange,
|
|
49
43
|
value,
|
|
50
44
|
onChange,
|
|
51
45
|
onSelectShortcut,
|
|
@@ -70,10 +64,6 @@ const usePickerLayout = props => {
|
|
|
70
64
|
elementType: ActionBar,
|
|
71
65
|
externalSlotProps: slotProps?.actionBar,
|
|
72
66
|
additionalProps: {
|
|
73
|
-
onAccept,
|
|
74
|
-
onClear,
|
|
75
|
-
onCancel,
|
|
76
|
-
onSetToday,
|
|
77
67
|
actions: variant === 'desktop' ? [] : ['cancel', 'accept']
|
|
78
68
|
},
|
|
79
69
|
className: classes.actionBar,
|
|
@@ -90,10 +80,7 @@ const usePickerLayout = props => {
|
|
|
90
80
|
isLandscape: orientation === 'landscape',
|
|
91
81
|
// Will be removed in a follow up PR?
|
|
92
82
|
onChange,
|
|
93
|
-
value
|
|
94
|
-
view,
|
|
95
|
-
onViewChange,
|
|
96
|
-
views
|
|
83
|
+
value
|
|
97
84
|
},
|
|
98
85
|
className: classes.toolbar,
|
|
99
86
|
ownerState
|
|
@@ -106,8 +93,6 @@ const usePickerLayout = props => {
|
|
|
106
93
|
// Tabs
|
|
107
94
|
const Tabs = slots?.tabs;
|
|
108
95
|
const tabs = view && Tabs ? /*#__PURE__*/_jsx(Tabs, _extends({
|
|
109
|
-
view: view,
|
|
110
|
-
onViewChange: onViewChange,
|
|
111
96
|
className: classes.tabs
|
|
112
97
|
}, slotProps?.tabs)) : null;
|
|
113
98
|
|
|
@@ -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", "value", "isLandscape", "onChange", "
|
|
5
|
+
const _excluded = ["ampm", "ampmInClock", "value", "isLandscape", "onChange", "className", "classes"];
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import clsx from 'clsx';
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
@@ -125,9 +125,6 @@ function TimePickerToolbar(inProps) {
|
|
|
125
125
|
value,
|
|
126
126
|
isLandscape,
|
|
127
127
|
onChange,
|
|
128
|
-
view,
|
|
129
|
-
onViewChange,
|
|
130
|
-
views,
|
|
131
128
|
className,
|
|
132
129
|
classes: classesProp
|
|
133
130
|
} = props,
|
|
@@ -138,7 +135,10 @@ function TimePickerToolbar(inProps) {
|
|
|
138
135
|
const classes = useUtilityClasses(classesProp, ownerState);
|
|
139
136
|
const {
|
|
140
137
|
disabled,
|
|
141
|
-
readOnly
|
|
138
|
+
readOnly,
|
|
139
|
+
view,
|
|
140
|
+
onViewChange,
|
|
141
|
+
views
|
|
142
142
|
} = usePickerContext();
|
|
143
143
|
const showAmPmControl = Boolean(ampm && !ampmInClock && views.includes('hours'));
|
|
144
144
|
const {
|
|
@@ -223,12 +223,6 @@ process.env.NODE_ENV !== "production" ? TimePickerToolbar.propTypes = {
|
|
|
223
223
|
hidden: PropTypes.bool,
|
|
224
224
|
isLandscape: PropTypes.bool.isRequired,
|
|
225
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
226
|
/**
|
|
233
227
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
234
228
|
*/
|
|
@@ -243,14 +237,6 @@ process.env.NODE_ENV !== "production" ? TimePickerToolbar.propTypes = {
|
|
|
243
237
|
* @default "––"
|
|
244
238
|
*/
|
|
245
239
|
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
|
|
240
|
+
value: PropTypes.object
|
|
255
241
|
} : void 0;
|
|
256
242
|
export { TimePickerToolbar };
|
package/modern/hooks/index.js
CHANGED
|
@@ -2,4 +2,5 @@ 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";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { PickerActionsContext } from "../internals/components/PickerProvider.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns a subset of the context passed by the picker wrapping the current component.
|
|
8
|
+
* It only contains the actions and never causes a re-render of the component using it.
|
|
9
|
+
*/
|
|
10
|
+
export const usePickerActionsContext = () => {
|
|
11
|
+
const value = React.useContext(PickerActionsContext);
|
|
12
|
+
if (value == null) {
|
|
13
|
+
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'));
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
};
|
package/modern/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { LocalizationProvider } from "../../LocalizationProvider/index.js";
|
|
3
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
4
|
export const PickerContext = /*#__PURE__*/React.createContext(null);
|
|
5
|
+
export const PickerActionsContext = /*#__PURE__*/React.createContext(null);
|
|
5
6
|
export const PickerPrivateContext = /*#__PURE__*/React.createContext({
|
|
6
7
|
ownerState: {
|
|
7
8
|
isPickerDisabled: false,
|
|
@@ -10,7 +11,8 @@ export const PickerPrivateContext = /*#__PURE__*/React.createContext({
|
|
|
10
11
|
isPickerOpen: false,
|
|
11
12
|
pickerVariant: 'desktop',
|
|
12
13
|
pickerOrientation: 'portrait'
|
|
13
|
-
}
|
|
14
|
+
},
|
|
15
|
+
dismissViews: () => {}
|
|
14
16
|
});
|
|
15
17
|
|
|
16
18
|
/**
|
|
@@ -23,17 +25,21 @@ export const PickerPrivateContext = /*#__PURE__*/React.createContext({
|
|
|
23
25
|
export function PickerProvider(props) {
|
|
24
26
|
const {
|
|
25
27
|
contextValue,
|
|
28
|
+
actionsContextValue,
|
|
26
29
|
privateContextValue,
|
|
27
30
|
localeText,
|
|
28
31
|
children
|
|
29
32
|
} = props;
|
|
30
33
|
return /*#__PURE__*/_jsx(PickerContext.Provider, {
|
|
31
34
|
value: contextValue,
|
|
32
|
-
children: /*#__PURE__*/_jsx(
|
|
33
|
-
value:
|
|
34
|
-
children: /*#__PURE__*/_jsx(
|
|
35
|
-
|
|
36
|
-
children:
|
|
35
|
+
children: /*#__PURE__*/_jsx(PickerActionsContext.Provider, {
|
|
36
|
+
value: actionsContextValue,
|
|
37
|
+
children: /*#__PURE__*/_jsx(PickerPrivateContext.Provider, {
|
|
38
|
+
value: privateContextValue,
|
|
39
|
+
children: /*#__PURE__*/_jsx(LocalizationProvider, {
|
|
40
|
+
localeText: localeText,
|
|
41
|
+
children: children
|
|
42
|
+
})
|
|
37
43
|
})
|
|
38
44
|
})
|
|
39
45
|
});
|
|
@@ -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;
|