|
| 1 | +@use 'sass:map'; |
1 | 2 | @use '@material/button/button' as mdc-button;
|
2 | 3 | @use '@material/button/button-theme' as mdc-button-theme;
|
3 |
| -@use '@material/ripple/ripple-theme' as mdc-ripple-theme; |
| 4 | +@use '@material/button/button-text-theme' as mdc-button-text-theme; |
| 5 | +@use '@material/button/button-filled-theme' as mdc-button-filled-theme; |
| 6 | +@use '@material/button/button-protected-theme' as mdc-button-protected-theme; |
| 7 | +@use '@material/button/button-outlined-theme' as mdc-button-outlined-theme; |
4 | 8 | @use '@material/theme/theme-color' as mdc-theme-color;
|
5 |
| -@use '@material/theme/theme' as mdc-theme; |
6 |
| -@use '@material/elevation/elevation-theme' as mdc-elevation-theme; |
7 |
| -@use '../../material/core/ripple/ripple-theme'; |
8 | 9 | @use '../../material/core/typography/typography';
|
9 | 10 | @use '../mdc-helpers/mdc-helpers';
|
10 | 11 | @use '../../material/core/theming/theming';
|
11 | 12 | @use './button-theme-private';
|
12 | 13 |
|
| 14 | +@mixin _button-variant($color) { |
| 15 | + @include mdc-button-text-theme.theme(( |
| 16 | + focus-state-layer-color: $color, |
| 17 | + hover-state-layer-color: $color, |
| 18 | + label-text-color: $color, |
| 19 | + pressed-state-layer-color: $color, |
| 20 | + )); |
| 21 | +} |
| 22 | + |
| 23 | +@mixin _unelevated-button-variant($foreground, $background) { |
| 24 | + @include mdc-button-filled-theme.theme(( |
| 25 | + container-color: $background, |
| 26 | + focus-state-layer-color: $foreground, |
| 27 | + hover-state-layer-color: $foreground, |
| 28 | + label-text-color: $foreground, |
| 29 | + pressed-state-layer-color: $foreground, |
| 30 | + )); |
| 31 | +} |
| 32 | + |
| 33 | +@mixin _raised-button-variant($foreground, $background) { |
| 34 | + @include mdc-button-protected-theme.theme(( |
| 35 | + container-color: $background, |
| 36 | + focus-state-layer-color: $foreground, |
| 37 | + hover-state-layer-color: $foreground, |
| 38 | + label-text-color: $foreground, |
| 39 | + pressed-state-layer-color: $foreground, |
| 40 | + )); |
| 41 | +} |
| 42 | + |
| 43 | +@mixin _outlined-button-variant($color) { |
| 44 | + @include mdc-button-outlined-theme.theme(( |
| 45 | + focus-state-layer-color: $color, |
| 46 | + hover-state-layer-color: $color, |
| 47 | + label-text-color: $color, |
| 48 | + outline-color: $color, |
| 49 | + pressed-state-layer-color: $color, |
| 50 | + )); |
| 51 | +} |
| 52 | + |
13 | 53 | @mixin color($config-or-theme) {
|
14 | 54 | $config: theming.get-color-config($config-or-theme);
|
15 | 55 | @include mdc-helpers.mat-using-mdc-theme($config) {
|
16 |
| - // Add state interactions for hover, focus, press, active. Colors are changed based on |
17 |
| - // the mixin mdc-states-base-color |
18 |
| - .mat-mdc-button, .mat-mdc-raised-button, .mat-mdc-unelevated-button, .mat-mdc-outlined-button { |
19 |
| - @include mdc-ripple-theme.states( |
20 |
| - $query: mdc-helpers.$mat-theme-styles-query, |
21 |
| - $ripple-target: button-theme-private.$button-state-target); |
22 |
| - } |
| 56 | + $is-dark: map.get($config, is-dark); |
| 57 | + $on-surface: mdc-theme-color.prop-value(on-surface); |
| 58 | + $surface: mdc-theme-color.prop-value(surface); |
| 59 | + $disabled-ink-color: rgba($on-surface, if($is-dark, 0.5, 0.38)); |
| 60 | + $disabled-container-color: rgba($on-surface, 0.12); |
| 61 | + $primary: mdc-theme-color.prop-value(primary); |
| 62 | + $on-primary: mdc-theme-color.prop-value(on-primary); |
| 63 | + $secondary: mdc-theme-color.prop-value(secondary); |
| 64 | + $on-secondary: mdc-theme-color.prop-value(on-secondary); |
| 65 | + $error: mdc-theme-color.prop-value(error); |
| 66 | + $on-error: mdc-theme-color.prop-value(on-error); |
| 67 | + |
| 68 | + .mat-mdc-button { |
| 69 | + @include mdc-button-text-theme.theme(button-theme-private.add-ripple-opacities($is-dark)); |
23 | 70 |
|
24 |
| - .mat-mdc-button, .mat-mdc-outlined-button { |
25 | 71 | &.mat-unthemed {
|
26 |
| - @include mdc-button-theme.ink-color(mdc-theme-color.$on-surface, |
27 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
| 72 | + @include _button-variant($on-surface); |
28 | 73 | }
|
29 | 74 |
|
30 | 75 | &.mat-primary {
|
31 |
| - @include mdc-button-theme.ink-color(primary, $query: mdc-helpers.$mat-theme-styles-query); |
32 |
| - @include mdc-ripple-theme.states-base-color(primary, |
33 |
| - $query: mdc-helpers.$mat-theme-styles-query, |
34 |
| - $ripple-target: button-theme-private.$button-state-target); |
35 |
| - @include button-theme-private.ripple-ink-color(primary); |
| 76 | + @include _button-variant($primary); |
36 | 77 | }
|
37 | 78 |
|
38 | 79 | &.mat-accent {
|
39 |
| - @include mdc-button-theme.ink-color(secondary, $query: mdc-helpers.$mat-theme-styles-query); |
40 |
| - @include mdc-ripple-theme.states-base-color(secondary, |
41 |
| - $query: mdc-helpers.$mat-theme-styles-query, |
42 |
| - $ripple-target: button-theme-private.$button-state-target); |
43 |
| - @include button-theme-private.ripple-ink-color(secondary); |
| 80 | + @include _button-variant($secondary); |
44 | 81 | }
|
45 | 82 |
|
46 | 83 | &.mat-warn {
|
47 |
| - @include mdc-button-theme.ink-color(error, $query: mdc-helpers.$mat-theme-styles-query); |
48 |
| - @include mdc-ripple-theme.states-base-color(error, |
49 |
| - $query: mdc-helpers.$mat-theme-styles-query, |
50 |
| - $ripple-target: button-theme-private.$button-state-target); |
51 |
| - @include button-theme-private.ripple-ink-color(error); |
| 84 | + @include _button-variant($error); |
| 85 | + } |
| 86 | + |
| 87 | + @include button-theme-private.apply-disabled-style() { |
| 88 | + @include mdc-button-text-theme.theme(( |
| 89 | + // We need to pass both the disabled and enabled values, because the enabled |
| 90 | + // ones apply to anchors while the disabled ones are for buttons. |
| 91 | + disabled-label-text-color: $disabled-ink-color, |
| 92 | + label-text-color: $disabled-ink-color |
| 93 | + )); |
52 | 94 | }
|
53 | 95 | }
|
54 | 96 |
|
55 |
| - .mat-mdc-raised-button, |
56 | 97 | .mat-mdc-unelevated-button {
|
| 98 | + @include mdc-button-filled-theme.theme(button-theme-private.add-ripple-opacities($is-dark)); |
| 99 | + |
57 | 100 | &.mat-unthemed {
|
58 |
| - @include mdc-button-theme.container-fill-color(mdc-theme-color.$surface, |
59 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
60 |
| - @include mdc-button-theme.ink-color(mdc-theme-color.$on-surface, |
61 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
62 |
| - @include mdc-ripple-theme.states-base-color(mdc-theme-color.$on-surface, |
63 |
| - $query: mdc-helpers.$mat-theme-styles-query, |
64 |
| - $ripple-target: button-theme-private.$button-state-target); |
| 101 | + @include _unelevated-button-variant($on-surface, $surface); |
65 | 102 | }
|
66 | 103 |
|
67 | 104 | &.mat-primary {
|
68 |
| - @include mdc-button-theme.container-fill-color(primary, |
69 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
70 |
| - @include mdc-button-theme.ink-color(on-primary, |
71 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
72 |
| - @include mdc-ripple-theme.states-base-color(on-primary, |
73 |
| - $query: mdc-helpers.$mat-theme-styles-query, |
74 |
| - $ripple-target: button-theme-private.$button-state-target); |
75 |
| - @include button-theme-private.ripple-ink-color(on-primary); |
| 105 | + @include _unelevated-button-variant($on-primary, $primary); |
76 | 106 | }
|
77 | 107 |
|
78 | 108 | &.mat-accent {
|
79 |
| - @include mdc-button-theme.container-fill-color(secondary, |
80 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
81 |
| - @include mdc-button-theme.ink-color(on-secondary, |
82 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
83 |
| - @include mdc-ripple-theme.states-base-color(on-secondary, |
84 |
| - $query: mdc-helpers.$mat-theme-styles-query, |
85 |
| - $ripple-target: button-theme-private.$button-state-target); |
86 |
| - @include button-theme-private.ripple-ink-color(on-secondary); |
| 109 | + @include _unelevated-button-variant($on-secondary, $secondary); |
87 | 110 | }
|
88 | 111 |
|
89 | 112 | &.mat-warn {
|
90 |
| - @include mdc-button-theme.container-fill-color(error, |
91 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
92 |
| - @include mdc-button-theme.ink-color(on-error, $query: mdc-helpers.$mat-theme-styles-query); |
93 |
| - @include mdc-ripple-theme.states-base-color(on-error, |
94 |
| - $query: mdc-helpers.$mat-theme-styles-query, |
95 |
| - $ripple-target: button-theme-private.$button-state-target); |
96 |
| - @include button-theme-private.ripple-ink-color(on-error); |
| 113 | + @include _unelevated-button-variant($on-error, $error); |
97 | 114 | }
|
98 | 115 |
|
99 | 116 | @include button-theme-private.apply-disabled-style() {
|
100 |
| - @include button-theme-private.apply-disabled-background(); |
| 117 | + @include mdc-button-filled-theme.theme(( |
| 118 | + // We need to pass both the disabled and enabled values, because the enabled |
| 119 | + // ones apply to anchors while the disabled ones are for buttons. |
| 120 | + disabled-container-color: $disabled-container-color, |
| 121 | + disabled-label-text-color: $disabled-ink-color, |
| 122 | + container-color: $disabled-container-color, |
| 123 | + label-text-color: $disabled-ink-color, |
| 124 | + )); |
101 | 125 | }
|
102 | 126 | }
|
103 | 127 |
|
104 |
| - .mat-mdc-outlined-button { |
| 128 | + .mat-mdc-raised-button { |
| 129 | + @include mdc-button-protected-theme.theme( |
| 130 | + button-theme-private.add-ripple-opacities($is-dark)); |
| 131 | + |
105 | 132 | &.mat-unthemed {
|
106 |
| - @include mdc-button-theme.outline-color(mdc-theme-color.$on-surface, |
107 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
| 133 | + @include _raised-button-variant($on-surface, $surface); |
108 | 134 | }
|
109 | 135 |
|
110 | 136 | &.mat-primary {
|
111 |
| - @include mdc-button-theme.outline-color(primary, |
112 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
| 137 | + @include _raised-button-variant($on-primary, $primary); |
113 | 138 | }
|
114 | 139 |
|
115 | 140 | &.mat-accent {
|
116 |
| - @include mdc-button-theme.outline-color(secondary, |
117 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
| 141 | + @include _raised-button-variant($on-secondary, $secondary); |
118 | 142 | }
|
119 | 143 |
|
120 | 144 | &.mat-warn {
|
121 |
| - @include mdc-button-theme.outline-color(error, |
122 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
| 145 | + @include _raised-button-variant($on-error, $error); |
123 | 146 | }
|
124 | 147 |
|
125 | 148 | @include button-theme-private.apply-disabled-style() {
|
126 |
| - @include mdc-theme.prop(border-color, |
127 |
| - mdc-theme-color.ink-color-for-fill_(disabled, mdc-theme-color.$background)); |
| 149 | + @include mdc-button-protected-theme.theme(( |
| 150 | + // We need to pass both the disabled and enabled values, because the enabled |
| 151 | + // ones apply to anchors while the disabled ones are for buttons. |
| 152 | + disabled-container-color: $disabled-container-color, |
| 153 | + disabled-label-text-color: $disabled-ink-color, |
| 154 | + container-color: $disabled-container-color, |
| 155 | + label-text-color: $disabled-ink-color, |
| 156 | + container-elevation: 0, |
| 157 | + )); |
128 | 158 | }
|
129 | 159 | }
|
130 | 160 |
|
131 |
| - .mat-mdc-raised-button { |
| 161 | + .mat-mdc-outlined-button { |
| 162 | + @include mdc-button-outlined-theme.theme(button-theme-private.add-ripple-opacities($is-dark)); |
| 163 | + |
| 164 | + &.mat-unthemed { |
| 165 | + @include _outlined-button-variant($on-surface); |
| 166 | + } |
| 167 | + |
| 168 | + &.mat-primary { |
| 169 | + @include _outlined-button-variant($primary); |
| 170 | + } |
| 171 | + |
| 172 | + &.mat-accent { |
| 173 | + @include _outlined-button-variant($secondary); |
| 174 | + } |
| 175 | + |
| 176 | + &.mat-warn { |
| 177 | + @include _outlined-button-variant($error); |
| 178 | + } |
| 179 | + |
132 | 180 | @include button-theme-private.apply-disabled-style() {
|
133 |
| - @include mdc-elevation-theme.elevation(0, $query: mdc-helpers.$mat-theme-styles-query); |
| 181 | + @include mdc-button-outlined-theme.theme(( |
| 182 | + // We need to pass both the disabled and enabled values, because the enabled |
| 183 | + // ones apply to anchors while the disabled ones are for buttons. |
| 184 | + label-text-color: $disabled-ink-color, |
| 185 | + outline-color: $disabled-ink-color, |
| 186 | + disabled-label-text-color: $disabled-ink-color, |
| 187 | + disabled-outline-color: $disabled-ink-color, |
| 188 | + )); |
134 | 189 | }
|
135 | 190 | }
|
136 | 191 |
|
137 |
| - .mat-mdc-button, .mat-mdc-raised-button, .mat-mdc-unelevated-button, .mat-mdc-outlined-button { |
138 |
| - @include button-theme-private.apply-disabled-style() { |
139 |
| - @include button-theme-private.apply-disabled-color(); |
| 192 | + // Ripple colors |
| 193 | + .mat-mdc-button, .mat-mdc-outlined-button { |
| 194 | + &.mat-primary { |
| 195 | + @include button-theme-private.ripple-ink-color($primary); |
| 196 | + } |
| 197 | + |
| 198 | + &.mat-accent { |
| 199 | + @include button-theme-private.ripple-ink-color($secondary); |
| 200 | + } |
| 201 | + |
| 202 | + &.mat-warn { |
| 203 | + @include button-theme-private.ripple-ink-color($error); |
140 | 204 | }
|
141 | 205 | }
|
142 | 206 |
|
143 |
| - @include mdc-button.without-ripple($query: mdc-helpers.$mat-theme-styles-query); |
| 207 | + .mat-mdc-raised-button, .mat-mdc-unelevated-button { |
| 208 | + &.mat-primary { |
| 209 | + @include button-theme-private.ripple-ink-color($on-primary); |
| 210 | + } |
| 211 | + |
| 212 | + &.mat-accent { |
| 213 | + @include button-theme-private.ripple-ink-color($on-secondary); |
| 214 | + } |
| 215 | + |
| 216 | + &.mat-warn { |
| 217 | + @include button-theme-private.ripple-ink-color($on-error); |
| 218 | + } |
| 219 | + } |
144 | 220 | }
|
145 | 221 | }
|
146 | 222 |
|
|
0 commit comments