|
1 |
| -@use '@material/theme/theme-color' as mdc-theme-color; |
2 |
| -@use '@material/switch/deprecated' as mdc-switch with ($deprecated-suffix: ''); |
3 |
| -@use '@material/form-field' as mdc-form-field; |
4 | 1 | @use 'sass:map';
|
| 2 | +@use 'sass:color'; |
| 3 | +@use '@material/switch/switch-theme' as mdc-switch-theme; |
| 4 | +@use '@material/theme/color-palette' as mdc-color-palette; |
| 5 | +@use '@material/form-field' as mdc-form-field; |
5 | 6 | @use '../mdc-helpers/mdc-helpers';
|
6 | 7 | @use '../../material/core/typography/typography';
|
7 | 8 | @use '../../material/core/theming/theming';
|
| 9 | +@use '../../material/core/theming/palette'; |
| 10 | + |
| 11 | +// Generates all color mapping for the properties that only change based on the theme. |
| 12 | +@function _get-theme-base-map($is-dark) { |
| 13 | + $on-surface: if($is-dark, mdc-color-palette.$grey-100, mdc-color-palette.$grey-800); |
| 14 | + $hairline: if($is-dark, mdc-color-palette.$grey-500, mdc-color-palette.$grey-300); |
| 15 | + $on-surface-variant: if($is-dark, mdc-color-palette.$grey-200, mdc-color-palette.$grey-700); |
| 16 | + $on-surface-state-content: if($is-dark, mdc-color-palette.$grey-50, mdc-color-palette.$grey-900); |
| 17 | + $disabled-handle-color: mdc-color-palette.$grey-800; |
| 18 | + $selected-icon-color: mdc-color-palette.$grey-100; |
| 19 | + $icon-color: if($is-dark, mdc-color-palette.$grey-800, mdc-color-palette.$grey-100); |
| 20 | + |
| 21 | + @return ( |
| 22 | + disabled-selected-handle-color: $disabled-handle-color, |
| 23 | + disabled-unselected-handle-color: $disabled-handle-color, |
| 24 | + |
| 25 | + disabled-selected-track-color: $on-surface, |
| 26 | + disabled-unselected-track-color: $on-surface, |
| 27 | + unselected-focus-state-layer-color: $on-surface, |
| 28 | + unselected-pressed-state-layer-color: $on-surface, |
| 29 | + unselected-hover-state-layer-color: $on-surface, |
| 30 | + |
| 31 | + unselected-focus-track-color: $hairline, |
| 32 | + unselected-hover-track-color: $hairline, |
| 33 | + unselected-pressed-track-color: $hairline, |
| 34 | + unselected-track-color: $hairline, |
| 35 | + |
| 36 | + unselected-focus-handle-color: $on-surface-state-content, |
| 37 | + unselected-hover-handle-color: $on-surface-state-content, |
| 38 | + unselected-pressed-handle-color: $on-surface-state-content, |
| 39 | + |
| 40 | + handle-surface-color: surface, |
| 41 | + unselected-handle-color: $on-surface-variant, |
| 42 | + |
| 43 | + selected-icon-color: $selected-icon-color, |
| 44 | + disabled-selected-icon-color: $icon-color, |
| 45 | + disabled-unselected-icon-color: $icon-color, |
| 46 | + unselected-icon-color: $icon-color, |
| 47 | + ); |
| 48 | +} |
8 | 49 |
|
| 50 | +// Generates the mapping for the properties that change based on the slide toggle color. |
| 51 | +@function _get-theme-color-map($color-palette) { |
| 52 | + $state-content: color.scale($color-palette, $blackness: 50%); |
| 53 | + $inverse: color.scale($color-palette, $lightness: 75%); |
| 54 | + |
| 55 | + @return ( |
| 56 | + selected-focus-state-layer-color: $color-palette, |
| 57 | + selected-handle-color: $color-palette, |
| 58 | + selected-hover-state-layer-color: $color-palette, |
| 59 | + selected-pressed-state-layer-color: $color-palette, |
| 60 | + |
| 61 | + selected-focus-handle-color: $state-content, |
| 62 | + selected-hover-handle-color: $state-content, |
| 63 | + selected-pressed-handle-color: $state-content, |
| 64 | + |
| 65 | + selected-focus-track-color: $inverse, |
| 66 | + selected-hover-track-color: $inverse, |
| 67 | + selected-pressed-track-color: $inverse, |
| 68 | + selected-track-color: $inverse, |
| 69 | + ); |
| 70 | +} |
9 | 71 |
|
10 | 72 | @mixin color($config-or-theme) {
|
11 | 73 | $config: theming.get-color-config($config-or-theme);
|
12 | 74 | $primary: theming.get-color-from-palette(map.get($config, primary));
|
13 | 75 | $accent: theming.get-color-from-palette(map.get($config, accent));
|
14 | 76 | $warn: theming.get-color-from-palette(map.get($config, warn));
|
15 |
| - |
16 |
| - // Save original values of MDC global variables. We need to save these so we can restore the |
17 |
| - // variables to their original values and prevent unintended side effects from using this mixin. |
18 |
| - $orig-baseline-theme-color: mdc-switch.$baseline-theme-color; |
19 |
| - $orig-toggled-off-thumb-color: mdc-switch.$toggled-off-thumb-color; |
20 |
| - $orig-toggled-off-track-color: mdc-switch.$toggled-off-track-color; |
21 |
| - $orig-disabled-thumb-color: mdc-switch.$disabled-thumb-color; |
22 |
| - $orig-disabled-track-color: mdc-switch.$disabled-track-color; |
| 77 | + $is-dark: map.get($config, is-dark); |
23 | 78 |
|
24 | 79 | @include mdc-helpers.mat-using-mdc-theme($config) {
|
25 |
| - mdc-switch.$baseline-theme-color: primary; |
26 |
| - mdc-switch.$toggled-off-thumb-color: mdc-theme-color.prop-value(surface); |
27 |
| - mdc-switch.$toggled-off-track-color: mdc-theme-color.prop-value(on-surface); |
28 |
| - mdc-switch.$disabled-thumb-color: mdc-theme-color.prop-value(surface); |
29 |
| - mdc-switch.$disabled-track-color: mdc-theme-color.prop-value(on-surface); |
30 |
| - |
31 | 80 | // MDC's switch doesn't support a `color` property. We add support
|
32 | 81 | // for it by adding a CSS class for accent and warn style.
|
33 | 82 | .mat-mdc-slide-toggle {
|
34 | 83 | @include mdc-form-field.core-styles($query: mdc-helpers.$mat-theme-styles-query);
|
35 |
| - |
36 |
| - .mdc-switch__thumb-underlay::after, .mat-ripple-element { |
37 |
| - background: mdc-switch.$toggled-off-ripple-color; |
38 |
| - } |
| 84 | + @include mdc-switch-theme.theme(_get-theme-base-map($is-dark)); |
39 | 85 |
|
40 | 86 | &.mat-primary {
|
41 |
| - @include mdc-switch.without-ripple($query: mdc-helpers.$mat-theme-styles-query); |
| 87 | + @include mdc-switch-theme.theme(_get-theme-color-map($primary)); |
42 | 88 | }
|
43 | 89 |
|
44 | 90 | &.mat-accent {
|
45 |
| - mdc-switch.$baseline-theme-color: secondary; |
46 |
| - @include mdc-switch.without-ripple($query: mdc-helpers.$mat-theme-styles-query); |
| 91 | + @include mdc-switch-theme.theme(_get-theme-color-map($accent)); |
47 | 92 | }
|
48 | 93 |
|
49 | 94 | &.mat-warn {
|
50 |
| - mdc-switch.$baseline-theme-color: error; |
51 |
| - @include mdc-switch.without-ripple($query: mdc-helpers.$mat-theme-styles-query); |
| 95 | + @include mdc-switch-theme.theme(_get-theme-color-map($warn)); |
52 | 96 | }
|
53 | 97 | }
|
54 | 98 |
|
55 | 99 | // The ripple color matches the palette only when it's checked.
|
56 | 100 | .mat-mdc-slide-toggle-checked {
|
57 |
| - .mdc-switch__thumb-underlay::after, .mat-ripple-element { |
| 101 | + .mdc-switch__ripple::after, .mat-ripple-element { |
58 | 102 | background: $primary;
|
59 | 103 | }
|
60 | 104 |
|
61 | 105 | &.mat-accent {
|
62 |
| - .mdc-switch__thumb-underlay::after, .mat-ripple-element { |
| 106 | + .mdc-switch__ripple::after, .mat-ripple-element { |
63 | 107 | background: $accent;
|
64 | 108 | }
|
65 | 109 | }
|
66 | 110 |
|
67 | 111 | &.mat-warn {
|
68 |
| - .mdc-switch__thumb-underlay::after, .mat-ripple-element { |
| 112 | + .mdc-switch__ripple::after, .mat-ripple-element { |
69 | 113 | background: $warn;
|
70 | 114 | }
|
71 | 115 | }
|
72 | 116 | }
|
73 | 117 | }
|
74 |
| - |
75 |
| - // Restore original values of MDC global variables. |
76 |
| - mdc-switch.$baseline-theme-color: $orig-baseline-theme-color; |
77 |
| - mdc-switch.$toggled-off-thumb-color: $orig-toggled-off-thumb-color; |
78 |
| - mdc-switch.$toggled-off-track-color: $orig-toggled-off-track-color; |
79 |
| - mdc-switch.$disabled-thumb-color: $orig-disabled-thumb-color; |
80 |
| - mdc-switch.$disabled-track-color: $orig-disabled-track-color; |
81 | 118 | }
|
82 | 119 |
|
83 | 120 | @mixin typography($config-or-theme) {
|
84 | 121 | $config: typography.private-typography-to-2018-config(
|
85 | 122 | theming.get-typography-config($config-or-theme));
|
86 | 123 | @include mdc-helpers.mat-using-mdc-typography($config) {
|
87 |
| - @include mdc-switch.without-ripple($query: mdc-helpers.$mat-typography-styles-query); |
88 | 124 | @include mdc-form-field.core-styles($query: mdc-helpers.$mat-typography-styles-query);
|
89 | 125 | }
|
90 | 126 | }
|
91 | 127 |
|
92 | 128 | @mixin density($config-or-theme) {
|
93 | 129 | $density-scale: theming.get-density-config($config-or-theme);
|
94 |
| - .mat-mdc-slide-toggle .mdc-switch { |
95 |
| - @include mdc-switch.density($density-scale, $query: mdc-helpers.$mat-base-styles-query); |
| 130 | + .mat-mdc-slide-toggle { |
| 131 | + @include mdc-switch-theme.theme(mdc-switch-theme.density($density-scale)); |
96 | 132 | }
|
97 | 133 | }
|
98 | 134 |
|
99 | 135 | @mixin theme($theme-or-color-config) {
|
100 | 136 | $theme: theming.private-legacy-get-theme($theme-or-color-config);
|
| 137 | + |
101 | 138 | @include theming.private-check-duplicate-theme-styles($theme, 'mat-mdc-slide-toggle') {
|
102 | 139 | $color: theming.get-color-config($theme);
|
103 | 140 | $density: theming.get-density-config($theme);
|
|
0 commit comments