forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MovingActions.tsx
54 lines (52 loc) · 1.71 KB
/
MovingActions.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
import * as React from 'react';
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 { pickersLayoutClasses } from '@mui/x-date-pickers/PickersLayout';
import { StaticDatePicker } from '@mui/x-date-pickers/StaticDatePicker';
import { PickersActionBarProps } from '@mui/x-date-pickers/PickersActionBar';
function ActionList(props: PickersActionBarProps) {
const { onAccept, onClear, onCancel, onSetToday, className } = props;
const actions = [
{ text: 'Accept', method: onAccept },
{ text: 'Clear', method: onClear },
{ text: 'Cancel', method: onCancel },
{ text: 'Today', method: onSetToday },
];
return (
// Propagate the className such that CSS selectors can be applied
<List className={className}>
{actions.map(({ text, method }) => (
<ListItem key={text} disablePadding>
<ListItemButton onClick={method}>
<ListItemText primary={text} />
</ListItemButton>
</ListItem>
))}
</List>
);
}
export default function MovingActions() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<StaticDatePicker
slotProps={{
layout: {
sx: {
[`.${pickersLayoutClasses.actionBar}`]: {
gridColumn: 1,
gridRow: 2,
},
},
},
}}
slots={{
actionBar: ActionList,
}}
/>
</LocalizationProvider>
);
}