Skip to content

Instantly share code, notes, and snippets.

@keithjgrant
Last active August 8, 2016 20:35
Show Gist options
  • Save keithjgrant/fc4edca2a5837d17aff6c4b4528b2733 to your computer and use it in GitHub Desktop.
Save keithjgrant/fc4edca2a5837d17aff6c4b4528b2733 to your computer and use it in GitHub Desktop.
Native Custom Properties + transpiled color()
:root {
--main-color: red;
--secondary-color: color(var(--main-color) hue(20%));
}
.module-one {
color: var(--main-color);
}
.module-two {
color: var(--secondary-color);
}
.module-three {
color: color(var(--main-color) hue(20%));
}
:root {
--main-color: red;
--secondary-color: rgb(255, 85, 0);
}
.module-one {
color: var(--main-color);
}
.module-two {
color: var(--secondary-color);
}
.module-three {
color: rgb(255, 85, 0);
}
The theory is this:
PostCSS plugin interprets (top-level) custom properties & knows their values,
but does not transpile them. If they are used to define new colors via
the color() function, the known variable value is used and the color()
is transpiled to the computed value.
It would have the same restrition as Custom Property transpiling does now:
only variables defined at the :root may be used inside color().
Of course, this would require a new PostCSS plugin that's a sort of
hybrid of postcss-custom-properties and postcss-color-function.
@keithjgrant
Copy link
Author

Trying to decide if there are some "gotchas" to this approach that aren't immediately apparent...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment