]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Add function `direction-opposite`
authorNicolas Coden <nicolas@ncoden.fr>
Thu, 15 Dec 2016 22:20:36 +0000 (23:20 +0100)
committerNicolas Coden <nicolas@ncoden.fr>
Thu, 15 Dec 2016 22:20:36 +0000 (23:20 +0100)
`@function direction-opposite($dir)`: Return the opposite direction of
$dir, between "top", "right", "bottom" and "left".

scss/util/_direction.scss [new file with mode: 0644]
scss/util/_util.scss

diff --git a/scss/util/_direction.scss b/scss/util/_direction.scss
new file mode 100644 (file)
index 0000000..c996506
--- /dev/null
@@ -0,0 +1,31 @@
+// Foundation for Sites by ZURB
+// foundation.zurb.com
+// Licensed under MIT Open Source
+
+////
+/// @group functions
+////
+
+/// Return the opposite direction of $dir
+///
+/// @param {Keyword} $dir - Used direction between "top", "right", "bottom" and "left".
+/// @return {Keyword} Opposite direction of $dir
+@function direction-opposite(
+  $dir
+) {
+  $dirs: (top, right, bottom, left);
+  $place: index($dirs, $dir);
+
+  @if $place == null {
+    @error 'direction-opposite: Invalid $dir parameter, expected a value from "' + $dirs + '", found "' + $dir + '".';
+    @return null;
+  }
+
+  // Calcul the opposite place in a circle, with a starting index of 1
+  $length: length($dirs);
+  $demi: $length / 2;
+  $opposite-place: (($place + $demi - 1) % $length) + 1;
+
+  @return nth($dirs, $opposite-place);
+}
+
index 6698812f45b783efd65ec3de9486f483827c9d6b..d08a40d79480830e7f0c906ca7232207f4a39bf5 100644 (file)
@@ -5,6 +5,7 @@
 @import 'math';
 @import 'unit';
 @import 'value';
+@import 'direction';
 @import 'color';
 @import 'selector';
 @import 'flex';