Skip to content

Instantly share code, notes, and snippets.

@innocenzi
Last active May 1, 2020 01:56
Show Gist options
  • Save innocenzi/44f984d74fcf493d5bc6b98ea4425b55 to your computer and use it in GitHub Desktop.
Save innocenzi/44f984d74fcf493d5bc6b98ea4425b55 to your computer and use it in GitHub Desktop.
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