Last active
November 15, 2024 15:56
-
-
Save sarahdayan/4d2cc04a636e8039f10a889a0e29fbd9 to your computer and use it in GitHub Desktop.
Sass Modifiers Mixin
This file contains hidden or 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 (v3.4.21) | |
// Compass (v1.0.3) | |
// ---- | |
// Sass modifiers mixin by Sarah Dayan | |
// Generate All Your Utility Classes with Sass Maps: frontstuff.io/generate-all-your-utility-classes-with-sass-maps | |
// http://frontstuff.io | |
// https://github.com/sarahdayan | |
$colors: ( | |
red: #ff3538, | |
grey: ( | |
base: #404145, | |
light: #c7c7cd | |
), | |
yellow: ( | |
base: #ecaf2d | |
), | |
green: ( | |
base: #5ad864 | |
) | |
); | |
$font-sizes: ( | |
small: 12px, | |
medium: 14px, | |
large: 16px, | |
x-large: 18px, | |
xx-large: 20px | |
); | |
@mixin modifiers($map, $attribute, $prefix: '-', $separator: '-', $base: 'base') { | |
@each $key, $value in $map { | |
&#{if($key != $base, #{$prefix}#{$key}, '')} { | |
@if type-of($value) == 'map' { | |
@include modifiers($value, $attribute, $separator); | |
} | |
@else { | |
#{$attribute}: $value; | |
} | |
} | |
} | |
} | |
.text { | |
@include modifiers($colors, 'color', $separator: ':'); | |
@include modifiers($font-sizes, 'font-size', '--'); | |
} |
This file contains hidden or 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
.text-red { | |
color: #ff3538; | |
} | |
.text-grey { | |
color: #404145; | |
} | |
.text-grey:light { | |
color: #c7c7cd; | |
} | |
.text-yellow { | |
color: #ecaf2d; | |
} | |
.text-green { | |
color: #5ad864; | |
} | |
.text--small { | |
font-size: 12px; | |
} | |
.text--medium { | |
font-size: 14px; | |
} | |
.text--large { | |
font-size: 16px; | |
} | |
.text--x-large { | |
font-size: 18px; | |
} | |
.text--xx-large { | |
font-size: 20px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the article, very well explained!