-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
64 lines (57 loc) · 1.78 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const _ = require("lodash");
const heros = require("./patterns");
const defaultColors = {
default: "#9C92AC"
};
const defaultOpacity = {
default: 0.4
};
function flattenThemeColors(colors) {
const flatColors = {};
_.each(colors, (color, colorName) => {
if (typeof color === "object") {
_.each(color, (value, modifier) => {
flatColors[`${colorName}-${modifier}`] = value;
});
} else {
flatColors[colorName] = color;
}
})
return flatColors;
}
module.exports = function({
variants = [],
patterns = [],
colors = defaultColors,
opacity = defaultOpacity,
includeThemeColors = false,
}) {
return function({ e, addUtilities, theme }) {
if (patterns.length === 0) patterns = Object.keys(heros);
if (Object.keys(colors).length === 0) colors = defaultColors;
if (Object.keys(opacity).length === 0) opacity = defaultOpacity;
if (includeThemeColors) {
colors = {...colors, ...flattenThemeColors(theme("colors")) };
}
const newUtilities = _.map(opacity, (alpha, opacityName) => {
return _.map(colors, (color, colorName) => {
color = color.replace("#", "%23");
return patterns.reduce((o, patternName) => {
let className = `bg-hero-${patternName}`;
if (colorName != "default") className += `-${colorName}`;
if (opacityName != "default") className += `-${opacityName}`;
className = `.${e(className)}`;
if (!heros[patternName]) return Object.assign(o, {});
return Object.assign(o, {
[className]: {
backgroundImage: heros[patternName]
.replace("FILLCOLOR", color)
.replace("FILLOPACITY", alpha)
}
});
}, {});
});
});
addUtilities(newUtilities, variants);
};
};