-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtailwindPlugin.ts
57 lines (46 loc) · 1.36 KB
/
tailwindPlugin.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
import plugin from 'tailwindcss/plugin'
import type {
CSSRuleObject,
KeyValuePair,
RecursiveKeyValuePair,
} from 'tailwindcss/types/config'
import { themeVars } from './themeVars'
export const tailwindPlugin = plugin(
({ addComponents }) => {
const utilities: CSSRuleObject = {}
//typography
for (const key in themeVars.typography) {
const style =
themeVars.typography[key as keyof typeof themeVars.typography]
const utility = {
color: themeVars.colors.typography.regular,
fontFamily: themeVars.fontFamily,
fontSize: style.fontSize + 'px',
fontWeight: style.fontWeight,
lineHeight: style.lineHeight + 'px',
}
utilities[`.${key}`] = utility
}
addComponents(utilities)
},
{
theme: {
extend: {
colors: (() => {
const colors: RecursiveKeyValuePair = {}
for (const colorKey in themeVars.colors) {
const colorVariants =
themeVars.colors[colorKey as keyof typeof themeVars.colors]
const colorValues: KeyValuePair = {}
for (const key in colorVariants) {
const color = colorVariants[key as keyof typeof colorVariants]
colorValues[key] = color
}
colors[colorKey] = colorValues
}
return colors
})(),
},
},
}
)