Skip to content

Commit

Permalink
refactor(multiple): convert components to theme inspection API (round…
Browse files Browse the repository at this point in the history
… 4) (#27740)

BREAKING CHANGE:
- Themes are now more strictly validated when calling Angular Material
theme mixins. For example, calling `mat.button-typography` with a theme
has `typography: null` is now an error.
- The `mat.legacy-typography-hierarchy` mixin has been removed in favor
  of `mat.typography-hierarchy`
  • Loading branch information
mmalerba authored Sep 1, 2023
1 parent ccff68c commit 90465a1
Show file tree
Hide file tree
Showing 62 changed files with 676 additions and 1,423 deletions.
37 changes: 1 addition & 36 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"./tools/stylelint/no-nested-mixin.ts",
"./tools/stylelint/no-concrete-rules.ts",
"./tools/stylelint/no-top-level-ampersand-in-mixin.ts",
"./tools/stylelint/theme-mixin-api.ts",
"./tools/stylelint/no-import.ts",
"./tools/stylelint/single-line-comment-only.ts",
"./tools/stylelint/no-unused-import.ts",
Expand All @@ -33,7 +32,6 @@
"filePattern": "**/!(*-example.css)"
}
],
"material/theme-mixin-api": true,
"material/selector-no-deep": true,
"material/no-nested-mixin": true,
"material/no-unused-import": true,
Expand Down Expand Up @@ -143,38 +141,5 @@
"resolveNestedSelectors": true
}
]
},
"overrides": [
{
"files": [
"**/_button-theme.scss",
"**/_card-theme.scss",
"**/_checkbox-theme.scss",
"**/_column-resize-theme.scss",
"**/_core-theme.scss",
"**/_datepicker-theme.scss",
"**/_fab-theme.scss",
"**/_form-field-theme.scss",
"**/_icon-button-theme.scss",
"**/_input-theme.scss",
"**/_list-theme.scss",
"**/_optgroup-theme.scss",
"**/_option-theme.scss",
"**/_paginator-theme.scss",
"**/_popover-edit-theme.scss",
"**/_progress-bar-theme.scss",
"**/_pseudo-checkbox-theme.scss",
"**/_radio-theme.scss",
"**/_ripple-theme.scss",
"**/_slide-toggle-theme.scss",
"**/_slider-theme.scss",
"**/_sort-theme.scss",
"**/_stepper-theme.scss",
"**/_tree-theme.scss"
],
"rules": {
"material/theme-mixin-api": false
}
}
]
}
}
5 changes: 2 additions & 3 deletions src/dev-app/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

// Plus imports for other components in your app.

// Disable legacy API compatibility.
// TODO: uncomment once conversion to inspection API is complete.
//mat.$theme-legacy-inspection-api-compatibility: false;
// Disable legacy API compatibility, since dev-app is fully migrated to theme inspection API.
mat.$theme-legacy-inspection-api-compatibility: false;

// Define the default (light) theme.
$candy-app-primary: mat.define-palette(mat.$indigo-palette);
Expand Down
3 changes: 3 additions & 0 deletions src/e2e-app/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

// Plus imports for other components in your app.

// Disable legacy API compatibility, since e2e-app is fully migrated to theme inspection API.
mat.$theme-legacy-inspection-api-compatibility: false;

// Include the common styles for Angular Material. We include this here so that you only
// have to load a single css file for Angular Material in your app.
// **Be sure that you only ever include this mixin once!**
Expand Down
5 changes: 2 additions & 3 deletions src/material-experimental/selection/_selection.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
@use '@angular/material' as mat;

@mixin theme($theme-or-color-config) {
$theme: mat.private-legacy-get-theme($theme-or-color-config);
@mixin theme($theme) {
@include mat.private-check-duplicate-theme-styles($theme, 'mat-selection');
}

@mixin typography($config-or-theme) {}
@mixin typography($theme) {}
3 changes: 1 addition & 2 deletions src/material/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
$gray-palette, $blue-grey-palette, $blue-gray-palette, $light-theme-background-palette,
$dark-theme-background-palette, $light-theme-foreground-palette, $dark-theme-foreground-palette;
@forward './core/typography/typography' show define-typography-level, define-rem-typography-config,
define-typography-config, typography-hierarchy, define-legacy-typography-config,
legacy-typography-hierarchy;
define-typography-config, typography-hierarchy, define-legacy-typography-config;
@forward './core/typography/typography-utils' show typography-level,
font-size, line-height, font-weight, letter-spacing, font-family, font-shorthand;
@forward './core/tokens/m2' show m2-tokens-from-theme;
Expand Down
30 changes: 12 additions & 18 deletions src/material/autocomplete/_autocomplete-theme.scss
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
@use '../core/theming/theming';
@use '../core/theming/inspection';
@use '../core/typography/typography';
@use '../core/style/sass-utils';
@use '../core/tokens/token-utils';
@use '../core/tokens/m2/mat/autocomplete' as tokens-mat-autocomplete;

@mixin color($config-or-theme) {
$config: theming.get-color-config($config-or-theme);

@mixin color($theme) {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-autocomplete.$prefix,
tokens-mat-autocomplete.get-color-tokens($config));
tokens-mat-autocomplete.get-color-tokens($theme));
}
}

@mixin typography($config-or-theme) {}
@mixin typography($theme) {}

@mixin density($config-or-theme) {}
@mixin density($theme) {}

@mixin theme($theme-or-color-config) {
$theme: theming.private-legacy-get-theme($theme-or-color-config);
@mixin theme($theme) {
@include theming.private-check-duplicate-theme-styles($theme, 'mat-autocomplete') {
$color: theming.get-color-config($theme);
$density: theming.get-density-config($theme);
$typography: theming.get-typography-config($theme);

@if $color != null {
@include color($color);
@if inspection.theme-has($theme, color) {
@include color($theme);
}
@if $density != null {
@include density($density);
@if inspection.theme-has($theme, density) {
@include density($theme);
}
@if $typography != null {
@include typography($typography);
@if inspection.theme-has($theme, typography) {
@include typography($theme);
}
}
}
42 changes: 15 additions & 27 deletions src/material/badge/_badge-theme.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@use 'sass:color';
@use 'sass:map';
@use 'sass:math';
@use '@angular/cdk';

@use '../core/theming/theming';
@use '../core/theming/inspection';
@use '../core/typography/typography';
@use '../core/tokens/m2/mat/badge' as tokens-mat-badge;
@use '../core/tokens/token-utils';
Expand Down Expand Up @@ -164,46 +164,34 @@ $_emit-fallback-vars: true;
}
}

@mixin color($config-or-theme) {
$config: theming.get-color-config($config-or-theme);
$accent: map.get($config, accent);
$warn: map.get($config, warn);

@mixin color($theme) {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-badge.$prefix,
tokens-mat-badge.get-color-tokens($config));
tokens-mat-badge.get-color-tokens($theme));
}

.mat-badge-accent {
@include token-utils.create-token-values(tokens-mat-badge.$prefix,
tokens-mat-badge.private-get-color-palette-color-tokens($accent));
tokens-mat-badge.private-get-color-palette-color-tokens($theme, accent));
}

.mat-badge-warn {
@include token-utils.create-token-values(tokens-mat-badge.$prefix,
tokens-mat-badge.private-get-color-palette-color-tokens($warn));
tokens-mat-badge.private-get-color-palette-color-tokens($theme, warn));
}
}

@mixin typography($config-or-theme) {
$config: typography.private-typography-to-2014-config(
theming.get-typography-config($config-or-theme));

@mixin typography($theme) {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-badge.$prefix,
tokens-mat-badge.get-typography-tokens($config));
tokens-mat-badge.get-typography-tokens($theme));
}
}

@mixin density($config-or-theme) {}
@mixin density($theme) {}

@mixin theme($theme-or-color-config) {
$theme: theming.private-legacy-get-theme($theme-or-color-config);
@mixin theme($theme) {
@include theming.private-check-duplicate-theme-styles($theme, 'mat-badge') {
$color: theming.get-color-config($theme);
$density: theming.get-density-config($theme);
$typography: theming.get-typography-config($theme);

// Try to reduce the number of times that the structural styles are emitted.
@if not $_badge-structure-emitted {
@include _badge-structure;
Expand All @@ -216,14 +204,14 @@ $_emit-fallback-vars: true;
}
}

@if $color != null {
@include color($color);
@if inspection.theme-has($theme, color) {
@include color($theme);
}
@if $density != null {
@include density($density);
@if inspection.theme-has($theme, density) {
@include density($theme);
}
@if $typography != null {
@include typography($typography);
@if inspection.theme-has($theme, typography) {
@include typography($theme);
}
}
}
35 changes: 13 additions & 22 deletions src/material/bottom-sheet/_bottom-sheet-theme.scss
Original file line number Diff line number Diff line change
@@ -1,45 +1,36 @@
@use '../core/typography/typography';
@use '../core/theming/theming';
@use '../core/theming/inspection';
@use '../core/style/sass-utils';
@use '../core/tokens/token-utils';
@use '../core/tokens/m2/mat/bottom-sheet' as tokens-mat-bottom-sheet;

@mixin color($config-or-theme) {
$config: theming.get-color-config($config-or-theme);

@mixin color($theme) {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-bottom-sheet.$prefix,
tokens-mat-bottom-sheet.get-color-tokens($config));
tokens-mat-bottom-sheet.get-color-tokens($theme));
}
}

@mixin typography($config-or-theme) {
$config: typography.private-typography-to-2014-config(
theming.get-typography-config($config-or-theme));

@mixin typography($theme) {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-bottom-sheet.$prefix,
tokens-mat-bottom-sheet.get-typography-tokens($config));
tokens-mat-bottom-sheet.get-typography-tokens($theme));
}
}

@mixin density($config-or-theme) {}
@mixin density($theme) {}

@mixin theme($theme-or-color-config) {
$theme: theming.private-legacy-get-theme($theme-or-color-config);
@mixin theme($theme) {
@include theming.private-check-duplicate-theme-styles($theme, 'mat-bottom-sheet') {
$color: theming.get-color-config($theme);
$density: theming.get-density-config($theme);
$typography: theming.get-typography-config($theme);

@if $color != null {
@include color($color);
@if inspection.theme-has($theme, color) {
@include color($theme);
}
@if $density != null {
@include density($density);
@if inspection.theme-has($theme, density) {
@include density($theme);
}
@if $typography != null {
@include typography($typography);
@if inspection.theme-has($theme, typography) {
@include typography($theme);
}
}
}
45 changes: 17 additions & 28 deletions src/material/button-toggle/_button-toggle-theme.scss
Original file line number Diff line number Diff line change
@@ -1,59 +1,48 @@
@use '../core/theming/theming';
@use '../core/theming/inspection';
@use '../core/typography/typography';
@use '../core/tokens/m2/mat/legacy-button-toggle' as tokens-mat-legacy-button-toggle;
@use '../core/tokens/m2/mat/standard-button-toggle' as tokens-mat-standard-button-toggle;
@use '../core/tokens/token-utils';
@use '../core/style/sass-utils';

@mixin color($config-or-theme) {
$config: theming.get-color-config($config-or-theme);

@mixin color($theme) {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-legacy-button-toggle.$prefix,
tokens-mat-legacy-button-toggle.get-color-tokens($config));
tokens-mat-legacy-button-toggle.get-color-tokens($theme));
@include token-utils.create-token-values(tokens-mat-standard-button-toggle.$prefix,
tokens-mat-standard-button-toggle.get-color-tokens($config));
tokens-mat-standard-button-toggle.get-color-tokens($theme));
}
}

@mixin typography($config-or-theme) {
$config: typography.private-typography-to-2014-config(
theming.get-typography-config($config-or-theme));

@mixin typography($theme) {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-legacy-button-toggle.$prefix,
tokens-mat-legacy-button-toggle.get-typography-tokens($config));
tokens-mat-legacy-button-toggle.get-typography-tokens($theme));
@include token-utils.create-token-values(tokens-mat-standard-button-toggle.$prefix,
tokens-mat-standard-button-toggle.get-typography-tokens($config));
tokens-mat-standard-button-toggle.get-typography-tokens($theme));
}
}

@mixin density($config-or-theme) {
$density-scale: theming.get-density-config($config-or-theme);

@mixin density($theme) {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-legacy-button-toggle.$prefix,
tokens-mat-legacy-button-toggle.get-density-tokens($density-scale));
tokens-mat-legacy-button-toggle.get-density-tokens($theme));
@include token-utils.create-token-values(tokens-mat-standard-button-toggle.$prefix,
tokens-mat-standard-button-toggle.get-density-tokens($density-scale));
tokens-mat-standard-button-toggle.get-density-tokens($theme));
}
}

@mixin theme($theme-or-color-config) {
$theme: theming.private-legacy-get-theme($theme-or-color-config);
@mixin theme($theme) {
@include theming.private-check-duplicate-theme-styles($theme, 'mat-button-toggle') {
$color: theming.get-color-config($theme);
$density: theming.get-density-config($theme);
$typography: theming.get-typography-config($theme);

@if $color != null {
@include color($color);
@if inspection.theme-has($theme, color) {
@include color($theme);
}
@if $density != null {
@include density($density);
@if inspection.theme-has($theme, density) {
@include density($theme);
}
@if $typography != null {
@include typography($typography);
@if inspection.theme-has($theme, typography) {
@include typography($theme);
}
}
}
Loading

0 comments on commit 90465a1

Please sign in to comment.