Created
September 30, 2017 07:42
-
-
Save akccakcctw/5d8bb0d459307346d2c7f339d76bc7ca to your computer and use it in GitHub Desktop.
CSS variable mixin with @supports
This file contains 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
$colors: ( | |
origin: grey, | |
warning: orange, | |
danger: red | |
); | |
:root { | |
@each $key, $color in $colors { | |
--#{key}: $color; | |
} | |
} | |
@mixin bgcss($prop, $key) { | |
#{$prop}: map-get($colors, $key); | |
@if (map-has-key($colors, $key) == false) { | |
@error "Unknown key `#{$key}`. checkout your `$colors` variable"; | |
} | |
@supports (--foo: "bar") { | |
#{$prop}: var(--#{$key}); | |
} | |
} | |
.container { | |
@include bgcss('background-color', "origin"); | |
} | |
// compiled | |
:root { | |
--main: grey; | |
--font: orange; | |
--danger: red; | |
} | |
.container { | |
background-color: grey; | |
@supports (--foo: "bar") { | |
background-color: var(--origin); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment