-
-
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
base: master
Are you sure you want to change the base?
Changes from all commits
6fb5cef
13975ee
51f703c
f825b20
e98f435
abb575a
0fd962d
0ffb3ed
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 |
||
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.
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 👍