Last active
May 16, 2023 10:22
-
-
Save vivid-web/8f7a23fe8b172b4238b6 to your computer and use it in GitHub Desktop.
BEM Helper (SCSS, SASS, LESS, Stylus)
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
// Mixins | |
.has(@element; @content) { | |
&__@{element} { | |
@content(); | |
} | |
} | |
.variant(@modifier; @content) { | |
&--@{modifier} { | |
@content(); | |
} | |
} | |
// Example | |
.Alert { | |
padding: 20px; | |
position: relative; | |
width: 500px; | |
.variant(danger; { | |
background-color: #c00; | |
color: #300; | |
}); | |
.has(close-button; { | |
display: inline-block; | |
position: absolute; | |
right: 20px; | |
top: 20px; | |
.variant(danger; { | |
color: #c00; | |
}); | |
}); | |
} |
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
// Mixins | |
=has($element) | |
@at-root #{&}__#{$element} | |
@content | |
=variant($modifier) | |
@at-root #{&}--#{$modifier} | |
@content | |
// Example | |
.Alert | |
padding: 20px | |
position: relative | |
width: 500px | |
+variant(danger) | |
background-color: #c00 | |
color: #300 | |
+has(close-button) | |
display: inline-block | |
position: absolute | |
right: 20px | |
top: 20px | |
+variant(danger) | |
color: #c00; |
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
// Mixins | |
@mixin has($element) { | |
&__#{$element} { | |
@content; | |
} | |
} | |
@mixin variant($modifier) { | |
&--#{$modifier} { | |
@content; | |
} | |
} | |
// Example | |
.Alert { | |
padding: 20px; | |
position: relative; | |
width: 500px; | |
@include variant(danger) { | |
background-color: #c00; | |
color: #300; | |
} | |
@include has(close-button) { | |
display: inline-block; | |
position: absolute; | |
right: 20px; | |
top: 20px; | |
@include variant(danger) { | |
color: #c00; | |
} | |
} | |
} |
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
// Mixins | |
has($element) | |
/&__{$element} | |
{block} | |
variant($modifier) | |
/&--{$modifier} | |
{block} | |
// Example | |
.Alert | |
padding: 20px | |
position: relative | |
width: 500px | |
+variant(danger) | |
background-color: #c00 | |
color: #300 | |
+has(close-button) | |
display: inline-block | |
position: absolute | |
right: 20px | |
top: 20px | |
+has(danger) | |
color: #c00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment