|
3 | 3 | //
|
4 | 4 |
|
5 | 5 | .switch {
|
6 |
| - position: relative; |
7 | 6 | display: inline-block;
|
8 | 7 | width: $switch-width;
|
9 | 8 | height: $switch-height;
|
10 |
| - vertical-align: top; |
11 |
| - cursor: pointer; |
12 |
| - background-color: transparent; |
13 | 9 | }
|
14 | 10 |
|
15 | 11 | .switch-input {
|
16 |
| - position: absolute; |
17 |
| - top: 0; |
18 |
| - left: 0; |
19 |
| - opacity: 0; |
| 12 | + display: none; |
20 | 13 | }
|
21 | 14 |
|
22 |
| -.switch-label { |
| 15 | +.switch-slider { |
23 | 16 | position: relative;
|
24 | 17 | display: block;
|
25 | 18 | height: inherit;
|
26 |
| - font-size: $switch-font-size; |
27 |
| - font-weight: 600; |
28 |
| - text-transform: uppercase; |
| 19 | + cursor: pointer; |
29 | 20 | background-color: #fff;
|
30 |
| - border: 1px solid $border-color; |
31 |
| - border-radius: 2px; |
32 |
| - transition: opacity background .15s ease-out; |
33 |
| - |
34 |
| - &::before, |
35 |
| - &::after { |
36 |
| - position: absolute; |
37 |
| - top: 50%; |
38 |
| - width: 50%; |
39 |
| - margin-top: -.5em; |
40 |
| - line-height: 1; |
41 |
| - text-align: center; |
42 |
| - transition: inherit; |
43 |
| - } |
| 21 | + border: $border-width solid $border-color; |
| 22 | + transition: .15s ease-out; |
| 23 | + @include border-radius($border-radius); |
44 | 24 |
|
45 | 25 | &::before {
|
46 |
| - right: 1px; |
47 |
| - color: $gray-200; |
48 |
| - content: attr(data-off); |
49 |
| - } |
50 |
| - |
51 |
| - &::after { |
52 |
| - left: 1px; |
53 |
| - color: #fff; |
54 |
| - content: attr(data-on); |
55 |
| - opacity: 0; |
| 26 | + position: absolute; |
| 27 | + top: $switch-handle-margin; |
| 28 | + left: $switch-handle-margin; |
| 29 | + box-sizing: border-box; |
| 30 | + width: $switch-height - ($switch-handle-margin * 2) - ($border-width * 2); |
| 31 | + height: $switch-height - ($switch-handle-margin * 2) - ($border-width * 2); |
| 32 | + content: ""; |
| 33 | + background-color: #fff; |
| 34 | + border: 1px solid $border-color; |
| 35 | + transition: .15s ease-out; |
| 36 | + @include border-radius($border-radius / 2); |
56 | 37 | }
|
57 | 38 | }
|
58 | 39 |
|
59 |
| -.switch-handle { |
60 |
| - position: absolute; |
61 |
| - top: $switch-handle-margin; |
62 |
| - left: $switch-handle-margin; |
63 |
| - width: $switch-height - $switch-handle-margin * 2; |
64 |
| - height: $switch-height - $switch-handle-margin * 2; |
65 |
| - background: #fff; |
66 |
| - border: 1px solid $border-color; |
67 |
| - border-radius: 1px; |
68 |
| - transition: left .15s ease-out; |
69 |
| -} |
70 |
| - |
71 |
| -.switch-input:checked { |
72 |
| - ~ .switch-label { |
73 |
| - //background: $gray-lightest; |
74 |
| - } |
75 |
| - |
76 |
| - ~ .switch-label::before { |
77 |
| - opacity: 0; |
78 |
| - } |
79 |
| - |
80 |
| - ~ .switch-label::after { |
81 |
| - opacity: 1; |
82 |
| - } |
83 |
| - |
84 |
| - ~ .switch-handle { |
85 |
| - left: $switch-width - $switch-height + $switch-handle-margin; |
| 40 | +.switch-input:checked ~ .switch-slider { |
| 41 | + &::before { |
| 42 | + transform: translateX($switch-width - $switch-height); |
86 | 43 | }
|
87 | 44 | }
|
88 | 45 |
|
89 |
| -@each $color, $value in $theme-colors { |
90 |
| - //normal style |
91 |
| - .switch-#{$color} { |
92 |
| - @include switch-variant($value); |
93 |
| - } |
94 |
| - //outline style |
95 |
| - .switch-#{$color}-outline { |
96 |
| - @include switch-outline-variant($value); |
97 |
| - } |
98 |
| - //outline alternative style |
99 |
| - .switch-#{$color}-outline-alt { |
100 |
| - @include switch-outline-alt-variant($value); |
101 |
| - } |
| 46 | +.switch-input:disabled ~ .switch-slider { |
| 47 | + cursor: not-allowed; |
| 48 | + opacity: .5; |
102 | 49 | }
|
103 | 50 |
|
104 | 51 | //
|
|
114 | 61 | }
|
115 | 62 |
|
116 | 63 | //
|
117 |
| -// Switch with text |
| 64 | +// Switch with label |
118 | 65 | //
|
| 66 | +.switch-label { |
| 67 | + width: $switch-label-width; |
| 68 | + |
| 69 | + .switch-slider { |
| 70 | + &::before { |
| 71 | + z-index: 2; |
| 72 | + } |
| 73 | + &::after { |
| 74 | + position: absolute; |
| 75 | + top: 50%; |
| 76 | + right: 1px; |
| 77 | + z-index: 1; |
| 78 | + width: 50%; |
| 79 | + margin-top: -.5em; |
| 80 | + font-size: $switch-font-size; |
| 81 | + font-weight: 600; |
| 82 | + line-height: 1; |
| 83 | + color: $gray-300; |
| 84 | + text-align: center; |
| 85 | + text-transform: uppercase; |
| 86 | + content: attr(data-unchecked); |
| 87 | + transition: inherit; |
| 88 | + } |
| 89 | + } |
119 | 90 |
|
120 |
| -.switch-text { |
121 |
| - @include switch-size($switch-text-width, $switch-height, $switch-font-size, $switch-handle-margin); |
| 91 | + .switch-input:checked ~ .switch-slider { |
| 92 | + &::before { |
| 93 | + transform: translateX($switch-label-width - $switch-height); |
| 94 | + } |
| 95 | + &::after { |
| 96 | + left: 1px; |
| 97 | + color: #fff; |
| 98 | + content: attr(data-checked); |
| 99 | + } |
| 100 | + } |
122 | 101 |
|
123 | 102 | // Sizes
|
124 | 103 | &.switch-lg {
|
125 |
| - @include switch-size($switch-text-lg-width, $switch-lg-height, $switch-lg-font-size, $switch-handle-margin); |
| 104 | + @include switch-size($switch-label-lg-width, $switch-lg-height, $switch-lg-font-size, $switch-handle-margin); |
126 | 105 | }
|
127 | 106 |
|
128 | 107 | &.switch-sm {
|
129 |
| - @include switch-size($switch-text-sm-width, $switch-sm-height, $switch-sm-font-size, $switch-handle-margin); |
| 108 | + @include switch-size($switch-label-sm-width, $switch-sm-height, $switch-sm-font-size, $switch-handle-margin); |
130 | 109 | }
|
131 | 110 | }
|
132 | 111 |
|
|
135 | 114 | //
|
136 | 115 |
|
137 | 116 | .switch-3d {
|
138 |
| - .switch-label { |
| 117 | + .switch-slider { |
139 | 118 | background-color: $gray-100;
|
140 | 119 | border-radius: 50em;
|
141 |
| - } |
142 |
| - .switch-handle { |
143 |
| - top: 0; |
144 |
| - left: 0; |
145 |
| - width: $switch-height; |
146 |
| - height: $switch-height; |
147 |
| - border: 0; |
148 |
| - border-radius: 50em; |
149 |
| - box-shadow: 0 2px 5px rgba(0, 0, 0, .3); |
| 120 | + |
| 121 | + &::before { |
| 122 | + top: -1px; |
| 123 | + left: -1px; |
| 124 | + width: $switch-height; |
| 125 | + height: $switch-height; |
| 126 | + border: 0; |
| 127 | + border-radius: 50em; |
| 128 | + box-shadow: 0 2px 5px rgba(0, 0, 0, .3); |
| 129 | + } |
150 | 130 | }
|
151 | 131 |
|
152 | 132 | // Sizes
|
153 | 133 | &.switch-lg {
|
154 |
| - @include switch-size($switch-text-lg-width, $switch-lg-height, $switch-lg-font-size, 0); |
| 134 | + @include switch-3d-size($switch-lg-width, $switch-lg-height); |
155 | 135 | }
|
156 | 136 |
|
157 | 137 | &.switch-sm {
|
158 |
| - @include switch-size($switch-text-sm-width, $switch-sm-height, $switch-sm-font-size, 0); |
| 138 | + @include switch-3d-size($switch-sm-width, $switch-sm-height); |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +// |
| 143 | +// Switch Variants |
| 144 | +// |
| 145 | + |
| 146 | +@each $color, $value in $theme-colors { |
| 147 | + //normal style |
| 148 | + .switch-#{$color} { |
| 149 | + @include switch-variant($value); |
| 150 | + } |
| 151 | + //outline style |
| 152 | + .switch-outline-#{$color} { |
| 153 | + @include switch-outline-variant($value); |
| 154 | + } |
| 155 | + //outline alternative style |
| 156 | + .switch-outline-#{$color}-alt { |
| 157 | + @include switch-outline-variant-alt($value); |
159 | 158 | }
|
160 | 159 | }
|
161 | 160 |
|
|
164 | 163 | //
|
165 | 164 |
|
166 | 165 | .switch-pill {
|
167 |
| - .switch-label, |
168 |
| - .switch-handle { |
| 166 | + .switch-slider { |
169 | 167 | border-radius: 50em;
|
170 |
| - } |
171 | 168 |
|
172 |
| - .switch-label { |
173 | 169 | &::before {
|
174 |
| - right: 2px; |
175 |
| - } |
176 |
| - &::after { |
177 |
| - left: 2px; |
| 170 | + border-radius: 50em; |
178 | 171 | }
|
179 | 172 | }
|
180 | 173 | }
|
0 commit comments