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

Commit 63876d8

Browse files
author
Jen Downs
committed
feat(utilities): Added mixin for constructing media queries. Modified getFluidSize().
1 parent 0cb5233 commit 63876d8

File tree

7 files changed

+46
-17
lines changed

7 files changed

+46
-17
lines changed
Binary file not shown.

examples/bootstrap/css-gridish/scss/_utilities.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@import "variables";
22
@import "values";
3-
3+
@debug $allBreakpoints;
44
/// Traverse maps and retrieve deeply nested values.
55
/// @author Hugo Giraudel
66
/// @param {map} A sass map.
@@ -61,3 +61,11 @@
6161

6262
@return $remValue;
6363
}
64+
65+
/// Utility for declaring mobile-first media queries.
66+
/// @param {String} $breakpoint-name The name of the breakpoint to set its width value to media query.
67+
@mixin media-query($breakpointNme) {
68+
@media screen and (min-width: #{getBreakpointValue($breakpointName)}) {
69+
@content;
70+
}
71+
}
0 Bytes
Binary file not shown.

examples/carbon/css-gridish/scss/_utilities.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@import "variables";
22
@import "values";
3-
3+
@debug $allBreakpoints;
44
/// Traverse maps and retrieve deeply nested values.
55
/// @author Hugo Giraudel
66
/// @param {map} A sass map.
@@ -61,3 +61,11 @@
6161

6262
@return $remValue;
6363
}
64+
65+
/// Utility for declaring mobile-first media queries.
66+
/// @param {String} $breakpoint-name The name of the breakpoint to set its width value to media query.
67+
@mixin media-query($breakpointNme) {
68+
@media screen and (min-width: #{getBreakpointValue($breakpointName)}) {
69+
@content;
70+
}
71+
}
Binary file not shown.

examples/material/css-gridish/scss/_utilities.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@import "variables";
22
@import "values";
3-
3+
@debug $allBreakpoints;
44
/// Traverse maps and retrieve deeply nested values.
55
/// @author Hugo Giraudel
66
/// @param {map} A sass map.
@@ -61,3 +61,11 @@
6161

6262
@return $remValue;
6363
}
64+
65+
/// Utility for declaring mobile-first media queries.
66+
/// @param {String} $breakpoint-name The name of the breakpoint to set its width value to media query.
67+
@mixin media-query($breakpointNme) {
68+
@media screen and (min-width: #{getBreakpointValue($breakpointName)}) {
69+
@content;
70+
}
71+
}

src/scss/_utilities.scss

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,29 @@
1717
/// @param {string} An existing breakpoint name (sm, md, lg, amd so on).
1818
/// @return {length} The breakpoint value in rems.
1919
@function getBreakpointValue($breakpointName) {
20-
$breakpointValue: map-deep-get($grid-values, 'breakpoints', $breakpointName, 'breakpoint');
20+
$breakpointValue: map-deep-get($allBreakpoints, $breakpointName, 'breakpoint');
2121
@return $breakpointValue * 1rem;
2222
}
2323

2424
/// Returns a calc() expression that represents a fluid width at a given breakpoint.
2525
/// @param {string} A valid breakpoint (sm, md, lg, xlg, or max)
2626
/// @param {number} The number of columns to span across.
2727
/// @return {length} A calc() expression representing fluid width.
28-
@function getFluidSize($breakpointName, $columns) {
29-
$fluidWidth: 0; // default
30-
31-
$breakpoint: map-deep-get($grid-values, 'breakpoints', $breakpointName);
28+
@function getFluidSize($breakpointName, $columnSpan) {
29+
$breakpoint: map-get($allBreakpoints, $breakpointName);
30+
$columnTotal: map-get($breakpoint, columns);
31+
$margin: map-get($breakpoint, margin);
3232

3333
@if (map-get($breakpoint, columns) != null) {
34-
$columnQuantity: map-get($breakpoint, columns);
35-
$fluidWidth: 100vw / $columnQuantity;
36-
37-
$totalMargin: 0;
38-
@if (map-get($breakpoint, margin) != null) {
39-
$totalMargin: map-get($breakpoint, margin) * 2;
40-
}
34+
@error 'The provided breakpoint #{$breakpointName} needs to have a total number of columns set in $grid-values.';
35+
}
4136

42-
$fluidWidth: calc((100vw - #{$totalMargin}) * #{$columns} / #{$columnQuantity});
37+
// For IE, we can't have a 0 in the $fluidWidth calc()
38+
@if ($margin == 0) {
39+
@return calc((100vw) * #{$columnSpan} / #{$columnTotal});
4340
}
4441

45-
@return $fluidWidth;
42+
@return calc((100vw - (#{$margin} * 2)) * #{$columnSpan} / #{$columnTotal});
4643
}
4744

4845
/// Gets a calculated rem value for a fixed nondimensional unit size.
@@ -60,4 +57,12 @@
6057
}
6158

6259
@return $remValue;
60+
}
61+
62+
/// Utility for declaring mobile-first media queries.
63+
/// @param {String} $breakpoint-name The name of the breakpoint to set its width value to media query.
64+
@mixin media-query($breakpointNme) {
65+
@media screen and (min-width: #{getBreakpointValue($breakpointName)}) {
66+
@content;
67+
}
6368
}

0 commit comments

Comments
 (0)