Created
June 1, 2019 19:18
-
-
Save sean-codes/85557a30fd06b33f01385b150debf383 to your computer and use it in GitHub Desktop.
SCSS: utility classes for margin/padding
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
// whitespace | |
$whitespace: 1rem; | |
$whitespace-types: ( | |
( 'short': p, 'long': padding ), | |
( 'short': m, 'long': margin ) | |
); | |
$whitespace-directions: ( | |
( 'name': t, 'prop': top ), | |
( 'name': b, 'prop': bottom ), | |
( 'name': l, 'prop': left ), | |
( 'name': r, 'prop': right ) | |
); | |
@for $typeId from 1 through length($whitespace-types) { | |
$type: nth($whitespace-types, $typeId); | |
$short: map-get($type, 'short'); | |
$long: map-get($type, 'long'); | |
.#{$short}-half { #{$long}: $whitespace/2; } | |
@for $o from 1 through 5 { | |
.#{$short}-#{$o} { #{$long}: $whitespace * $o; } | |
} | |
@for $i from 1 through length($whitespace-directions) { | |
$direction: nth($whitespace-directions, $i); | |
$name: map-get($direction, 'name'); | |
$prop: map-get($direction, 'prop'); | |
$classPrefix: #{$short}#{$name}; | |
$propPrefix: #{$long}-#{$prop}; | |
.#{$classPrefix}-half { #{$propPrefix}: $whitespace/2; } | |
@for $o from 1 through 5 { | |
.#{$classPrefix}-#{$o} { #{$propPrefix}: $whitespace * $o; } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment