Last active
May 1, 2020 01:56
-
-
Save innocenzi/44f984d74fcf493d5bc6b98ea4425b55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function withAlphaVariable({ color, property, variable }) { | |
if (_.isFunction(color)) { | |
return { | |
[property]: color(variable), | |
} | |
} | |
try { | |
const [r, g, b, a] = toRgba(color) | |
if (a !== undefined) { | |
return { | |
[property]: color, | |
} | |
} | |
return { | |
[variable]: '1', | |
[property]: [color, `rgba(${r}, ${g}, ${b}, var(${variable}))`], | |
} | |
} catch (error) { | |
return { | |
[property]: color, | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment