_directional-values.scss 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. @charset "UTF-8";
  2. /// Directional-property mixins are shorthands for writing properties like the following
  3. ///
  4. /// @ignore You can also use `false` instead of `null`.
  5. ///
  6. /// @param {List} $vals
  7. /// List of directional values
  8. ///
  9. /// @example scss - Usage
  10. /// .element {
  11. /// @include border-style(dotted null);
  12. /// @include margin(null 0 10px);
  13. /// }
  14. ///
  15. /// @example css - CSS Output
  16. /// .element {
  17. /// border-bottom-style: dotted;
  18. /// border-top-style: dotted;
  19. /// margin-bottom: 10px;
  20. /// margin-left: 0;
  21. /// margin-right: 0;
  22. /// }
  23. ///
  24. /// @require {function} contains-falsy
  25. ///
  26. /// @return {List}
  27. @function collapse-directionals($vals) {
  28. $output: null;
  29. $a: nth($vals, 1);
  30. $b: if(length($vals) < 2, $a, nth($vals, 2));
  31. $c: if(length($vals) < 3, $a, nth($vals, 3));
  32. $d: if(length($vals) < 2, $a, nth($vals, if(length($vals) < 4, 2, 4)));
  33. @if $a == 0 { $a: 0; }
  34. @if $b == 0 { $b: 0; }
  35. @if $c == 0 { $c: 0; }
  36. @if $d == 0 { $d: 0; }
  37. @if $a == $b and $a == $c and $a == $d { $output: $a; }
  38. @else if $a == $c and $b == $d { $output: $a $b; }
  39. @else if $b == $d { $output: $a $b $c; }
  40. @else { $output: $a $b $c $d; }
  41. @return $output;
  42. }
  43. /// Output directional properties, for instance `margin`.
  44. ///
  45. /// @access private
  46. ///
  47. /// @param {String} $pre
  48. /// Prefix to use
  49. /// @param {String} $suf
  50. /// Suffix to use
  51. /// @param {List} $vals
  52. /// List of values
  53. ///
  54. /// @require {function} collapse-directionals
  55. /// @require {function} contains-falsy
  56. @mixin directional-property($pre, $suf, $vals) {
  57. // Property Names
  58. $top: $pre + "-top" + if($suf, "-#{$suf}", "");
  59. $bottom: $pre + "-bottom" + if($suf, "-#{$suf}", "");
  60. $left: $pre + "-left" + if($suf, "-#{$suf}", "");
  61. $right: $pre + "-right" + if($suf, "-#{$suf}", "");
  62. $all: $pre + if($suf, "-#{$suf}", "");
  63. $vals: collapse-directionals($vals);
  64. @if contains-falsy($vals) {
  65. @if nth($vals, 1) { #{$top}: nth($vals, 1); }
  66. @if length($vals) == 1 {
  67. @if nth($vals, 1) { #{$right}: nth($vals, 1); }
  68. } @else {
  69. @if nth($vals, 2) { #{$right}: nth($vals, 2); }
  70. }
  71. @if length($vals) == 2 {
  72. @if nth($vals, 1) { #{$bottom}: nth($vals, 1); }
  73. @if nth($vals, 2) { #{$left}: nth($vals, 2); }
  74. } @else if length($vals) == 3 {
  75. @if nth($vals, 3) { #{$bottom}: nth($vals, 3); }
  76. @if nth($vals, 2) { #{$left}: nth($vals, 2); }
  77. } @else if length($vals) == 4 {
  78. @if nth($vals, 3) { #{$bottom}: nth($vals, 3); }
  79. @if nth($vals, 4) { #{$left}: nth($vals, 4); }
  80. }
  81. } @else {
  82. #{$all}: $vals;
  83. }
  84. }