Skip to content

refactor: align m2 and m3 token file functions by using get-tokens #31425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/material/autocomplete/_autocomplete-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@use 'm3-autocomplete';

@mixin base($theme) {
$tokens: m2-autocomplete.get-unthemable-tokens();
$tokens: map.get(m2-autocomplete.get-tokens($theme), base);
@if inspection.get-theme-version($theme) == 1 {
$tokens: map.get(m3-autocomplete.get-tokens($theme), base);
}
Expand All @@ -15,7 +15,7 @@
}

@mixin color($theme) {
$tokens: m2-autocomplete.get-color-tokens($theme);
$tokens: map.get(m2-autocomplete.get-tokens($theme), color);
@if inspection.get-theme-version($theme) == 1 {
$tokens: map.get(m3-autocomplete.get-tokens($theme), color);
}
Expand All @@ -24,7 +24,7 @@
}

@mixin typography($theme) {
$tokens: m2-autocomplete.get-typography-tokens($theme);
$tokens: map.get(m2-autocomplete.get-tokens($theme), typography);
@if inspection.get-theme-version($theme) == 1 {
$tokens: map.get(m3-autocomplete.get-tokens($theme), typography);
}
Expand All @@ -33,7 +33,7 @@
}

@mixin density($theme) {
$tokens: m2-autocomplete.get-density-tokens($theme);
$tokens: map.get(m2-autocomplete.get-tokens($theme), density);
@if inspection.get-theme-version($theme) == 1 {
$tokens: map.get(m3-autocomplete.get-tokens($theme), density);
}
Expand Down
32 changes: 10 additions & 22 deletions src/material/autocomplete/_m2-autocomplete.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,18 @@
@use '../core/tokens/m2-utils';
@use 'sass:map';

// Tokens that can't be configured through Angular Material's current theming API,
// but may be in a future version of the theming API.
@function get-unthemable-tokens() {
@return (
autocomplete-container-shape: 4px,
autocomplete-container-elevation-shadow: elevation.get-box-shadow(8),
);
}

// Tokens that can be configured through Angular Material's color theming API.
@function get-color-tokens($theme) {
@function get-tokens($theme) {
$system: m2-utils.get-system($theme);

@return (
autocomplete-background-color: map.get($system, surface)
base: (
autocomplete-container-shape: 4px,
autocomplete-container-elevation-shadow: elevation.get-box-shadow(8),
),
color: (
autocomplete-background-color: map.get($system, surface)
),
typography: (),
density: (),
);
}

// Tokens that can be configured through Angular Material's typography theming API.
@function get-typography-tokens($theme) {
@return ();
}

// Tokens that can be configured through Angular Material's density theming API.
@function get-density-tokens($theme) {
@return ();
}
8 changes: 4 additions & 4 deletions src/material/badge/_badge-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/// for the mat-badge.
/// @param {Map} $theme The theme to generate base styles for.
@mixin base($theme) {
$tokens: m2-badge.get-unthemable-tokens();
$tokens: map.get(m2-badge.get-tokens($theme), base);
@if inspection.get-theme-version($theme) == 1 {
$tokens: map.get(m3-badge.get-tokens($theme), base);
}
Expand All @@ -24,7 +24,7 @@
/// the badge: primary, secondary, tertiary, or error (If not specified,
/// default error color will be used).
@mixin color($theme, $color-variant: null) {
$tokens: m2-badge.get-color-tokens($theme);
$tokens: map.get(m2-badge.get-tokens($theme), color);
@if inspection.get-theme-version($theme) == 1 {
$tokens: map.get(m3-badge.get-tokens($theme, $color-variant), color);
}
Expand All @@ -47,7 +47,7 @@
/// Outputs typography theme styles for the mat-badge.
/// @param {Map} $theme The theme to generate typography styles for.
@mixin typography($theme) {
$tokens: m2-badge.get-typography-tokens($theme);
$tokens: map.get(m2-badge.get-tokens($theme), typography);
@if inspection.get-theme-version($theme) == 1 {
$tokens: map.get(m3-badge.get-tokens($theme), typography);
}
Expand All @@ -58,7 +58,7 @@
/// Outputs density theme styles for the mat-badge.
/// @param {Map} $theme The theme to generate density styles for.
@mixin density($theme) {
$tokens: m2-badge.get-density-tokens($theme);
$tokens: map.get(m2-badge.get-tokens($theme), density);
@if inspection.get-theme-version($theme) == 1 {
$tokens: map.get(m3-badge.get-tokens($theme), density);
}
Expand Down
112 changes: 49 additions & 63 deletions src/material/badge/_m2-badge.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,59 @@ $_default-size: 22px;
$_small-size: $_default-size - 6px;
$_large-size: $_default-size + 6px;

// Tokens that can't be configured through Angular Material's current theming API,
// but may be in a future version of the theming API.
@function get-unthemable-tokens() {
$default-size: $_default-size;
$small-size: $_small-size;
$large-size: $_large-size;

@return (
badge-container-shape: 50%,
badge-container-size: unset,
badge-small-size-container-size: unset,
badge-large-size-container-size: unset,

badge-legacy-container-size: $default-size,
badge-legacy-small-size-container-size: $small-size,
badge-legacy-large-size-container-size: $large-size,

badge-container-offset: math.div($default-size, -2) 0,
badge-small-size-container-offset: math.div($small-size, -2) 0,
badge-large-size-container-offset: math.div($large-size, -2) 0,

badge-container-overlap-offset: math.div($default-size, -2),
badge-small-size-container-overlap-offset: math.div($small-size, -2),
badge-large-size-container-overlap-offset: math.div($large-size, -2),

badge-container-padding: 0,
badge-small-size-container-padding: 0,
badge-large-size-container-padding: 0,
);
}
@function get-tokens($theme) {
$default-size: 22px;
$small-size: $default-size - 6px;
$large-size: $default-size + 6px;
$base-size: 12px;

// Tokens that can be configured through Angular Material's color theming API.
@function get-color-tokens($theme) {
$system: m2-utils.get-system($theme);
$disabled: m3-utils.color-with-opacity(map.get($system, on-surface), 38%);
$disabled-container : m3-utils.color-with-opacity(map.get($system, on-surface), 12%);
$disabled-container: m3-utils.color-with-opacity(map.get($system, on-surface), 12%);
$primary-color-tokens: private-get-color-palette-color-tokens($theme, primary);
@return map.merge($primary-color-tokens, (
badge-disabled-state-background-color: $disabled-container,
badge-disabled-state-text-color: $disabled,
));
}

@return (
base: (
badge-container-shape: 50%,
badge-container-size: unset,
badge-small-size-container-size: unset,
badge-large-size-container-size: unset,

badge-legacy-container-size: $default-size,
badge-legacy-small-size-container-size: $small-size,
badge-legacy-large-size-container-size: $large-size,

badge-container-offset: math.div($default-size, -2) 0,
badge-small-size-container-offset: math.div($small-size, -2) 0,
badge-large-size-container-offset: math.div($large-size, -2) 0,

badge-container-overlap-offset: math.div($default-size, -2),
badge-small-size-container-overlap-offset: math.div($small-size, -2),
badge-large-size-container-overlap-offset: math.div($large-size, -2),

badge-container-padding: 0,
badge-small-size-container-padding: 0,
badge-large-size-container-padding: 0,
),
color: map.merge($primary-color-tokens, (
badge-disabled-state-background-color: $disabled-container,
badge-disabled-state-text-color: $disabled,
)),
typography: (
badge-text-font: map.get($system, body-medium-font),
badge-line-height: $_default-size,
badge-text-size: $base-size,
badge-text-weight: 600,

badge-small-size-text-size: $base-size * 0.75,
badge-small-size-line-height: $_small-size,

badge-large-size-text-size: $base-size * 2,
badge-large-size-line-height: $_large-size,
),
density: (),
);
};

// Generates the tokens used to theme the badge based on a palette.
@function private-get-color-palette-color-tokens($theme, $color-variant) {
Expand All @@ -60,28 +71,3 @@ $_large-size: $_default-size + 6px;
badge-text-color: map.get($system, on-primary),
);
}

// Tokens that can be configured through Angular Material's typography theming API.
@function get-typography-tokens($theme) {
$system: m2-utils.get-system($theme);

$base-size: 12px;

@return (
badge-text-font: map.get($system, body-medium-font),
badge-line-height: $_default-size,
badge-text-size: $base-size,
badge-text-weight: 600,

badge-small-size-text-size: $base-size * 0.75,
badge-small-size-line-height: $_small-size,

badge-large-size-text-size: $base-size * 2,
badge-large-size-line-height: $_large-size,
);
}

// Tokens that can be configured through Angular Material's density theming API.
@function get-density-tokens($theme) {
@return ();
}
8 changes: 4 additions & 4 deletions src/material/bottom-sheet/_bottom-sheet-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@use './m3-bottom-sheet';

@mixin base($theme) {
$tokens: m2-bottom-sheet.get-unthemable-tokens();
$tokens: map.get(m2-bottom-sheet.get-tokens($theme), base);
@if inspection.get-theme-version($theme) == 1 {
$tokens: map.get(m3-bottom-sheet.get-tokens($theme), base);
}
Expand All @@ -15,7 +15,7 @@
}

@mixin color($theme) {
$tokens: m2-bottom-sheet.get-color-tokens($theme);
$tokens: map.get(m2-bottom-sheet.get-tokens($theme), color);
@if inspection.get-theme-version($theme) == 1 {
$tokens: map.get(m3-bottom-sheet.get-tokens($theme), color);
}
Expand All @@ -24,7 +24,7 @@
}

@mixin typography($theme) {
$tokens: m2-bottom-sheet.get-typography-tokens($theme);
$tokens: map.get(m2-bottom-sheet.get-tokens($theme), typography);
@if inspection.get-theme-version($theme) == 1 {
$tokens: map.get(m3-bottom-sheet.get-tokens($theme), typography);
}
Expand All @@ -33,7 +33,7 @@
}

@mixin density($theme) {
$tokens: m2-bottom-sheet.get-density-tokens($theme);
$tokens: map.get(m2-bottom-sheet.get-tokens($theme), density);
@if inspection.get-theme-version($theme) == 1 {
$tokens: map.get(m3-bottom-sheet.get-tokens($theme), density);
}
Expand Down
46 changes: 16 additions & 30 deletions src/material/bottom-sheet/_m2-bottom-sheet.scss
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
@use '../core/tokens/m2-utils';
@use 'sass:map';

// Tokens that can't be configured through Angular Material's current theming API,
// but may be in a future version of the theming API.
@function get-unthemable-tokens() {
@return (
// TODO: will be necessary for M3.
bottom-sheet-container-shape: 4px,
);
}

// Tokens that can be configured through Angular Material's color theming API.
@function get-color-tokens($theme) {
@function get-tokens($theme) {
$system: m2-utils.get-system($theme);

@return (
bottom-sheet-container-text-color: map.get($system, on-surface),
bottom-sheet-container-background-color: map.get($system, surface),
base: (
bottom-sheet-container-shape: 4px,
),
color: (
bottom-sheet-container-text-color: map.get($system, on-surface),
bottom-sheet-container-background-color: map.get($system, surface),
),
typography: (
bottom-sheet-container-text-font: map.get($system, body-medium-font),
bottom-sheet-container-text-line-height: map.get($system, body-medium-line-height),
bottom-sheet-container-text-size: map.get($system, body-medium-size),
bottom-sheet-container-text-tracking: map.get($system, body-medium-tracking),
bottom-sheet-container-text-weight: map.get($system, body-medium-weight),
),
density: (),
);
}

// Tokens that can be configured through Angular Material's typography theming API.
@function get-typography-tokens($theme) {
$system: m2-utils.get-system($theme);
@return (
bottom-sheet-container-text-font: map.get($system, body-medium-font),
bottom-sheet-container-text-line-height: map.get($system, body-medium-line-height),
bottom-sheet-container-text-size: map.get($system, body-medium-size),
bottom-sheet-container-text-tracking: map.get($system, body-medium-tracking),
bottom-sheet-container-text-weight: map.get($system, body-medium-weight),
);
}

// Tokens that can be configured through Angular Material's density theming API.
@function get-density-tokens($theme) {
@return ();
}
8 changes: 4 additions & 4 deletions src/material/button-toggle/_button-toggle-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// for the mat-button-toggle.
/// @param {Map} $theme The theme to generate base styles for.
@mixin base($theme) {
$tokens: m2-button-toggle.get-unthemable-tokens($theme);
$tokens: map.get(m2-button-toggle.get-tokens($theme), base);
@if inspection.get-theme-version($theme) == 1 {
$tokens: map.get(m3-button-toggle.get-tokens($theme), base);
}
Expand All @@ -22,7 +22,7 @@
/// @param {String} $color-variant: The color variant to use for the button toggle: primary,
/// secondary, tertiary, or error (If not specified, default secondary color will be used).
@mixin color($theme, $color-variant: null) {
$tokens: m2-button-toggle.get-color-tokens($theme);
$tokens: map.get(m2-button-toggle.get-tokens($theme), color);
@if inspection.get-theme-version($theme) == 1 {
$tokens: map.get(m3-button-toggle.get-tokens($theme, $color-variant), color);
}
Expand All @@ -33,7 +33,7 @@
/// Outputs typography theme styles for the mat-button-toggle.
/// @param {Map} $theme The theme to generate typography styles for.
@mixin typography($theme) {
$tokens: m2-button-toggle.get-typography-tokens($theme);
$tokens: map.get(m2-button-toggle.get-tokens($theme), typography);
@if inspection.get-theme-version($theme) == 1 {
$tokens: map.get(m3-button-toggle.get-tokens($theme), typography);
}
Expand All @@ -44,7 +44,7 @@
/// Outputs density theme styles for the mat-button-toggle.
/// @param {Map} $theme The theme to generate density styles for.
@mixin density($theme) {
$tokens: m2-button-toggle.get-density-tokens($theme);
$tokens: map.get(m2-button-toggle.get-tokens($theme), density);
@if inspection.get-theme-version($theme) == 1 {
$tokens: map.get(m3-button-toggle.get-tokens($theme), density);
}
Expand Down
Loading
Loading