1
+ @import " variables" ;
2
+ @import " values" ;
3
+
4
+ /// Traverse maps and retrieve deeply nested values.
5
+ /// @author Hugo Giraudel
6
+ /// @param {map} A sass map.
7
+ /// @param {arglist} Any number of keys.
8
+ /// @return {*} Nested values or nested map.
9
+ @function map-deep-get ($map , $keys ... ) {
10
+ @each $key in $keys {
11
+ $map : map-get ($map , $key );
12
+ }
13
+ @return $map ;
14
+ }
15
+
16
+ /// Function returns the rem value of a given breakpoint.
17
+ /// @param {string} An existing breakpoint name (sm, md, lg, amd so on).
18
+ /// @return {length} The breakpoint value in rems.
19
+ @function getBreakpointValue ($breakpointName ) {
20
+ $breakpointValue : map-deep-get ($grid-values , ' breakpoints' , $breakpointName , ' breakpoint' );
21
+ @return $breakpointValue * 1rem ;
22
+ }
23
+
24
+ /// Returns a calc() expression that represents a fluid width at a given breakpoint.
25
+ /// @param {string} A valid breakpoint (sm, md, lg, xlg, or max)
26
+ /// @param {number} The number of columns to span across.
27
+ /// @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 );
32
+
33
+ @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
+ }
41
+
42
+ $fluidWidth : calc ((100vw - #{$totalMargin } ) * #{$columns } / #{$columnQuantity } );
43
+ }
44
+
45
+ @return $fluidWidth ;
46
+ }
47
+
48
+ /// Gets a calculated rem value for a fixed nondimensional unit size.
49
+ /// @param {number} Fixed nondimensional units.
50
+ /// @return {length} A calculated rem value.
51
+ @function getFixedSize ($fixedUnit ) {
52
+
53
+ $remValue : 0 ; // default
54
+
55
+ @if $fixedUnit != null and $fixedUnit > 0 {
56
+ $remValue : $fixedUnit * map-get ($grid-values , ' rowHeight' ) * 1rem ;
57
+ }
58
+ @else {
59
+ @error ' The provided value #{$fixedUnit } to getFixedSize() is not a number.'
60
+ }
61
+
62
+ @return $remValue ;
63
+ }
0 commit comments