Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// directional-property mixins are shorthands
// for writing properties like the following
//
// @include margin(null 0 10px);
// ------
// margin-right: 0;
// margin-bottom: 10px;
// margin-left: 0;
//
// - or -
//
// @include border-style(dotted null);
// ------
// border-top-style: dotted;
// border-bottom-style: dotted;
//
// ------
//
// Note: You can also use false instead of null

@function collapse-directionals($vals) {
  $output: null;

  $A: nth( $vals, 1 );
  $B: if( length($vals) < 2, $A, nth($vals, 2));
  $C: if( length($vals) < 3, $A, nth($vals, 3));
  $D: if( length($vals) < 2, $A, nth($vals, if( length($vals) < 4, 2, 4) ));

  @if $A == 0 { $A: 0 }
  @if $B == 0 { $B: 0 }
  @if $C == 0 { $C: 0 }
  @if $D == 0 { $D: 0 }

  @if $A == $B and $A == $C and $A == $D { $output: $A          }
  @else if $A == $C and $B == $D         { $output: $A $B       }
  @else if $B == $D                      { $output: $A $B $C    }
  @else                                  { $output: $A $B $C $D }

  @return $output;
}

@function contains-falsy($list) {
  @each $item in $list {
    @if not $item {
      @return true;
    }
  }

  @return false;
}

@mixin directional-property($pre, $suf, $vals) {
  // Property Names
  $top:    $pre + "-top"    + if($suf, "-#{$suf}", "");
  $bottom: $pre + "-bottom" + if($suf, "-#{$suf}", "");
  $left:   $pre + "-left"   + if($suf, "-#{$suf}", "");
  $right:  $pre + "-right"  + if($suf, "-#{$suf}", "");
  $all:    $pre +             if($suf, "-#{$suf}", "");

  $vals: collapse-directionals($vals);

  @if contains-falsy($vals) {
    @if nth($vals, 1) { #{$top}: nth($vals, 1); }

    @if length($vals) == 1 {
      @if nth($vals, 1) { #{$right}: nth($vals, 1); }
    } @else {
      @if nth($vals, 2) { #{$right}: nth($vals, 2); }
    }

    // prop: top/bottom right/left
    @if length($vals) == 2 {
      @if nth($vals, 1) { #{$bottom}: nth($vals, 1); }
      @if nth($vals, 2) { #{$left}:   nth($vals, 2); }

    // prop: top right/left bottom
    } @else if length($vals) == 3 {
      @if nth($vals, 3) { #{$bottom}: nth($vals, 3); }
      @if nth($vals, 2) { #{$left}:   nth($vals, 2); }

    // prop: top right bottom left
    } @else if length($vals) == 4 {
      @if nth($vals, 3) { #{$bottom}: nth($vals, 3); }
      @if nth($vals, 4) { #{$left}:   nth($vals, 4); }
    }

  // prop: top/right/bottom/left
  } @else {
    #{$all}: $vals;
  }
}

@mixin margin($vals...) {
  @include directional-property(margin, false, $vals...);
}

@mixin padding($vals...) {
  @include directional-property(padding, false, $vals...);
}

@mixin border-style($vals...) {
  @include directional-property(border, style, $vals...);
}

@mixin border-color($vals...) {
  @include directional-property(border, color, $vals...);
}

@mixin border-width($vals...) {
  @include directional-property(border, width, $vals...);
}

Commits for Nextrek/Aiba_backup/public/sass/plug-in/bourbon/addons/_directional-values.scss

Diff revisions: vs.
Revision Author Commited Message
1464 MOliva picture MOliva Tue 13 Oct, 2020 11:16:56 +0000