|
1 | 1 | @use 'sass:map';
|
| 2 | +@use '@material/density/functions' as mdc-density-functions; |
2 | 3 | @use '@material/icon-button/mixins' as mdc-icon-button;
|
3 | 4 | @use '@material/icon-button/icon-button-theme' as mdc-icon-button-theme;
|
4 | 5 | @use '@material/theme/theme-color' as mdc-theme-color;
|
| 6 | +@use '../core/tokens/m2/mdc/icon-button' as tokens-mdc-icon-button; |
5 | 7 |
|
6 | 8 | @use './button-theme-private';
|
7 | 9 | @use '../core/mdc-helpers/mdc-helpers';
|
8 | 10 | @use '../core/theming/theming';
|
9 | 11 | @use '../core/typography/typography';
|
10 | 12 |
|
| 13 | +@mixin _ripple-color($color) { |
| 14 | + --mat-mdc-button-persistent-ripple-color: #{$color}; |
| 15 | + --mat-mdc-button-ripple-color: #{rgba($color, 0.1)}; |
| 16 | +} |
| 17 | + |
| 18 | +@function _variable-safe-contrast-tone($value, $is-dark) { |
| 19 | + @if ($value == 'dark' or $value == 'light' or type-of($value) == 'color') { |
| 20 | + @return mdc-theme-color.contrast-tone($value); |
| 21 | + } |
| 22 | + |
| 23 | + @return if($is-dark, 'light', 'dark'); |
| 24 | +} |
| 25 | + |
| 26 | + |
11 | 27 | @mixin color($config-or-theme) {
|
12 | 28 | $config: theming.get-color-config($config-or-theme);
|
13 |
| - @include mdc-helpers.using-mdc-theme($config) { |
14 |
| - $is-dark: map.get($config, is-dark); |
15 |
| - $on-surface: mdc-theme-color.prop-value(on-surface); |
16 |
| - $disabled-color: rgba($on-surface, if($is-dark, 0.5, 0.38)); |
17 |
| - |
18 |
| - .mat-mdc-icon-button { |
19 |
| - @include button-theme-private.ripple-theme-styles($config, false); |
20 |
| - |
21 |
| - &.mat-primary { |
22 |
| - @include mdc-icon-button-theme.theme((icon-color: mdc-theme-color.prop-value(primary))); |
23 |
| - } |
24 |
| - |
25 |
| - &.mat-accent { |
26 |
| - @include mdc-icon-button-theme.theme((icon-color: mdc-theme-color.prop-value(secondary))); |
27 |
| - } |
28 |
| - |
29 |
| - &.mat-warn { |
30 |
| - @include mdc-icon-button-theme.theme((icon-color: (mdc-theme-color.prop-value(error)))); |
31 |
| - } |
32 |
| - |
33 |
| - @include button-theme-private.apply-disabled-style() { |
34 |
| - @include mdc-icon-button-theme.theme(( |
35 |
| - icon-color: $disabled-color, |
36 |
| - disabled-icon-color: $disabled-color, |
37 |
| - )); |
38 |
| - } |
| 29 | + $color-tokens: tokens-mdc-icon-button.get-color-tokens($config); |
| 30 | + $background-palette: map.get($config, background); |
| 31 | + $surface: theming.get-color-from-palette($background-palette, card); |
| 32 | + $is-dark: map.get($config, is-dark); |
| 33 | + $on-surface: if(_variable-safe-contrast-tone($surface, $is-dark) == 'dark', #000, #fff); |
| 34 | + |
| 35 | + .mat-mdc-icon-button { |
| 36 | + @include button-theme-private.ripple-theme-styles($config, false); |
| 37 | + @include mdc-icon-button-theme.theme($color-tokens); |
| 38 | + @include _ripple-color($on-surface); |
| 39 | + |
| 40 | + &.mat-primary { |
| 41 | + $color: theming.get-color-from-palette(map.get($config, primary)); |
| 42 | + @include mdc-icon-button-theme.theme((icon-color: $color)); |
| 43 | + @include _ripple-color($color); |
| 44 | + } |
| 45 | + |
| 46 | + &.mat-accent { |
| 47 | + $color: theming.get-color-from-palette(map.get($config, accent)); |
| 48 | + @include mdc-icon-button-theme.theme((icon-color: $color)); |
| 49 | + @include _ripple-color($color); |
| 50 | + } |
| 51 | + |
| 52 | + &.mat-warn { |
| 53 | + $color: theming.get-color-from-palette(map.get($config, warn)); |
| 54 | + @include mdc-icon-button-theme.theme((icon-color: $color)); |
| 55 | + @include _ripple-color($color); |
| 56 | + } |
| 57 | + |
| 58 | + @include button-theme-private.apply-disabled-style() { |
| 59 | + $disabled-color: rgba($on-surface, if($is-dark, 0.5, 0.38)); |
| 60 | + @include mdc-icon-button-theme.theme(( |
| 61 | + icon-color: $disabled-color, |
| 62 | + disabled-icon-color: $disabled-color, |
| 63 | + )); |
39 | 64 | }
|
40 | 65 | }
|
41 | 66 | }
|
|
50 | 75 |
|
51 | 76 | @mixin density($config-or-theme) {
|
52 | 77 | $density-scale: theming.get-density-config($config-or-theme);
|
53 |
| - // Use `mat-mdc-button-base` to increase the specificity over the button's structural styles. |
54 |
| - .mat-mdc-icon-button.mat-mdc-button-base { |
55 |
| - @include mdc-icon-button.density($density-scale, $query: mdc-helpers.$mdc-base-styles-query); |
56 |
| - @include button-theme-private.touch-target-density($density-scale); |
| 78 | + |
| 79 | + .mat-mdc-icon-button { |
| 80 | + // Manually apply the expected density theming, and include the padding |
| 81 | + // as it was applied before |
| 82 | + $calculated-size: mdc-density-functions.prop-value( |
| 83 | + $density-config: ( |
| 84 | + size: ( |
| 85 | + default: 48px, |
| 86 | + maximum: 48px, |
| 87 | + minimum: 28px, |
| 88 | + ), |
| 89 | + ), |
| 90 | + $density-scale: $density-scale, |
| 91 | + $property-name: size, |
| 92 | + ); |
| 93 | + |
| 94 | + @include mdc-icon-button-theme.theme(( |
| 95 | + state-layer-size: $calculated-size, |
| 96 | + )); |
57 | 97 | }
|
58 | 98 | }
|
59 | 99 |
|
|
0 commit comments