Skip to content

Commit 3950d0f

Browse files
committed
refactor: add duplicated theme styles check to all individual theme mixins
Adds the duplicated theme styles check to all individual theme mixins. Also, adds a lint rule that enforces that the theme styles check is included in every theme mixin w/ autofix.
1 parent db8f7b7 commit 3950d0f

File tree

74 files changed

+257
-85
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+257
-85
lines changed

.stylelintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
"./tools/stylelint/selector-no-deep.ts",
77
"./tools/stylelint/no-nested-mixin.ts",
88
"./tools/stylelint/no-concrete-rules.ts",
9-
"./tools/stylelint/no-top-level-ampersand-in-mixin.ts"
9+
"./tools/stylelint/no-top-level-ampersand-in-mixin.ts",
10+
"./tools/stylelint/theme-duplicate-styles-check.js"
1011
],
1112
"rules": {
1213
"material/no-prefixes": [true, {
1314
"browsers": ["last 2 versions", "not ie <= 10", "not ie_mob <= 10"],
1415
"filePattern": "**/!(*-example.css)"
1516
}],
17+
"material/theme-duplicate-styles-check": true,
1618
"material/selector-no-deep": true,
1719
"material/no-nested-mixin": true,
1820
"material/no-ampersand-beyond-selector-start": [true, {

guides/duplicate-theming-styles.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,6 @@ extract the configuration for the color system from the theme.
6363
}
6464
```
6565

66-
Alternatively, a new theme object can be constructed that explicitly disables
67-
styles from other systems such as `density` or `typography`:
68-
69-
```scss
70-
.my-custom-dark-button {
71-
$only-color-theme: map_merge($my-theme, (
72-
density: null,
73-
typography: null
74-
));
75-
// This will only generate the color styles for `mat-button`.
76-
@include mat-button-theme($only-color-theme);
77-
}
78-
```
79-
8066
#### Disabling duplication warnings
8167

8268
If your application intentionally duplicates styles, a global Sass variable can be

src/dev-app/theme.scss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@import '../material/core/theming/all-theme';
77
@import '../material-experimental/column-resize/column-resize';
88
@import '../material-experimental/mdc-helpers/mdc-helpers';
9-
@import '../material-experimental/mdc-helpers/focus-indicator';
9+
@import '../material-experimental/mdc-helpers/focus-indicators';
1010
@import '../material-experimental/mdc-color/all-color';
1111
@import '../material-experimental/mdc-theming/all-theme';
1212
@import '../material-experimental/mdc-typography/all-typography';
@@ -69,14 +69,14 @@ $dark-theme: mat-dark-theme((
6969
.demo-unicorn-dark-theme {
7070
@include angular-material-color($dark-theme);
7171
@include angular-material-mdc-color($dark-theme);
72-
@include mat-column-resize-theme($dark-theme);
73-
@include mat-popover-edit-theme($dark-theme);
72+
@include mat-column-resize-color(map_get($dark-theme, color));
73+
@include mat-popover-edit-color(map_get($dark-theme, color));
7474
}
7575

7676
// Include the dark theme for focus indicators.
7777
.demo-unicorn-dark-theme.demo-strong-focus {
78-
@include mat-strong-focus-indicators-theme($dark-theme);
79-
@include mat-mdc-strong-focus-indicators-theme($dark-theme);
78+
@include mat-strong-focus-indicators-color(map_get($dark-theme, color));
79+
@include mat-mdc-strong-focus-indicators-color(map_get($dark-theme, color));
8080
}
8181

8282
// Create classes for all density scales which are supported by all MDC-based components.

src/material-experimental/column-resize/_column-resize.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
@mixin mat-column-resize-density($density-scale) {}
101101

102102
@mixin mat-column-resize-theme($theme) {
103+
@include _mat-check-duplicate-theme-styles($theme, 'mat-column-resize');
103104
$color: mat-get-color-config($theme);
104105
$density: mat-get-density-config($theme);
105106
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-autocomplete/_autocomplete-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
@mixin mat-mdc-autocomplete-density($density-scale) {}
1616

1717
@mixin mat-mdc-autocomplete-theme($theme) {
18+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-autocomplete');
1819
$color: mat-get-color-config($theme);
1920
$density: mat-get-density-config($theme);
2021
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-button/_button-theme.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ $mat-button-state-target: '.mdc-button__ripple';
180180
}
181181

182182
@mixin mat-mdc-button-theme($theme) {
183+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-button');
183184
$color: mat-get-color-config($theme);
184185
$density: mat-get-density-config($theme);
185186
$typography: mat-get-typography-config($theme);
@@ -253,6 +254,7 @@ $mat-button-state-target: '.mdc-button__ripple';
253254
@mixin mat-mdc-fab-density($density-scale) {}
254255

255256
@mixin mat-mdc-fab-theme($theme) {
257+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-fab');
256258
$color: mat-get-color-config($theme);
257259
$density: mat-get-density-config($theme);
258260
$typography: mat-get-typography-config($theme);
@@ -325,6 +327,7 @@ $mat-button-state-target: '.mdc-button__ripple';
325327
}
326328

327329
@mixin mat-mdc-icon-button-theme($theme) {
330+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-icon-button');
328331
$color: mat-get-color-config($theme);
329332
$density: mat-get-density-config($theme);
330333
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-card/_card-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
@mixin mat-mdc-card-density($density-scale) {}
5050

5151
@mixin mat-mdc-card-theme($theme) {
52+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-card');
5253
$color: mat-get-color-config($theme);
5354
$density: mat-get-density-config($theme);
5455
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-checkbox/_checkbox-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
}
8585

8686
@mixin mat-mdc-checkbox-theme($theme) {
87+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-checkbox');
8788
$color: mat-get-color-config($theme);
8889
$density: mat-get-density-config($theme);
8990
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-chips/_chips-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
}
6969

7070
@mixin mat-mdc-chips-theme($theme) {
71+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-chips');
7172
$color: mat-get-color-config($theme);
7273
$density: mat-get-density-config($theme);
7374
$typography: mat-get-typography-config($theme);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
}
7777

7878
@mixin mat-mdc-form-field-theme($theme) {
79+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-form-field');
7980
$color: mat-get-color-config($theme);
8081
$density: mat-get-density-config($theme);
8182
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-helpers/_focus-indicator.scss renamed to src/material-experimental/mdc-helpers/_focus-indicators.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@
102102
/// .demo-red-theme {
103103
/// @include mat-mdc-strong-focus-indicators-theme(#f00);
104104
/// }
105+
/* stylelint-disable-next-line material/theme-duplicate-styles-check */
105106
@mixin mat-mdc-strong-focus-indicators-theme($theme-or-color) {
106107
@if type-of($theme-or-color) != 'map' {
107108
@include _mat-mdc-strong-focus-indicators-border-color($theme-or-color);
108109
}
109110
@else {
111+
@include _mat-check-duplicate-theme-styles($theme-or-color, 'mat-mdc-strong-focus-indicators');
110112
$color: mat-get-color-config($theme-or-color);
111113
@if $color != null {
112114
@include mat-mdc-strong-focus-indicators-color($color);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@import '@material/typography/variables.import';
99
@import '../../material/core/style/layout-common';
1010
@import '../../material/core/theming/theming';
11+
@import '../../material/core/theming/check-duplicate-styles';
1112
@import '../../material/core/typography/typography';
1213

1314
// A set of standard queries to use with MDC's queryable mixins.
@@ -113,6 +114,7 @@ $mat-typography-level-mappings: (
113114

114115
// Configures MDC's global variables to reflect the given theme, applies the given styles,
115116
// then resets the global variables to prevent unintended side effects.
117+
/* stylelint-disable-next-line material/theme-duplicate-styles-check */
116118
@mixin mat-using-mdc-theme($config) {
117119
$primary: mat-color(map-get($config, primary));
118120
$accent: mat-color(map-get($config, accent));

src/material-experimental/mdc-input/_input-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
@mixin mat-mdc-input-density($density-scale) {}
1212

1313
@mixin mat-mdc-input-theme($theme) {
14+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-input');
1415
$color: mat-get-color-config($theme);
1516
$density: mat-get-density-config($theme);
1617
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-list/_list-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
}
5353

5454
@mixin mat-mdc-list-theme($theme) {
55+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-list');
5556
$color: mat-get-color-config($theme);
5657
$density: mat-get-density-config($theme);
5758
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-menu/_menu-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
@mixin mat-mdc-menu-density($density-scale) {}
5454

5555
@mixin mat-mdc-menu-theme($theme) {
56+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-menu');
5657
$color: mat-get-color-config($theme);
5758
$density: mat-get-density-config($theme);
5859
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-progress-bar/_progress-bar-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
@mixin mat-mdc-progress-bar-density($density-scale) {}
3636

3737
@mixin mat-mdc-progress-bar-theme($theme) {
38+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-progress-bar');
3839
$color: mat-get-color-config($theme);
3940
$density: mat-get-density-config($theme);
4041
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-radio/_radio-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
}
5252

5353
@mixin mat-mdc-radio-theme($theme) {
54+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-radio');
5455
$color: mat-get-color-config($theme);
5556
$density: mat-get-density-config($theme);
5657
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-select/_select-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
@mixin mat-mdc-select-density($density-scale) {}
1616

1717
@mixin mat-mdc-select-theme($theme) {
18+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-select');
1819
$color: mat-get-color-config($theme);
1920
$density: mat-get-density-config($theme);
2021
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-sidenav/_sidenav-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
@mixin mat-mdc-sidenav-density($density-scale) {}
1616

1717
@mixin mat-mdc-sidenav-theme($theme) {
18+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-sidenav');
1819
$color: mat-get-color-config($theme);
1920
$density: mat-get-density-config($theme);
2021
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-slide-toggle/_slide-toggle-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
}
9292

9393
@mixin mat-mdc-slide-toggle-theme($theme) {
94+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-slide-toggle');
9495
$color: mat-get-color-config($theme);
9596
$density: mat-get-density-config($theme);
9697
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-slider/_slider-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
@mixin mat-mdc-slider-density($density-scale) {}
2727

2828
@mixin mat-mdc-slider-theme($theme) {
29+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-slider');
2930
$color: mat-get-color-config($theme);
3031
$density: mat-get-density-config($theme);
3132
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-snackbar/_snackbar-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@mixin mat-mdc-snackbar-density($density-scale) {}
1010

1111
@mixin mat-mdc-snackbar-theme($theme) {
12+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-snackbar');
1213
$color: mat-get-color-config($theme);
1314
$density: mat-get-density-config($theme);
1415
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-table/_table-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
}
5555

5656
@mixin mat-mdc-table-theme($theme) {
57+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-table');
5758
$color: mat-get-color-config($theme);
5859
$density: mat-get-density-config($theme);
5960
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-tabs/_tabs-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
}
107107

108108
@mixin mat-mdc-tabs-theme($theme) {
109+
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc-tabs');
109110
$color: mat-get-color-config($theme);
110111
$density: mat-get-density-config($theme);
111112
$typography: mat-get-typography-config($theme);

src/material-experimental/mdc-theming/_all-theme.scss

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@
1515
@import '../../material/core/theming/check-duplicate-styles';
1616

1717
@mixin angular-material-mdc-theme($theme) {
18-
@include _mat-check-duplicate-theme-styles($theme, 'mat-mdc');
19-
@include mat-mdc-button-theme($theme);
20-
@include mat-mdc-fab-theme($theme);
21-
@include mat-mdc-icon-button-theme($theme);
22-
@include mat-mdc-card-theme($theme);
23-
@include mat-mdc-checkbox-theme($theme);
24-
@include mat-mdc-chips-theme($theme);
25-
@include mat-mdc-list-theme($theme);
26-
@include mat-mdc-menu-theme($theme);
27-
@include mat-mdc-progress-bar-theme($theme);
28-
@include mat-mdc-radio-theme($theme);
29-
@include mat-mdc-slide-toggle-theme($theme);
30-
@include mat-mdc-table-theme($theme);
31-
@include mat-mdc-form-field-theme($theme);
32-
@include mat-mdc-input-theme($theme);
33-
@include mat-mdc-slider-theme($theme);
34-
@include mat-mdc-tabs-theme($theme);
18+
@include _mat-check-duplicate-theme-styles($theme, 'angular-material-mdc-theme') {
19+
@include mat-mdc-button-theme($theme);
20+
@include mat-mdc-fab-theme($theme);
21+
@include mat-mdc-icon-button-theme($theme);
22+
@include mat-mdc-card-theme($theme);
23+
@include mat-mdc-checkbox-theme($theme);
24+
@include mat-mdc-chips-theme($theme);
25+
@include mat-mdc-list-theme($theme);
26+
@include mat-mdc-menu-theme($theme);
27+
@include mat-mdc-progress-bar-theme($theme);
28+
@include mat-mdc-radio-theme($theme);
29+
@include mat-mdc-slide-toggle-theme($theme);
30+
@include mat-mdc-table-theme($theme);
31+
@include mat-mdc-form-field-theme($theme);
32+
@include mat-mdc-input-theme($theme);
33+
@include mat-mdc-slider-theme($theme);
34+
@include mat-mdc-tabs-theme($theme);
35+
}
3536
}

src/material-experimental/popover-edit/_popover-edit.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
@mixin mat-popover-edit-density($density-scale) {}
152152

153153
@mixin mat-popover-edit-theme($theme) {
154+
@include _mat-check-duplicate-theme-styles($theme, 'mat-popover-edit');
154155
$color: mat-get-color-config($theme);
155156
$density: mat-get-density-config($theme);
156157
$typography: mat-get-typography-config($theme);

src/material/autocomplete/_autocomplete-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import '../core/style/elevation';
22
@import '../core/theming/theming';
3+
@import '../core/theming/check-duplicate-styles';
34

45
@mixin mat-autocomplete-color($config) {
56
$foreground: map-get($config, foreground);
@@ -30,6 +31,7 @@
3031
@mixin _mat-autocomplete-density($density-scale) { }
3132

3233
@mixin mat-autocomplete-theme($theme) {
34+
@include _mat-check-duplicate-theme-styles($theme, 'mat-autocomplete');
3335
$color: mat-get-color-config($theme);
3436
$density: mat-get-density-config($theme);
3537
$typography: mat-get-typography-config($theme);

src/material/badge/_badge-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// no style sheet support for directives.
44
@import '../core/theming/palette';
55
@import '../core/theming/theming';
6+
@import '../core/theming/check-duplicate-styles';
67
@import '../core/typography/typography-utils';
78
@import '../../cdk/a11y/a11y';
89

@@ -206,6 +207,7 @@ $mat-badge-large-size: $mat-badge-default-size + 6;
206207
@mixin _mat-badge-density($density-scale) {}
207208

208209
@mixin mat-badge-theme($theme) {
210+
@include _mat-check-duplicate-theme-styles($theme, 'mat-badge');
209211
$color: mat-get-color-config($theme);
210212
$density: mat-get-density-config($theme);
211213
$typography: mat-get-typography-config($theme);

src/material/bottom-sheet/_bottom-sheet-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@import '../core/typography/typography-utils';
33
@import '../core/theming/palette';
44
@import '../core/theming/theming';
5+
@import '../core/theming/check-duplicate-styles';
56

67
@mixin mat-bottom-sheet-color($theme) {
78
$background: map-get($theme, background);
@@ -23,6 +24,7 @@
2324
@mixin _mat-bottom-sheet-density($density-scale) {}
2425

2526
@mixin mat-bottom-sheet-theme($theme) {
27+
@include _mat-check-duplicate-theme-styles($theme, 'mat-bottom-sheet');
2628
$color: mat-get-color-config($theme);
2729
$density: mat-get-density-config($theme);
2830
$typography: mat-get-typography-config($theme);

src/material/button-toggle/_button-toggle-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@import '../core/style/elevation';
33
@import '../core/theming/palette';
44
@import '../core/theming/theming';
5+
@import '../core/theming/check-duplicate-styles';
56
@import '../core/typography/typography-utils';
67
@import '../core/density/index';
78
@import './button-toggle-variables';
@@ -106,6 +107,7 @@
106107
}
107108

108109
@mixin mat-button-toggle-theme($theme) {
110+
@include _mat-check-duplicate-theme-styles($theme, 'mat-button-toggle');
109111
$color: mat-get-color-config($theme);
110112
$density: mat-get-density-config($theme);
111113
$typography: mat-get-typography-config($theme);

src/material/button/_button-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import '../core/theming/theming';
22
@import '../core/style/elevation';
33
@import '../core/typography/typography-utils';
4+
@import '../core/theming/check-duplicate-styles';
45

56
$_mat-button-ripple-opacity: 0.1;
67

@@ -172,6 +173,7 @@ $_mat-button-ripple-opacity: 0.1;
172173
@mixin _mat-button-density($density-scale) {}
173174

174175
@mixin mat-button-theme($theme) {
176+
@include _mat-check-duplicate-theme-styles($theme, 'mat-button');
175177
$color: mat-get-color-config($theme);
176178
$density: mat-get-density-config($theme);
177179
$typography: mat-get-typography-config($theme);

0 commit comments

Comments
 (0)