-
Notifications
You must be signed in to change notification settings - Fork 0
/
tailwind.config.ts
143 lines (128 loc) · 3.91 KB
/
tailwind.config.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
134
135
136
137
138
139
140
141
142
143
import { type Config } from 'tailwindcss'
import plugin from 'tailwindcss/plugin'
import postcss from 'postcss'
import postcssJs from 'postcss-js'
import clampGenerator from './src/css-utils/clamp-generator'
import tokensToTailwind from './src/css-utils/tokens-to-tailwind'
// Raw design tokens
import colorTokens from './src/design-tokens/colors.json'
import fontTokens from './src/design-tokens/fonts.json'
import spacingTokens from './src/design-tokens/spacing.json'
import textSizeTokens from './src/design-tokens/text-sizes.json'
import textLeadingTokens from './src/design-tokens/text-leading.json'
import textWeightTokens from './src/design-tokens/text-weights.json'
import viewportTokens from './src/design-tokens/viewports.json'
// Process design tokens
const colors = tokensToTailwind(colorTokens.items)
const fontFamily = tokensToTailwind(fontTokens.items)
const fontWeight = tokensToTailwind(textWeightTokens.items)
const fontSize = tokensToTailwind(clampGenerator(textSizeTokens.items))
const lineHeight = tokensToTailwind(textLeadingTokens.items)
const spacing = tokensToTailwind(clampGenerator(spacingTokens.items))
const tailwindConfig: Config = {
content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],
safelist: [],
theme: {
screens: {
sm: `${viewportTokens.sm}px`,
md: `${viewportTokens.md}px`,
lg: `${viewportTokens.lg}px`,
xl: `${viewportTokens.xl}px`,
},
colors,
spacing: () => ({
'0': '0',
px: '1px',
...spacing,
}),
fontSize,
lineHeight,
fontFamily,
fontWeight,
backgroundColor: ({ theme }) => theme('colors'),
textColor: ({ theme }) => theme('colors'),
margin: ({ theme }) => ({
auto: 'auto',
...theme('spacing'),
}),
padding: ({ theme }) => ({
...theme('spacing'),
}),
},
variantOrder: [
'first',
'last',
'odd',
'even',
'visited',
'checked',
'empty',
'read-only',
'group-hover',
'group-focus',
'focus-within',
'hover',
'focus',
'focus-visible',
'active',
'disabled',
],
corePlugins: {
preflight: false,
textOpacity: false,
backgroundOpacity: false,
borderOpacity: false,
},
blocklist: ['container'],
// Remove empty custom properties
// experimental: {
// optimizeUniversalDefaults: true,
// },
// Add custom properties from the design-tokens to the root element
plugins: [
plugin(function ({ addComponents, config }) {
let result = ''
const currentConfig = config()
const groups = [
{ key: 'colors', prefix: 'color' },
{ key: 'spacing', prefix: 'space' },
{ key: 'fontSize', prefix: 'size' },
{ key: 'lineHeight', prefix: 'leading' },
{ key: 'fontFamily', prefix: 'font' },
{ key: 'fontWeight', prefix: 'font' },
]
groups.forEach(({ key, prefix }) => {
const group = currentConfig?.theme?.[key]
if (!group) {
return
}
Object.keys(group).forEach((key) => {
result += `--${prefix}-${key}: ${group[key]};`
})
})
addComponents({
':root': postcssJs.objectify(postcss.parse(result)),
})
}),
plugin(function ({ addUtilities, config }) {
const currentConfig = config()
const customUtilities = [
{ key: 'spacing', prefix: 'flow-space', property: '--flow-space' },
{ key: 'spacing', prefix: 'region-space', property: '--region-space' },
{ key: 'spacing', prefix: 'gutter', property: '--gutter' },
]
customUtilities.forEach(({ key, prefix, property }) => {
const group = currentConfig?.theme?.[key]
if (!group) {
return
}
Object.keys(group).forEach((key) => {
addUtilities({
[`.${prefix}-${key}`]: postcssJs.objectify(postcss.parse(`${property}: ${group[key]}`)),
})
})
})
}),
],
}
export default tailwindConfig