Skip to content

Commit a8500c8

Browse files
crisbetoandrewseguin
authored andcommitted
refactor(material-experimental/mdc-button): reorganize styles and expose all themes (#22449)
When I was setting up the new theming API for MDC, I assumed that the button theme would include the icon button and fab themes as well, but that's not the case. These changes reorganize the button theming styles into separate files so that we can easily expose the missing mixins under the correct prefix. (cherry picked from commit ba06cd8)
1 parent caf37a9 commit a8500c8

11 files changed

+274
-264
lines changed

src/material-experimental/_index.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
mdc-autocomplete-typography, mdc-autocomplete-density, mdc-autocomplete-theme;
2828
@forward './mdc-button/button-theme' as mdc-button-* show mdc-button-color, mdc-button-typography,
2929
mdc-button-density, mdc-button-theme;
30+
@forward './mdc-button/fab-theme' as mdc-fab-* show mdc-fab-color, mdc-fab-typography,
31+
mdc-fab-density, mdc-fab-theme;
32+
@forward './mdc-button/icon-button-theme' as mdc-icon-button-* show mdc-icon-button-color,
33+
mdc-icon-button-typography, mdc-icon-button-density, mdc-icon-button-theme;
3034
@forward './mdc-card/card-theme' as mdc-card-* show mdc-card-color, mdc-card-typography,
3135
mdc-card-density, mdc-card-theme;
3236
@forward './mdc-checkbox/checkbox-theme' as mdc-checkbox-* show mdc-checkbox-color,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
@use '@material/theme/theme-color' as mdc-theme-color;
2+
@use '@material/theme/theme' as mdc-theme;
3+
@use '../../material/core/ripple/ripple-theme';
4+
5+
// Selector for the element that has a background color and opacity applied to its ::before and
6+
// ::after for state interactions (hover, active, focus). Their API calls this their
7+
// "ripple target", but we do not use it as our ripple, just state color.
8+
$button-state-target: '.mdc-button__ripple';
9+
$fab-state-target: '.mdc-fab__ripple';
10+
11+
// The MDC button's ripple ink color is based on the theme color, not on the foreground base
12+
// which is what the ripple mixin uses. This creates a new theme that sets the color to the
13+
// foreground base to appropriately color the ink.
14+
@mixin ripple-ink-color($mdc-color) {
15+
@include ripple-theme.theme((
16+
foreground: (
17+
base: mdc-theme-color.prop-value($mdc-color)
18+
),
19+
));
20+
}
21+
22+
// Applies the disabled theme color to the text color.
23+
@mixin apply-disabled-color() {
24+
@include mdc-theme.prop(color,
25+
mdc-theme-color.ink-color-for-fill_(disabled, mdc-theme-color.$background));
26+
}
27+
28+
// Wraps the content style in a selector for the disabled state.
29+
// MDC adds theme color by using :not(:disabled), so just using [disabled] once will not
30+
// override this, neither will it apply to anchor tags. This needs to override the
31+
// previously set theme color, so it must be ordered after the theme styles.
32+
// TODO(andrewseguin): Discuss with the MDC team to see if we can avoid the :not(:disabled) by
33+
// manually styling disabled buttons with a [disabled] selector.
34+
@mixin apply-disabled-style() {
35+
&[disabled][disabled] {
36+
@content;
37+
}
38+
}
39+
40+
// Applies the disabled theme background color for raised buttons. Value is taken from
41+
// mixin `mdc-button--filled`.
42+
// TODO(andrewseguin): Discuss with the MDC team about providing a variable for the 0.12 value
43+
// or otherwise have a mixin we can call to apply this style for both button and anchors.
44+
@mixin apply-disabled-background() {
45+
@include mdc-theme.prop(background-color, rgba(mdc-theme-color.prop-value(on-surface), 0.12));
46+
}
47+
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
@forward '../mdc-helpers/mdc-helpers.import';
22
@forward '../../material/core/ripple/ripple.import';
33
@forward '../mdc-helpers/mdc-helpers';
4-
@forward 'button-theme' hide color, density, fab-color, fab-density, fab-theme, fab-typography,
5-
icon-button-color, icon-button-density, icon-button-theme, icon-button-typography, theme,
6-
typography;
4+
@forward 'button-theme' hide color, density, theme, typography;
75
@forward 'button-theme' as mat-mdc-* hide $mat-mdc-mat-button-state-target, mat-mdc-color,
86
mat-mdc-density, mat-mdc-mat-button-apply-disabled-style, mat-mdc-mat-button-disabled-background,
97
mat-mdc-mat-button-disabled-color, mat-mdc-mat-button-ripple-ink-color, mat-mdc-theme,
108
mat-mdc-typography;
119
@forward 'button-theme' as mat-mdc-button-* hide $mat-mdc-button-mat-button-state-target,
12-
mat-mdc-button-fab-color, mat-mdc-button-fab-density, mat-mdc-button-fab-theme,
13-
mat-mdc-button-fab-typography, mat-mdc-button-icon-button-color, mat-mdc-button-icon-button-density,
14-
mat-mdc-button-icon-button-theme, mat-mdc-button-icon-button-typography,
1510
mat-mdc-button-mat-button-apply-disabled-style, mat-mdc-button-mat-button-disabled-background,
1611
mat-mdc-button-mat-button-disabled-color, mat-mdc-button-mat-button-ripple-ink-color;
12+
@forward 'fab-theme' as mat-mdc-fab-*;
13+
@forward 'icon-button-theme' as mat-mdc-icon-button-*;
1714

1815
@import '../../material/core/ripple/ripple';
1916
@import '../mdc-helpers/mdc-helpers';

0 commit comments

Comments
 (0)