-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pickers] Remove orientation
, isLandscape
, isRtl
, wrapperVariant
and disabled
props from PickersLayout
#15494
Changes from 1 commit
6fb5cef
13975ee
51f703c
f825b20
e98f435
abb575a
0fd962d
0ffb3ed
a0d8116
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,16 @@ | ||
import * as React from 'react'; | ||
|
||
import Box from '@mui/material/Box'; | ||
import Stack from '@mui/material/Stack'; | ||
import IconButton from '@mui/material/IconButton'; | ||
import ModeEditIcon from '@mui/icons-material/ModeEdit'; | ||
import CalendarMonthIcon from '@mui/icons-material/CalendarMonth'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
|
||
import { | ||
pickersLayoutClasses, | ||
PickersLayoutContentWrapper, | ||
PickersLayoutRoot, | ||
usePickerLayout, | ||
} from '@mui/x-date-pickers/PickersLayout'; | ||
import { MobileDatePicker } from '@mui/x-date-pickers/MobileDatePicker'; | ||
import { DateField } from '@mui/x-date-pickers/DateField'; | ||
import { DatePickerToolbar } from '@mui/x-date-pickers/DatePicker'; | ||
|
||
function LayoutWithKeyboardView(props) { | ||
const { value, onChange } = props; | ||
const [showKeyboardView, setShowKeyboardView] = React.useState(false); | ||
|
||
const { toolbar, tabs, content, actionBar } = usePickerLayout({ | ||
...props, | ||
slotProps: { | ||
...props.slotProps, | ||
toolbar: { | ||
...props.slotProps?.toolbar, | ||
// @ts-ignore | ||
showKeyboardViewSwitch: props.wrapperVariant === 'mobile', | ||
showKeyboardView, | ||
setShowKeyboardView, | ||
}, | ||
}, | ||
}); | ||
|
||
return ( | ||
<PickersLayoutRoot ownerState={props}> | ||
{toolbar} | ||
{actionBar} | ||
<PickersLayoutContentWrapper className={pickersLayoutClasses.contentWrapper}> | ||
{tabs} | ||
{showKeyboardView ? ( | ||
<Box sx={{ mx: 3, my: 2, width: 272 }}> | ||
<DateField value={value} onChange={onChange} sx={{ width: '100%' }} /> | ||
</Box> | ||
) : ( | ||
content | ||
)} | ||
</PickersLayoutContentWrapper> | ||
</PickersLayoutRoot> | ||
); | ||
} | ||
|
||
function ToolbarWithKeyboardViewSwitch(props) { | ||
const { showKeyboardViewSwitch, showKeyboardView, setShowKeyboardView, ...other } = | ||
props; | ||
|
||
if (showKeyboardViewSwitch) { | ||
return ( | ||
<Stack | ||
spacing={2} | ||
direction={other.isLandscape ? 'column' : 'row'} | ||
alignItems="center" | ||
sx={ | ||
other.isLandscape | ||
? { | ||
gridColumn: 1, | ||
gridRow: '1 / 3', | ||
} | ||
: { gridColumn: '1 / 4', gridRow: 1, mr: 1 } | ||
} | ||
> | ||
<DatePickerToolbar {...other} sx={{ flex: '1 1 100%' }} /> | ||
<IconButton | ||
color="inherit" | ||
onClick={() => setShowKeyboardView((prev) => !prev)} | ||
> | ||
{showKeyboardView ? <CalendarMonthIcon /> : <ModeEditIcon />} | ||
</IconButton> | ||
</Stack> | ||
); | ||
} | ||
|
||
return <DatePickerToolbar {...other} />; | ||
} | ||
export default function MobileKeyboardView() { | ||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<MobileDatePicker | ||
slots={{ | ||
layout: LayoutWithKeyboardView, | ||
toolbar: ToolbarWithKeyboardViewSwitch, | ||
}} | ||
/> | ||
</LocalizationProvider> | ||
<iframe | ||
title="codesandbox" | ||
src="https://codesandbox.io/embed/https-mui-com-x-migration-migration-pickers-v7-forked-9fz6f6?hidenavigation=1&fontsize=14&view=preview" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm breaking APIs that were used in the demo, and we want this demo to still use only v6 API,s not v8 APIs. The layout is not great There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels fine to me 👌 |
||
style={{ | ||
width: '100%', | ||
height: 520, | ||
border: 0, | ||
}} | ||
sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin" | ||
/> | ||
); | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -258,6 +258,19 @@ const theme = createTheme({ | |
|
||
### Slot: `layout` | ||
|
||
- The `PickersLayoutRoot` must now receive the `ownerState` returned by `usePickerLayout` instead of its props: | ||
|
||
```diff | ||
-const { toolbar, tabs, content, actionBar } = usePickerLayout(props); | ||
+const { toolbar, tabs, content, actionBar, ownerState } = usePickerLayout(props); | ||
return ( | ||
- <PickersLayoutRoot ownerState={props}> | ||
+ <PickersLayoutRoot ownerState={ownerState}> | ||
Layout content | ||
</PickersLayoutRoot> | ||
); | ||
``` | ||
|
||
- The component passed to the `layout` slot no longer receives a `disabled` prop, instead you can use the `usePickersContext` hook: | ||
|
||
```diff | ||
|
@@ -276,6 +289,39 @@ const theme = createTheme({ | |
+console.log(readOnly); | ||
``` | ||
|
||
- 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`: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively I can suggest to use |
||
|
||
```diff | ||
+import { useRtl } from '@mui/system/RtlProvider'; | ||
function CustomLayout(props) { | ||
- console.log(props.isRtl); | ||
+ const isRtl = useRtl(); | ||
+ console.log(isRtl); | ||
} | ||
``` | ||
|
||
- The component passed to the `layout` slot no longer receives an `orientation` and the `isLandscape` props, instead you can use the `usePickersContext` hook: | ||
|
||
```diff | ||
-console.log(props.orientation); | ||
+import { usePickersContext } from '@mui/x-date-pickers/hooks'; | ||
+const { orientation } = usePickersContext(); | ||
+console.log(orientation); | ||
-console.log(props.isLandscape); | ||
+import { usePickersContext } from '@mui/x-date-pickers/hooks'; | ||
+const { orientation } = usePickersContext(); | ||
+console.log(orientation === 'landscape'); | ||
``` | ||
|
||
- The component passed to the `layout` slot no longer receives a `wrapperVariant` prop, instead you can use the `usePickersContext` hook: | ||
|
||
```diff | ||
-console.log(props.wrapperVariant); | ||
+import { usePickersContext } from '@mui/x-date-pickers/hooks'; | ||
+const { variant } = usePickersContext(); | ||
+console.log(variant); | ||
``` | ||
|
||
### Slot: `toolbar` | ||
|
||
- The component passed to the `toolbar` slot no longer receives a `disabled` prop, instead you can use the `usePickersContext` hook: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try to write a first migration guide for the new
ownerState
now that we migrated a good portion of the components.This will be done in a follow up 👍