]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
refactor: move current breakpoint resolution to its own function `-zf-current-breakpoint`
authorNicolas Coden <nicolas@ncoden.fr>
Sun, 15 Jul 2018 20:16:59 +0000 (22:16 +0200)
committerNicolas Coden <nicolas@ncoden.fr>
Sun, 15 Jul 2018 20:16:59 +0000 (22:16 +0200)
scss/util/_breakpoint.scss
scss/xy-grid/_cell.scss

index 897db233244256441143dc765f806b6d72a7bcb1..8f7fab6326695b0ad211863b7f41cac7616d11b4 100644 (file)
@@ -328,6 +328,28 @@ $breakpoint-classes: (small medium large) !default;
   }
 }
 
+/// Return the best breakpoint to use according to the calling context. It returns in order:
+/// 1. the given `$value` argument if it is not null.
+/// 2. the global breakpoint context `$-zf-size` if it is not null (like if called inside then `breakpoint()` mixin)
+/// 3. the given `$default` argument.
+/// @access private
+///
+/// @param {Keyword} $value [null] - Breakpoint to use in priority if non-null.
+/// @param {Keyword} $default [null] - Breakpoint to use by default if no other value can be used.
+///
+/// @return {Keyword} The resolved breakpoint.
+@function -zf-current-breakpoint($value: null, $default: null) {
+  @if ($value != null) {
+    @return $value;
+  }
+  @else if (variable-exists(-zf-size) and type-of($-zf-size) != 'number') and $-zf-size != null {
+    @return $-zf-size;
+  }
+  @else {
+    @return $default;
+  }
+}
+
 $small-up: '';
 $small-only: '';
 
index d98a72a5eca68d31d259783af500942704f1f3de..7873e66be16be7d59988cb00dffe91cfb9b3078d 100644 (file)
     }
   }
 
+  // Use the contextual breakpoint by default. Otherwise revert to the smallest breakpoint
+  $breakpoint: -zf-current-breakpoint($breakpoint);
   @if($breakpoint == null) {
-    // If `$bp-size` is available then use this, otherwise revert to the smallest bp.
-    @if(variable-exists(-zf-size) and type-of($-zf-size) != 'number') and $-zf-size != null {
-      $breakpoint: $-zf-size;
-    }
-    @else {
-      $breakpoint: $-zf-zero-breakpoint;
-      $bp-is-fallback: true;
-    }
+    $breakpoint: $-zf-zero-breakpoint;
+    $bp-is-fallback: true;
   }
 
   // Get the default gutter position according to cell direction