forked from benface/tailwindcss-gradients
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (35 loc) · 1.01 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
const _ = require('lodash');
module.exports = ({
variants = {},
directions = {
't': 'to top',
'tr': 'to top right',
'r': 'to right',
'br': 'to bottom right',
'b': 'to bottom',
'bl': 'to bottom left',
'l': 'to left',
'tl': 'to top left',
},
gradients = {},
} = {}) => ({ e, addUtilities }) => {
addUtilities(
{
...(function() {
const utilities = {};
_.forEach(gradients, (gradientColors, gradientName) => {
if (!_.isArray(gradientColors) || gradientColors.length === 1) {
gradientColors = ['transparent', _.isArray(gradientColors) ? gradientColors[0] : gradientColors];
}
_.forEach(directions, (directionValue, directionName) => {
utilities[`.${e(`bg-gradient-${directionName}-${gradientName}`)}`] = {
backgroundImage: `linear-gradient(${directionValue}, ${gradientColors.join(', ')})`,
};
});
});
return utilities;
})(),
},
variants,
);
};