1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | $switch-background: $medium-gray !default;
|
12 |
|
13 |
|
14 |
|
15 | $switch-background-active: $primary-color !default;
|
16 |
|
17 |
|
18 |
|
19 | $switch-height: 2rem !default;
|
20 |
|
21 |
|
22 |
|
23 | $switch-height-tiny: 1.5rem !default;
|
24 |
|
25 |
|
26 |
|
27 | $switch-height-small: 1.75rem !default;
|
28 |
|
29 |
|
30 |
|
31 | $switch-height-large: 2.5rem !default;
|
32 |
|
33 |
|
34 |
|
35 | $switch-radius: $global-radius !default;
|
36 |
|
37 |
|
38 |
|
39 | $switch-margin: $global-margin !default;
|
40 |
|
41 |
|
42 |
|
43 | $switch-paddle-background: $white !default;
|
44 |
|
45 |
|
46 |
|
47 | $switch-paddle-offset: 0.25rem !default;
|
48 |
|
49 |
|
50 |
|
51 | $switch-paddle-radius: $global-radius !default;
|
52 |
|
53 |
|
54 |
|
55 | $switch-paddle-transition: all 0.25s ease-out !default;
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | @mixin switch-container {
|
63 | position: relative;
|
64 | margin-bottom: $switch-margin;
|
65 | outline: 0;
|
66 |
|
67 |
|
68 | font-size: rem-calc(14);
|
69 | font-weight: bold;
|
70 | color: $white;
|
71 |
|
72 | user-select: none;
|
73 | }
|
74 |
|
75 |
|
76 | @mixin switch-input {
|
77 | position: absolute;
|
78 | margin-bottom: 0;
|
79 | opacity: 0;
|
80 | }
|
81 |
|
82 |
|
83 | @mixin switch-paddle {
|
84 | $switch-width: $switch-height * 2;
|
85 | $paddle-height: $switch-height - ($switch-paddle-offset * 2);
|
86 | $paddle-width: $switch-height - ($switch-paddle-offset * 2);
|
87 | $paddle-active-offest: $switch-width - $paddle-width - $switch-paddle-offset;
|
88 |
|
89 | position: relative;
|
90 | display: block;
|
91 | width: $switch-width;
|
92 | height: $switch-height;
|
93 |
|
94 | border-radius: $switch-radius;
|
95 | background: $switch-background;
|
96 | transition: $switch-paddle-transition;
|
97 |
|
98 |
|
99 | font-weight: inherit;
|
100 | color: inherit;
|
101 |
|
102 | cursor: pointer;
|
103 |
|
104 |
|
105 | input + & {
|
106 | margin: 0;
|
107 | }
|
108 |
|
109 |
|
110 | &::after {
|
111 | position: absolute;
|
112 | top: $switch-paddle-offset;
|
113 | #{$global-left}: $switch-paddle-offset;
|
114 |
|
115 | display: block;
|
116 | width: $paddle-width;
|
117 | height: $paddle-height;
|
118 |
|
119 | transform: translate3d(0, 0, 0);
|
120 | border-radius: $switch-paddle-radius;
|
121 | background: $switch-paddle-background;
|
122 | transition: $switch-paddle-transition;
|
123 | content: '';
|
124 | }
|
125 |
|
126 |
|
127 | input:checked ~ & {
|
128 | background: $switch-background-active;
|
129 |
|
130 | &::after {
|
131 | #{$global-left}: $paddle-active-offest;
|
132 | }
|
133 | }
|
134 |
|
135 | input:focus ~ & {
|
136 | @include disable-mouse-outline;
|
137 | }
|
138 | }
|
139 |
|
140 |
|
141 | @mixin switch-text {
|
142 | position: absolute;
|
143 | top: 50%;
|
144 | transform: translateY(-50%);
|
145 | }
|
146 |
|
147 |
|
148 | @mixin switch-text-active {
|
149 | #{$global-left}: 8%;
|
150 | display: none;
|
151 |
|
152 | input:checked + label > & {
|
153 | display: block;
|
154 | }
|
155 | }
|
156 |
|
157 |
|
158 | @mixin switch-text-inactive {
|
159 | #{$global-right}: 15%;
|
160 |
|
161 | input:checked + label > & {
|
162 | display: none;
|
163 | }
|
164 | }
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 | @mixin switch-size(
|
171 | $font-size: 1rem,
|
172 | $switch-height: 2rem,
|
173 | $paddle-offset: 0.25rem
|
174 | ) {
|
175 |
|
176 | $switch-width: $switch-height * 2;
|
177 | $paddle-width: $switch-height - ($paddle-offset * 2);
|
178 | $paddle-height: $switch-height - ($paddle-offset * 2);
|
179 | $paddle-active-offest: $switch-width - $paddle-width - $paddle-offset;
|
180 |
|
181 | height: $switch-height;
|
182 |
|
183 | .switch-paddle {
|
184 | width: $switch-width;
|
185 | height: $switch-height;
|
186 | font-size: $font-size;
|
187 | }
|
188 |
|
189 | .switch-paddle::after {
|
190 | top: $paddle-offset;
|
191 | #{$global-left}: $paddle-offset;
|
192 | width: $paddle-width;
|
193 | height: $paddle-height;
|
194 | }
|
195 |
|
196 | input:checked ~ .switch-paddle::after {
|
197 | #{$global-left}: $paddle-active-offest;
|
198 | }
|
199 | }
|
200 |
|
201 | @mixin foundation-switch {
|
202 |
|
203 | .switch {
|
204 | height: $switch-height;
|
205 | @include switch-container;
|
206 | }
|
207 |
|
208 |
|
209 | .switch-input {
|
210 | @include switch-input;
|
211 | }
|
212 |
|
213 |
|
214 | .switch-paddle {
|
215 | @include switch-paddle;
|
216 | }
|
217 |
|
218 |
|
219 | %switch-text {
|
220 | @include switch-text;
|
221 | }
|
222 |
|
223 |
|
224 | .switch-active {
|
225 | @extend %switch-text;
|
226 | @include switch-text-active;
|
227 | }
|
228 |
|
229 |
|
230 | .switch-inactive {
|
231 | @extend %switch-text;
|
232 | @include switch-text-inactive;
|
233 | }
|
234 |
|
235 |
|
236 | .switch.tiny {
|
237 | @include switch-size(rem-calc(10), $switch-height-tiny, $switch-paddle-offset);
|
238 | }
|
239 |
|
240 | .switch.small {
|
241 | @include switch-size(rem-calc(12), $switch-height-small, $switch-paddle-offset);
|
242 | }
|
243 |
|
244 | .switch.large {
|
245 | @include switch-size(rem-calc(16), $switch-height-large, $switch-paddle-offset);
|
246 | }
|
247 | }
|