Allow colors to be defined as closures

This commit is contained in:
Haew 2020-05-01 05:22:52 +02:00
parent 67ec21e870
commit 109dec1681
2 changed files with 19 additions and 0 deletions

View file

@ -1,4 +1,5 @@
import createColor from 'color'
import _ from 'lodash'
function hasAlpha(color) {
return (
@ -18,6 +19,12 @@ function toRgba(color) {
}
export default function withAlphaVariable({ color, property, variable }) {
if (_.isFunction(color)) {
return {
[property]: color(variable),
}
}
try {
const [r, g, b, a] = toRgba(color)