Skip to content

Instantly share code, notes, and snippets.

@khamer
Created April 7, 2022 20:43
Show Gist options
  • Save khamer/f4c89b441d89c99d9374c97d858709ec to your computer and use it in GitHub Desktop.
Save khamer/f4c89b441d89c99d9374c97d858709ec to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
@use "sass:list";
@use "sass:string";
@use "sass:map";
// Skip to line 50
@function unslash-colons($str) {
$index: string.index($str, \:);
@if $index != null {
@return unslash-colons(string.slice($str, 1, $index - 1) + string.slice($str, $index + 1));
} @else {
@return $str;
}
}
@mixin modifiers($map, $default-map: (), $prefix: '.-', $suffixes: \:hover \:active \:focus) {
@each $pair in $map {
$key: list.nth($pair, 1);
$value: null;
@if list.length($pair) > 1 {
$value: list.nth($pair, 2);
} @else if map.has-key($default-map, $key) {
$value: map.get($default-map, $key);
}
@if $value != null {
&#{$prefix}#{unslash-colons($key)} {
@content($value);
}
} @else {
@content($key);
}
@each $suffix in $suffixes {
@if map.has-key($default-map, $key + $suffix) {
$value: map.get($default-map, $key + $suffix);
&#{$prefix}#{functions.unslash-colons($key + $suffix)} {
@content($value);
}
}
}
}
}
// Look below this line
.button {
@include modifiers((
primary red,
primary\:hover pink,
secondary blue,
secondary\:hover lightblue,
)) using ($color) {
color: $color;
}
}
.button2 {
@each $modifier, $color in (
"primary": red,
"primary:hover": pink,
"secondary": blue,
"secondary:hover": lightblue,
) {
&.-#{$modifier} {
color: $color;
}
}
}
.button.-primary {
color: red;
}
.button.-primary:hover {
color: pink;
}
.button.-secondary {
color: blue;
}
.button.-secondary:hover {
color: lightblue;
}
.button2.-primary {
color: red;
}
.button2.-primary:hover {
color: pink;
}
.button2.-secondary {
color: blue;
}
.button2.-secondary:hover {
color: lightblue;
}
{
"sass": {
"compiler": "dart-sass/1.32.12",
"extensions": {},
"syntax": "SCSS",
"outputStyle": "expanded"
},
"autoprefixer": false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment