Skip to content

Commit 7be5dde

Browse files
authored
feat(material/theming): Add 'base' theming dimension to all components (#27924)
Adds a `base` theming dimension to go along with `color`,`typography`, and `density`. The base dimension includes styles such as border-radiuses that do not vary with the chosen color, typography, or density, but may vary depending on the theming system (e.g. Material 2 vs Material 3). BREAKING CHANGE: There are new styles emitted by `mat.<component>-theme` that are not emitted by any of: `mat.<component>-color`, `mat.<component>-typography`, or `mat.<component>-density`. If you rely on the partial mixins only and don't call `mat.<component>-theme`, you can add `mat.<component>-base` to get the missing styles. Alternatively you can call `mat.all-component-bases` to get just the base styles for all components.
1 parent 4787631 commit 7be5dde

File tree

12 files changed

+109
-12
lines changed

12 files changed

+109
-12
lines changed

src/material/_index.scss

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@
5252
@forward './core/typography/all-typography' show all-component-typographies;
5353

5454
// Component themes
55-
@forward './core/core-theme' as core-* show core-color, core-theme, core-typography, core-density;
56-
@forward './core/ripple/ripple-theme' as ripple-* show ripple-color, ripple-theme;
55+
@forward './core/core-theme' as core-* show core-color, core-theme, core-typography, core-density,
56+
core-base;
57+
@forward './core/ripple/ripple-theme' as ripple-* show ripple-color, ripple-theme, ripple-base;
5758
@forward './core/option/option-theme' as option-* show option-color, option-typography,
5859
option-theme, option-density, option-base;
5960
@forward './core/option/optgroup-theme' as optgroup-* show optgroup-color, optgroup-typography,
6061
optgroup-theme, optgroup-density, optgroup-base;
6162
@forward './core/selection/pseudo-checkbox/pseudo-checkbox-theme' as pseudo-checkbox-* show
62-
pseudo-checkbox-color, pseudo-checkbox-typography, pseudo-checkbox-theme;
63+
pseudo-checkbox-color, pseudo-checkbox-typography, pseudo-checkbox-theme, pseudo-checkbox-base;
6364
@forward './core/selection/pseudo-checkbox/pseudo-checkbox-common' as pseudo-checkbox-* show
6465
pseudo-checkbox-legacy-size;
6566
@forward './core/focus-indicators/focus-indicators-theme' as strong-focus-indicators-* show
@@ -71,11 +72,11 @@
7172
@forward './bottom-sheet/bottom-sheet-theme' as bottom-sheet-* show bottom-sheet-theme,
7273
bottom-sheet-color, bottom-sheet-typography, bottom-sheet-density, bottom-sheet-base;
7374
@forward './button/button-theme' as button-* show button-theme, button-color, button-typography,
74-
button-density;
75+
button-density, button-base;
7576
@forward './button/fab-theme' as fab-* show fab-color, fab-typography,
7677
fab-density, fab-theme, fab-base;
7778
@forward './button/icon-button-theme' as icon-button-* show icon-button-color,
78-
icon-button-typography, icon-button-density, icon-button-theme;
79+
icon-button-typography, icon-button-density, icon-button-theme, icon-button-base;
7980
@forward './button-toggle/button-toggle-theme' as button-toggle-* show button-toggle-theme,
8081
button-toggle-color, button-toggle-typography, button-toggle-density, button-toggle-base;
8182
@forward './card/card-theme' as card-* show card-theme, card-color, card-typography, card-density,
@@ -90,21 +91,21 @@
9091
dialog-density, dialog-base;
9192
@forward './dialog/dialog-legacy-padding' as dialog-* show dialog-legacy-padding;
9293
@forward './divider/divider-theme' as divider-* show divider-theme, divider-color,
93-
divider-typography, divider-density;
94+
divider-typography, divider-density, divider-base;
9495
@forward './expansion/expansion-theme' as expansion-* show expansion-theme, expansion-color,
95-
expansion-typography, expansion-density;
96+
expansion-typography, expansion-density, expansion-base;
9697
@forward './form-field/form-field-theme' as form-field-* show form-field-theme,
97-
form-field-color, form-field-typography, form-field-density;
98+
form-field-color, form-field-typography, form-field-density, form-field-base;
9899
@forward './grid-list/grid-list-theme' as grid-list-* show grid-list-theme, grid-list-color,
99100
grid-list-typography, grid-list-density, grid-list-base;
100101
@forward './icon/icon-theme' as icon-* show icon-theme, icon-color, icon-typography, icon-density,
101102
icon-base;
102103
@forward './input/input-theme' as input-* show input-theme, input-color, input-typography,
103104
input-density, input-base;
104105
@forward './list/list-theme' as list-* show list-theme, list-color, list-typography,
105-
list-density, list-base;
106+
list-density, list-base;
106107
@forward './menu/menu-theme' as menu-* show menu-theme, menu-color, menu-typography, menu-density,
107-
menu-base;
108+
menu-base;
108109
@forward './paginator/paginator-theme' as paginator-* show paginator-theme, paginator-color,
109110
paginator-typography, paginator-density, paginator-base;
110111
@forward './progress-bar/progress-bar-theme' as progress-bar-* show
@@ -126,7 +127,8 @@ menu-base;
126127
slider-density, slider-base;
127128
@forward './snack-bar/snack-bar-theme' as snack-bar-* show snack-bar-theme, snack-bar-color,
128129
snack-bar-typography, snack-bar-density, snack-bar-base;
129-
@forward './sort/sort-theme' as sort-* show sort-theme, sort-color, sort-typography, sort-density;
130+
@forward './sort/sort-theme' as sort-* show sort-theme, sort-color, sort-typography, sort-density,
131+
sort-base;
130132
@forward './stepper/stepper-theme' as stepper-* show stepper-theme, stepper-color,
131133
stepper-typography, stepper-density, stepper-base;
132134
@forward './table/table-theme' as table-* show table-theme, table-color, table-typography,
@@ -137,7 +139,8 @@ menu-base;
137139
toolbar-typography, toolbar-density, toolbar-base;
138140
@forward './tooltip/tooltip-theme' as tooltip-* show tooltip-theme, tooltip-color,
139141
tooltip-typography, tooltip-density, tooltip-base;
140-
@forward './tree/tree-theme' as tree-* show tree-theme, tree-color, tree-typography, tree-density;
142+
@forward './tree/tree-theme' as tree-* show tree-theme, tree-color, tree-typography, tree-density,
143+
tree-base;
141144

142145
// MDC Helpers
143146
@forward './core/mdc-helpers/mdc-helpers' as private-* show private-using-mdc-theme,

src/material/button/_button-theme.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
));
3333
}
3434

35+
@mixin base($theme) {
36+
// TODO(mmalerba): Move button base tokens here
37+
}
38+
3539
@mixin color($theme) {
3640
@include mdc-helpers.using-mdc-theme($theme) {
3741
$is-dark: inspection.get-theme-type($theme) == dark;
@@ -254,6 +258,7 @@
254258

255259
@mixin theme($theme) {
256260
@include theming.private-check-duplicate-theme-styles($theme, 'mat-button') {
261+
@include base($theme);
257262
@if inspection.theme-has($theme, color) {
258263
@include color($theme);
259264
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ $_icon-size: 24px;
2323
@return if($is-dark, 'light', 'dark');
2424
}
2525

26+
@mixin base($theme) {
27+
// TODO(mmalerba): Move icon button base tokens here
28+
}
29+
2630
@mixin color($theme) {
2731
$color-tokens: tokens-mdc-icon-button.get-color-tokens($theme);
2832
$surface: inspection.get-theme-color($theme, background, card);
@@ -104,6 +108,7 @@ $_icon-size: 24px;
104108

105109
@mixin theme($theme) {
106110
@include theming.private-check-duplicate-theme-styles($theme, 'mat-icon-button') {
111+
@include base($theme);
107112
@if inspection.theme-has($theme, color) {
108113
@include color($theme);
109114
}

src/material/core/_core-theme.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
@use './style/elevation';
99
@use './typography/typography';
1010

11+
@mixin base($theme) {
12+
@include ripple-theme.base($theme);
13+
@include option-theme.base($theme);
14+
@include optgroup-theme.base($theme);
15+
@include pseudo-checkbox-theme.base($theme);
16+
// TODO(mmalerba): Move additional core base tokens here
17+
}
18+
1119
@mixin color($theme) {
1220
@include ripple-theme.color($theme);
1321
@include option-theme.color($theme);
@@ -64,6 +72,7 @@
6472
// there won't be multiple warnings. e.g. if `mat-core-theme` reports a warning, then
6573
// the imported themes (such as `mat-ripple-theme`) should not report again.
6674
@include theming.private-check-duplicate-theme-styles($theme, 'mat-core') {
75+
@include base($theme);
6776
@if inspection.theme-has($theme, color) {
6877
@include color($theme);
6978
}

src/material/core/ripple/_ripple-theme.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
@use '../theming/theming';
33
@use '../theming/inspection';
44

5+
@mixin base($theme) {
6+
// TODO(mmalerba): Move ripple base tokens here
7+
}
8+
59
// Colors for the ripple elements.
610
@mixin color($theme) {
711
$foreground-base: inspection.get-theme-color($theme, foreground, base);
@@ -22,6 +26,7 @@
2226

2327
@mixin theme($theme) {
2428
@include theming.private-check-duplicate-theme-styles($theme, 'mat-ripple') {
29+
@include base($theme);
2530
@if inspection.theme-has($theme, color) {
2631
@include color($theme);
2732
}

src/material/core/selection/pseudo-checkbox/_pseudo-checkbox-theme.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
}
2020
}
2121

22+
@mixin base($theme) {
23+
// TODO(mmalerba): Move pseudo checkbox base tokens here
24+
}
25+
2226
@mixin color($theme) {
2327
$is-dark-theme: inspection.get-theme-type($theme) == dark;
2428
$primary: inspection.get-theme-color($theme, primary);
@@ -78,6 +82,7 @@
7882

7983
@mixin theme($theme) {
8084
@include theming.private-check-duplicate-theme-styles($theme, 'mat-pseudo-checkbox') {
85+
@include base($theme);
8186
@if inspection.theme-has($theme, color) {
8287
@include color($theme);
8388
}

src/material/core/theming/_all-theme.scss

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,46 @@
8282
}
8383
}
8484

85+
@mixin all-component-bases($theme) {
86+
@include core-theme.base($theme);
87+
@include card-theme.base($theme);
88+
@include progress-bar-theme.base($theme);
89+
@include tooltip-theme.base($theme);
90+
@include form-field-theme.base($theme);
91+
@include input-theme.base($theme);
92+
@include select-theme.base($theme);
93+
@include autocomplete-theme.base($theme);
94+
@include dialog-theme.base($theme);
95+
@include chips-theme.base($theme);
96+
@include slide-toggle-theme.base($theme);
97+
@include radio-theme.base($theme);
98+
@include slider-theme.base($theme);
99+
@include menu-theme.base($theme);
100+
@include list-theme.base($theme);
101+
@include paginator-theme.base($theme);
102+
@include tabs-theme.base($theme);
103+
@include checkbox-theme.base($theme);
104+
@include button-theme.base($theme);
105+
@include icon-button-theme.base($theme);
106+
@include fab-theme.base($theme);
107+
@include snack-bar-theme.base($theme);
108+
@include table-theme.base($theme);
109+
@include progress-spinner-theme.base($theme);
110+
@include badge-theme.base($theme);
111+
@include bottom-sheet-theme.base($theme);
112+
@include button-toggle-theme.base($theme);
113+
@include datepicker-theme.base($theme);
114+
@include divider-theme.base($theme);
115+
@include expansion-theme.base($theme);
116+
@include grid-list-theme.base($theme);
117+
@include icon-theme.base($theme);
118+
@include sidenav-theme.base($theme);
119+
@include stepper-theme.base($theme);
120+
@include sort-theme.base($theme);
121+
@include toolbar-theme.base($theme);
122+
@include tree-theme.base($theme);
123+
}
124+
85125
// @deprecated Use `all-component-themes`.
86126
@mixin angular-material-theme($theme) {
87127
@include all-component-themes($theme);

src/material/divider/_divider-theme.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
@use '../core/tokens/token-utils';
55
@use '../core/tokens/m2/mat/divider' as tokens-mat-divider;
66

7+
@mixin base($theme) {
8+
// TODO(mmalerba): Move divider base tokens here
9+
}
10+
711
@mixin color($theme) {
812
@include sass-utils.current-selector-or-root() {
913
@include token-utils.create-token-values(tokens-mat-divider.$prefix,
@@ -17,6 +21,7 @@
1721

1822
@mixin theme($theme) {
1923
@include theming.private-check-duplicate-theme-styles($theme, 'mat-divider') {
24+
@include base($theme);
2025
@if inspection.theme-has($theme, color) {
2126
@include color($theme);
2227
}

src/material/expansion/_expansion-theme.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
@use '../core/tokens/token-utils';
66
@use '../core/tokens/m2/mat/expansion' as tokens-mat-expansion;
77

8+
@mixin base($theme) {
9+
// TODO(mmalerba): Move expansion panel base tokens here
10+
}
11+
812
@mixin color($theme) {
913
@include sass-utils.current-selector-or-root() {
1014
@include token-utils.create-token-values(tokens-mat-expansion.$prefix,
@@ -31,6 +35,7 @@
3135

3236
@mixin theme($theme) {
3337
@include theming.private-check-duplicate-theme-styles($theme, 'mat-expansion') {
38+
@include base($theme);
3439
@if inspection.theme-has($theme, color) {
3540
@include color($theme);
3641
}

src/material/form-field/_form-field-theme.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
@use '../core/tokens/token-utils';
1212
@use './form-field-density';
1313

14+
@mixin base($theme) {
15+
// TODO(mmalerba): Move form field base tokens here
16+
}
17+
1418
@mixin color($theme) {
1519
@include sass-utils.current-selector-or-root() {
1620
@include mdc-filled-text-field-theme.theme(
@@ -57,6 +61,7 @@
5761

5862
@mixin theme($theme) {
5963
@include theming.private-check-duplicate-theme-styles($theme, 'mat-form-field') {
64+
@include base($theme);
6065
@if inspection.theme-has($theme, color) {
6166
@include color($theme);
6267
}

0 commit comments

Comments
 (0)