/
Table.styles.ts
97 lines (85 loc) · 2.85 KB
/
Table.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
91
92
93
94
95
96
97
import { createStyles, MantineNumberSize } from '@mantine/styles';
export interface TableStylesParams {
captionSide: 'top' | 'bottom';
horizontalSpacing: MantineNumberSize;
verticalSpacing: MantineNumberSize;
fontSize: MantineNumberSize;
withBorder: boolean;
withColumnBorders: boolean;
}
export default createStyles(
(
theme,
{
captionSide,
horizontalSpacing,
verticalSpacing,
fontSize,
withBorder,
withColumnBorders,
}: TableStylesParams
) => {
const border = `1px solid ${
theme.colorScheme === 'dark' ? theme.colors.dark[4] : theme.colors.gray[3]
}`;
return {
root: {
...theme.fn.fontStyles(),
width: '100%',
borderCollapse: 'collapse',
captionSide,
color: theme.colorScheme === 'dark' ? theme.colors.dark[0] : theme.black,
lineHeight: theme.lineHeight,
border: withBorder ? border : '',
'& caption': {
marginTop: captionSide === 'top' ? 0 : theme.spacing.xs,
marginBottom: captionSide === 'bottom' ? 0 : theme.spacing.xs,
fontSize: theme.fontSizes.sm,
color: theme.colorScheme === 'dark' ? theme.colors.dark[2] : theme.colors.gray[6],
},
'& thead tr th, & tfoot tr th': {
textAlign: 'left',
fontWeight: 'bold',
color: theme.colorScheme === 'dark' ? theme.colors.dark[0] : theme.colors.gray[7],
fontSize: theme.fn.size({ size: fontSize, sizes: theme.fontSizes }),
padding: `${theme.fn.size({
size: verticalSpacing,
sizes: theme.spacing,
})}px ${theme.fn.size({ size: horizontalSpacing, sizes: theme.spacing })}px`,
},
'& thead tr th': {
borderBottom: border,
},
'& tfoot tr th': {
borderTop: border,
},
'& tbody tr td': {
padding: `${theme.fn.size({
size: verticalSpacing,
sizes: theme.spacing,
})}px ${theme.fn.size({ size: horizontalSpacing, sizes: theme.spacing })}px`,
borderTop: border,
fontSize: theme.fn.size({ size: fontSize, sizes: theme.fontSizes }),
},
'& tbody tr:first-of-type td': {
borderTop: 'none',
},
'& thead th, & tbody td': {
borderRight: withColumnBorders ? border : 'none',
'&:last-of-type': {
borderRight: 'none',
borderLeft: withColumnBorders ? border : 'none',
},
},
'&[data-striped] tbody tr:nth-of-type(odd)': {
backgroundColor:
theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[0],
},
'&[data-hover] tbody tr': theme.fn.hover({
backgroundColor:
theme.colorScheme === 'dark' ? theme.colors.dark[5] : theme.colors.gray[1],
}),
},
};
}
);