-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathindex.ts
133 lines (110 loc) · 2.99 KB
/
index.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import { zipThemes } from '@table-library/react-table-library/theme/index';
import { Theme } from '@table-library/react-table-library/types/theme';
type Configuration = {
isVirtualized?: boolean;
};
type ConfigurationSound = Required<Configuration>;
type Options = {
horizontalSpacing?: number;
verticalSpacing?: number;
striped?: boolean;
};
type OptionsSound = Required<Options>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const getCommonTheme = (options: OptionsSound, _: ConfigurationSound) => ({
Table: `
.caption-container {
display: flex;
justify-content: center;
width: 100%;
}
caption {
color: #868e96;
}
`,
BaseRow: `
color: #4a5568;
`,
HeaderRow: `
text-transform: uppercase;
font-size: 12px;
&.tr-header .th {
border-bottom: 1px solid #e2e8f0;
}
&.tr-footer .th {
border-top: 1px solid #e2e8f0;
}
`,
Row: `
font-size: 16px;
&.tr.tr-body.row-select.row-select-single-selected, &.tr.tr-body.row-select.row-select-selected {
background-color: #81E6D9;
border-bottom: 1px solid #81E6D9;
}
`,
BaseCell: `
padding: ${options.verticalSpacing}px ${options.horizontalSpacing}px;
`,
HeaderCell: `
& > div {
padding-top: 3px;
padding-bottom: 3px;
}
`,
});
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const getVirtualizedTheme = (options: OptionsSound, configuration: ConfigurationSound) => ({
Row: `
& .td {
border-bottom: 1px solid #e2e8f0;
}
`,
Body: `
& > div:nth-of-type(odd) > .tr {
background-color: ${options.striped ? '#E6FFFA' : '#ffffff'};
}
& > div:nth-of-type(even) > .tr {
background-color: #ffffff;
}
`,
});
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const getNoneVirtualizedTheme = (options: OptionsSound, configuration: ConfigurationSound) => ({
Row: `
&:not(:last-of-type) > .td {
border-bottom: 1px solid #e2e8f0;
}
&:nth-of-type(odd) {
background-color: ${options.striped ? '#E6FFFA' : '#ffffff'};
}
&:nth-of-type(even) {
background-color: #ffffff;
}
`,
});
const getZipTheme = (options: OptionsSound, configuration: ConfigurationSound) => {
const commonTheme = getCommonTheme(options, configuration);
const specificTheme = configuration.isVirtualized
? getVirtualizedTheme(options, configuration)
: getNoneVirtualizedTheme(options, configuration);
return zipThemes([commonTheme, specificTheme]);
};
export const DEFAULT_OPTIONS = {
horizontalSpacing: 24,
verticalSpacing: 12,
striped: false,
};
export const DEFAULT_CONFIGURATION = {
isVirtualized: false,
};
export const getTheme = (options?: Options, configuration?: Configuration): Theme => {
const mergedOptions = {
...DEFAULT_OPTIONS,
...(options ?? {}),
};
const mergedConfiguration = {
...DEFAULT_CONFIGURATION,
...(configuration ?? {}),
};
return getZipTheme(mergedOptions, mergedConfiguration);
};