Created
May 10, 2019 21:45
-
-
Save zeshanshani/18297141d1165463260b29d0d871e8a9 to your computer and use it in GitHub Desktop.
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
// Usage: m-0 to m-7 | |
// Usage: p-0 to p-7 | |
// Usage: mb-0 to mb-7 | |
$sizeUnit: rem; | |
$marginKey: 'm'; | |
$paddingKey: 'p'; | |
$separator: '-'; | |
$sizes: ( | |
('0', 0), | |
('1', 0.125), | |
('2', 0.25), | |
('3', 0.5), | |
('4', 1), | |
('5', 2), | |
('6', 4), | |
('7', 8), | |
); | |
$positions: ( | |
('t', 'top'), | |
('r', 'right'), | |
('b', 'bottom'), | |
('l', 'left') | |
); | |
@function sizeValue( $key, $value ) { | |
@return if( $key == 'none', 0, $value + $sizeUnit ); | |
} | |
// Run through all sizes. | |
@each $size in $sizes { | |
$sizeKey: nth( $size, 1 ); | |
$sizeValue: nth( $size, 2 ); | |
// For all positions margin | |
.#{$marginKey}#{$separator}#{$sizeKey} { | |
margin: sizeValue( $sizeKey, $sizeValue ) !important; | |
} | |
// For all positions padding | |
.#{$paddingKey}#{$separator}#{$sizeKey} { | |
padding: sizeValue( $sizeKey, $sizeValue ) !important; | |
} | |
// For each position | |
@each $position in $positions { | |
$posKey: nth( $position, 1 ); | |
$posValue: nth( $position, 2 ); | |
// For each margin | |
.#{$marginKey}#{$posKey}#{$separator}#{$sizeKey} { | |
margin-#{$posValue}: sizeValue( $sizeKey, $sizeValue ) !important; | |
} | |
// For each padding | |
.#{$paddingKey}#{$posKey}#{$separator}#{$sizeKey} { | |
padding-#{$posValue}: sizeValue( $sizeKey, $sizeValue ) !important; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment