]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Refactor grid-framework followup
authorGleb Mazovetskiy <glex.spb@gmail.com>
Sun, 7 Dec 2014 14:52:44 +0000 (14:52 +0000)
committerGleb Mazovetskiy <glex.spb@gmail.com>
Sun, 7 Dec 2014 16:22:39 +0000 (16:22 +0000)
* Split up calc-grid-column, generate selectors in make-grid
* Iterate over $grid-breakpoints and (pull, push, offset)

scss/_variables.scss
scss/mixins/_grid-framework.scss

index 5f41979f0e3788117ceef4c5db7704455a13ddc0..8f9e26d68dc55289ec3223a52b7eafa0f67f6ee3 100644 (file)
@@ -294,7 +294,7 @@ $screen-xs-max:              ($screen-sm-min - .1);
 //== Grid system
 //
 //## Define your custom responsive grid.
-
+$grid-breakpoints: (xs sm md lg xl);
 //** Number of columns in the grid.
 $grid-columns:               12;
 //** Padding between columns. Gets divided in half for the left and right.
index 5ac62751fd055bbb609c88982aa6f1910434f950..3eecbae8b27788c6edcc8c640757ac9d5b7c1409 100644 (file)
@@ -3,65 +3,69 @@
 // Used only by Bootstrap to generate the correct number of grid classes given
 // any value of `$grid-columns`.
 
-%twbs-grid-column {
-  position: relative;
-  // Prevent columns from collapsing when empty
-  min-height: 1px;
-  // Inner gutter via padding
-  padding-left: ($grid-gutter-width / 2);
-  padding-right: ($grid-gutter-width / 2);
-}
-
-%twbs-grid-column-float {
-  float: left
-}
-
-@mixin make-grid-columns($columns: $grid-columns) {
-  @for $i from 1 through $columns {
-    .col-xs-#{$i}, .col-sm-#{$i}, .col-md-#{$i}, .col-lg-#{$i}, .col-xl-#{$i} {
-      @extend %twbs-grid-column;
-    }
+// Common properties for all breakpoints
+@mixin make-grid-columns($columns: $grid-columns, $breakpoints: $grid-breakpoints) {
+  %grid-column {
+    position: relative;
+    // Prevent columns from collapsing when empty
+    min-height: 1px;
+    // Inner gutter via padding
+    padding-left: ($grid-gutter-width / 2);
+    padding-right: ($grid-gutter-width / 2);
   }
-}
-
-@mixin float-grid-columns($class, $columns: $grid-columns) {
   @for $i from 1 through $columns {
-    .col-#{$class}-#{$i} {
-      @extend %twbs-grid-column-float;
+    @each $breakpoint in $breakpoints {
+      .col-#{$breakpoint}-#{$i} {
+        @extend %grid-column;
+      }
     }
   }
 }
 
-@mixin calc-grid-column($index, $class, $type, $columns: $grid-columns) {
-  @if ($type == width) and ($index > 0) {
-    .col-#{$class}-#{$index} {
-      width: percentage($index / $columns);
-    }
-  }
-  @if $type == push {
-    .col-#{$class}-push-#{$index} {
-      left: if($index > 0, percentage($index / $columns), auto);
-    }
+// Breakpoint-specific properties
+@mixin make-grid($breakpoint, $columns: $grid-columns) {
+  // Work around cross-media @extend (https://github.com/sass/sass/issues/1050)
+  %grid-column-float-#{$breakpoint} {
+    float: left;
   }
-  @if $type == pull {
-    .col-#{$class}-pull-#{$index} {
-      right: if($index > 0, percentage($index / $columns), auto);
+  @for $i from 1 through $columns {
+    .col-#{$breakpoint}-#{$i} {
+      @extend %grid-column-float-#{$breakpoint};
+      @include grid-column-width($i, $columns);
     }
   }
-  @if $type == offset {
-    .col-#{$class}-offset-#{$index} {
-      margin-left: percentage($index / $columns);
+  @each $modifier in (pull, push, offset) {
+    @for $i from 0 through $columns {
+      .col-#{$breakpoint}-#{$modifier}-#{$i} {
+        @include grid-column-modifier($modifier, $i, $columns)
+      }
     }
   }
 }
 
-// Create grid for specific class
-@mixin make-grid($class, $columns: $grid-columns) {
-  @include float-grid-columns($class);
-  @for $i from 0 through $columns {
-    @include calc-grid-column($i, $class, width, $columns);
-    @include calc-grid-column($i, $class, push, $columns);
-    @include calc-grid-column($i, $class, pull, $columns);
-    @include calc-grid-column($i, $class, offset, $columns);
+@mixin grid-column-width($index, $columns) {
+  width: percentage($index / $columns);
+}
+
+@mixin grid-column-push($index, $columns) {
+  left: if($index > 0, percentage($index / $columns), auto);
+}
+
+@mixin grid-column-pull($index, $columns) {
+  right: if($index > 0, percentage($index / $columns), auto);
+}
+
+@mixin grid-column-offset($index, $columns) {
+  margin-left: percentage($index / $columns);
+}
+
+// Work around the lack of dynamic mixin @include support (https://github.com/sass/sass/issues/626)
+@mixin grid-column-modifier($type, $index, $columns) {
+  @if $type == push {
+    @include grid-column-push($index, $columns);
+  } @else if $type == pull {
+    @include grid-column-pull($index, $columns);
+  } @else if $type == offset {
+    @include grid-column-offset($index, $columns);
   }
 }