/// Makes a pure CSS triangle.
/// @param {direction} $direction - Triangle direction, either `top`, `right`, `bottom` or `left`
/// @param {color} $color [currentcolor] - Triangle color
/// @param {length} $size [1em] - Triangle size
@mixin triangle($direction, $color: currentcolor, $size: 1em) {
  @if not index(top right bottom left, $direction) {
    @error 'Direction must be either `top`, `right`, `bottom` or `left`.';
  }

  z-index: 2;
  width: 0;
  height: 0;
  content: '';
  border-#{opposite-position($direction)}: ($size * 1.5) solid $color;

  $perpendicular-borders: $size solid transparent;

  @if $direction == top or $direction == bottom {
    border-right:  $perpendicular-borders;
    border-left:   $perpendicular-borders;
  }
  @else if $direction == right or $direction == left {
    border-top:    $perpendicular-borders;
    border-bottom: $perpendicular-borders;
  }
}
