generated from madrilene/eleventy-excellent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tailwind.config.js
143 lines (124 loc) · 3.99 KB
/
tailwind.config.js
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
/* © Andy Bell - https://github.com/Set-Creative-Studio/cube-boilerplate */
import plugin from 'tailwindcss/plugin';
import postcss from 'postcss';
import postcssJs from 'postcss-js';
import {clampGenerator} from './src/_config/utils/clamp-generator.js';
import {tokensToTailwind} from './src/_config/utils/tokens-to-tailwind.js';
// Raw design tokens
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 textSizeTokens from './src/_data/designTokens/textSizes.json';
import textLeadingTokens from './src/_data/designTokens/textLeading.json';
import textWeightTokens from './src/_data/designTokens/textWeights.json';
import viewportTokens from './src/_data/designTokens/viewports.json';
// Process design tokens
const colors = tokensToTailwind(colorTokens.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`,
navigation: `${viewportTokens.navigation}px`
},
colors,
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: '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))
});
}),
// Generates custom utility classes
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]}`))
});
});
});
})
]
};