Skip to content

Commit

Permalink
feat(material-experimental/theming): add M3 grid-list support (#28131)
Browse files Browse the repository at this point in the history
(cherry picked from commit f67c871)
  • Loading branch information
mmalerba committed Nov 16, 2023
1 parent c0e7622 commit 61401f5
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/dev-app/theme-m3.scss
Expand Up @@ -39,6 +39,7 @@ html {
@include mat.card-theme($light-theme);
@include mat.checkbox-theme($light-theme);
@include mat.form-field-theme($light-theme);
@include mat.grid-list-theme($light-theme);
@include mat.input-theme($light-theme);
@include mat.list-theme($light-theme);
@include mat.progress-bar-theme($light-theme);
Expand Down Expand Up @@ -66,6 +67,7 @@ html {
@include mat.card-color($dark-theme);
@include mat.checkbox-color($dark-theme);
@include mat.form-field-color($dark-theme);
@include mat.grid-list-color($dark-theme);
@include mat.input-color($dark-theme);
@include mat.list-color($dark-theme);
@include mat.progress-bar-color($dark-theme);
Expand All @@ -92,6 +94,7 @@ html {
@include mat.card-density($scale-theme);
@include mat.checkbox-density($scale-theme);
@include mat.form-field-density($scale-theme);
@include mat.grid-list-density($scale-theme);
@include mat.input-density($scale-theme);
@include mat.list-density($scale-theme);
@include mat.progress-bar-density($scale-theme);
Expand Down
13 changes: 13 additions & 0 deletions src/material-experimental/theming/_custom-tokens.scss
Expand Up @@ -62,6 +62,19 @@
);
}

/// Generates custom tokens for the mat-grid-list.
/// @param {Map} $systems The MDC system tokens
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
/// @return {Map} A set of custom tokens for the mat-grid-list
@function grid-list($systems, $exclude-hardcoded) {
@return (
tile-header-primary-text-size: map.get($systems, md-sys-typescale, body-large),
tile-header-secondary-text-size: map.get($systems, md-sys-typescale, body-medium),
tile-footer-primary-text-size: map.get($systems, md-sys-typescale, body-large),
tile-footer-secondary-text-size: map.get($systems, md-sys-typescale, body-medium),
);
}

/// Generates custom tokens for the mat-toolbar.
/// @param {Map} $systems The MDC system tokens
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
Expand Down
1 change: 1 addition & 0 deletions src/material-experimental/theming/_m3-density.scss
Expand Up @@ -45,6 +45,7 @@ $_density-tokens: (
// Custom Angular Material tokens
(mat, card): (),
(mat, form-fild): (),
(mat, grid-list): (),
(mat, toolbar): (
standard-height: (64px, 60px, 56px, 52px),
mobile-height: (56px, 52px, 48px, 44px),
Expand Down
5 changes: 5 additions & 0 deletions src/material-experimental/theming/_m3-tokens.scss
Expand Up @@ -259,6 +259,11 @@
custom-tokens.form-field($systems, $exclude-hardcoded),
$token-slots
),
_namespace-tokens(
(mat, grid-list),
custom-tokens.grid-list($systems, $exclude-hardcoded),
$token-slots
),
_namespace-tokens(
(mat, toolbar),
custom-tokens.toolbar($systems, $exclude-hardcoded),
Expand Down
2 changes: 2 additions & 0 deletions src/material/core/tokens/m2/_index.scss
Expand Up @@ -3,6 +3,7 @@
@use '../../style/sass-utils';
@use './mat/card' as tokens-mat-card;
@use './mat/form-field' as tokens-mat-form-field;
@use './mat/grid-list' as tokens-mat-grid-list;
@use './mat/radio' as tokens-mat-radio;
@use './mat/ripple' as tokens-mat-ripple;
@use './mat/slide-toggle' as tokens-mat-slide-toggle;
Expand Down Expand Up @@ -78,6 +79,7 @@
@return sass-utils.deep-merge-all(
_get-tokens-for-module($theme, tokens-mat-card),
_get-tokens-for-module($theme, tokens-mat-form-field),
_get-tokens-for-module($theme, tokens-mat-grid-list),
_get-tokens-for-module($theme, tokens-mat-radio),
_get-tokens-for-module($theme, tokens-mat-ripple),
_get-tokens-for-module($theme, tokens-mat-slide-toggle),
Expand Down
61 changes: 47 additions & 14 deletions src/material/grid-list/_grid-list-theme.scss
@@ -1,35 +1,68 @@
@use 'sass:map';
@use '../core/theming/theming';
@use '../core/theming/inspection';
@use '../core/typography/typography';
@use '../core/tokens/m2/mat/grid-list' as tokens-mat-grid-list;
@use '../core/style/sass-utils';
@use '../core/tokens/token-utils';

@mixin base($theme) {}
@mixin base($theme) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
}
@else {}
}

// Include this empty mixin for consistency with the other components.
@mixin color($theme) {}
@mixin color($theme) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
}
@else {}
}

@mixin typography($theme) {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-grid-list.$prefix,
tokens-mat-grid-list.get-typography-tokens($theme));
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
}
@else {
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-grid-list.$prefix,
tokens-mat-grid-list.get-typography-tokens($theme));
}
}
}

@mixin density($theme) {}
@mixin density($theme) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
}
@else {}
}

@mixin theme($theme) {
@include theming.private-check-duplicate-theme-styles($theme, 'mat-grid-list') {
@include base($theme);
@if inspection.theme-has($theme, color) {
@include color($theme);
}
@if inspection.theme-has($theme, density) {
@include density($theme);
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme));
}
@if inspection.theme-has($theme, typography) {
@include typography($theme);
@else {
@include base($theme);
@if inspection.theme-has($theme, color) {
@include color($theme);
}
@if inspection.theme-has($theme, density) {
@include density($theme);
}
@if inspection.theme-has($theme, typography) {
@include typography($theme);
}
}
}
}

@mixin _theme-from-tokens($tokens) {
@if ($tokens != ()) {
@include token-utils.create-token-values(
tokens-mat-grid-list.$prefix, map.get($tokens, tokens-mat-grid-list.$prefix));
}
}

0 comments on commit 61401f5

Please sign in to comment.