forked from cerebral/overmind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.ts
More file actions
51 lines (48 loc) · 1.28 KB
/
theme.ts
File metadata and controls
51 lines (48 loc) · 1.28 KB
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
export function getThemeCss<
T extends { [key: string]: { [key: string]: string } }
>(variables: T): string {
return `
:root {
${Object.keys(variables).reduce((parentAggr, parentKey) => {
return Object.keys(variables[parentKey]).reduce((aggr, key) => {
return `${aggr}\n--${parentKey}-${key}: ${variables[parentKey][key]};`
}, parentAggr)
}, '')}
}
`
}
export function getTheme<
T extends { [key: string]: { [key: string]: string } }
>(variables: T): { [P in keyof T]: { [C in keyof T[P]]: string } } {
return Object.keys(variables).reduce(
(aggr, key) => ({
...aggr,
[key]: variables[key],
}),
{}
) as any
}
const variables = {
colors: {
primary: 'hsl(206, 57%, 17%)',
purple: '#c5a5c5',
yellow: '#fac863',
green: '#5bd85d',
blue: '#79b6f2',
red: '#cc0000',
dark: 'hsl(206, 57%, 17%)',
dark2: 'hsl(206, 57%, 13%)',
dark3: 'hsl(206, 57%, 16%)',
white: 'hsl(0, 0%, 90%)',
white2: 'hsl(0, 0%, 85%)',
white3: 'hsl(0, 0%, 80%)',
white4: 'hsl(0, 0%, 75%)',
black: 'hsl(0, 0%, 20%)',
black2: 'hsl(0, 0%, 25%)',
gray: 'hsl(0, 0%, 90%)',
gray2: 'hsl(0, 0%, 95%)',
},
}
export const css = getThemeCss(variables)
export const theme = getTheme(variables)
export const colors = theme.colors