|
| 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 |
| - } |
23 |
| - |
24 |
| - .mat-mdc-button, .mat-mdc-outlined-button { |
| 56 | + $on-surface: mdc-theme-color.prop-value(on-surface); |
| 57 | + $surface: mdc-theme-color.prop-value(surface); |
| 58 | + $disabled-ink-color: rgba($on-surface, if(map.get($config, is-dark), 0.5, 0.38)); |
| 59 | + $disabled-container-color: rgba($on-surface, 0.12); |
| 60 | + $primary: mdc-theme-color.prop-value(primary); |
| 61 | + $on-primary: mdc-theme-color.prop-value(on-primary); |
| 62 | + $secondary: mdc-theme-color.prop-value(secondary); |
| 63 | + $on-secondary: mdc-theme-color.prop-value(on-secondary); |
| 64 | + $error: mdc-theme-color.prop-value(error); |
| 65 | + $on-error: mdc-theme-color.prop-value(on-error); |
| 66 | + |
| 67 | + .mat-mdc-button { |
25 | 68 | &.mat-unthemed {
|
26 |
| - @include mdc-button-theme.ink-color(mdc-theme-color.$on-surface, |
27 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
| 69 | + @include _button-variant($on-surface); |
28 | 70 | }
|
29 | 71 |
|
30 | 72 | &.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); |
| 73 | + @include _button-variant($primary); |
36 | 74 | }
|
37 | 75 |
|
38 | 76 | &.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); |
| 77 | + @include _button-variant($secondary); |
44 | 78 | }
|
45 | 79 |
|
46 | 80 | &.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); |
| 81 | + @include _button-variant($error); |
| 82 | + } |
| 83 | + |
| 84 | + @include button-theme-private.apply-disabled-style() { |
| 85 | + @include mdc-button-text-theme.theme(( |
| 86 | + // We need to pass both the disabled and enabled values, because the enabled |
| 87 | + // ones apply to anchors while the disabled ones are for buttons. |
| 88 | + disabled-label-text-color: $disabled-ink-color, |
| 89 | + label-text-color: $disabled-ink-color |
| 90 | + )); |
52 | 91 | }
|
53 | 92 | }
|
54 | 93 |
|
55 |
| - .mat-mdc-raised-button, |
56 | 94 | .mat-mdc-unelevated-button {
|
57 | 95 | &.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); |
| 96 | + @include _unelevated-button-variant($on-surface, $surface); |
65 | 97 | }
|
66 | 98 |
|
67 | 99 | &.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); |
| 100 | + @include _unelevated-button-variant($on-primary, $primary); |
76 | 101 | }
|
77 | 102 |
|
78 | 103 | &.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); |
| 104 | + @include _unelevated-button-variant($on-secondary, $secondary); |
87 | 105 | }
|
88 | 106 |
|
89 | 107 | &.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); |
| 108 | + @include _unelevated-button-variant($on-error, $error); |
97 | 109 | }
|
98 | 110 |
|
99 | 111 | @include button-theme-private.apply-disabled-style() {
|
100 |
| - @include button-theme-private.apply-disabled-background(); |
| 112 | + @include mdc-button-filled-theme.theme(( |
| 113 | + // We need to pass both the disabled and enabled values, because the enabled |
| 114 | + // ones apply to anchors while the disabled ones are for buttons. |
| 115 | + disabled-container-color: $disabled-container-color, |
| 116 | + disabled-label-text-color: $disabled-ink-color, |
| 117 | + container-color: $disabled-container-color, |
| 118 | + label-text-color: $disabled-ink-color, |
| 119 | + )); |
101 | 120 | }
|
102 | 121 | }
|
103 | 122 |
|
104 |
| - .mat-mdc-outlined-button { |
| 123 | + .mat-mdc-raised-button { |
105 | 124 | &.mat-unthemed {
|
106 |
| - @include mdc-button-theme.outline-color(mdc-theme-color.$on-surface, |
107 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
| 125 | + @include _raised-button-variant($on-surface, $surface); |
108 | 126 | }
|
109 | 127 |
|
110 | 128 | &.mat-primary {
|
111 |
| - @include mdc-button-theme.outline-color(primary, |
112 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
| 129 | + @include _raised-button-variant($on-primary, $primary); |
113 | 130 | }
|
114 | 131 |
|
115 | 132 | &.mat-accent {
|
116 |
| - @include mdc-button-theme.outline-color(secondary, |
117 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
| 133 | + @include _raised-button-variant($on-secondary, $secondary); |
118 | 134 | }
|
119 | 135 |
|
120 | 136 | &.mat-warn {
|
121 |
| - @include mdc-button-theme.outline-color(error, |
122 |
| - $query: mdc-helpers.$mat-theme-styles-query); |
| 137 | + @include _raised-button-variant($on-error, $error); |
123 | 138 | }
|
124 | 139 |
|
125 | 140 | @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)); |
| 141 | + @include mdc-button-protected-theme.theme(( |
| 142 | + // We need to pass both the disabled and enabled values, because the enabled |
| 143 | + // ones apply to anchors while the disabled ones are for buttons. |
| 144 | + disabled-container-color: $disabled-container-color, |
| 145 | + disabled-label-text-color: $disabled-ink-color, |
| 146 | + container-color: $disabled-container-color, |
| 147 | + label-text-color: $disabled-ink-color, |
| 148 | + container-elevation: 0, |
| 149 | + )); |
128 | 150 | }
|
129 | 151 | }
|
130 | 152 |
|
131 |
| - .mat-mdc-raised-button { |
| 153 | + .mat-mdc-outlined-button { |
| 154 | + &.mat-unthemed { |
| 155 | + @include _outlined-button-variant($on-surface); |
| 156 | + } |
| 157 | + |
| 158 | + &.mat-primary { |
| 159 | + @include _outlined-button-variant($primary); |
| 160 | + } |
| 161 | + |
| 162 | + &.mat-accent { |
| 163 | + @include _outlined-button-variant($secondary); |
| 164 | + } |
| 165 | + |
| 166 | + &.mat-warn { |
| 167 | + @include _outlined-button-variant($error); |
| 168 | + } |
| 169 | + |
132 | 170 | @include button-theme-private.apply-disabled-style() {
|
133 |
| - @include mdc-elevation-theme.elevation(0, $query: mdc-helpers.$mat-theme-styles-query); |
| 171 | + @include mdc-button-outlined-theme.theme(( |
| 172 | + // We need to pass both the disabled and enabled values, because the enabled |
| 173 | + // ones apply to anchors while the disabled ones are for buttons. |
| 174 | + label-text-color: $disabled-ink-color, |
| 175 | + outline-color: $disabled-ink-color, |
| 176 | + disabled-label-text-color: $disabled-ink-color, |
| 177 | + disabled-outline-color: $disabled-ink-color, |
| 178 | + )); |
134 | 179 | }
|
135 | 180 | }
|
136 | 181 |
|
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(); |
| 182 | + // Ripple colors |
| 183 | + .mat-mdc-button, .mat-mdc-outlined-button { |
| 184 | + &.mat-primary { |
| 185 | + @include button-theme-private.ripple-ink-color($primary); |
| 186 | + } |
| 187 | + |
| 188 | + &.mat-accent { |
| 189 | + @include button-theme-private.ripple-ink-color($secondary); |
| 190 | + } |
| 191 | + |
| 192 | + &.mat-warn { |
| 193 | + @include button-theme-private.ripple-ink-color($error); |
140 | 194 | }
|
141 | 195 | }
|
142 | 196 |
|
143 |
| - @include mdc-button.without-ripple($query: mdc-helpers.$mat-theme-styles-query); |
| 197 | + .mat-mdc-raised-button, .mat-mdc-unelevated-button { |
| 198 | + &.mat-primary { |
| 199 | + @include button-theme-private.ripple-ink-color($on-primary); |
| 200 | + } |
| 201 | + |
| 202 | + &.mat-accent { |
| 203 | + @include button-theme-private.ripple-ink-color($on-secondary); |
| 204 | + } |
| 205 | + |
| 206 | + &.mat-warn { |
| 207 | + @include button-theme-private.ripple-ink-color($on-error); |
| 208 | + } |
| 209 | + } |
144 | 210 | }
|
145 | 211 | }
|
146 | 212 |
|
|
0 commit comments