Skip to content

Commit 6fb5cef

Browse files
[pickers] Remove orientation, isLandscape, isRtl, wrapperVariant and disabled props from PickersLayout
1 parent c73f6af commit 6fb5cef

File tree

22 files changed

+136
-423
lines changed

22 files changed

+136
-423
lines changed

docs/data/date-pickers/custom-components/custom-components.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ You can override the actions displayed by passing the `actions` prop to the `act
3434
actions: ['clear'],
3535
},
3636
// The actions will be different between desktop and mobile
37-
actionBar: ({ wrapperVariant }) => ({
38-
actions: wrapperVariant === 'desktop' ? [] : ['clear'],
37+
actionBar: ({ variant }) => ({
38+
actions: variant === 'desktop' ? [] : ['clear'],
3939
}),
4040
}}
4141
/>

docs/data/date-pickers/custom-layout/AddComponent.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ function RestaurantHeader() {
5858
}
5959

6060
function CustomLayout(props) {
61-
const { toolbar, tabs, content, actionBar } = usePickerLayout(props);
61+
const { toolbar, tabs, content, actionBar, ownerState } = usePickerLayout(props);
6262

6363
return (
6464
<PickersLayoutRoot
65-
ownerState={props}
65+
ownerState={ownerState}
6666
sx={{
6767
overflow: 'auto',
6868
[`.${pickersLayoutClasses.actionBar}`]: {

docs/data/date-pickers/custom-layout/AddComponent.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ function RestaurantHeader() {
5959
}
6060

6161
function CustomLayout(props: PickersLayoutProps<Dayjs | null, DateView>) {
62-
const { toolbar, tabs, content, actionBar } = usePickerLayout(props);
62+
const { toolbar, tabs, content, actionBar, ownerState } = usePickerLayout(props);
6363

6464
return (
6565
<PickersLayoutRoot
66-
ownerState={props}
66+
ownerState={ownerState}
6767
sx={{
6868
overflow: 'auto',
6969
[`.${pickersLayoutClasses.actionBar}`]: {

docs/data/date-pickers/custom-layout/custom-layout.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ import {
8686
} from '@mui/x-date-pickers/PickersLayout';
8787

8888
function MyCustomLayout(props) {
89-
const { toolbar, tabs, content, actionBar } = usePickerLayout(props);
89+
const { toolbar, tabs, content, actionBar, ownerState } = usePickerLayout(props);
9090

9191
// Put the action bar before the content
9292
return (
93-
<PickersLayoutRoot className={pickersLayoutClasses.root} ownerState={props}>
93+
<PickersLayoutRoot className={pickersLayoutClasses.root} ownerState={ownerState}>
9494
{toolbar}
9595
{actionBar}
9696
<PickersLayoutContentWrapper className={pickersLayoutClasses.contentWrapper}>
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,16 @@
11
import * as React from 'react';
22

3-
import Box from '@mui/material/Box';
4-
import Stack from '@mui/material/Stack';
5-
import IconButton from '@mui/material/IconButton';
6-
import ModeEditIcon from '@mui/icons-material/ModeEdit';
7-
import CalendarMonthIcon from '@mui/icons-material/CalendarMonth';
8-
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
9-
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
10-
11-
import {
12-
pickersLayoutClasses,
13-
PickersLayoutContentWrapper,
14-
PickersLayoutRoot,
15-
usePickerLayout,
16-
} from '@mui/x-date-pickers/PickersLayout';
17-
import { MobileDatePicker } from '@mui/x-date-pickers/MobileDatePicker';
18-
import { DateField } from '@mui/x-date-pickers/DateField';
19-
import { DatePickerToolbar } from '@mui/x-date-pickers/DatePicker';
20-
21-
function LayoutWithKeyboardView(props) {
22-
const { value, onChange } = props;
23-
const [showKeyboardView, setShowKeyboardView] = React.useState(false);
24-
25-
const { toolbar, tabs, content, actionBar } = usePickerLayout({
26-
...props,
27-
slotProps: {
28-
...props.slotProps,
29-
toolbar: {
30-
...props.slotProps?.toolbar,
31-
// @ts-ignore
32-
showKeyboardViewSwitch: props.wrapperVariant === 'mobile',
33-
showKeyboardView,
34-
setShowKeyboardView,
35-
},
36-
},
37-
});
38-
39-
return (
40-
<PickersLayoutRoot ownerState={props}>
41-
{toolbar}
42-
{actionBar}
43-
<PickersLayoutContentWrapper className={pickersLayoutClasses.contentWrapper}>
44-
{tabs}
45-
{showKeyboardView ? (
46-
<Box sx={{ mx: 3, my: 2, width: 272 }}>
47-
<DateField value={value} onChange={onChange} sx={{ width: '100%' }} />
48-
</Box>
49-
) : (
50-
content
51-
)}
52-
</PickersLayoutContentWrapper>
53-
</PickersLayoutRoot>
54-
);
55-
}
56-
57-
function ToolbarWithKeyboardViewSwitch(props) {
58-
const { showKeyboardViewSwitch, showKeyboardView, setShowKeyboardView, ...other } =
59-
props;
60-
61-
if (showKeyboardViewSwitch) {
62-
return (
63-
<Stack
64-
spacing={2}
65-
direction={other.isLandscape ? 'column' : 'row'}
66-
alignItems="center"
67-
sx={
68-
other.isLandscape
69-
? {
70-
gridColumn: 1,
71-
gridRow: '1 / 3',
72-
}
73-
: { gridColumn: '1 / 4', gridRow: 1, mr: 1 }
74-
}
75-
>
76-
<DatePickerToolbar {...other} sx={{ flex: '1 1 100%' }} />
77-
<IconButton
78-
color="inherit"
79-
onClick={() => setShowKeyboardView((prev) => !prev)}
80-
>
81-
{showKeyboardView ? <CalendarMonthIcon /> : <ModeEditIcon />}
82-
</IconButton>
83-
</Stack>
84-
);
85-
}
86-
87-
return <DatePickerToolbar {...other} />;
88-
}
893
export default function MobileKeyboardView() {
904
return (
91-
<LocalizationProvider dateAdapter={AdapterDayjs}>
92-
<MobileDatePicker
93-
slots={{
94-
layout: LayoutWithKeyboardView,
95-
toolbar: ToolbarWithKeyboardViewSwitch,
96-
}}
97-
/>
98-
</LocalizationProvider>
5+
<iframe
6+
title="codesandbox"
7+
src="https://codesandbox.io/embed/https-mui-com-x-migration-migration-pickers-v7-forked-9fz6f6?hidenavigation=1&fontsize=14&view=preview"
8+
style={{
9+
width: '100%',
10+
height: 520,
11+
border: 0,
12+
}}
13+
sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"
14+
/>
9915
);
10016
}

docs/data/migration/migration-pickers-v5/MobileKeyboardView.tsx

-110
This file was deleted.

docs/data/migration/migration-pickers-v5/MobileKeyboardView.tsx.preview

-6
This file was deleted.

docs/data/migration/migration-pickers-v5/migration-pickers-v5.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ The picker components no longer have a keyboard view to render the input inside
171171

172172
- If you want to keep the old keyboard view, you can pass a custom `Layout` component slot to re-introduce the keyboard view.
173173

174-
{{"demo": "MobileKeyboardView.js", "defaultCodeOpen": false}}
174+
{{"demo": "MobileKeyboardView.js", "hideToolbar": true, "bg": true}}
175175

176176
:::info
177177
At some point, the mobile pickers should have a prop allowing to have an editable field without opening the modal.

docs/data/migration/migration-pickers-v7/migration-pickers-v7.md

+46
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,19 @@ const theme = createTheme({
258258

259259
### Slot: `layout`
260260

261+
- The `PickersLayoutRoot` must now receive the `ownerState` returned by `usePickerLayout` instead of its props:
262+
263+
```diff
264+
-const { toolbar, tabs, content, actionBar } = usePickerLayout(props);
265+
+const { toolbar, tabs, content, actionBar, ownerState } = usePickerLayout(props);
266+
return (
267+
- <PickersLayoutRoot ownerState={props}>
268+
+ <PickersLayoutRoot ownerState={ownerState}>
269+
Layout content
270+
</PickersLayoutRoot>
271+
);
272+
```
273+
261274
- The component passed to the `layout` slot no longer receives a `disabled` prop, instead you can use the `usePickersContext` hook:
262275

263276
```diff
@@ -276,6 +289,39 @@ const theme = createTheme({
276289
+console.log(readOnly);
277290
```
278291

292+
- The component passed to the `layout` slot no longer receives a `isRtl` prop. If you need to access this information, you can use the `useRtl` hook from `@mui/system`:
293+
294+
```diff
295+
+import { useRtl } from '@mui/system/RtlProvider';
296+
function CustomLayout(props) {
297+
- console.log(props.isRtl);
298+
+ const isRtl = useRtl();
299+
+ console.log(isRtl);
300+
}
301+
```
302+
303+
- The component passed to the `layout` slot no longer receives an `orientation` and the `isLandscape` props, instead you can use the `usePickersContext` hook:
304+
305+
```diff
306+
-console.log(props.orientation);
307+
+import { usePickersContext } from '@mui/x-date-pickers/hooks';
308+
+const { orientation } = usePickersContext();
309+
+console.log(orientation);
310+
-console.log(props.isLandscape);
311+
+import { usePickersContext } from '@mui/x-date-pickers/hooks';
312+
+const { orientation } = usePickersContext();
313+
+console.log(orientation === 'landscape');
314+
```
315+
316+
- The component passed to the `layout` slot no longer receives a `wrapperVariant` prop, instead you can use the `usePickersContext` hook:
317+
318+
```diff
319+
-console.log(props.wrapperVariant);
320+
+import { usePickersContext } from '@mui/x-date-pickers/hooks';
321+
+const { variant } = usePickersContext();
322+
+console.log(variant);
323+
```
324+
279325
### Slot: `toolbar`
280326

281327
- The component passed to the `toolbar` slot no longer receives a `disabled` prop, instead you can use the `usePickersContext` hook:

docs/pages/x/api/date-pickers/pickers-layout.json

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
{
22
"props": {
3-
"isRtl": { "type": { "name": "bool" }, "required": true },
43
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
5-
"orientation": {
6-
"type": { "name": "enum", "description": "'landscape'<br>&#124;&nbsp;'portrait'" }
7-
},
84
"slotProps": { "type": { "name": "object" }, "default": "{}" },
95
"slots": {
106
"type": { "name": "object" },

docs/src/modules/components/overview/mainDemo/Clock.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ const StyledLayout = styled(PickersLayoutRoot)({
3232
});
3333

3434
function CustomLayout(props: PickersLayoutProps<Dayjs | null, TimeView>) {
35-
const { actionBar, content, toolbar } = usePickerLayout(props);
35+
const { actionBar, content, toolbar, ownerState } = usePickerLayout(props);
3636
return (
37-
<StyledLayout ownerState={props}>
37+
<StyledLayout ownerState={ownerState}>
3838
{toolbar}
3939
<PickersLayoutContentWrapper className={pickersLayoutClasses.contentWrapper}>
4040
{content}

docs/src/modules/components/overview/mainDemo/DateRangeWithShortcuts.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ interface CustomLayoutProps extends PickersLayoutProps<DateRange<Dayjs>, 'day'>
6060
}
6161
function CustomLayout(props: CustomLayoutProps) {
6262
const { isHorizontal, ...other } = props;
63-
const { tabs, content, shortcuts } = usePickerLayout(other);
63+
const { tabs, content, shortcuts, ownerState } = usePickerLayout(other);
6464

6565
return (
6666
<PickersLayoutRoot
67-
ownerState={props}
67+
ownerState={ownerState}
6868
sx={{
6969
overflow: 'auto',
7070
[`.${pickersLayoutClasses.shortcuts}`]: isHorizontal

0 commit comments

Comments
 (0)