-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (42 loc) · 1.43 KB
/
index.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
module.exports = function ({ addUtilities, theme }) {
const breakpoints = theme('screens');
const userColors = theme('backgroundColorsByBreakpoint', {});
const allColors = theme('colors');
// Function to resolve Tailwind color classes to actual color codes
// Without this, only rgb values would have to be used instead of
// tailwind colors like 'red-500' or 'gray-100', etc
const resolveColor = (colorName) => {
const [color, shade] = colorName.split('-');
return allColors[color] && allColors[color][shade]
? allColors[color][shade]
: colorName;
};
const defaultColors = {
DEFAULT: 'black',
sm: '#a3e635',
md: '#f59e0b',
lg: '#ea580c',
xl: '#991b1b',
'2xl': '#881337',
};
// Merge user-defined colors with defaults, in order to override
// default colors with user-defined colors.
const finalColors = { ...defaultColors, ...userColors };
let newUtilities = {
'.bg-breakpoint': {
backgroundColor: finalColors.DEFAULT,
},
};
Object.entries(breakpoints).forEach(([breakpoint]) => {
if (finalColors[breakpoint]) {
const colorCode = resolveColor(finalColors[breakpoint]);
if (!newUtilities[`@screen ${breakpoint}`]) {
newUtilities[`@screen ${breakpoint}`] = {};
}
newUtilities[`@screen ${breakpoint}`]['.bg-breakpoint'] = {
backgroundColor: colorCode,
};
}
});
addUtilities(newUtilities, ['responsive']);
};