|
1 | 1 | import * as React from 'react';
|
2 | 2 |
|
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 |
| -} |
89 | 3 | export default function MobileKeyboardView() {
|
90 | 4 | 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 | + /> |
99 | 15 | );
|
100 | 16 | }
|
0 commit comments