Last active
January 24, 2021 11:19
-
-
Save jakob-e/48ef59b3631a028b69f2b7c612b22d43 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
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
// ---------------------------------------- | |
// emulate mixin-context | |
// ---------------------------------------- | |
$mixin-context-list: (); | |
@mixin mixin-context($name){ | |
$mixin-context-list: append($mixin-context-list, $name, comma) !global; | |
@content; | |
$mixin-context-list: nth-remove($mixin-context-list, -1) !global; | |
} | |
@function mixin-context(){ | |
@return $mixin-context-list; | |
} | |
// helper | |
@function nth-remove($list, $n){ | |
$r: ();$n: if($n < 0, length($list) + $n + 1, $n); $b: is-bracketed($list); $s: list-separator($list); | |
@for $i from 1 through length($list){ @if $i != $n { $r: append($r, nth($list, $i)); }} | |
@return join((), $r, $s, $b); | |
} | |
// ---------------------------------------- | |
// ---------------------------------------- | |
// Mixins | |
// ---------------------------------------- | |
@mixin button { | |
@include mixin-context(button){ | |
button { | |
mixin-context: mixin-context(); | |
@if index(mixin-context(), log-in){ | |
message: 'login buttons are special'; | |
} | |
} | |
} | |
} | |
@mixin card { | |
@include mixin-context(card){ | |
.card { | |
@include button; | |
} | |
} | |
} | |
@mixin collection { | |
@include mixin-context(collection){ | |
.collection { | |
@include card; | |
} | |
} | |
} | |
@mixin sign-up { | |
@include mixin-context(sign-up){ | |
.sign-up { | |
@include button; | |
} | |
} | |
} | |
@mixin log-in { | |
@include mixin-context(log-in){ | |
.log-in { | |
@include button; | |
} | |
} | |
} | |
@mixin modal { | |
@include mixin-context(modal){ | |
.modal { | |
@include log-in; | |
} | |
} | |
} | |
@mixin sidebar { | |
@include mixin-context(sidebar){ | |
.sidebar { | |
@include collection; | |
@include button; | |
} | |
} | |
} | |
// ---------------------------------------- | |
// Assemble | |
// ---------------------------------------- | |
@include button; | |
@include log-in; | |
@include card; | |
@include collection; | |
@include sign-up; | |
@include sidebar; | |
@include modal; | |
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
button { | |
mixin-context: button; | |
} | |
.log-in button { | |
mixin-context: log-in, button; | |
message: "login buttons are special"; | |
} | |
.card button { | |
mixin-context: card, button; | |
} | |
.collection .card button { | |
mixin-context: collection, card, button; | |
} | |
.sign-up button { | |
mixin-context: sign-up, button; | |
} | |
.sidebar .collection .card button { | |
mixin-context: sidebar, collection, card, button; | |
} | |
.sidebar button { | |
mixin-context: sidebar, button; | |
} | |
.modal .log-in button { | |
mixin-context: modal, log-in, button; | |
message: "login buttons are special"; | |
} |
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
{ | |
"sass": { | |
"compiler": "dart-sass/1.26.11", | |
"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