forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClock.tsx
52 lines (50 loc) · 1.46 KB
/
Clock.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
import * as React from 'react';
import dayjs, { Dayjs } from 'dayjs';
import { styled } from '@mui/material/styles';
import Card from '@mui/material/Card';
import { StaticTimePicker } from '@mui/x-date-pickers/StaticTimePicker';
import {
PickersLayoutProps,
usePickerLayout,
pickersLayoutClasses,
PickersLayoutRoot,
PickersLayoutContentWrapper,
} from '@mui/x-date-pickers/PickersLayout';
import { TimeView } from '@mui/x-date-pickers/models';
const StyledLayout = styled(PickersLayoutRoot)({
overflow: 'auto',
minWidth: 'fit-content',
[`.${pickersLayoutClasses.toolbar}`]: {
padding: '4px 16px',
},
[`.${pickersLayoutClasses.contentWrapper}`]: {
'& .MuiTimeClock-root': {
width: 'fit-content',
},
'& .MuiPickersArrowSwitcher-root': {
justifyContent: 'space-between',
width: '100%',
right: 0,
top: '2px',
},
},
});
function CustomLayout(props: PickersLayoutProps<Dayjs | null, TimeView>) {
const { actionBar, content, toolbar, ownerState } = usePickerLayout(props);
return (
<StyledLayout ownerState={ownerState}>
{toolbar}
<PickersLayoutContentWrapper className={pickersLayoutClasses.contentWrapper}>
{content}
{actionBar}
</PickersLayoutContentWrapper>
</StyledLayout>
);
}
export default function Clock() {
return (
<Card variant="outlined">
<StaticTimePicker defaultValue={dayjs('2022-04-17T15:30')} slots={{ layout: CustomLayout }} />
</Card>
);
}