Skip to content

Commit 1a1e087

Browse files
committed
refactor(material/icon-button): simplify structural styles
Simplifies the structural styles for the icon button to make them smaller and easier to maintain.
1 parent 202f058 commit 1a1e087

File tree

2 files changed

+37
-46
lines changed

2 files changed

+37
-46
lines changed

src/material/button/_icon-button-theme.scss

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
@use 'sass:map';
22
@use 'sass:math';
3-
@use '@material/density/functions' as mdc-density-functions;
4-
@use '@material/icon-button/icon-button-theme' as mdc-icon-button-theme;
53
@use '../core/tokens/m2/mdc/icon-button' as tokens-mdc-icon-button;
64
@use '../core/tokens/m2/mat/icon-button' as tokens-mat-icon-button;
75
@use '../core/style/sass-utils';
@@ -18,7 +16,8 @@
1816
@else {
1917
// Add default values for tokens not related to color, typography, or density.
2018
@include sass-utils.current-selector-or-root() {
21-
@include mdc-icon-button-theme.theme(tokens-mdc-icon-button.get-unthemable-tokens());
19+
@include token-utils.create-token-values(tokens-mdc-icon-button.$prefix,
20+
tokens-mdc-icon-button.get-unthemable-tokens());
2221
}
2322
}
2423
}
@@ -34,7 +33,7 @@
3433
tokens-mat-icon-button.get-color-tokens($theme)
3534
);
3635

37-
@include mdc-icon-button-theme.theme($mdc-tokens);
36+
@include token-utils.create-token-values(tokens-mdc-icon-button.$prefix, $mdc-tokens);
3837
@include token-utils.create-token-values(tokens-mat-icon-button.$prefix, $mat-tokens);
3938
}
4039

@@ -82,19 +81,15 @@
8281
@else {
8382
$icon-size: 24px;
8483
$density-scale: inspection.get-theme-density($theme);
85-
// Manually apply the expected density theming, and include the padding
86-
// as it was applied before
87-
$calculated-size: mdc-density-functions.prop-value(
88-
$density-config: (
89-
size: (
90-
default: 48px,
91-
maximum: 48px,
92-
minimum: 28px,
93-
),
94-
),
95-
$density-scale: $density-scale,
96-
$property-name: size,
84+
$size-map: (
85+
0: 48px,
86+
-1: 44px,
87+
-2: 40px,
88+
-3: 36px,
89+
-4: 32px,
90+
-5: 28px,
9791
);
92+
$calculated-size: map.get($size-map, $density-scale);
9893

9994
@include sass-utils.current-selector-or-root() {
10095
@include token-utils.create-token-values(tokens-mat-icon-button.$prefix,
@@ -105,9 +100,7 @@
105100
.mat-mdc-icon-button.mat-mdc-button-base {
106101
// Match the styles that used to be present. This is necessary for backwards
107102
// compat to match the previous implementations selector count (two classes).
108-
@include mdc-icon-button-theme.theme((
109-
state-layer-size: $calculated-size,
110-
));
103+
--mdc-icon-button-state-layer-size: #{$calculated-size};
111104

112105
// TODO: Switch calculated-size to "var(--mdc-icon-button-state-layer-size)"
113106
// Currently fails validation because the variable is "undefined"
@@ -153,7 +146,8 @@
153146
@include validation.selector-defined(
154147
'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector');
155148
@if ($tokens != ()) {
156-
@include mdc-icon-button-theme.theme(map.get($tokens, tokens-mdc-icon-button.$prefix));
149+
@include token-utils.create-token-values(
150+
tokens-mdc-icon-button.$prefix, map.get($tokens, tokens-mdc-icon-button.$prefix));
157151
@include token-utils.create-token-values(
158152
tokens-mat-icon-button.$prefix, map.get($tokens, tokens-mat-icon-button.$prefix));
159153
}

src/material/button/icon-button.scss

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
1-
@use 'sass:map';
2-
@use '@material/icon-button/icon-button' as mdc-icon-button;
3-
@use '@material/icon-button/icon-button-theme' as mdc-icon-button-theme;
4-
@use '@material/theme/custom-properties' as mdc-custom-properties;
5-
61
@use '../core/tokens/m2/mdc/icon-button' as tokens-mdc-icon-button;
72
@use '../core/tokens/m2/mat/icon-button' as tokens-mat-icon-button;
83

94
@use './button-base';
105
@use '../core/style/private';
6+
@use '../core/style/vendor-prefixes';
117
@use '../core/tokens/token-utils';
128

13-
// The slots for tokens that will be configured in the theme can be emitted with no fallback.
14-
@include mdc-custom-properties.configure($emit-fallback-values: false, $emit-fallback-vars: false) {
15-
$token-slots: tokens-mdc-icon-button.get-token-slots();
16-
17-
// Add the MDC component static styles.
18-
@include mdc-icon-button.static-styles();
19-
20-
.mat-mdc-icon-button {
21-
// Add the official slots for the MDC component.
22-
@include mdc-icon-button-theme.theme-styles(map.merge($token-slots, (
23-
// Exclude the state layer size since we'll re-emit it below with a default value.
24-
state-layer-size: null,
25-
)));
26-
}
27-
}
289

2910
.mat-mdc-icon-button {
11+
@include vendor-prefixes.user-select(none);
12+
display: inline-block;
13+
position: relative;
14+
box-sizing: border-box;
15+
border: none;
16+
outline: none;
17+
background-color: transparent;
18+
fill: currentColor;
19+
color: inherit;
20+
text-decoration: none;
21+
cursor: pointer;
22+
z-index: 0;
23+
overflow: visible;
24+
3025
// Border radius is inherited by ripple to know its shape. Set to 50% so the ripple is round.
3126
border-radius: 50%;
3227

@@ -36,10 +31,6 @@
3631
// Ensure the icons are centered.
3732
text-align: center;
3833

39-
svg {
40-
vertical-align: baseline;
41-
}
42-
4334
@include token-utils.use-tokens(
4435
tokens-mdc-icon-button.$prefix, tokens-mdc-icon-button.get-token-slots()) {
4536
$button-size: var(#{token-utils.get-token-variable(state-layer-size)}, 48px);
@@ -57,12 +48,18 @@
5748
// Icon size used to be placed on the host element. Now, in `theme-styles` it is placed on
5849
// the unused `.mdc-button__icon` class. Explicitly set the font-size here.
5950
@include token-utils.create-token-slot(font-size, icon-size);
51+
@include token-utils.create-token-slot(color, icon-color);
6052

6153
@include button-base.mat-private-button-disabled {
62-
// MDC's disabled styles target the `:disabled` selector which doesn't work on links.
63-
// We re-apply the disabled icon color here since we support Material buttons on links too.
6454
@include token-utils.create-token-slot(color, disabled-icon-color);
6555
};
56+
57+
img,
58+
svg {
59+
@include token-utils.create-token-slot(width, icon-size);
60+
@include token-utils.create-token-slot(height, icon-size);
61+
vertical-align: baseline;
62+
}
6663
}
6764

6865
@include button-base.mat-private-button-interactive();

0 commit comments

Comments
 (0)