Skip to content

Instantly share code, notes, and snippets.

@akccakcctw
Created September 30, 2017 07:42
Show Gist options
  • Save akccakcctw/5d8bb0d459307346d2c7f339d76bc7ca to your computer and use it in GitHub Desktop.
Save akccakcctw/5d8bb0d459307346d2c7f339d76bc7ca to your computer and use it in GitHub Desktop.
CSS variable mixin with @supports
$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