Skip to content

Commit 7b12a81

Browse files
authored
feat(material-experimental/button): support unthemed version (#16986)
1 parent 7ad684c commit 7b12a81

File tree

5 files changed

+84
-15
lines changed

5 files changed

+84
-15
lines changed

src/dev-app/button/button-demo.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ <h4 class="demo-section-header">Buttons</h4>
1111

1212
<h4 class="demo-section-header">Anchors</h4>
1313
<section>
14-
<a href="//www.google.com" mat-button color="primary">SEARCH</a>
14+
<a href="//www.google.com" mat-button>SEARCH</a>
1515
<a href="//www.google.com" mat-raised-button>SEARCH</a>
16-
<a href="//www.google.com" mat-stroked-button color="primary">SEARCH</a>
16+
<a href="//www.google.com" mat-stroked-button>SEARCH</a>
1717
<a href="//www.google.com" mat-flat-button>SEARCH</a>
1818
<a href="//www.google.com" mat-fab><mat-icon>check</mat-icon></a>
1919
<a href="//www.google.com" mat-mini-fab><mat-icon>check</mat-icon></a>
2020
</section>
2121

2222
<h4 class="demo-section-header">Text Buttons [mat-button]</h4>
2323
<section>
24+
<button mat-button>unthemed</button>
2425
<button mat-button color="primary">primary</button>
2526
<button mat-button color="accent">accent</button>
2627
<button mat-button color="warn">warn</button>
@@ -29,6 +30,7 @@ <h4 class="demo-section-header">Text Buttons [mat-button]</h4>
2930

3031
<h4 class="demo-section-header">Raised Buttons [mat-raised-button]</h4>
3132
<section>
33+
<button mat-raised-button>unthemed</button>
3234
<button mat-raised-button color="primary">primary</button>
3335
<button mat-raised-button color="accent">accent</button>
3436
<button mat-raised-button color="warn">warn</button>
@@ -37,6 +39,7 @@ <h4 class="demo-section-header">Raised Buttons [mat-raised-button]</h4>
3739

3840
<h4 class="demo-section-header">Stroked Buttons [mat-stroked-button]</h4>
3941
<section>
42+
<button mat-stroked-button>unthemed</button>
4043
<button mat-stroked-button color="primary">primary</button>
4144
<button mat-stroked-button color="accent">accent</button>
4245
<button mat-stroked-button color="warn">warn</button>
@@ -45,6 +48,7 @@ <h4 class="demo-section-header">Stroked Buttons [mat-stroked-button]</h4>
4548

4649
<h4 class="demo-section-header">Flat Buttons [mat-flat-button]</h4>
4750
<section>
51+
<button mat-flat-button>unthemed</button>
4852
<button mat-flat-button color="primary">primary</button>
4953
<button mat-flat-button color="accent">accent</button>
5054
<button mat-flat-button color="warn">warn</button>
@@ -53,6 +57,7 @@ <h4 class="demo-section-header">Flat Buttons [mat-flat-button]</h4>
5357

5458
<h4 class="demo-section-header"> Icon Buttons [mat-icon-button]</h4>
5559
<section>
60+
<button mat-icon-button><mat-icon>cached</mat-icon></button>
5661
<button mat-icon-button color="primary"><mat-icon>cached</mat-icon></button>
5762
<button mat-icon-button color="accent"><mat-icon>backup</mat-icon></button>
5863
<button mat-icon-button color="warn"><mat-icon>trending_up</mat-icon></button>
@@ -61,6 +66,7 @@ <h4 class="demo-section-header"> Icon Buttons [mat-icon-button]</h4>
6166

6267
<h4 class="demo-section-header">Fab Buttons [mat-fab]</h4>
6368
<section>
69+
<button mat-fab><mat-icon>delete</mat-icon></button>
6470
<button mat-fab color="primary"><mat-icon>delete</mat-icon></button>
6571
<button mat-fab color="accent"><mat-icon>bookmark</mat-icon></button>
6672
<button mat-fab color="warn"><mat-icon>home</mat-icon></button>
@@ -69,6 +75,7 @@ <h4 class="demo-section-header">Fab Buttons [mat-fab]</h4>
6975

7076
<h4 class="demo-section-header"> Mini Fab Buttons [mat-mini-fab]</h4>
7177
<section>
78+
<button mat-mini-fab><mat-icon>menu</mat-icon></button>
7279
<button mat-mini-fab color="primary"><mat-icon>menu</mat-icon></button>
7380
<button mat-mini-fab color="accent"><mat-icon>plus_one</mat-icon></button>
7481
<button mat-mini-fab color="warn"><mat-icon>filter_list</mat-icon></button>

src/dev-app/mdc-button/mdc-button-demo.html

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ <h4 class="demo-section-header">Buttons</h4>
2727

2828
<h4 class="demo-section-header">Anchors</h4>
2929
<section>
30-
<a href="//www.google.com" mat-button color="primary">SEARCH</a>
30+
<a href="//www.google.com" mat-button>SEARCH</a>
3131
<a href="//www.google.com" mat-raised-button>SEARCH</a>
32-
<a href="//www.google.com" mat-stroked-button color="primary">SEARCH</a>
32+
<a href="//www.google.com" mat-stroked-button>SEARCH</a>
3333
<a href="//www.google.com" mat-flat-button>SEARCH</a>
3434
<a href="//www.google.com" mat-fab>
3535
<mat-icon>check</mat-icon>
@@ -53,6 +53,7 @@ <h4 class="demo-section-header">Anchors</h4>
5353

5454
<h4 class="demo-section-header">Text Buttons [mat-button]</h4>
5555
<section>
56+
<button mat-button>unthemed</button>
5657
<button mat-button color="primary">primary</button>
5758
<button mat-button color="accent">accent</button>
5859
<button mat-button color="warn">warn</button>
@@ -61,6 +62,7 @@ <h4 class="demo-section-header">Text Buttons [mat-button]</h4>
6162

6263
<h4 class="demo-section-header">Raised Buttons [mat-raised-button]</h4>
6364
<section>
65+
<button mat-raised-button>unthemed</button>
6466
<button mat-raised-button color="primary">primary</button>
6567
<button mat-raised-button color="accent">accent</button>
6668
<button mat-raised-button color="warn">warn</button>
@@ -69,6 +71,7 @@ <h4 class="demo-section-header">Raised Buttons [mat-raised-button]</h4>
6971

7072
<h4 class="demo-section-header">Stroked Buttons [mat-stroked-button]</h4>
7173
<section>
74+
<button mat-stroked-button>unthemed</button>
7275
<button mat-stroked-button color="primary">primary</button>
7376
<button mat-stroked-button color="accent">accent</button>
7477
<button mat-stroked-button color="warn">warn</button>
@@ -77,6 +80,7 @@ <h4 class="demo-section-header">Stroked Buttons [mat-stroked-button]</h4>
7780

7881
<h4 class="demo-section-header">Flat Buttons [mat-flat-button]</h4>
7982
<section>
83+
<button mat-flat-button>unthemed</button>
8084
<button mat-flat-button color="primary">primary</button>
8185
<button mat-flat-button color="accent">accent</button>
8286
<button mat-flat-button color="warn">warn</button>
@@ -85,6 +89,9 @@ <h4 class="demo-section-header">Flat Buttons [mat-flat-button]</h4>
8589

8690
<h4 class="demo-section-header"> Icon Buttons [mat-icon-button]</h4>
8791
<section>
92+
<button mat-icon-button>
93+
<mat-icon>cached</mat-icon>
94+
</button>
8895
<button mat-icon-button color="primary">
8996
<mat-icon>cached</mat-icon>
9097
</button>
@@ -101,6 +108,9 @@ <h4 class="demo-section-header"> Icon Buttons [mat-icon-button]</h4>
101108

102109
<h4 class="demo-section-header">Fab Buttons [mat-fab]</h4>
103110
<section>
111+
<button mat-fab>
112+
<mat-icon>delete</mat-icon>
113+
</button>
104114
<button mat-fab color="primary">
105115
<mat-icon>delete</mat-icon>
106116
</button>
@@ -117,6 +127,9 @@ <h4 class="demo-section-header">Fab Buttons [mat-fab]</h4>
117127

118128
<h4 class="demo-section-header"> Mini Fab Buttons [mat-mini-fab]</h4>
119129
<section>
130+
<button mat-mini-fab>
131+
<mat-icon>menu</mat-icon>
132+
</button>
120133
<button mat-mini-fab color="primary">
121134
<mat-icon>menu</mat-icon>
122135
</button>

src/material-experimental/mdc-button/README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
### Open Issues
2-
3-
- Anchor button does not support disabled - see MDC issue #1339
4-
51
### TODO
6-
- Determine coloring for non-primary buttons (MDC does not support this)
72
- Write README - looks like lot of overlap with checkbox README. Create common readme for setup
8-
- Move tests over (both unit and e2e)
93
- JSDoc comments on all classes, consts
104
- Consider supporting button[mat-outlined-button]
115
- Add to universal app

src/material-experimental/mdc-button/_mdc-button.scss

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,40 @@
4141
}
4242

4343
.mat-mdc-button, .mat-mdc-outlined-button {
44-
@include mdc-states-base-color(primary, $query: $mat-theme-styles-query);
44+
&.mat-unthemed {
45+
@include mdc-button-ink-color($mdc-theme-on-surface, $query: $mat-theme-styles-query);
46+
}
47+
48+
&.mat-primary {
49+
@include mdc-button-ink-color(primary, $query: $mat-theme-styles-query);
50+
@include mdc-states-base-color(primary, $query: $mat-theme-styles-query);
51+
}
4552

4653
&.mat-accent {
4754
@include mdc-button-ink-color(secondary, $query: $mat-theme-styles-query);
55+
@include mdc-states-base-color(secondary, $query: $mat-theme-styles-query);
4856
}
4957

5058
&.mat-warn {
5159
@include mdc-button-ink-color(error, $query: $mat-theme-styles-query);
60+
@include mdc-states-base-color(error, $query: $mat-theme-styles-query);
5261
}
5362
}
5463

5564
.mat-mdc-raised-button,
5665
.mat-mdc-unelevated-button {
57-
@include mdc-states-base-color(on-primary, $query: $mat-theme-styles-query);
66+
&.mat-unthemed {
67+
@include mdc-button-container-fill-color(
68+
$mdc-theme-surface, $query: $mat-theme-styles-query);
69+
@include mdc-button-ink-color($mdc-theme-on-surface, $query: $mat-theme-styles-query);
70+
@include mdc-states-base-color($mdc-theme-on-surface, $query: $mat-theme-styles-query);
71+
}
72+
73+
&.mat-primary {
74+
@include mdc-button-container-fill-color(primary, $query: $mat-theme-styles-query);
75+
@include mdc-button-ink-color(on-primary, $query: $mat-theme-styles-query);
76+
@include mdc-states-base-color(on-primary, $query: $mat-theme-styles-query);
77+
}
5878

5979
&.mat-accent {
6080
@include mdc-button-container-fill-color(secondary, $query: $mat-theme-styles-query);
@@ -74,6 +94,14 @@
7494
}
7595

7696
.mat-mdc-outlined-button {
97+
&.mat-unthemed {
98+
@include mdc-button-outline-color($mdc-theme-on-surface, $query: $mat-theme-styles-query);
99+
}
100+
101+
&.mat-primary {
102+
@include mdc-button-outline-color(primary, $query: $mat-theme-styles-query);
103+
}
104+
77105
&.mat-accent {
78106
@include mdc-button-outline-color(secondary, $query: $mat-theme-styles-query);
79107
}
@@ -113,15 +141,26 @@
113141
@mixin mat-fab-theme-mdc($theme) {
114142
@include mat-using-mdc-theme($theme) {
115143
.mat-mdc-fab, .mat-mdc-mini-fab {
116-
@include mdc-states-base-color(secondary, $query: $mat-theme-styles-query);
117144
@include mdc-states($query: $mat-theme-styles-query);
118145

146+
&.mat-unthemed {
147+
@include mdc-states-base-color($mdc-theme-on-surface, $query: $mat-theme-styles-query);
148+
@include mdc-fab-container-color($mdc-theme-surface, $query: $mat-theme-styles-query);
149+
@include mdc-fab-ink-color($mdc-theme-on-surface, $query: $mat-theme-styles-query);
150+
}
151+
119152
&.mat-primary {
120153
@include mdc-states-base-color(on-primary, $query: $mat-theme-styles-query);
121154
@include mdc-fab-container-color(primary, $query: $mat-theme-styles-query);
122155
@include mdc-fab-ink-color(on-primary, $query: $mat-theme-styles-query);
123156
}
124157

158+
&.mat-accent {
159+
@include mdc-states-base-color(on-secondary, $query: $mat-theme-styles-query);
160+
@include mdc-fab-container-color(secondary, $query: $mat-theme-styles-query);
161+
@include mdc-fab-ink-color(on-secondary, $query: $mat-theme-styles-query);
162+
}
163+
125164
&.mat-warn {
126165
@include mdc-states-base-color(on-error, $query: $mat-theme-styles-query);
127166
@include mdc-fab-container-color(error, $query: $mat-theme-styles-query);
@@ -149,8 +188,16 @@
149188
@include mat-using-mdc-theme($theme) {
150189
.mat-mdc-icon-button {
151190
@include mdc-states($query: $mat-theme-styles-query);
152-
@include mdc-states-base-color(primary, $query: $mat-theme-styles-query);
153-
@include mdc-icon-button-ink-color(primary, $query: $mat-theme-styles-query);
191+
192+
&.mat-unthemed {
193+
@include mdc-states-base-color($mdc-theme-surface, $query: $mat-theme-styles-query);
194+
@include mdc-icon-button-ink-color($mdc-theme-on-surface, $query: $mat-theme-styles-query);
195+
}
196+
197+
&.mat-primary {
198+
@include mdc-states-base-color(primary, $query: $mat-theme-styles-query);
199+
@include mdc-icon-button-ink-color(primary, $query: $mat-theme-styles-query);
200+
}
154201

155202
&.mat-accent {
156203
@include mdc-states-base-color(secondary, $query: $mat-theme-styles-query);

src/material-experimental/mdc-button/button-base.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export const MAT_BUTTON_INPUTS = ['disabled', 'disableRipple', 'color'];
3030
export const MAT_BUTTON_HOST = {
3131
'[attr.disabled]': 'disabled || null',
3232
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
33+
// MDC automatically applies the primary theme color to the button, but we want to support
34+
// an unthemed version. If color is undefined, apply a CSS class that makes it easy to
35+
// select and style this "theme".
36+
'[class.mat-unthemed]': '!color',
3337
};
3438

3539
/** List of classes to add to buttons instances based on host attribute selector. */
@@ -131,6 +135,10 @@ export const MAT_ANCHOR_HOST = {
131135
'[attr.tabindex]': 'disabled ? -1 : (tabIndex || 0)',
132136
'[attr.aria-disabled]': 'disabled.toString()',
133137
'(click)': '_haltDisabledEvents($event)',
138+
// MDC automatically applies the primary theme color to the button, but we want to support
139+
// an unthemed version. If color is undefined, apply a CSS class that makes it easy to
140+
// select and style this "theme".
141+
'[class.mat-unthemed]': '!color',
134142
};
135143

136144
/**

0 commit comments

Comments
 (0)