-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
74 lines (69 loc) · 2.67 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
65
66
67
68
69
70
71
72
73
74
const _ = require('lodash');
const Color = require('color');
module.exports = function() {
return ({ theme, e, addComponents, postcss }) => {
const defaultBgColors = {};
const rippleBgColors = theme('ripple.colors', defaultBgColors);
const defaultDarkenValue = 0.2;
let darkenValue = theme('ripple.darken', defaultDarkenValue);
if (isNaN(darkenValue) || darkenValue > 1 || darkenValue < 0) {
darkenValue = defaultDarkenValue;
}
const defaultModifierTransition = 'background 0.8s';
let modifierTransition = theme('ripple.modifierTransition', defaultModifierTransition);
const defaultActiveTransition = 'background 0s';
let activeTransition = theme('ripple.activeTransition', defaultActiveTransition);
function returnColorPair([modifier, value]) {
return [
`${modifier}`,
{
backgroundColor: value,
backgroundPosition: 'center',
transition: modifierTransition,
'&:hover': {
background: `${Color(value)
.darken(darkenValue)
.hex()
.toString()} radial-gradient(circle, transparent 1%, ${Color(
value
)
.darken(darkenValue)
.hex()
.toString()} 1%) center/15000%`,
},
'&:active': {
backgroundColor: value,
backgroundSize: '100%',
transition: activeTransition,
},
},
];
}
const allTheColors = _(rippleBgColors)
.flatMap((value, modifier) => {
if (typeof value == 'object') {
return _.map(value, (v, m) => {
return [`.${e(`ripple-bg-${modifier}-${m}`)}`, v];
});
}
if (
typeof value == 'string' &&
value.length > 1
) {
try {
Color(value)
} catch (err) {
return [];
}
return [[`.${e(`ripple-bg-${modifier}`)}`, value]];
}
})
.value();
const components = _.fromPairs(
_.map(allTheColors, (color, index) => {
return returnColorPair(color);
})
);
addComponents(components);
};
};