|
| 1 | +@use 'sass:map'; |
1 | 2 | @use '@material/switch/switch-theme' as mdc-switch-theme;
|
2 | 3 | @use '@material/form-field' as mdc-form-field;
|
3 | 4 | @use '../core/theming/theming';
|
4 | 5 | @use '../core/theming/inspection';
|
5 | 6 | @use '../core/mdc-helpers/mdc-helpers';
|
6 | 7 | @use '../core/typography/typography';
|
7 |
| -@use '../core/tokens/m2/mdc/switch' as m2-mdc-switch; |
8 |
| -@use '../core/tokens/m2/mat/slide-toggle' as m2-mat-slide-toggle; |
| 8 | +@use '../core/tokens/m2/mdc/switch' as tokens-mdc-switch; |
| 9 | +@use '../core/tokens/m2/mat/slide-toggle' as tokens-mat-slide-toggle; |
9 | 10 | @use '../core/tokens/token-utils';
|
10 | 11 |
|
11 | 12 | @mixin base($theme) {
|
12 |
| - .mdc-switch { |
13 |
| - @include mdc-switch-theme.theme(m2-mdc-switch.get-unthemable-tokens()); |
| 13 | + @if inspection.get-theme-version($theme) == 1 { |
| 14 | + @include _theme-from-tokens(inspection.get-theme-tokens($theme, base)); |
| 15 | + } |
| 16 | + @else { |
| 17 | + .mdc-switch { |
| 18 | + @include mdc-switch-theme.theme(tokens-mdc-switch.get-unthemable-tokens()); |
| 19 | + } |
14 | 20 | }
|
15 | 21 | }
|
16 | 22 |
|
17 | 23 | @mixin color($theme) {
|
18 |
| - $is-dark: inspection.get-theme-type($theme) == dark; |
19 |
| - $mdc-switch-color-tokens: m2-mdc-switch.get-color-tokens($theme); |
| 24 | + @if inspection.get-theme-version($theme) == 1 { |
| 25 | + @include _theme-from-tokens(inspection.get-theme-tokens($theme, color)); |
| 26 | + } |
| 27 | + @else { |
| 28 | + $is-dark: inspection.get-theme-type($theme) == dark; |
| 29 | + $mdc-switch-color-tokens: tokens-mdc-switch.get-color-tokens($theme); |
20 | 30 |
|
21 |
| - @include mdc-helpers.using-mdc-theme($theme) { |
22 |
| - // Add values for MDC slide toggles tokens |
23 |
| - .mat-mdc-slide-toggle { |
24 |
| - @include mdc-form-field.core-styles($query: mdc-helpers.$mdc-theme-styles-query); |
25 |
| - @include mdc-switch-theme.theme($mdc-switch-color-tokens); |
| 31 | + @include mdc-helpers.using-mdc-theme($theme) { |
| 32 | + // Add values for MDC slide toggles tokens |
| 33 | + .mat-mdc-slide-toggle { |
| 34 | + @include mdc-form-field.core-styles($query: mdc-helpers.$mdc-theme-styles-query); |
| 35 | + @include mdc-switch-theme.theme($mdc-switch-color-tokens); |
26 | 36 |
|
27 |
| - // MDC should set the disabled color on the label, but doesn't, so we do it here instead. |
28 |
| - .mdc-switch--disabled + label { |
29 |
| - color: inspection.get-theme-color($theme, foreground, disabled-text); |
30 |
| - } |
| 37 | + // MDC should set the disabled color on the label, but doesn't, so we do it here instead. |
| 38 | + .mdc-switch--disabled + label { |
| 39 | + color: inspection.get-theme-color($theme, foreground, disabled-text); |
| 40 | + } |
31 | 41 |
|
32 |
| - // Change the color palette related tokens to accent or warn if applicable |
33 |
| - &.mat-accent { |
34 |
| - @include mdc-switch-theme.theme( |
35 |
| - m2-mdc-switch.private-get-color-palette-color-tokens($theme, accent)); |
36 |
| - } |
| 42 | + // Change the color palette related tokens to accent or warn if applicable |
| 43 | + &.mat-accent { |
| 44 | + @include mdc-switch-theme.theme( |
| 45 | + tokens-mdc-switch.private-get-color-palette-color-tokens($theme, accent)); |
| 46 | + } |
37 | 47 |
|
38 |
| - &.mat-warn { |
39 |
| - @include mdc-switch-theme.theme( |
40 |
| - m2-mdc-switch.private-get-color-palette-color-tokens($theme, warn)); |
| 48 | + &.mat-warn { |
| 49 | + @include mdc-switch-theme.theme( |
| 50 | + tokens-mdc-switch.private-get-color-palette-color-tokens($theme, warn)); |
| 51 | + } |
41 | 52 | }
|
42 | 53 | }
|
43 | 54 | }
|
44 | 55 | }
|
45 | 56 |
|
46 | 57 | @mixin typography($theme) {
|
47 |
| - $mdc-switch-typography-tokens: m2-mdc-switch.get-typography-tokens($theme); |
48 |
| - $mat-slide-toggle-typography-tokens: m2-mat-slide-toggle.get-typography-tokens($theme); |
| 58 | + @if inspection.get-theme-version($theme) == 1 { |
| 59 | + @include _theme-from-tokens(inspection.get-theme-tokens($theme, typography)); |
| 60 | + } |
| 61 | + @else { |
| 62 | + $mdc-switch-typography-tokens: tokens-mdc-switch.get-typography-tokens($theme); |
| 63 | + $mat-slide-toggle-typography-tokens: tokens-mat-slide-toggle.get-typography-tokens($theme); |
49 | 64 |
|
50 |
| - //Add values for MDC slide toggle tokens |
51 |
| - .mat-mdc-slide-toggle { |
52 |
| - @include mdc-form-field.core-styles($query: mdc-helpers.$mdc-typography-styles-query); |
53 |
| - @include mdc-switch-theme.theme($mdc-switch-typography-tokens); |
54 |
| - @include token-utils.create-token-values( |
55 |
| - m2-mat-slide-toggle.$prefix, |
56 |
| - $mat-slide-toggle-typography-tokens |
57 |
| - ); |
| 65 | + //Add values for MDC slide toggle tokens |
| 66 | + .mat-mdc-slide-toggle { |
| 67 | + @include mdc-form-field.core-styles($query: mdc-helpers.$mdc-typography-styles-query); |
| 68 | + @include mdc-switch-theme.theme($mdc-switch-typography-tokens); |
| 69 | + @include token-utils.create-token-values( |
| 70 | + tokens-mat-slide-toggle.$prefix, |
| 71 | + $mat-slide-toggle-typography-tokens |
| 72 | + ); |
| 73 | + } |
58 | 74 | }
|
59 | 75 | }
|
60 | 76 |
|
61 | 77 | @mixin density($theme) {
|
62 |
| - $density-scale: inspection.get-theme-density($theme); |
| 78 | + @if inspection.get-theme-version($theme) == 1 { |
| 79 | + @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); |
| 80 | + } |
| 81 | + @else { |
| 82 | + $density-scale: inspection.get-theme-density($theme); |
63 | 83 |
|
64 |
| - .mat-mdc-slide-toggle { |
65 |
| - @include mdc-switch-theme.theme(mdc-switch-theme.density($density-scale)); |
| 84 | + .mat-mdc-slide-toggle { |
| 85 | + @include mdc-switch-theme.theme(mdc-switch-theme.density($density-scale)); |
| 86 | + } |
66 | 87 | }
|
67 | 88 | }
|
68 | 89 |
|
69 | 90 | @mixin theme($theme) {
|
70 | 91 | @include theming.private-check-duplicate-theme-styles($theme, 'mat-slide-toggle') {
|
71 |
| - @include base($theme); |
72 |
| - @if inspection.theme-has($theme, color) { |
73 |
| - @include color($theme); |
74 |
| - } |
75 |
| - @if inspection.theme-has($theme, density) { |
76 |
| - @include density($theme); |
| 92 | + @if inspection.get-theme-version($theme) == 1 { |
| 93 | + @include _theme-from-tokens(inspection.get-theme-tokens($theme)); |
77 | 94 | }
|
78 |
| - @if inspection.theme-has($theme, typography) { |
79 |
| - @include typography($theme); |
| 95 | + @else { |
| 96 | + @include base($theme); |
| 97 | + @if inspection.theme-has($theme, color) { |
| 98 | + @include color($theme); |
| 99 | + } |
| 100 | + @if inspection.theme-has($theme, density) { |
| 101 | + @include density($theme); |
| 102 | + } |
| 103 | + @if inspection.theme-has($theme, typography) { |
| 104 | + @include typography($theme); |
| 105 | + } |
80 | 106 | }
|
81 | 107 | }
|
82 | 108 | }
|
| 109 | + |
| 110 | +@mixin _theme-from-tokens($tokens) { |
| 111 | + @if ($tokens != ()) { |
| 112 | + @include mdc-switch-theme.theme(map.get($tokens, tokens-mdc-switch.$prefix)); |
| 113 | + @include token-utils.create-token-values( |
| 114 | + tokens-mat-slide-toggle.$prefix, map.get($tokens, tokens-mat-slide-toggle.$prefix)); |
| 115 | + } |
| 116 | +} |
0 commit comments