Last active
August 8, 2016 20:35
-
-
Save keithjgrant/fc4edca2a5837d17aff6c4b4528b2733 to your computer and use it in GitHub Desktop.
Native Custom Properties + transpiled color()
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
: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%)); | |
} |
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
: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); | |
} |
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
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trying to decide if there are some "gotchas" to this approach that aren't immediately apparent...