forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddComponent.tsx
100 lines (96 loc) · 2.73 KB
/
AddComponent.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import * as React from 'react';
import { Dayjs } from 'dayjs';
import Box from '@mui/material/Box';
import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem';
import ListItemButton from '@mui/material/ListItemButton';
import ListItemText from '@mui/material/ListItemText';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { StaticDatePicker } from '@mui/x-date-pickers/StaticDatePicker';
import { PickersActionBarProps } from '@mui/x-date-pickers/PickersActionBar';
import RestaurantIcon from '@mui/icons-material/Restaurant';
import {
PickersLayoutProps,
usePickerLayout,
pickersLayoutClasses,
PickersLayoutRoot,
PickersLayoutContentWrapper,
} from '@mui/x-date-pickers/PickersLayout';
import { DateView } from '@mui/x-date-pickers/models';
function ActionList(props: PickersActionBarProps) {
const { onAccept, onClear, onCancel, onSetToday } = props;
const actions = [
{ text: 'Accept', method: onAccept },
{ text: 'Clear', method: onClear },
{ text: 'Cancel', method: onCancel },
{ text: 'Today', method: onSetToday },
];
return (
<List>
{actions.map(({ text, method }) => (
<ListItem key={text} disablePadding>
<ListItemButton onClick={method}>
<ListItemText primary={text} />
</ListItemButton>
</ListItem>
))}
</List>
);
}
function RestaurantHeader() {
return (
<Box
sx={{
// Place the element in the grid layout
gridColumn: 1,
gridRow: 1,
// Center the icon
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
<RestaurantIcon />
</Box>
);
}
function CustomLayout(props: PickersLayoutProps<Dayjs | null, DateView>) {
const { toolbar, tabs, content, actionBar, ownerState } = usePickerLayout(props);
return (
<PickersLayoutRoot
ownerState={ownerState}
sx={{
overflow: 'auto',
[`.${pickersLayoutClasses.actionBar}`]: {
gridColumn: 1,
gridRow: 2,
},
[`.${pickersLayoutClasses.toolbar}`]: {
gridColumn: 2,
gridRow: 1,
},
}}
>
<RestaurantHeader />
{toolbar}
{actionBar}
<PickersLayoutContentWrapper className={pickersLayoutClasses.contentWrapper}>
{tabs}
{content}
</PickersLayoutContentWrapper>
</PickersLayoutRoot>
);
}
export default function AddComponent() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<StaticDatePicker
slots={{
layout: CustomLayout,
actionBar: ActionList,
}}
/>
</LocalizationProvider>
);
}