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 | @use 'sass:math';
|
27 | @use '@material/density/functions' as density-functions;
|
28 | @use '@material/elevation/mixins' as elevation-mixins;
|
29 | @use '@material/feature-targeting/feature-targeting';
|
30 | @use '@material/ripple/ripple';
|
31 | @use '@material/ripple/ripple-theme';
|
32 | @use '@material/rtl/rtl';
|
33 | @use '@material/theme/theme';
|
34 | @use './functions';
|
35 | @use './variables';
|
36 | @use '@material/dom/mixins' as dom-mixins;
|
37 |
|
38 |
|
39 | $deprecated-suffix: '-deprecated' !default;
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | @mixin core-styles($query: feature-targeting.all()) {
|
46 | @include without-ripple($query);
|
47 | @include ripple($query);
|
48 | }
|
49 |
|
50 |
|
51 |
|
52 | @mixin without-ripple($query: feature-targeting.all()) {
|
53 |
|
54 |
|
55 | $feat-animation: feature-targeting.create-target($query, animation);
|
56 | $feat-structure: feature-targeting.create-target($query, structure);
|
57 |
|
58 | @include density(variables.$density-scale, $query: $query);
|
59 |
|
60 | .mdc-switch#{$deprecated-suffix} {
|
61 | @include feature-targeting.targets($feat-structure) {
|
62 | @include base_;
|
63 | }
|
64 |
|
65 | @include toggled-on-track-color(variables.$baseline-theme-color, $query);
|
66 | @include toggled-on-thumb-color(variables.$baseline-theme-color, $query);
|
67 | @include toggled-off-track-color(
|
68 | variables.$toggled-off-track-color,
|
69 | $query
|
70 | );
|
71 | @include toggled-off-thumb-color(
|
72 | variables.$toggled-off-thumb-color,
|
73 | $query
|
74 | );
|
75 | }
|
76 |
|
77 | .mdc-switch__native-control {
|
78 | @include feature-targeting.targets($feat-structure) {
|
79 | @include native-control_;
|
80 | }
|
81 | @include feature-targeting.targets($feat-animation) {
|
82 | transition: functions.transition(transform);
|
83 | }
|
84 | }
|
85 |
|
86 | .mdc-switch__track#{$deprecated-suffix} {
|
87 | @include track_($query);
|
88 | }
|
89 |
|
90 | .mdc-switch__thumb-underlay {
|
91 | @include thumb-underlay_($query);
|
92 | }
|
93 |
|
94 | .mdc-switch__thumb {
|
95 | @include thumb_($query);
|
96 | }
|
97 |
|
98 | .mdc-switch--checked {
|
99 | @include feature-targeting.targets($feat-structure) {
|
100 | .mdc-switch__track#{$deprecated-suffix} {
|
101 | @include track-checked_;
|
102 | }
|
103 |
|
104 | .mdc-switch__thumb-underlay {
|
105 | @include thumb-underlay-checked_;
|
106 | }
|
107 |
|
108 | .mdc-switch__native-control {
|
109 | @include native-control-checked_;
|
110 | }
|
111 | }
|
112 | }
|
113 |
|
114 | .mdc-switch--disabled {
|
115 | @include feature-targeting.targets($feat-structure) {
|
116 | @include disabled-base_;
|
117 |
|
118 | .mdc-switch__thumb {
|
119 | @include thumb-disabled_;
|
120 | }
|
121 |
|
122 | .mdc-switch__native-control {
|
123 | @include native-control-disabled_;
|
124 | }
|
125 | }
|
126 | }
|
127 |
|
128 |
|
129 | }
|
130 |
|
131 |
|
132 |
|
133 | @mixin ripple($query: feature-targeting.all()) {
|
134 | @include ripple.common($query);
|
135 |
|
136 | .mdc-switch#{$deprecated-suffix} {
|
137 | @include toggled-off-ripple-color(
|
138 | variables.$toggled-off-ripple-color,
|
139 | $query
|
140 | );
|
141 | }
|
142 |
|
143 | .mdc-switch__thumb-underlay {
|
144 | @include ripple.surface($query);
|
145 | @include ripple.radius-unbounded(100%, $query);
|
146 | @include ripple-theme.states(
|
147 | variables.$baseline-theme-color,
|
148 | false,
|
149 | $query
|
150 | );
|
151 | }
|
152 | }
|
153 |
|
154 | @mixin toggled-on-color($color, $query: feature-targeting.all()) {
|
155 | @include toggled-on-track-color($color, $query);
|
156 | @include toggled-on-thumb-color($color, $query);
|
157 | @include toggled-on-ripple-color($color, $query);
|
158 | }
|
159 |
|
160 | @mixin toggled-off-color($color, $query: feature-targeting.all()) {
|
161 | @include toggled-off-track-color($color, $query);
|
162 | @include toggled-off-thumb-color($color, $query);
|
163 | @include toggled-off-ripple-color($color, $query);
|
164 | }
|
165 |
|
166 | @mixin toggled-on-track-color($color, $query: feature-targeting.all()) {
|
167 | $feat-color: feature-targeting.create-target($query, color);
|
168 |
|
169 | &.mdc-switch--checked .mdc-switch__track#{$deprecated-suffix} {
|
170 | @include feature-targeting.targets($feat-color) {
|
171 | @include theme.property(background-color, $color);
|
172 | }
|
173 | }
|
174 | }
|
175 |
|
176 | @mixin toggled-on-thumb-color($color, $query: feature-targeting.all()) {
|
177 | $feat-color: feature-targeting.create-target($query, color);
|
178 |
|
179 | &.mdc-switch--checked .mdc-switch__thumb {
|
180 | @include feature-targeting.targets($feat-color) {
|
181 | @include theme.property(background-color, $color);
|
182 | @include theme.property(border-color, $color);
|
183 | }
|
184 | }
|
185 | }
|
186 |
|
187 | @mixin toggled-on-ripple-color($color, $query: feature-targeting.all()) {
|
188 | &.mdc-switch--checked .mdc-switch__thumb-underlay {
|
189 | @include ripple-theme.states($color, false, $query);
|
190 | }
|
191 | }
|
192 |
|
193 | @mixin toggled-off-track-color($color, $query: feature-targeting.all()) {
|
194 | $feat-color: feature-targeting.create-target($query, color);
|
195 |
|
196 | &:not(.mdc-switch--checked) .mdc-switch__track#{$deprecated-suffix} {
|
197 | @include feature-targeting.targets($feat-color) {
|
198 | @include theme.property(background-color, $color);
|
199 | }
|
200 | }
|
201 | }
|
202 |
|
203 | @mixin toggled-off-thumb-color($color, $query: feature-targeting.all()) {
|
204 | $feat-color: feature-targeting.create-target($query, color);
|
205 |
|
206 | &:not(.mdc-switch--checked) .mdc-switch__thumb {
|
207 | @include feature-targeting.targets($feat-color) {
|
208 | @include theme.property(background-color, $color);
|
209 | @include theme.property(border-color, $color);
|
210 | }
|
211 | }
|
212 | }
|
213 |
|
214 | @mixin toggled-off-ripple-color($color, $query: feature-targeting.all()) {
|
215 | &:not(.mdc-switch--checked) .mdc-switch__thumb-underlay {
|
216 | @include ripple-theme.states($color, false, $query);
|
217 | }
|
218 | }
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 | @mixin density($density-scale, $query: feature-targeting.all()) {
|
228 | $size: density-functions.prop-value(
|
229 | $density-config: variables.$density-config,
|
230 | $density-scale: $density-scale,
|
231 | $property-name: size,
|
232 | );
|
233 |
|
234 | @include ripple-size($size, $query: $query);
|
235 | }
|
236 |
|
237 | @mixin ripple-size($ripple-size, $query: feature-targeting.all()) {
|
238 | $feat-structure: feature-targeting.create-target($query, structure);
|
239 |
|
240 |
|
241 |
|
242 | $tap-target-initial-position: math.div(-$ripple-size, 2) +
|
243 | math.div(variables.$thumb-diameter, 2);
|
244 |
|
245 |
|
246 | $native-control-width: variables.$track-width +
|
247 | ($ripple-size - variables.$thumb-diameter);
|
248 |
|
249 | .mdc-switch__thumb-underlay {
|
250 | @include feature-targeting.targets($feat-structure) {
|
251 | @include rtl.reflexive-position(left, $tap-target-initial-position);
|
252 |
|
253 |
|
254 | top: -(math.div($ripple-size - variables.$track-height, 2));
|
255 | width: $ripple-size;
|
256 | height: $ripple-size;
|
257 | }
|
258 | }
|
259 |
|
260 | .mdc-switch__native-control {
|
261 | @include feature-targeting.targets($feat-structure) {
|
262 | width: $native-control-width;
|
263 | height: $ripple-size;
|
264 | }
|
265 | }
|
266 | }
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 | @mixin ripple-states-opacity(
|
274 | $opacity-map: (),
|
275 | $query: feature-targeting.all()
|
276 | ) {
|
277 |
|
278 | &.mdc-switch#{$deprecated-suffix} .mdc-switch__thumb-underlay {
|
279 | @include ripple-theme.states-opacities($opacity-map, $query: $query);
|
280 | }
|
281 | }
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 | @mixin base_ {
|
289 | display: inline-block;
|
290 | position: relative;
|
291 | outline: none;
|
292 | user-select: none;
|
293 | }
|
294 |
|
295 | @mixin track_($query: feature-targeting.all()) {
|
296 | $feat-animation: feature-targeting.create-target($query, animation);
|
297 | $feat-structure: feature-targeting.create-target($query, structure);
|
298 |
|
299 | @include feature-targeting.targets($feat-structure) {
|
300 | box-sizing: border-box;
|
301 | width: variables.$track-width;
|
302 | height: variables.$track-height;
|
303 | border: 1px solid transparent;
|
304 | border-radius: math.div(variables.$track-height, 2);
|
305 | opacity: 0.38;
|
306 | }
|
307 |
|
308 | @include feature-targeting.targets($feat-animation) {
|
309 | transition: functions.transition(opacity),
|
310 | functions.transition(background-color), functions.transition(border-color);
|
311 | }
|
312 | }
|
313 |
|
314 | @mixin thumb-underlay_($query: feature-targeting.all()) {
|
315 | $feat-animation: feature-targeting.create-target($query, animation);
|
316 | $feat-color: feature-targeting.create-target($query, color);
|
317 | $feat-structure: feature-targeting.create-target($query, structure);
|
318 |
|
319 | @include feature-targeting.targets($feat-structure) {
|
320 | display: flex;
|
321 | position: absolute;
|
322 | align-items: center;
|
323 | justify-content: center;
|
324 | transform: translateX(0);
|
325 | }
|
326 |
|
327 | @include feature-targeting.targets($feat-animation) {
|
328 | transition: functions.transition(transform),
|
329 | functions.transition(background-color), functions.transition(border-color);
|
330 | }
|
331 | }
|
332 |
|
333 | @mixin native-control_ {
|
334 | @include rtl.reflexive-position(left, 0);
|
335 |
|
336 | position: absolute;
|
337 | top: 0;
|
338 | margin: 0;
|
339 | opacity: 0;
|
340 | cursor: pointer;
|
341 | pointer-events: auto;
|
342 | }
|
343 |
|
344 | @mixin thumb_($query: feature-targeting.all()) {
|
345 | $feat-structure: feature-targeting.create-target($query, structure);
|
346 | $feat-color: feature-targeting.create-target($query, color);
|
347 |
|
348 | @include elevation-mixins.elevation($z-value: 2, $query: $query);
|
349 |
|
350 | @include feature-targeting.targets($feat-structure) {
|
351 | box-sizing: border-box;
|
352 | width: variables.$thumb-diameter;
|
353 | height: variables.$thumb-diameter;
|
354 | border: math.div(variables.$thumb-diameter, 2) solid;
|
355 | border-radius: 50%;
|
356 |
|
357 | pointer-events: none;
|
358 | z-index: 1;
|
359 | }
|
360 | }
|
361 |
|
362 |
|
363 |
|
364 | @mixin track-checked_ {
|
365 | opacity: 0.54;
|
366 | }
|
367 |
|
368 | @mixin thumb-underlay-checked_ {
|
369 | transform: translateX(variables.$thumb-active-margin);
|
370 |
|
371 | @include rtl.rtl {
|
372 | transform: translateX(-(variables.$thumb-active-margin));
|
373 | }
|
374 | }
|
375 |
|
376 | @mixin native-control-checked_ {
|
377 |
|
378 | transform: translateX(-(variables.$thumb-active-margin));
|
379 |
|
380 | @include rtl.rtl {
|
381 | transform: translateX(variables.$thumb-active-margin);
|
382 | }
|
383 | }
|
384 |
|
385 |
|
386 |
|
387 | @mixin disabled-base_ {
|
388 | opacity: 0.38;
|
389 | pointer-events: none;
|
390 | }
|
391 |
|
392 | @mixin thumb-disabled_ {
|
393 | border-width: 1px;
|
394 | }
|
395 |
|
396 | @mixin native-control-disabled_ {
|
397 | cursor: default;
|
398 | pointer-events: none;
|
399 | }
|
400 |
|
401 |
|
402 |
|
403 |
|
404 | @mixin high-contrast-mode-shim($query: feature-targeting.all()) {
|
405 | & .mdc-ripple-upgraded--background-focused .mdc-switch__thumb::before {
|
406 | @include dom-mixins.transparent-border($border-width: 3px);
|
407 | }
|
408 | }
|