Skip to content

Commit

Permalink
Add function direction-opposite
Browse files Browse the repository at this point in the history
`@function direction-opposite($dir)`: Return the opposite direction of
$dir, between "top", "right", "bottom" and "left".
  • Loading branch information
ncoden committed Dec 15, 2016
1 parent 5573453 commit 7fb8173
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions scss/util/_direction.scss
Original file line number Diff line number Diff line change
@@ -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);
}

1 change: 1 addition & 0 deletions scss/util/_util.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@import 'math';
@import 'unit';
@import 'value';
@import 'direction';
@import 'color';
@import 'selector';
@import 'flex';
Expand Down

0 comments on commit 7fb8173

Please sign in to comment.