forked from madrilene/eleventy-excellent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtailwind.config.js
More file actions
189 lines (168 loc) · 5.49 KB
/
Copy pathtailwind.config.js
File metadata and controls
189 lines (168 loc) · 5.49 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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* © Andy Bell - https://github.com/Set-Creative-Studio/cube-boilerplate */
import postcss from 'postcss';
import postcssJs from 'postcss-js';
import plugin from 'tailwindcss/plugin';
import {clampGenerator} from './src/_config/utils/clamp-generator.js';
import {tokensToTailwind} from './src/_config/utils/tokens-to-tailwind.js';
// Raw design tokens
import borderRadiusTokens from './src/_data/designTokens/borderRadius.json';
import colorTokens from './src/_data/designTokens/colors.json';
import fontTokens from './src/_data/designTokens/fonts.json';
import spacingTokens from './src/_data/designTokens/spacing.json';
import textLeadingTokens from './src/_data/designTokens/textLeading.json';
import textSizeTokens from './src/_data/designTokens/textSizes.json';
import textWeightTokens from './src/_data/designTokens/textWeights.json';
import viewportTokens from './src/_data/designTokens/viewports.json';
const tokenPrefixes = {
colors: colorTokens.prefix ?? 'color',
borderRadius: borderRadiusTokens.prefix ?? 'border-radius',
spacing: spacingTokens.prefix ?? 'space',
fontSize: textSizeTokens.prefix ?? 'size',
lineHeight: textLeadingTokens.prefix ?? 'leading',
fontFamily: fontTokens.prefix ?? 'font',
fontWeight: textWeightTokens.prefix ?? 'font'
};
const tokenColors = tokensToTailwind(colorTokens.items);
const semanticColors = {
'theme-light': 'var(--color-light)',
'theme-dark': 'var(--color-dark)',
'theme-mid': 'var(--color-mid)',
'theme-text': 'var(--color-text)',
'theme-text-accent': 'var(--color-text-accent)',
'theme-bg': 'var(--color-bg)',
'theme-bg-accent': 'var(--color-bg-accent)',
'theme-primary': 'var(--color-primary)',
'theme-secondary': 'var(--color-secondary)',
'theme-tertiary': 'var(--color-tertiary)'
};
// Process design tokens
const colors = {...tokenColors, ...semanticColors};
const borderRadius = tokensToTailwind(borderRadiusTokens.items);
const fontFamily = tokensToTailwind(fontTokens.items);
const fontSize = tokensToTailwind(clampGenerator(textSizeTokens.items));
const fontWeight = tokensToTailwind(textWeightTokens.items);
const lineHeight = tokensToTailwind(textLeadingTokens.items);
const spacing = tokensToTailwind(clampGenerator(spacingTokens.items));
export default {
content: ['./src/**/*.{html,js,md,njk,liquid,webc}'],
presets: [],
theme: {
screens: {
ltsm: {max: `${viewportTokens.sm}px`},
sm: `${viewportTokens.sm}px`,
md: `${viewportTokens.md}px`,
ltnavigation: {max: `${viewportTokens.navigation}px`},
navigation: `${viewportTokens.navigation}px`
},
colors,
borderRadius,
spacing,
fontFamily,
fontSize,
fontWeight,
lineHeight,
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'
],
// Disables Tailwind's reset etc
corePlugins: {
preflight: false,
textOpacity: false,
backgroundOpacity: false,
borderOpacity: false
},
// Prevents Tailwind's core components
blocklist: ['container'],
// Prevents Tailwind from generating that wall of empty custom properties
experimental: {
optimizeUniversalDefaults: true
},
plugins: [
// Generates custom property values from tailwind config
plugin(function ({addComponents, config}) {
let result = '';
const currentConfig = config();
const groups = [
{key: 'colors', prefix: tokenPrefixes.colors},
{key: 'borderRadius', prefix: tokenPrefixes.borderRadius},
{key: 'spacing', prefix: tokenPrefixes.spacing},
{key: 'fontSize', prefix: tokenPrefixes.fontSize},
{key: 'lineHeight', prefix: tokenPrefixes.lineHeight},
{key: 'fontFamily', prefix: tokenPrefixes.fontFamily},
{key: 'fontWeight', prefix: tokenPrefixes.fontWeight}
];
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))
});
}),
// Generates custom utility classes
plugin(function ({addUtilities, config}) {
const currentConfig = config();
const customUtilities = [
{
key: 'spacing',
prefix: `flow-${tokenPrefixes.spacing}`,
property: '--flow-space'
},
{
key: 'spacing',
prefix: `region-${tokenPrefixes.spacing}`,
property: '--region-space'
},
{
key: 'spacing',
prefix: 'gutter',
property: '--gutter'
},
{
key: 'colors',
prefix: `spot-${tokenPrefixes.colors}`,
property: '--spot-color'
}
];
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]}`))
});
});
});
})
]
};