Skip to content

Commit

Permalink
use $responsive-variants for margin utils
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnbot committed Jul 18, 2018
1 parent cff39b5 commit 6bf88ce
Showing 1 changed file with 28 additions and 61 deletions.
89 changes: 28 additions & 61 deletions modules/primer-utilities/lib/margin.scss
Original file line number Diff line number Diff line change
@@ -1,86 +1,53 @@
// Margin spacer utilities
// stylelint-disable block-opening-brace-space-before, declaration-colon-space-before, primer/selector-no-utility, comment-empty-line-before
@for $i from 1 through length($spacers) {
$size: #{nth($spacers, $i)};
$scale: #{$i - 1};

/* Set a #{$size} margin to all sides */
.m-#{$scale} { margin : #{$size} !important; }
/* Set a #{$size} margin on the top */
.mt-#{$scale} { margin-top : #{$size} !important; }
/* Set a #{$size} margin on the right */
.mr-#{$scale} { margin-right : #{$size} !important; }
/* Set a #{$size} margin on the bottom */
.mb-#{$scale} { margin-bottom: #{$size} !important; }
/* Set a #{$size} margin on the left */
.ml-#{$scale} { margin-left : #{$size} !important; }
/* Set a negative #{$size} margin on top */
.mt-n#{$scale} { margin-top : -#{$size} !important; }
/* Set a negative #{$size} margin on the right */
.mr-n#{$scale} { margin-right : -#{$size} !important; }
/* Set a negative #{$size} margin on the bottom */
.mb-n#{$scale} { margin-bottom: -#{$size} !important; }
/* Set a negative #{$size} margin on the left */
.ml-n#{$scale} { margin-left : -#{$size} !important; }

/* Set a #{$size} margin on the left & right */
.mx-#{$scale} {
margin-right: #{$size} !important;
margin-left : #{$size} !important;
}

/* Set a #{$size} margin on the top & bottom */
.my-#{$scale} {
margin-top : #{$size} !important;
margin-bottom: #{$size} !important;
}
}

/* Set an auto margin on left & right */
.mx-auto {
margin-right: auto !important;
margin-left: auto !important;
}

// Loop through the breakpoint values
@each $breakpoint in map-keys($breakpoints) {

// Loop through the spacer values
@for $i from 1 through length($spacers) {
@include breakpoint($breakpoint) {
@each $breakpoint, $variant in $responsive-variants {
@include breakpoint($breakpoint) {
// Loop through the spacer values
@for $i from 1 through length($spacers) {
$size: #{nth($spacers, $i)}; // sm, md, lg, xl
$scale: #{$i - 1}; // 0, 1, 2, 3, 4, 5, 6

/* Set a #{$size} margin to all sides at the breakpoint #{$breakpoint} */
.m-#{$breakpoint}-#{$scale} { margin: #{$size} !important; }
.m#{$variant}-#{$scale} { margin: #{$size} !important; }
/* Set a #{$size} margin on the top at the breakpoint #{$breakpoint} */
.mt-#{$breakpoint}-#{$scale} { margin-top: #{$size} !important; }
.mt#{$variant}-#{$scale} { margin-top: #{$size} !important; }
/* Set a #{$size} margin on the right at the breakpoint #{$breakpoint} */
.mr-#{$breakpoint}-#{$scale} { margin-right: #{$size} !important; }
.mr#{$variant}-#{$scale} { margin-right: #{$size} !important; }
/* Set a #{$size} margin on the bottom at the breakpoint #{$breakpoint} */
.mb-#{$breakpoint}-#{$scale} { margin-bottom: #{$size} !important; }
.mb#{$variant}-#{$scale} { margin-bottom: #{$size} !important; }
/* Set a #{$size} margin on the left at the breakpoint #{$breakpoint} */
.ml-#{$breakpoint}-#{$scale} { margin-left: #{$size} !important; }
/* Set a negative #{$size} margin on top at the breakpoint #{$breakpoint} */
.mt-#{$breakpoint}-n#{$scale} { margin-top : -#{$size} !important; }
/* Set a negative #{$size} margin on the right at the breakpoint #{$breakpoint} */
.mr-#{$breakpoint}-n#{$scale} { margin-right : -#{$size} !important; }
/* Set a negative #{$size} margin on the bottom at the breakpoint #{$breakpoint} */
.mb-#{$breakpoint}-n#{$scale} { margin-bottom: -#{$size} !important; }
/* Set a negative #{$size} margin on the left at the breakpoint #{$breakpoint} */
.ml-#{$breakpoint}-n#{$scale} { margin-left : -#{$size} !important; }
.ml#{$variant}-#{$scale} { margin-left: #{$size} !important; }

@if $size != 0 {
/* Set a negative #{$size} margin on top at the breakpoint #{$breakpoint} */
.mt#{$variant}-n#{$scale} { margin-top : -#{$size} !important; }
/* Set a negative #{$size} margin on the right at the breakpoint #{$breakpoint} */
.mr#{$variant}-n#{$scale} { margin-right : -#{$size} !important; }
/* Set a negative #{$size} margin on the bottom at the breakpoint #{$breakpoint} */
.mb#{$variant}-n#{$scale} { margin-bottom: -#{$size} !important; }
/* Set a negative #{$size} margin on the left at the breakpoint #{$breakpoint} */
.ml#{$variant}-n#{$scale} { margin-left : -#{$size} !important; }
}

/* Set a #{$size} margin on the left & right at the breakpoint #{$breakpoint} */
.mx-#{$breakpoint}-#{$scale} {
.mx#{$variant}-#{$scale} {
margin-right: #{$size} !important;
margin-left: #{$size} !important;
}

/* Set a #{$size} margin on the top & bottom at the breakpoint #{$breakpoint} */
.my-#{$breakpoint}-#{$scale} {
.my#{$variant}-#{$scale} {
margin-top: #{$size} !important;
margin-bottom: #{$size} !important;
}
}
}
}

/* Set an auto margin on left & right */
.mx-auto {
margin-right: auto !important;
margin-left: auto !important;
}

0 comments on commit 6bf88ce

Please sign in to comment.