Merge pull request #1676 from innocenzi/color-closure

Allow colors to be defined as closures
This commit is contained in:
Adam Wathan 2020-08-15 09:09:46 -04:00 • committed by GitHub
commit 7371ea992b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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({ opacityVariable: variable }),
}
}
try {
const [r, g, b, a] = toRgba(color)