Skip to content
This repository was archived by the owner on Jul 14, 2023. It is now read-only.

Commit 3b13688

Browse files
kgcreativewhmii
authored andcommitted
Extend grid-media to accept multiple custom grids
1 parent 9cecc30 commit 3b13688

File tree

4 files changed

+58
-33
lines changed

4 files changed

+58
-33
lines changed

contrib/patterns/_grid-media.scss

+1-17
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,7 @@ $print-neat-grid: (
2626
content: "#{map-get($neat-grid, media)}";
2727
}
2828

29-
@include grid-media($custom-neat-grid) {
30-
@include grid-column(6);
31-
32-
&::before {
33-
content: "#{map-get($neat-grid, media)}";
34-
}
35-
}
36-
37-
@include grid-media($specific-neat-grid) {
38-
@include grid-column(6);
39-
40-
&::before {
41-
content: "#{map-get($neat-grid, media)}";
42-
}
43-
}
44-
45-
@include grid-media($print-neat-grid) {
29+
@include grid-media($custom-neat-grid, $specific-neat-grid, $print-neat-grid) {
4630
@include grid-column(6);
4731

4832
&::before {

core/neat/mixins/_grid-media.scss

+37-16
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,39 @@
1313
/// @name Grid media
1414
///
1515
/// @argument {map} $grid
16-
/// The grid to be used within the scope of the block.
17-
/// This grid should include the `media` property to determine the expression
16+
/// The grid or grids to be used within the scope of the block.
17+
/// These grids should include the `media` property to determine the expression
1818
/// for the media query.
1919
///
2020
/// @content
21-
/// Grid media will temporarily the override the default grid with the
22-
/// attributes of the custom grid. This change is scoped to within the mixin
23-
/// block, and once the mixin has ended the default grid will revert to its
24-
/// original state as defined by `$neat-grid`. This allows for different
21+
/// Grid media will temporarily override the default grid with the attributes
22+
/// of the custom grids. When `grid-media` is given a custom grid, it will
23+
/// apply that grid to any of other Neat mixins within the `grid-media` block
24+
/// (`{…}`). Once the mixin block has ended the default grid will revert to
25+
/// its original state as defined by `$neat-grid`. This allows for different
2526
/// gutter width and column count based on screen size or other properties.
2627
///
28+
/// If multiple grids are passed in to `grid-media`, it will loop through the
29+
/// contents of the block, quickly allowing you to apply multiple grids in a
30+
/// single mixin.
31+
///
2732
/// @example scss
2833
/// $custom-neat-grid: (
2934
/// columns: 12,
3035
/// gutter: 50px,
36+
/// media: "screen and (max-width: 999px)",
37+
/// );
38+
///
39+
/// $custom-neat-grid-2: (
40+
/// columns: 12,
41+
/// gutter: 70px,
3142
/// media: 1000px,
3243
/// );
3344
///
3445
/// .element {
3546
/// @include grid-column(3);
3647
///
37-
/// @include grid-media($custom-neat-grid){
48+
/// @include grid-media($custom-neat-grid, $custom-neat-grid-2){
3849
/// @include grid-column(6);
3950
/// }
4051
/// }
@@ -46,22 +57,32 @@
4657
/// margin-left: 20px;
4758
/// }
4859
///
49-
/// @media only screen and (min-width: 1000px) {
60+
/// @media only screen and (max-width: 999px) {
5061
/// .element {
5162
/// width: calc(50% - 75px);
5263
/// float: left;
5364
/// margin-left: 50px;
5465
/// }
5566
/// }
67+
///
68+
/// @media only screen and (min-width: 1000px) {
69+
/// .element {
70+
/// width: calc(50% - 75px);
71+
/// float: left;
72+
/// margin-left: 70px;
73+
/// }
74+
/// }
5675

57-
@mixin grid-media($grid) {
58-
$_media: _retrieve-neat-setting($grid, media);
59-
$_query: _neat-parse-media($_media);
76+
@mixin grid-media($grids...) {
77+
@each $_grid in $grids {
78+
$_media: _retrieve-neat-setting($_grid, media);
79+
$_query: _neat-parse-media($_media);
6080

61-
@media #{$_query} {
62-
$_default-neat-grid: $neat-grid;
63-
$neat-grid: map-merge($neat-grid, $grid) !global;
64-
@content;
65-
$neat-grid: $_default-neat-grid !global;
81+
@media #{$_query} {
82+
$_default-neat-grid: $neat-grid;
83+
$neat-grid: map-merge($neat-grid, $_grid) !global;
84+
@content;
85+
$neat-grid: $_default-neat-grid !global;
86+
}
6687
}
6788
}

spec/fixtures/mixins/grid-media.scss

+6
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ $print-neat-grid: (
3737
@include grid-column(8);
3838
}
3939
}
40+
41+
.grid-column-media-combined-grid {
42+
@include grid-media($custom-neat-grid, $specific-neat-grid, $print-neat-grid) {
43+
@include grid-column(3);
44+
}
45+
}

spec/neat/mixins/grid_media_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,18 @@
2222
expect(".grid-column-media-print-neat-grid").to be_contained_in("print")
2323
end
2424
end
25+
26+
context "with argument ($custom-neat-grid, $specific-neat-grid, $print-neat-grid)" do
27+
it "outputs @media only screen and (min-width: 1000px)" do
28+
expect(".grid-column-media-combined-grid").to be_contained_in("only screen and (min-width: 1000px)")
29+
end
30+
31+
it "outputs @media only screen and (min-width: 1000px) and (max-width: 1100px)" do
32+
expect(".grid-column-media-combined-grid").to be_contained_in("only screen and (min-width: 1000px) and (max-width: 1100px)")
33+
end
34+
35+
it "outputs @media print" do
36+
expect(".grid-column-media-combined-grid").to be_contained_in("print")
37+
end
38+
end
2539
end

0 commit comments

Comments
 (0)