_unpack.scss 729 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
@charset "UTF-8";

/// Converts shorthand to the 4-value syntax.
///
/// @param {List} $shorthand
///
/// @example scss - Usage
///   .element {
///     margin: unpack(1em 2em);
///   }
///
/// @example css - CSS Output
///   .element {
///     margin: 1em 2em 1em 2em;
///   }
16 17 18 19

@function unpack($shorthand) {
  @if length($shorthand) == 1 {
    @return nth($shorthand, 1) nth($shorthand, 1) nth($shorthand, 1) nth($shorthand, 1);
20
  } @else if length($shorthand) == 2 {
21
    @return nth($shorthand, 1) nth($shorthand, 2) nth($shorthand, 1) nth($shorthand, 2);
22
  } @else if length($shorthand) == 3 {
23
    @return nth($shorthand, 1) nth($shorthand, 2) nth($shorthand, 3) nth($shorthand, 2);
24
  } @else {
25 26 27
    @return $shorthand;
  }
}