@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
|
@@ -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 };
|
|
@@ -3,16 +3,14 @@ import { SxProps, Theme } from '@mui/material/styles';
|
|
|
3
3
|
import { SlotComponentProps } from '@mui/utils';
|
|
4
4
|
import { PickersActionBar, PickersActionBarProps } from '../PickersActionBar';
|
|
5
5
|
import { BaseToolbarProps, ExportedBaseToolbarProps } from '../internals/models/props/toolbar';
|
|
6
|
-
import {
|
|
6
|
+
import { ExportedBaseTabsProps } from '../internals/models/props/tabs';
|
|
7
7
|
import { PickersLayoutClasses } from './pickersLayoutClasses';
|
|
8
|
-
import { DateOrTimeViewWithMeridiem } from '../internals/models/common';
|
|
9
8
|
import { PickersShortcutsProps } from '../PickersShortcuts';
|
|
10
9
|
import { ExportedPickersShortcutProps, PickersShortcuts } from '../PickersShortcuts/PickersShortcuts';
|
|
11
10
|
import { PickerOwnerState } from '../models';
|
|
12
11
|
import { PickerValidValue } from '../internals/models';
|
|
13
|
-
import { UsePickerViewsLayoutResponse } from '../internals/hooks/usePicker/usePickerViews';
|
|
14
12
|
import { UsePickerValueLayoutResponse } from '../internals/hooks/usePicker/usePickerValue.types';
|
|
15
|
-
export interface ExportedPickersLayoutSlots<TValue extends PickerValidValue
|
|
13
|
+
export interface ExportedPickersLayoutSlots<TValue extends PickerValidValue> {
|
|
16
14
|
/**
|
|
17
15
|
* Custom component for the action bar, it is placed below the picker views.
|
|
18
16
|
* @default PickersActionBar
|
|
@@ -27,7 +25,7 @@ export interface ExportedPickersLayoutSlots<TValue extends PickerValidValue, TVi
|
|
|
27
25
|
* Custom component for wrapping the layout.
|
|
28
26
|
* It wraps the toolbar, views, action bar, and shortcuts.
|
|
29
27
|
*/
|
|
30
|
-
layout?: React.JSXElementConstructor<PickersLayoutProps<TValue
|
|
28
|
+
layout?: React.JSXElementConstructor<PickersLayoutProps<TValue> & React.RefAttributes<HTMLDivElement>>;
|
|
31
29
|
}
|
|
32
30
|
export interface PickerLayoutOwnerState extends PickerOwnerState {
|
|
33
31
|
/**
|
|
@@ -37,7 +35,7 @@ export interface PickerLayoutOwnerState extends PickerOwnerState {
|
|
|
37
35
|
*/
|
|
38
36
|
layoutDirection: 'ltr' | 'rtl';
|
|
39
37
|
}
|
|
40
|
-
export interface ExportedPickersLayoutSlotProps<TValue extends PickerValidValue
|
|
38
|
+
export interface ExportedPickersLayoutSlotProps<TValue extends PickerValidValue> {
|
|
41
39
|
/**
|
|
42
40
|
* Props passed down to the action bar component.
|
|
43
41
|
*/
|
|
@@ -49,20 +47,20 @@ export interface ExportedPickersLayoutSlotProps<TValue extends PickerValidValue,
|
|
|
49
47
|
/**
|
|
50
48
|
* Props passed down to the layoutRoot component.
|
|
51
49
|
*/
|
|
52
|
-
layout?: Partial<PickersLayoutProps<TValue
|
|
50
|
+
layout?: Partial<PickersLayoutProps<TValue>>;
|
|
53
51
|
}
|
|
54
|
-
export interface PickersLayoutSlots<TValue extends PickerValidValue
|
|
52
|
+
export interface PickersLayoutSlots<TValue extends PickerValidValue> extends ExportedPickersLayoutSlots<TValue> {
|
|
55
53
|
/**
|
|
56
54
|
* Tabs enabling toggling between views.
|
|
57
55
|
*/
|
|
58
|
-
tabs?: React.ElementType<
|
|
56
|
+
tabs?: React.ElementType<{}>;
|
|
59
57
|
/**
|
|
60
58
|
* Custom component for the toolbar.
|
|
61
59
|
* It is placed above the picker views.
|
|
62
60
|
*/
|
|
63
|
-
toolbar?: React.JSXElementConstructor<BaseToolbarProps<TValue
|
|
61
|
+
toolbar?: React.JSXElementConstructor<BaseToolbarProps<TValue>>;
|
|
64
62
|
}
|
|
65
|
-
export interface PickersLayoutSlotProps<TValue extends PickerValidValue
|
|
63
|
+
export interface PickersLayoutSlotProps<TValue extends PickerValidValue> extends ExportedPickersLayoutSlotProps<TValue> {
|
|
66
64
|
/**
|
|
67
65
|
* Props passed down to the tabs component.
|
|
68
66
|
*/
|
|
@@ -72,7 +70,7 @@ export interface PickersLayoutSlotProps<TValue extends PickerValidValue, TView e
|
|
|
72
70
|
*/
|
|
73
71
|
toolbar?: ExportedBaseToolbarProps;
|
|
74
72
|
}
|
|
75
|
-
export interface PickersLayoutProps<TValue extends PickerValidValue
|
|
73
|
+
export interface PickersLayoutProps<TValue extends PickerValidValue> extends UsePickerValueLayoutResponse<TValue> {
|
|
76
74
|
className?: string;
|
|
77
75
|
children?: React.ReactNode;
|
|
78
76
|
/**
|
|
@@ -87,12 +85,12 @@ export interface PickersLayoutProps<TValue extends PickerValidValue, TView exten
|
|
|
87
85
|
* Overridable component slots.
|
|
88
86
|
* @default {}
|
|
89
87
|
*/
|
|
90
|
-
slots?: PickersLayoutSlots<TValue
|
|
88
|
+
slots?: PickersLayoutSlots<TValue>;
|
|
91
89
|
/**
|
|
92
90
|
* The props used for each component slot.
|
|
93
91
|
* @default {}
|
|
94
92
|
*/
|
|
95
|
-
slotProps?: PickersLayoutSlotProps<TValue
|
|
93
|
+
slotProps?: PickersLayoutSlotProps<TValue>;
|
|
96
94
|
}
|
|
97
95
|
export interface SubComponents<TValue extends PickerValidValue> {
|
|
98
96
|
toolbar: React.ReactElement<ExportedBaseToolbarProps> | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PickerLayoutOwnerState, PickersLayoutProps, SubComponents } from './PickersLayout.types';
|
|
2
|
-
import {
|
|
2
|
+
import { PickerValidValue } from '../internals/models';
|
|
3
3
|
interface UsePickerLayoutResponse<TValue extends PickerValidValue> extends SubComponents<TValue> {
|
|
4
4
|
ownerState: PickerLayoutOwnerState;
|
|
5
5
|
}
|
|
6
|
-
declare const usePickerLayout: <TValue extends PickerValidValue
|
|
6
|
+
declare const usePickerLayout: <TValue extends PickerValidValue>(props: PickersLayoutProps<TValue>) => UsePickerLayoutResponse<TValue>;
|
|
7
7
|
export default usePickerLayout;
|
|
@@ -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
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { MakeOptional } from '@mui/x-internals/types';
|
|
2
2
|
import { BaseDatePickerProps, BaseDatePickerSlots, BaseDatePickerSlotProps } from '../DatePicker/shared';
|
|
3
3
|
import { StaticOnlyPickerProps, UseStaticPickerSlots, UseStaticPickerSlotProps } from '../internals/hooks/useStaticPicker';
|
|
4
|
-
|
|
5
|
-
export interface StaticDatePickerSlots extends BaseDatePickerSlots, UseStaticPickerSlots<DateView> {
|
|
4
|
+
export interface StaticDatePickerSlots extends BaseDatePickerSlots, UseStaticPickerSlots {
|
|
6
5
|
}
|
|
7
|
-
export interface StaticDatePickerSlotProps extends BaseDatePickerSlotProps, UseStaticPickerSlotProps
|
|
6
|
+
export interface StaticDatePickerSlotProps extends BaseDatePickerSlotProps, UseStaticPickerSlotProps {
|
|
8
7
|
}
|
|
9
8
|
export interface StaticDatePickerProps extends BaseDatePickerProps, MakeOptional<StaticOnlyPickerProps, 'displayStaticWrapperAs'> {
|
|
10
9
|
/**
|
|
@@ -2,9 +2,9 @@ import { MakeOptional } from '@mui/x-internals/types';
|
|
|
2
2
|
import { BaseDateTimePickerProps, BaseDateTimePickerSlots, BaseDateTimePickerSlotProps } from '../DateTimePicker/shared';
|
|
3
3
|
import { StaticOnlyPickerProps, UseStaticPickerSlots, UseStaticPickerSlotProps } from '../internals/hooks/useStaticPicker';
|
|
4
4
|
import { DateOrTimeView } from '../models';
|
|
5
|
-
export interface StaticDateTimePickerSlots extends BaseDateTimePickerSlots, UseStaticPickerSlots
|
|
5
|
+
export interface StaticDateTimePickerSlots extends BaseDateTimePickerSlots, UseStaticPickerSlots {
|
|
6
6
|
}
|
|
7
|
-
export interface StaticDateTimePickerSlotProps extends BaseDateTimePickerSlotProps, UseStaticPickerSlotProps
|
|
7
|
+
export interface StaticDateTimePickerSlotProps extends BaseDateTimePickerSlotProps, UseStaticPickerSlotProps {
|
|
8
8
|
}
|
|
9
9
|
export interface StaticDateTimePickerProps extends BaseDateTimePickerProps<DateOrTimeView>, MakeOptional<StaticOnlyPickerProps, 'displayStaticWrapperAs'> {
|
|
10
10
|
/**
|
|
@@ -2,9 +2,9 @@ import { MakeOptional } from '@mui/x-internals/types';
|
|
|
2
2
|
import { BaseTimePickerProps, BaseTimePickerSlots, BaseTimePickerSlotProps } from '../TimePicker/shared';
|
|
3
3
|
import { StaticOnlyPickerProps, UseStaticPickerSlots, UseStaticPickerSlotProps } from '../internals/hooks/useStaticPicker';
|
|
4
4
|
import { TimeView } from '../models';
|
|
5
|
-
export interface StaticTimePickerSlots extends BaseTimePickerSlots, UseStaticPickerSlots
|
|
5
|
+
export interface StaticTimePickerSlots extends BaseTimePickerSlots, UseStaticPickerSlots {
|
|
6
6
|
}
|
|
7
|
-
export interface StaticTimePickerSlotProps extends BaseTimePickerSlotProps, UseStaticPickerSlotProps
|
|
7
|
+
export interface StaticTimePickerSlotProps extends BaseTimePickerSlotProps, UseStaticPickerSlotProps {
|
|
8
8
|
}
|
|
9
9
|
export interface StaticTimePickerProps extends BaseTimePickerProps<TimeView>, MakeOptional<StaticOnlyPickerProps, 'displayStaticWrapperAs'> {
|
|
10
10
|
/**
|
|
@@ -3,9 +3,9 @@ import { BaseSingleInputFieldProps, PickerValue, TimeViewWithMeridiem } from '..
|
|
|
3
3
|
import { MobileTimePickerProps, MobileTimePickerSlots, MobileTimePickerSlotProps } from '../MobileTimePicker';
|
|
4
4
|
import { TimeValidationError } from '../models';
|
|
5
5
|
import { ValidateTimeProps } from '../validation/validateTime';
|
|
6
|
-
export interface TimePickerSlots extends DesktopTimePickerSlots, MobileTimePickerSlots
|
|
6
|
+
export interface TimePickerSlots extends DesktopTimePickerSlots, MobileTimePickerSlots {
|
|
7
7
|
}
|
|
8
|
-
export interface TimePickerSlotProps<TEnableAccessibleFieldDOMStructure extends boolean> extends DesktopTimePickerSlotProps<TEnableAccessibleFieldDOMStructure>, MobileTimePickerSlotProps<
|
|
8
|
+
export interface TimePickerSlotProps<TEnableAccessibleFieldDOMStructure extends boolean> extends DesktopTimePickerSlotProps<TEnableAccessibleFieldDOMStructure>, MobileTimePickerSlotProps<TEnableAccessibleFieldDOMStructure> {
|
|
9
9
|
}
|
|
10
10
|
export interface TimePickerProps<TEnableAccessibleFieldDOMStructure extends boolean = true> extends DesktopTimePickerProps<TEnableAccessibleFieldDOMStructure>, Omit<MobileTimePickerProps<TimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure>, 'views'> {
|
|
11
11
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { BaseToolbarProps, ExportedBaseToolbarProps } from '../internals/models/props/toolbar';
|
|
3
3
|
import { TimePickerToolbarClasses } from './timePickerToolbarClasses';
|
|
4
|
-
import { PickerValue
|
|
5
|
-
export interface TimePickerToolbarProps extends BaseToolbarProps<PickerValue
|
|
4
|
+
import { PickerValue } from '../internals/models';
|
|
5
|
+
export interface TimePickerToolbarProps extends BaseToolbarProps<PickerValue>, ExportedTimePickerToolbarProps {
|
|
6
6
|
ampm?: boolean;
|
|
7
7
|
ampmInClock?: boolean;
|
|
8
8
|
}
|
|
@@ -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/hooks/index.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export { usePickerTranslations } from './usePickerTranslations';
|
|
|
4
4
|
export { useSplitFieldProps } from './useSplitFieldProps';
|
|
5
5
|
export { useParsedFormat } from './useParsedFormat';
|
|
6
6
|
export { usePickerContext } from './usePickerContext';
|
|
7
|
+
export { usePickerActionsContext } from './usePickerActionsContext';
|
package/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,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a subset of the context passed by the picker wrapping the current component.
|
|
3
|
+
* It only contains the actions and never causes a re-render of the component using it.
|
|
4
|
+
*/
|
|
5
|
+
export declare const usePickerActionsContext: () => import("../internals/components/PickerProvider").PickerActionsContextValue;
|
|
@@ -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
|
+
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { PickerContextValue } from '../internals/components/PickerProvider';
|
|
2
|
+
import { DateOrTimeViewWithMeridiem } from '../internals/models';
|
|
1
3
|
/**
|
|
2
4
|
* Returns the context passed by the picker that wraps the current component.
|
|
3
5
|
*/
|
|
4
|
-
export declare const usePickerContext: () =>
|
|
6
|
+
export declare const usePickerContext: <TView extends DateOrTimeViewWithMeridiem = DateOrTimeViewWithMeridiem>() => PickerContextValue<TView>;
|
package/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { PickerOwnerState } from '../../models';
|
|
3
3
|
import { PickersInputLocaleText } from '../../locales';
|
|
4
|
-
import { PickerOrientation, PickerVariant } from '../models';
|
|
5
|
-
import type { UsePickerValueContextValue } from '../hooks/usePicker/usePickerValue.types';
|
|
6
|
-
|
|
4
|
+
import { DateOrTimeViewWithMeridiem, PickerOrientation, PickerVariant } from '../models';
|
|
5
|
+
import type { UsePickerValueActionsContextValue, UsePickerValueContextValue, UsePickerValuePrivateContextValue } from '../hooks/usePicker/usePickerValue.types';
|
|
6
|
+
import { UsePickerViewsContextValue } from '../hooks/usePicker/usePickerViews';
|
|
7
|
+
export declare const PickerContext: React.Context<PickerContextValue<any> | null>;
|
|
8
|
+
export declare const PickerActionsContext: React.Context<PickerActionsContextValue | null>;
|
|
7
9
|
export declare const PickerPrivateContext: React.Context<PickerPrivateContextValue>;
|
|
8
10
|
/**
|
|
9
11
|
* Provides the context for the various parts of a picker component:
|
|
@@ -14,12 +16,13 @@ export declare const PickerPrivateContext: React.Context<PickerPrivateContextVal
|
|
|
14
16
|
*/
|
|
15
17
|
export declare function PickerProvider(props: PickerProviderProps): React.JSX.Element;
|
|
16
18
|
export interface PickerProviderProps {
|
|
17
|
-
contextValue: PickerContextValue
|
|
19
|
+
contextValue: PickerContextValue<any>;
|
|
20
|
+
actionsContextValue: PickerActionsContextValue;
|
|
18
21
|
privateContextValue: PickerPrivateContextValue;
|
|
19
22
|
localeText: PickersInputLocaleText | undefined;
|
|
20
23
|
children: React.ReactNode;
|
|
21
24
|
}
|
|
22
|
-
export interface PickerContextValue extends UsePickerValueContextValue {
|
|
25
|
+
export interface PickerContextValue<TView extends DateOrTimeViewWithMeridiem = DateOrTimeViewWithMeridiem> extends UsePickerValueContextValue, UsePickerViewsContextValue<TView> {
|
|
23
26
|
/**
|
|
24
27
|
* `true` if the picker is disabled, `false` otherwise.
|
|
25
28
|
*/
|
|
@@ -46,7 +49,9 @@ export interface PickerContextValue extends UsePickerValueContextValue {
|
|
|
46
49
|
*/
|
|
47
50
|
orientation: PickerOrientation;
|
|
48
51
|
}
|
|
49
|
-
export interface
|
|
52
|
+
export interface PickerActionsContextValue extends UsePickerValueActionsContextValue {
|
|
53
|
+
}
|
|
54
|
+
export interface PickerPrivateContextValue extends UsePickerValuePrivateContextValue {
|
|
50
55
|
/**
|
|
51
56
|
* The ownerState of the picker.
|
|
52
57
|
*/
|
|
@@ -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
|
});
|
|
@@ -2,7 +2,6 @@ import * as React from 'react';
|
|
|
2
2
|
import { DialogProps as MuiDialogProps } from '@mui/material/Dialog';
|
|
3
3
|
import { PaperProps as MuiPaperProps } from '@mui/material/Paper';
|
|
4
4
|
import { TransitionProps as MuiTransitionProps } from '@mui/material/transitions';
|
|
5
|
-
import { UsePickerValueActions } from '../hooks/usePicker/usePickerValue.types';
|
|
6
5
|
export interface PickersModalDialogSlots {
|
|
7
6
|
/**
|
|
8
7
|
* Custom component for the dialog inside which the views are rendered on mobile.
|
|
@@ -34,7 +33,7 @@ export interface PickersModalDialogSlotProps {
|
|
|
34
33
|
*/
|
|
35
34
|
mobileTransition?: Partial<MuiTransitionProps>;
|
|
36
35
|
}
|
|
37
|
-
export interface PickersModalDialogProps
|
|
36
|
+
export interface PickersModalDialogProps {
|
|
38
37
|
/**
|
|
39
38
|
* Overridable component slots.
|
|
40
39
|
* @default {}
|
|
@@ -45,6 +44,5 @@ export interface PickersModalDialogProps extends UsePickerValueActions {
|
|
|
45
44
|
* @default {}
|
|
46
45
|
*/
|
|
47
46
|
slotProps?: PickersModalDialogSlotProps;
|
|
48
|
-
open: boolean;
|
|
49
47
|
}
|
|
50
48
|
export declare function PickersModalDialog(props: React.PropsWithChildren<PickersModalDialogProps>): React.JSX.Element;
|
|
@@ -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,
|
|
@@ -5,7 +5,6 @@ import { TrapFocusProps as MuiTrapFocusProps } from '@mui/material/Unstable_Trap
|
|
|
5
5
|
import { TransitionProps as MuiTransitionProps } from '@mui/material/transitions';
|
|
6
6
|
import { SlotComponentPropsFromProps } from '@mui/x-internals/types';
|
|
7
7
|
import { PickersPopperClasses } from './pickersPopperClasses';
|
|
8
|
-
import { UsePickerValueActions } from '../hooks/usePicker/usePickerValue.types';
|
|
9
8
|
import { PickerOwnerState } from '../../models';
|
|
10
9
|
interface PickerPopperOwnerState extends PickerOwnerState {
|
|
11
10
|
popperPlacement: PopperPlacementType;
|
|
@@ -50,10 +49,9 @@ export interface PickersPopperSlotProps {
|
|
|
50
49
|
*/
|
|
51
50
|
popper?: SlotComponentPropsFromProps<PopperProps, {}, PickerPopperOwnerState>;
|
|
52
51
|
}
|
|
53
|
-
export interface PickerPopperProps
|
|
52
|
+
export interface PickerPopperProps {
|
|
54
53
|
role: 'tooltip' | 'dialog';
|
|
55
54
|
anchorEl: MuiPopperProps['anchorEl'];
|
|
56
|
-
open: MuiPopperProps['open'];
|
|
57
55
|
/**
|
|
58
56
|
* @default "bottom"
|
|
59
57
|
*/
|
|
@@ -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,14 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { BaseToolbarProps } from '../models/props/toolbar';
|
|
3
3
|
import { PickersToolbarClasses } from './pickersToolbarClasses';
|
|
4
|
-
import {
|
|
5
|
-
export interface PickersToolbarProps<TValue extends PickerValidValue
|
|
4
|
+
import { PickerValidValue } from '../models';
|
|
5
|
+
export interface PickersToolbarProps<TValue extends PickerValidValue> extends Pick<BaseToolbarProps<TValue>, 'isLandscape' | 'hidden' | 'titleId'> {
|
|
6
6
|
className?: string;
|
|
7
7
|
landscapeDirection?: 'row' | 'column';
|
|
8
8
|
toolbarTitle: React.ReactNode;
|
|
9
9
|
classes?: Partial<PickersToolbarClasses>;
|
|
10
10
|
}
|
|
11
|
-
type PickersToolbarComponent = (<TValue extends PickerValidValue
|
|
11
|
+
type PickersToolbarComponent = (<TValue extends PickerValidValue>(props: React.PropsWithChildren<PickersToolbarProps<TValue>> & React.RefAttributes<HTMLDivElement>) => React.JSX.Element) & {
|
|
12
12
|
propTypes?: any;
|
|
13
13
|
};
|
|
14
14
|
export declare const PickersToolbar: PickersToolbarComponent;
|