/
Drawer.styles.ts
90 lines (76 loc) · 1.96 KB
/
Drawer.styles.ts
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
import React from 'react';
import { createStyles, MantineTheme } from '@mantine/styles';
const sizes = {
xs: 180,
sm: 240,
md: 320,
lg: 360,
xl: 500,
full: '100%',
};
export type DrawerPosition = 'top' | 'bottom' | 'left' | 'right';
export interface DrawerStylesParams {
position: DrawerPosition;
size: number | string;
zIndex: React.CSSProperties['zIndex'];
withOverlay: boolean;
}
interface GetPositionStyles {
position: DrawerPosition;
size: number | string;
theme: MantineTheme;
}
function getPositionStyles({
position,
size,
theme,
}: GetPositionStyles): Partial<Record<keyof React.CSSProperties, any>> {
switch (position) {
case 'top':
return { top: 0, left: 0, right: 0, height: theme.fn.size({ size, sizes }) };
case 'bottom':
return { bottom: 0, left: 0, right: 0, height: theme.fn.size({ size, sizes }) };
case 'right':
return { bottom: 0, top: 0, right: 0, width: theme.fn.size({ size, sizes }) };
case 'left':
return { bottom: 0, top: 0, left: 0, width: theme.fn.size({ size, sizes }) };
default:
return null;
}
}
export default createStyles(
(theme, { position, size, zIndex, withOverlay }: DrawerStylesParams) => ({
closeButton: {},
overlay: {},
root: {
position: 'fixed',
zIndex,
top: 0,
left: 0,
right: 0,
bottom: 0,
pointerEvents: withOverlay === false ? 'none' : undefined,
},
drawer: {
...getPositionStyles({ position, size, theme }),
maxWidth: '100%',
maxHeight: '100vh',
position: 'fixed',
outline: 0,
zIndex: 1,
pointerEvents: withOverlay === false ? 'auto' : undefined,
},
title: {
marginRight: theme.spacing.md,
textOverflow: 'ellipsis',
display: 'block',
wordBreak: 'break-word',
},
header: {
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
marginBottom: theme.spacing.md,
},
})
);