summaryrefslogtreecommitdiffstats
path: root/afb-client/bower_components/foundation-apps/scss/components/_switch.scss
blob: 7710ad4bd14ef2674306ba538f1b99169d205045 (plain)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
  SWITCH
  ------
*/

/// @Foundation.settings
// Switch
$switch-width: rem-calc(50) !default;
$switch-height: rem-calc(32) !default;
$switch-background: #ccc !default;
$switch-background-active: $primary-color !default;
$switch-border: 0 !default;
$switch-radius: 9999px !default;
$switch-animation-speed: 0.15s !default;

$switch-paddle-color: white !default;
$switch-paddle-offset: 4px !default;
///

%switch {
  position: relative;
  overflow: hidden;
  display: inline-block;

  > input {
    position: absolute;
    left: -9999px;
    outline: none;
  }

  > label {
    -ms-touch-action: manipulation;
        touch-action: manipulation;
    display: block;
    width: 100%;
    height: 100%;
    cursor: pointer;
    margin: 0;

    // Paddle
    &::after {
      content: '';
      display: block;
      position: absolute;
      top: 0;
      left: 0;
    }
  }
}

/*
  Defines the dimmensions of the switch.

  $width - width of the switch.
  $height - height of the switch.
*/
@mixin switch-layout(
  $width: $switch-width,
  $height: $switch-height
) {
  width: $width;
  height: $height;

  > label {
    &::after {
      width: $height;
      height: $height;
    }
  }
  input:checked + label {
    &::after {
      left: $width - $height;
    }
  }
}

@mixin switch-style(
  $background: $switch-background,
  $background-active: $switch-background-active,
  $border: $switch-border,
  $radius: $switch-radius,
  $paddle-color: $switch-paddle-color,
  $paddle-offset: $switch-paddle-offset,
  $animation-speed: $switch-animation-speed
) {
  @if hasvalue($border) {
    border: $border;
  }
  border-radius: $radius;

  > label {
    background: $background;

    &::after {
      background: $paddle-color;
      border-radius: $radius;
      transition: left $animation-speed ease-out;

      @if hasvalue($paddle-offset) {
        border: $paddle-offset solid $background
      }
    }
  }

  input:checked + label {
    background: $background-active;
    margin: 0;

    &::after {
      @if hasvalue($paddle-offset) {
        border-color: $background-active;
      }
    }
  }
}

@mixin switch() {
  @extend %switch;
  @include switch-layout;
  @include switch-style;
}

@include exports(switch) {
  .switch {
    @include switch;

    &.small { @include switch-layout(rem-calc(40), rem-calc(26)); }
    &.large { @include switch-layout(rem-calc(60), rem-calc(38)); }
  }
}