Skip to content

Commit

Permalink
feat(material/core): switch system prefix from sys to mat-sys (#29908)
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/material/core/tokens/_m3-system.scss
  • Loading branch information
andrewseguin authored Oct 23, 2024
1 parent a8e40ec commit 4b49d73
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
14 changes: 12 additions & 2 deletions src/material/core/theming/_definition.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
@use '../tokens/m3-tokens';
@use './config-validation';

// Prefix used for component token fallback variables, e.g.
// `color: var(--mdc-text-button-label-text-color, var(--mat-sys-primary));`
$system-fallback-prefix: mat-sys;

// Default system level prefix to use when directly calling the `system-level-*` mixins.
// Prefix used for component token fallback variables, e.g.
// `color: var(--mdc-text-button-label-text-color, var(--mat-sys-primary));`
// TODO: Remove this variable after internal clients are migrated from "sys"
$system-level-prefix: mat-sys;

/// Map key used to store internals of theme config.
$internals: _mat-theming-internals-do-not-access;
/// The theme version of generated themes.
Expand Down Expand Up @@ -40,7 +50,7 @@ $theme-version: 1;
$type: map.get($config, theme-type) or light;
$primary: map.get($config, primary) or palettes.$violet-palette;
$tertiary: map.get($config, tertiary) or $primary;
$system-variables-prefix: map.get($config, system-variables-prefix) or sys;
$system-variables-prefix: map.get($config, system-variables-prefix) or $system-level-prefix;
sass-utils.$use-system-color-variables: map.get($config, use-system-variables) or false;

@return (
Expand Down Expand Up @@ -76,7 +86,7 @@ $theme-version: 1;
$bold: map.get($config, bold-weight) or 700;
$medium: map.get($config, medium-weight) or 500;
$regular: map.get($config, regular-weight) or 400;
$system-variables-prefix: map.get($config, system-variables-prefix) or sys;
$system-variables-prefix: map.get($config, system-variables-prefix) or $system-level-prefix;
sass-utils.$use-system-typography-variables: map.get($config, use-system-variables) or false;

@return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ describe('theming definition api', () => {
expect(vars['color-tokens']).toBe('true');
expect(vars['typography-tokens']).toBe('true');
expect(vars['density-tokens']).toBe('true');
expect(vars['typography-system-variables-prefix']).toBe('sys');
expect(vars['color-system-variables-prefix']).toBe('sys');
expect(vars['typography-system-variables-prefix']).toBe('mat-sys');
expect(vars['color-system-variables-prefix']).toBe('mat-sys');
});

it('should customize colors', () => {
Expand Down
36 changes: 15 additions & 21 deletions src/material/core/tokens/_m3-system.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
@use 'sass:list';
@use './m3-tokens';

// Prefix used for component token fallback variables, e.g.
// `color: var(--mdc-text-button-label-text-color, var(--mat-sys-primary));`
$_system-fallback-prefix: mat-sys;

// Default system level prefix to use when directly calling the `system-level-*` mixins
$_system-level-prefix: sys;

/// Emits necessary CSS variables for Material's system level values for the values defined in the
/// config map. The config map can have values color, typography, and/or density.
///
Expand Down Expand Up @@ -56,8 +49,8 @@ $_system-level-prefix: sys;
$color-config: if($is-palette,
definition.define-colors((primary: $color, theme-type: color-scheme)),
definition.define-colors($color));
@include system-level-colors($color-config, $overrides, $_system-fallback-prefix);
@include system-level-elevation($color-config, $overrides, $_system-fallback-prefix);
@include system-level-colors($color-config, $overrides, definition.$system-fallback-prefix);
@include system-level-elevation($color-config, $overrides, definition.$system-fallback-prefix);
}

$typography: map.get($config, typography);
Expand All @@ -66,7 +59,8 @@ $_system-level-prefix: sys;
$typography-config: if(meta.type-of($typography) == 'map',
definition.define-typography($typography),
definition.define-typography((plain-family: $typography)));
@include system-level-typography($typography-config, $overrides, $_system-fallback-prefix);
@include system-level-typography(
$typography-config, $overrides, definition.$system-fallback-prefix);
}

$density: map.get($config, density);
Expand All @@ -88,14 +82,14 @@ $_system-level-prefix: sys;
}
}

@include system-level-shape($overrides: $overrides, $prefix: $_system-fallback-prefix);
@include system-level-motion($overrides:$overrides, $prefix: $_system-fallback-prefix);
@include system-level-state($overrides: $overrides, $prefix: $_system-fallback-prefix);
@include system-level-shape($overrides: $overrides, $prefix: definition.$system-fallback-prefix);
@include system-level-motion($overrides:$overrides, $prefix: definition.$system-fallback-prefix);
@include system-level-state($overrides: $overrides, $prefix: definition.$system-fallback-prefix);
}

/// Emits the system-level CSS variables for each of the provided override values. E.g. to
/// change the primary color to red, use `mat.theme-overrides((primary: red));`
@mixin theme-overrides($overrides, $prefix: $_system-fallback-prefix) {
@mixin theme-overrides($overrides, $prefix: definition.$system-fallback-prefix) {
$sys-names: map-merge-all(
definitions.md-sys-color-values-light(),
definitions.md-sys-typescale-values(),
Expand Down Expand Up @@ -128,7 +122,7 @@ $_system-level-prefix: sys;

@if (not $prefix) {
$prefix: map.get($theme, _mat-theming-internals-do-not-access,
color-system-variables-prefix) or $_system-level-prefix;
color-system-variables-prefix) or definition.$system-level-prefix;
}

$ref: (
Expand Down Expand Up @@ -188,7 +182,7 @@ $_system-level-prefix: sys;

@if (not $prefix) {
$prefix: map.get($theme, _mat-theming-internals-do-not-access,
typography-system-variables-prefix) or $_system-level-prefix;
typography-system-variables-prefix) or definition.$system-level-prefix;
}

& {
Expand All @@ -198,7 +192,7 @@ $_system-level-prefix: sys;
}
}

@mixin system-level-elevation($theme, $overrides: (), $prefix: $_system-level-prefix) {
@mixin system-level-elevation($theme, $overrides: (), $prefix: definition.$system-level-prefix) {
$shadow-color: map.get(
$theme, _mat-theming-internals-do-not-access, color-tokens, (mdc, theme), shadow);

Expand All @@ -211,23 +205,23 @@ $_system-level-prefix: sys;
}
}

@mixin system-level-shape($theme: (), $overrides: (), $prefix: $_system-level-prefix) {
@mixin system-level-shape($theme: (), $overrides: (), $prefix: definition.$system-level-prefix) {
& {
@each $name, $value in definitions.md-sys-shape-values() {
--#{$prefix}-#{$name}: #{map.get($overrides, $name) or $value};
}
}
}

@mixin system-level-state($theme: (), $overrides: (), $prefix: $_system-level-prefix) {
@mixin system-level-state($theme: (), $overrides: (), $prefix: definition.$system-level-prefix) {
& {
@each $name, $value in definitions.md-sys-state-values() {
--#{$prefix}-#{$name}: #{map.get($overrides, $name) or $value};
}
}
}

@mixin system-level-motion($theme: (), $overrides: (), $prefix: $_system-level-prefix) {
@mixin system-level-motion($theme: (), $overrides: (), $prefix: definition.$system-level-prefix) {
& {
@each $name, $value in definitions.md-sys-motion-values() {
--#{$prefix}-#{$name}: #{map.get($overrides, $name) or $value};
Expand All @@ -241,7 +235,7 @@ $_system-level-prefix: sys;
@function _create-system-app-vars-map($map) {
$new-map: ();
@each $key, $value in $map {
$new-map: map.set($new-map, $key, --#{$_system-fallback-prefix}-#{$key});
$new-map: map.set($new-map, $key, --#{definition.$system-fallback-prefix}-#{$key});
}
@return $new-map;
}
Expand Down

0 comments on commit 4b49d73

Please sign in to comment.