| 1 |
// Grid system |
| 2 |
// |
| 3 |
// Generate semantic grid columns with these mixins. |
| 4 |
|
| 5 |
@mixin make-row($gutter: $grid-gutter-width) { |
| 6 |
--#{$prefix}gutter-x: #{$gutter}; |
| 7 |
--#{$prefix}gutter-y: 0; |
| 8 |
display: flex; |
| 9 |
display: -webkit-flex; |
| 10 |
flex-wrap: wrap; |
| 11 |
-webkit-flex-wrap: wrap; |
| 12 |
// TODO: Revisit calc order after https://github.com/react-bootstrap/react-bootstrap/issues/6039 is fixed |
| 13 |
margin-top: calc(-1 * var(--#{$prefix}gutter-y)); // stylelint-disable-line function-disallowed-list |
| 14 |
margin-right: calc(-.5 * var(--#{$prefix}gutter-x)); // stylelint-disable-line function-disallowed-list |
| 15 |
margin-left: calc(-.5 * var(--#{$prefix}gutter-x)); // stylelint-disable-line function-disallowed-list |
| 16 |
} |
| 17 |
|
| 18 |
@mixin make-col-ready() { |
| 19 |
// Add box sizing if only the grid is loaded |
| 20 |
box-sizing: if(variable-exists(include-column-box-sizing) and $include-column-box-sizing, border-box, null); |
| 21 |
// Prevent columns from becoming too narrow when at smaller grid tiers by |
| 22 |
// always setting `width: 100%;`. This works because we set the width |
| 23 |
// later on to override this initial width. |
| 24 |
flex-shrink: 0; |
| 25 |
-webkit-flex-shrink: 0; |
| 26 |
width: 100%; |
| 27 |
max-width: 100%; // Prevent `.col-auto`, `.col` (& responsive variants) from breaking out the grid |
| 28 |
padding-right: calc(var(--#{$prefix}gutter-x) * .5); // stylelint-disable-line function-disallowed-list |
| 29 |
padding-left: calc(var(--#{$prefix}gutter-x) * .5); // stylelint-disable-line function-disallowed-list |
| 30 |
margin-top: var(--#{$prefix}gutter-y); |
| 31 |
} |
| 32 |
|
| 33 |
@mixin make-col($size: false, $columns: $grid-columns) { |
| 34 |
@if $size { |
| 35 |
flex: 0 0 auto; |
| 36 |
-webkit-flex: 0 0 auto; |
| 37 |
width: percentage(divide($size, $columns)); |
| 38 |
|
| 39 |
} @else { |
| 40 |
flex: 1 1 0; |
| 41 |
-webkit-flex: 1 1 0; |
| 42 |
max-width: 100%; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
@mixin make-col-auto() { |
| 47 |
flex: 0 0 auto; |
| 48 |
-webkit-flex: 0 0 auto; |
| 49 |
width: auto; |
| 50 |
} |
| 51 |
|
| 52 |
@mixin make-col-offset($size, $columns: $grid-columns) { |
| 53 |
$num: divide($size, $columns); |
| 54 |
margin-left: if($num == 0, 0, percentage($num)); |
| 55 |
} |
| 56 |
|
| 57 |
// Row columns |
| 58 |
// |
| 59 |
// Specify on a parent element(e.g., .row) to force immediate children into NN |
| 60 |
// number of columns. Supports wrapping to new lines, but does not do a Masonry |
| 61 |
// style grid. |
| 62 |
@mixin row-cols($count) { |
| 63 |
> * { |
| 64 |
flex: 0 0 auto; |
| 65 |
-webkit-flex: 0 0 auto; |
| 66 |
width: divide(100%, $count); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
// Framework grid generation |
| 71 |
// |
| 72 |
// Used only by Bootstrap to generate the correct number of grid classes given |
| 73 |
// any value of `$grid-columns`. |
| 74 |
|
| 75 |
@mixin make-grid-columns($columns: $grid-columns, $gutter: $grid-gutter-width, $breakpoints: $grid-breakpoints) { |
| 76 |
@each $breakpoint in map-keys($breakpoints) { |
| 77 |
$infix: breakpoint-infix($breakpoint, $breakpoints); |
| 78 |
|
| 79 |
@include media-breakpoint-up($breakpoint, $breakpoints) { |
| 80 |
// Provide basic `.col-{bp}` classes for equal-width flexbox columns |
| 81 |
.col#{$infix} { |
| 82 |
flex: 1 0 0%; // Flexbugs #4: https://github.com/philipwalton/flexbugs#flexbug-4 |
| 83 |
-webkit-flex: 1 0 0%; // Flexbugs #4: https://github.com/philipwalton/flexbugs#flexbug-4 |
| 84 |
} |
| 85 |
|
| 86 |
.row-cols#{$infix}-auto > * { |
| 87 |
@include make-col-auto(); |
| 88 |
} |
| 89 |
|
| 90 |
@if $grid-row-columns > 0 { |
| 91 |
@for $i from 1 through $grid-row-columns { |
| 92 |
.row-cols#{$infix}-#{$i} { |
| 93 |
@include row-cols($i); |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
.col#{$infix}-auto { |
| 99 |
@include make-col-auto(); |
| 100 |
} |
| 101 |
|
| 102 |
@if $columns > 0 { |
| 103 |
@for $i from 1 through $columns { |
| 104 |
.col#{$infix}-#{$i} { |
| 105 |
@include make-col($i, $columns); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
// `$columns - 1` because offsetting by the width of an entire row isn't possible |
| 110 |
@for $i from 0 through ($columns - 1) { |
| 111 |
@if not ($infix == "" and $i == 0) { // Avoid emitting useless .offset-0 |
| 112 |
.offset#{$infix}-#{$i} { |
| 113 |
@include make-col-offset($i, $columns); |
| 114 |
} |
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
// Gutters |
| 120 |
// |
| 121 |
// Make use of `.g-*`, `.gx-*` or `.gy-*` utilities to change spacing between the columns. |
| 122 |
@each $key, $value in $gutters { |
| 123 |
.g#{$infix}-#{$key}, |
| 124 |
.gx#{$infix}-#{$key} { |
| 125 |
--#{$prefix}gutter-x: #{$value}; |
| 126 |
} |
| 127 |
|
| 128 |
.g#{$infix}-#{$key}, |
| 129 |
.gy#{$infix}-#{$key} { |
| 130 |
--#{$prefix}gutter-y: #{$value}; |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
@mixin make-cssgrid($columns: $grid-columns, $breakpoints: $grid-breakpoints) { |
| 138 |
@each $breakpoint in map-keys($breakpoints) { |
| 139 |
$infix: breakpoint-infix($breakpoint, $breakpoints); |
| 140 |
|
| 141 |
@include media-breakpoint-up($breakpoint, $breakpoints) { |
| 142 |
@if $columns > 0 { |
| 143 |
@for $i from 1 through $columns { |
| 144 |
.g-col#{$infix}-#{$i} { |
| 145 |
grid-column: auto / span $i; |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
// Start with `1` because `0` is and invalid value. |
| 150 |
// Ends with `$columns - 1` because offsetting by the width of an entire row isn't possible. |
| 151 |
@for $i from 1 through ($columns - 1) { |
| 152 |
.g-start#{$infix}-#{$i} { |
| 153 |
grid-column-start: $i; |
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
} |
| 158 |
} |
| 159 |
} |