diff --git a/src/material/autocomplete/_autocomplete-theme.scss b/src/material/autocomplete/_autocomplete-theme.scss index 21c46b92c6c6..1eeda823fb32 100644 --- a/src/material/autocomplete/_autocomplete-theme.scss +++ b/src/material/autocomplete/_autocomplete-theme.scss @@ -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); } @@ -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); } @@ -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); } @@ -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); } diff --git a/src/material/autocomplete/_m2-autocomplete.scss b/src/material/autocomplete/_m2-autocomplete.scss index 5039d9c2d24f..bc5264890e0a 100644 --- a/src/material/autocomplete/_m2-autocomplete.scss +++ b/src/material/autocomplete/_m2-autocomplete.scss @@ -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 (); -} diff --git a/src/material/badge/_badge-theme.scss b/src/material/badge/_badge-theme.scss index d3df753f607f..ef5801f8fab9 100644 --- a/src/material/badge/_badge-theme.scss +++ b/src/material/badge/_badge-theme.scss @@ -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); } @@ -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); } @@ -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); } @@ -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); } diff --git a/src/material/badge/_m2-badge.scss b/src/material/badge/_m2-badge.scss index d18de9cdbabc..226d8fb774df 100644 --- a/src/material/badge/_m2-badge.scss +++ b/src/material/badge/_m2-badge.scss @@ -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) { @@ -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 (); -} diff --git a/src/material/bottom-sheet/_bottom-sheet-theme.scss b/src/material/bottom-sheet/_bottom-sheet-theme.scss index 39e8ec2e31a2..2e887e713a12 100644 --- a/src/material/bottom-sheet/_bottom-sheet-theme.scss +++ b/src/material/bottom-sheet/_bottom-sheet-theme.scss @@ -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); } @@ -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); } @@ -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); } @@ -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); } diff --git a/src/material/bottom-sheet/_m2-bottom-sheet.scss b/src/material/bottom-sheet/_m2-bottom-sheet.scss index 034194186ef1..f4a0889bae34 100644 --- a/src/material/bottom-sheet/_m2-bottom-sheet.scss +++ b/src/material/bottom-sheet/_m2-bottom-sheet.scss @@ -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 (); -} diff --git a/src/material/button-toggle/_button-toggle-theme.scss b/src/material/button-toggle/_button-toggle-theme.scss index d41e22c742a8..dc5512d2f49a 100644 --- a/src/material/button-toggle/_button-toggle-theme.scss +++ b/src/material/button-toggle/_button-toggle-theme.scss @@ -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); } @@ -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); } @@ -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); } @@ -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); } diff --git a/src/material/button-toggle/_m2-button-toggle.scss b/src/material/button-toggle/_m2-button-toggle.scss index 19e46a6544ef..e826eb874ffb 100644 --- a/src/material/button-toggle/_m2-button-toggle.scss +++ b/src/material/button-toggle/_m2-button-toggle.scss @@ -3,83 +3,66 @@ @use '../core/tokens/m2-utils'; @use '../core/tokens/m3-utils'; -// 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($theme) { - $system: m2-utils.get-system($theme); - @return ( - button-toggle-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), - button-toggle-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), - button-toggle-legacy-focus-state-layer-opacity: 1, - button-toggle-legacy-height: 36px, - button-toggle-legacy-shape: 2px, - button-toggle-shape: 4px, - ); -} - -// Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme) { - $system: m2-utils.get-system($theme); - - @return ( - button-toggle-background-color: map.get($system, surface), - button-toggle-disabled-selected-state-background-color: - m3-utils.color-with-opacity(map.get($system, on-surface), 12%), - button-toggle-disabled-selected-state-text-color: - m3-utils.color-with-opacity(map.get($system, on-surface), 38%), - button-toggle-disabled-state-background-color: map.get($system, surface), - button-toggle-disabled-state-text-color: - m3-utils.color-with-opacity(map.get($system, on-surface), 38%), - button-toggle-divider-color: map.get($system, outline), - button-toggle-legacy-disabled-selected-state-background-color: - m3-utils.color-with-opacity(map.get($system, on-surface), 12%), - button-toggle-legacy-disabled-state-background-color: map.get($system, surface), - button-toggle-legacy-disabled-state-text-color: - m3-utils.color-with-opacity(map.get($system, on-surface), 38%), - button-toggle-legacy-selected-state-background-color: - m3-utils.color-with-opacity(map.get($system, on-surface), 12%), - button-toggle-legacy-selected-state-text-color: map.get($system, on-surface), - button-toggle-legacy-state-layer-color: - m3-utils.color-with-opacity(map.get($system, on-surface), 12%), - button-toggle-legacy-text-color: map.get($system, on-surface), - button-toggle-selected-state-background-color: - m3-utils.color-with-opacity(map.get($system, on-surface), 12%), - button-toggle-selected-state-text-color: map.get($system, on-surface), - button-toggle-state-layer-color: map.get($system, on-surface), - button-toggle-text-color: map.get($system, on-surface), - ); -} - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - button-toggle-label-text-font: map.get($system, body-large-font), - button-toggle-label-text-line-height: map.get($system, body-large-line-height), - button-toggle-label-text-size: map.get($system, body-large-size), - button-toggle-label-text-tracking: map.get($system, body-large-tracking), - button-toggle-label-text-weight: map.get($system, body-large-weight), - button-toggle-legacy-label-text-font: map.get($system, body-large-font), - button-toggle-legacy-label-text-line-height: map.get($system, body-large-line-height), - button-toggle-legacy-label-text-size: map.get($system, body-large-size), - button-toggle-legacy-label-text-tracking: map.get($system, body-large-tracking), - button-toggle-legacy-label-text-weight: map.get($system, body-large-weight), - ); -} - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { +@function get-tokens($theme) { $system: m2-utils.get-system($theme); $density-scale: theming.clamp-density(map.get($system, density-scale), -4); - $size-scale: ( - 0: 48px, - -1: 44px, - -2: 40px, - -3: 36px, - -4: 24px, - ); @return ( - button-toggle-height: map.get($size-scale, $density-scale) + base: ( + button-toggle-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), + button-toggle-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), + button-toggle-legacy-focus-state-layer-opacity: 1, + button-toggle-legacy-height: 36px, + button-toggle-legacy-shape: 2px, + button-toggle-shape: 4px, + ), + color: ( + button-toggle-background-color: map.get($system, surface), + button-toggle-disabled-selected-state-background-color: + m3-utils.color-with-opacity(map.get($system, on-surface), 12%), + button-toggle-disabled-selected-state-text-color: + m3-utils.color-with-opacity(map.get($system, on-surface), 38%), + button-toggle-disabled-state-background-color: map.get($system, surface), + button-toggle-disabled-state-text-color: + m3-utils.color-with-opacity(map.get($system, on-surface), 38%), + button-toggle-divider-color: map.get($system, outline), + button-toggle-legacy-disabled-selected-state-background-color: + m3-utils.color-with-opacity(map.get($system, on-surface), 12%), + button-toggle-legacy-disabled-state-background-color: map.get($system, surface), + button-toggle-legacy-disabled-state-text-color: + m3-utils.color-with-opacity(map.get($system, on-surface), 38%), + button-toggle-legacy-selected-state-background-color: + m3-utils.color-with-opacity(map.get($system, on-surface), 12%), + button-toggle-legacy-selected-state-text-color: map.get($system, on-surface), + button-toggle-legacy-state-layer-color: + m3-utils.color-with-opacity(map.get($system, on-surface), 12%), + button-toggle-legacy-text-color: map.get($system, on-surface), + button-toggle-selected-state-background-color: + m3-utils.color-with-opacity(map.get($system, on-surface), 12%), + button-toggle-selected-state-text-color: map.get($system, on-surface), + button-toggle-state-layer-color: map.get($system, on-surface), + button-toggle-text-color: map.get($system, on-surface), + ), + typography: ( + button-toggle-label-text-font: map.get($system, body-large-font), + button-toggle-label-text-line-height: map.get($system, body-large-line-height), + button-toggle-label-text-size: map.get($system, body-large-size), + button-toggle-label-text-tracking: map.get($system, body-large-tracking), + button-toggle-label-text-weight: map.get($system, body-large-weight), + button-toggle-legacy-label-text-font: map.get($system, body-large-font), + button-toggle-legacy-label-text-line-height: map.get($system, body-large-line-height), + button-toggle-legacy-label-text-size: map.get($system, body-large-size), + button-toggle-legacy-label-text-tracking: map.get($system, body-large-tracking), + button-toggle-legacy-label-text-weight: map.get($system, body-large-weight), + ), + density: ( + button-toggle-height: map.get(( + 0: 48px, + -1: 44px, + -2: 40px, + -3: 36px, + -4: 24px, + ), $density-scale) + ), ); } diff --git a/src/material/button/_button-theme.scss b/src/material/button/_button-theme.scss index d57977f1b7c7..00b50eb0d276 100644 --- a/src/material/button/_button-theme.scss +++ b/src/material/button/_button-theme.scss @@ -9,7 +9,7 @@ /// for the mat-button. /// @param {Map} $theme The theme to generate base styles for. @mixin base($theme) { - $tokens: m2-button.get-unthemable-tokens(); + $tokens: map.get(m2-button.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-button.get-tokens($theme), base); } @@ -23,7 +23,7 @@ /// the badge: primary, secondary, tertiary, or error (If not specified, /// default primary color will be used). @mixin color($theme, $color-variant: null) { - $tokens: m2-button.get-color-tokens($theme); + $tokens: map.get(m2-button.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-button.get-tokens($theme, $color-variant), color); } @@ -55,7 +55,7 @@ } @mixin typography($theme) { - $tokens: m2-button.get-typography-tokens($theme); + $tokens: map.get(m2-button.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-button.get-tokens($theme), typography); } @@ -64,7 +64,7 @@ } @mixin density($theme) { - $tokens: m2-button.get-density-tokens($theme); + $tokens: map.get(m2-button.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-button.get-tokens($theme), density); } diff --git a/src/material/button/_fab-theme.scss b/src/material/button/_fab-theme.scss index 71f6504194a3..2ced18f9f544 100644 --- a/src/material/button/_fab-theme.scss +++ b/src/material/button/_fab-theme.scss @@ -9,7 +9,7 @@ /// for the mat-fab. /// @param {Map} $theme The theme to generate base styles for. @mixin base($theme) { - $tokens: m2-fab.get-unthemable-tokens(); + $tokens: map.get(m2-fab.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-fab.get-tokens($theme), base); } @@ -22,7 +22,7 @@ /// @param {ArgList} $color-variant: The color variant to use for the fab: primary, secondary, // or tertiary. (If not specified, default primary color will be used). @mixin color($theme, $color-variant: null) { - $tokens: m2-fab.get-color-tokens($theme); + $tokens: map.get(m2-fab.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-fab.get-tokens($theme, $color-variant), color); } @@ -52,7 +52,7 @@ /// Outputs typography theme styles for the mat-fab. /// @param {Map} $theme The theme to generate typography styles for. @mixin typography($theme) { - $tokens: m2-fab.get-typography-tokens($theme); + $tokens: map.get(m2-fab.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-fab.get-tokens($theme), typography); } @@ -63,7 +63,7 @@ /// Outputs density theme styles for the mat-fab. /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { - $tokens: m2-fab.get-density-tokens($theme); + $tokens: map.get(m2-fab.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-fab.get-tokens($theme), density); } diff --git a/src/material/button/_icon-button-theme.scss b/src/material/button/_icon-button-theme.scss index 805fdaece563..0115351874e8 100644 --- a/src/material/button/_icon-button-theme.scss +++ b/src/material/button/_icon-button-theme.scss @@ -8,7 +8,7 @@ @use '../core/theming/theming'; @mixin base($theme) { - $tokens: m2-icon-button.get-unthemable-tokens(); + $tokens: map.get(m2-icon-button.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-icon-button.get-tokens($theme), base); } @@ -21,7 +21,7 @@ /// @param {String} $color-variant: The color variant to use for the // button: primary, secondary, tertiary, or error. @mixin color($theme, $color-variant: null) { - $tokens: m2-icon-button.get-color-tokens($theme); + $tokens: map.get(m2-icon-button.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-icon-button.get-tokens($theme, $color-variant), color); } @@ -49,7 +49,7 @@ } @mixin typography($theme) { - $tokens: m2-icon-button.get-typography-tokens($theme); + $tokens: map.get(m2-icon-button.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-icon-button.get-tokens($theme), typography); } @@ -74,10 +74,9 @@ ); $calculated-size: map.get($size-map, $density-scale); - @include token-utils.values( - m2-icon-button.get-density-tokens( - $theme, $exclude: (icon-button-state-layer-size)) - ); + $density-tokens: map.get(m2-icon-button.get-tokens($theme), density); + $density-tokens: map.remove($density-tokens, icon-button-state-layer-size); + @include token-utils.values($density-tokens); // Use `mat-mdc-button-base` to increase the specificity over the button's structural styles. .mat-mdc-icon-button.mat-mdc-button-base { diff --git a/src/material/button/_m2-button.scss b/src/material/button/_m2-button.scss index d2c96fcb3303..af81b87e7785 100644 --- a/src/material/button/_m2-button.scss +++ b/src/material/button/_m2-button.scss @@ -2,105 +2,147 @@ @use '../core/tokens/m2-utils'; @use '../core/tokens/m3-utils'; @use '../core/theming/theming'; -@use '../core/theming/inspection'; @use '../core/style/elevation'; -// 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 ( - button-filled-container-shape: 4px, - button-filled-horizontal-padding: 16px, - button-filled-icon-offset: -4px, - button-filled-icon-spacing: 8px, - button-outlined-container-shape: 4px, - button-outlined-horizontal-padding: 15px, // Normally it's 16px, but -1px for the outline. - button-outlined-icon-offset: -4px, - button-outlined-icon-spacing: 8px, - button-outlined-keep-touch-target: false, - button-outlined-outline-width: 1px, - button-protected-container-elevation-shadow: elevation.get-box-shadow(2), - button-protected-container-shape: 4px, - button-protected-disabled-container-elevation-shadow: elevation.get-box-shadow(0), - button-protected-focus-container-elevation-shadow: elevation.get-box-shadow(4), - button-protected-horizontal-padding: 16px, - button-protected-hover-container-elevation-shadow: elevation.get-box-shadow(4), - button-protected-icon-offset: -4px, - button-protected-icon-spacing: 8px, - button-protected-pressed-container-elevation-shadow: elevation.get-box-shadow(8), - button-text-container-shape: 4px, - button-text-horizontal-padding: 8px, - button-text-icon-offset: 0, - button-text-icon-spacing: 8px, - button-text-with-icon-horizontal-padding: 8px, - button-tonal-container-shape: 4px, - button-tonal-horizontal-padding: 16px, - button-tonal-icon-offset: -4px, - button-tonal-icon-spacing: 8px, - ); -} - -// 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); - $is-dark: inspection.get-theme-type($theme) == dark; $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%); + $scale: theming.clamp-density(map.get($system, density-scale), -3); + $height: map.get(( + 0: 36px, + -1: 32px, + -2: 28px, + -3: 24px, + ), $scale); + $touch-target-display: if($scale < -1, none, block); + @return ( - button-filled-container-color: map.get($system, surface), - button-filled-disabled-container-color: $disabled-container, - button-filled-disabled-label-text-color: $disabled, - button-filled-disabled-state-layer-color: map.get($system, on-surface-variant), - button-filled-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), - button-filled-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), - button-filled-label-text-color: map.get($system, on-surface), - button-filled-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), - button-filled-ripple-color: m3-utils.color-with-opacity( - map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), - button-filled-state-layer-color: map.get($system, on-surface), - button-outlined-disabled-label-text-color: $disabled, - button-outlined-disabled-outline-color: map.get($system, outline), - button-outlined-disabled-state-layer-color: map.get($system, on-surface-variant), - button-outlined-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), - button-outlined-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), - button-outlined-label-text-color: map.get($system, on-surface), - button-outlined-outline-color: map.get($system, outline), - button-outlined-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), - button-outlined-ripple-color: m3-utils.color-with-opacity( - map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), - button-outlined-state-layer-color: map.get($system, on-surface), - button-protected-container-color: map.get($system, surface), - button-protected-disabled-container-color: $disabled-container, - button-protected-disabled-label-text-color: $disabled, - button-protected-disabled-state-layer-color: map.get($system, on-surface-variant), - button-protected-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), - button-protected-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), - button-protected-label-text-color: map.get($system, on-surface), - button-protected-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), - button-protected-ripple-color: m3-utils.color-with-opacity( - map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), - button-protected-state-layer-color: map.get($system, on-surface), - button-text-disabled-label-text-color: $disabled, - button-text-disabled-state-layer-color: map.get($system, on-surface-variant), - button-text-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), - button-text-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), - button-text-label-text-color: map.get($system, on-surface), - button-text-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), - button-text-ripple-color: m3-utils.color-with-opacity( - map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), - button-text-state-layer-color: map.get($system, on-surface), - button-tonal-container-color: map.get($system, surface), - button-tonal-disabled-container-color: $disabled-container, - button-tonal-disabled-label-text-color: $disabled, - button-tonal-disabled-state-layer-color: map.get($system, on-surface-variant), - button-tonal-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), - button-tonal-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), - button-tonal-label-text-color: map.get($system, on-surface), - button-tonal-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), - button-tonal-ripple-color: m3-utils.color-with-opacity( - map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), - button-tonal-state-layer-color: map.get($system, on-surface), + base: ( + button-filled-container-shape: 4px, + button-filled-horizontal-padding: 16px, + button-filled-icon-offset: -4px, + button-filled-icon-spacing: 8px, + button-outlined-container-shape: 4px, + button-outlined-horizontal-padding: 15px, // Normally it's 16px, but -1px for the outline. + button-outlined-icon-offset: -4px, + button-outlined-icon-spacing: 8px, + button-outlined-keep-touch-target: false, + button-outlined-outline-width: 1px, + button-protected-container-elevation-shadow: elevation.get-box-shadow(2), + button-protected-container-shape: 4px, + button-protected-disabled-container-elevation-shadow: elevation.get-box-shadow(0), + button-protected-focus-container-elevation-shadow: elevation.get-box-shadow(4), + button-protected-horizontal-padding: 16px, + button-protected-hover-container-elevation-shadow: elevation.get-box-shadow(4), + button-protected-icon-offset: -4px, + button-protected-icon-spacing: 8px, + button-protected-pressed-container-elevation-shadow: elevation.get-box-shadow(8), + button-text-container-shape: 4px, + button-text-horizontal-padding: 8px, + button-text-icon-offset: 0, + button-text-icon-spacing: 8px, + button-text-with-icon-horizontal-padding: 8px, + button-tonal-container-shape: 4px, + button-tonal-horizontal-padding: 16px, + button-tonal-icon-offset: -4px, + button-tonal-icon-spacing: 8px, + ), + color: ( + button-filled-container-color: map.get($system, surface), + button-filled-disabled-container-color: $disabled-container, + button-filled-disabled-label-text-color: $disabled, + button-filled-disabled-state-layer-color: map.get($system, on-surface-variant), + button-filled-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), + button-filled-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), + button-filled-label-text-color: map.get($system, on-surface), + button-filled-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), + button-filled-ripple-color: m3-utils.color-with-opacity( + map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), + button-filled-state-layer-color: map.get($system, on-surface), + button-outlined-disabled-label-text-color: $disabled, + button-outlined-disabled-outline-color: map.get($system, outline), + button-outlined-disabled-state-layer-color: map.get($system, on-surface-variant), + button-outlined-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), + button-outlined-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), + button-outlined-label-text-color: map.get($system, on-surface), + button-outlined-outline-color: map.get($system, outline), + button-outlined-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), + button-outlined-ripple-color: m3-utils.color-with-opacity( + map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), + button-outlined-state-layer-color: map.get($system, on-surface), + button-protected-container-color: map.get($system, surface), + button-protected-disabled-container-color: $disabled-container, + button-protected-disabled-label-text-color: $disabled, + button-protected-disabled-state-layer-color: map.get($system, on-surface-variant), + button-protected-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), + button-protected-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), + button-protected-label-text-color: map.get($system, on-surface), + button-protected-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), + button-protected-ripple-color: m3-utils.color-with-opacity( + map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), + button-protected-state-layer-color: map.get($system, on-surface), + button-text-disabled-label-text-color: $disabled, + button-text-disabled-state-layer-color: map.get($system, on-surface-variant), + button-text-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), + button-text-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), + button-text-label-text-color: map.get($system, on-surface), + button-text-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), + button-text-ripple-color: m3-utils.color-with-opacity( + map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), + button-text-state-layer-color: map.get($system, on-surface), + button-tonal-container-color: map.get($system, surface), + button-tonal-disabled-container-color: $disabled-container, + button-tonal-disabled-label-text-color: $disabled, + button-tonal-disabled-state-layer-color: map.get($system, on-surface-variant), + button-tonal-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), + button-tonal-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), + button-tonal-label-text-color: map.get($system, on-surface), + button-tonal-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), + button-tonal-ripple-color: m3-utils.color-with-opacity( + map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), + button-tonal-state-layer-color: map.get($system, on-surface), + ), + typography: ( + button-filled-label-text-font: map.get($system, label-small-font), + button-filled-label-text-size: map.get($system, label-small-size), + button-filled-label-text-tracking: map.get($system, label-small-tracking), + button-filled-label-text-transform: none, + button-filled-label-text-weight: map.get($system, label-small-weight), + button-outlined-label-text-font: map.get($system, label-small-font), + button-outlined-label-text-size: map.get($system, label-small-size), + button-outlined-label-text-tracking: map.get($system, label-small-tracking), + button-outlined-label-text-transform: none, + button-outlined-label-text-weight: map.get($system, label-small-weight), + button-protected-label-text-font: map.get($system, label-small-font), + button-protected-label-text-size: map.get($system, label-small-size), + button-protected-label-text-tracking: map.get($system, label-small-tracking), + button-protected-label-text-transform: none, + button-protected-label-text-weight: map.get($system, label-small-weight), + button-text-label-text-font: map.get($system, label-small-font), + button-text-label-text-size: map.get($system, label-small-size), + button-text-label-text-tracking: map.get($system, label-small-tracking), + button-text-label-text-transform: none, + button-text-label-text-weight: map.get($system, label-small-weight), + button-tonal-label-text-font: map.get($system, label-small-font), + button-tonal-label-text-size: map.get($system, label-small-size), + button-tonal-label-text-tracking: map.get($system, label-small-tracking), + button-tonal-label-text-transform: none, + button-tonal-label-text-weight: map.get($system, label-small-weight), + ), + density: ( + button-filled-container-height: $height, + button-filled-touch-target-display: $touch-target-display, + button-outlined-container-height: $height, + button-outlined-touch-target-display: $touch-target-display, + button-protected-container-height: $height, + button-protected-touch-target-display: $touch-target-display, + button-text-container-height: $height, + button-text-touch-target-display: $touch-target-display, + button-tonal-container-height: $height, + button-tonal-touch-target-display: $touch-target-display, + ), ); } @@ -120,7 +162,7 @@ map.get($system, on-primary), map.get($system, pressed-state-layer-opacity)), button-filled-state-layer-color: map.get($system, on-primary), button-outlined-label-text-color: map.get($system, primary), - button-outlined-outline-color: map.get(get-color-tokens($theme), button-outlined-outline-color), + button-outlined-outline-color: map.get($system, outline), button-outlined-ripple-color: m3-utils.color-with-opacity( map.get($system, primary), map.get($system, pressed-state-layer-opacity)), button-outlined-state-layer-color: map.get($system, primary), @@ -140,64 +182,3 @@ button-tonal-state-layer-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); - - @return ( - button-filled-label-text-font: map.get($system, label-small-font), - button-filled-label-text-size: map.get($system, label-small-size), - button-filled-label-text-tracking: map.get($system, label-small-tracking), - button-filled-label-text-transform: none, - button-filled-label-text-weight: map.get($system, label-small-weight), - button-outlined-label-text-font: map.get($system, label-small-font), - button-outlined-label-text-size: map.get($system, label-small-size), - button-outlined-label-text-tracking: map.get($system, label-small-tracking), - button-outlined-label-text-transform: none, - button-outlined-label-text-weight: map.get($system, label-small-weight), - button-protected-label-text-font: map.get($system, label-small-font), - button-protected-label-text-size: map.get($system, label-small-size), - button-protected-label-text-tracking: map.get($system, label-small-tracking), - button-protected-label-text-transform: none, - button-protected-label-text-weight: map.get($system, label-small-weight), - button-text-label-text-font: map.get($system, label-small-font), - button-text-label-text-size: map.get($system, label-small-size), - button-text-label-text-tracking: map.get($system, label-small-tracking), - button-text-label-text-transform: none, - button-text-label-text-weight: map.get($system, label-small-weight), - button-tonal-label-text-font: map.get($system, label-small-font), - button-tonal-label-text-size: map.get($system, label-small-size), - button-tonal-label-text-tracking: map.get($system, label-small-tracking), - button-tonal-label-text-transform: none, - button-tonal-label-text-weight: map.get($system, label-small-weight), - ); -} - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { - $system: m2-utils.get-system($theme); - $scale: theming.clamp-density(map.get($system, density-scale), -3); - $sizes: ( - 0: 36px, - -1: 32px, - -2: 28px, - -3: 24px, - ); - - $height: map.get($sizes, $scale); - $touch-target-display: if($scale < -1, none, block); - - @return ( - button-filled-container-height: $height, - button-filled-touch-target-display: $touch-target-display, - button-outlined-container-height: $height, - button-outlined-touch-target-display: $touch-target-display, - button-protected-container-height: $height, - button-protected-touch-target-display: $touch-target-display, - button-text-container-height: $height, - button-text-touch-target-display: $touch-target-display, - button-tonal-container-height: $height, - button-tonal-touch-target-display: $touch-target-display, - ); -} diff --git a/src/material/button/_m2-fab.scss b/src/material/button/_m2-fab.scss index b965ec092a00..a666c2a474e3 100644 --- a/src/material/button/_m2-fab.scss +++ b/src/material/button/_m2-fab.scss @@ -1,63 +1,75 @@ @use 'sass:map'; +@use 'sass:meta'; @use '../core/tokens/m2-utils'; @use '../core/tokens/m3-utils'; @use '../core/theming/theming'; @use '../core/theming/inspection'; @use '../core/style/elevation'; -// 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 ( - fab-container-elevation-shadow: elevation.get-box-shadow(6), - fab-container-shape: 50%, - fab-extended-container-elevation-shadow: elevation.get-box-shadow(6), - fab-extended-container-height: 48px, - fab-extended-container-shape: 24px, - fab-extended-focus-container-elevation-shadow: elevation.get-box-shadow(8), - fab-extended-hover-container-elevation-shadow: elevation.get-box-shadow(8), - fab-extended-pressed-container-elevation-shadow: elevation.get-box-shadow(12), - fab-focus-container-elevation-shadow: elevation.get-box-shadow(8), - fab-hover-container-elevation-shadow: elevation.get-box-shadow(8), - fab-pressed-container-elevation-shadow: elevation.get-box-shadow(12), - fab-small-container-elevation-shadow: elevation.get-box-shadow(6), - fab-small-container-shape: 50%, - fab-small-focus-container-elevation-shadow: elevation.get-box-shadow(8), - fab-small-hover-container-elevation-shadow: elevation.get-box-shadow(8), - fab-small-pressed-container-elevation-shadow: elevation.get-box-shadow(12), - ); -} - -// 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); - $is-dark: inspection.get-theme-type($theme) == dark; + // TODO: Use system colors instead of checking theme type + $is-dark: false; + @if (meta.type-of($theme) == map and map.get($theme, color)) { + $is-dark: inspection.get-theme-type($theme) == dark; + } $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%); + $density-scale: theming.clamp-density(map.get($system, density-scale), -3); @return ( - fab-container-color: map.get($system, surface), - fab-disabled-state-container-color: $disabled-container, - fab-disabled-state-foreground-color: $disabled, - fab-disabled-state-layer-color: map.get($system, on-surface-variant), - fab-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), - fab-foreground-color: map.get($system, on-surface), - fab-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), - fab-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), - fab-ripple-color: m3-utils.color-with-opacity( - map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), - fab-small-container-color: map.get($system, surface), - fab-small-disabled-state-container-color: $disabled-container, - fab-small-disabled-state-foreground-color: $disabled, - fab-small-disabled-state-layer-color: map.get($system, on-surface-variant), - fab-small-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), - fab-small-foreground-color: map.get($system, on-surface), - fab-small-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), - fab-small-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), - fab-small-ripple-color: m3-utils.color-with-opacity( - map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), - fab-small-state-layer-color: map.get($system, on-surface), - fab-state-layer-color: map.get($system, on-surface), + base: ( + fab-container-elevation-shadow: elevation.get-box-shadow(6), + fab-container-shape: 50%, + fab-extended-container-elevation-shadow: elevation.get-box-shadow(6), + fab-extended-container-height: 48px, + fab-extended-container-shape: 24px, + fab-extended-focus-container-elevation-shadow: elevation.get-box-shadow(8), + fab-extended-hover-container-elevation-shadow: elevation.get-box-shadow(8), + fab-extended-pressed-container-elevation-shadow: elevation.get-box-shadow(12), + fab-focus-container-elevation-shadow: elevation.get-box-shadow(8), + fab-hover-container-elevation-shadow: elevation.get-box-shadow(8), + fab-pressed-container-elevation-shadow: elevation.get-box-shadow(12), + fab-small-container-elevation-shadow: elevation.get-box-shadow(6), + fab-small-container-shape: 50%, + fab-small-focus-container-elevation-shadow: elevation.get-box-shadow(8), + fab-small-hover-container-elevation-shadow: elevation.get-box-shadow(8), + fab-small-pressed-container-elevation-shadow: elevation.get-box-shadow(12), + ), + color: ( + fab-container-color: map.get($system, surface), + fab-disabled-state-container-color: $disabled-container, + fab-disabled-state-foreground-color: $disabled, + fab-disabled-state-layer-color: map.get($system, on-surface-variant), + fab-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), + fab-foreground-color: map.get($system, on-surface), + fab-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), + fab-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), + fab-ripple-color: m3-utils.color-with-opacity( + map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), + fab-small-container-color: map.get($system, surface), + fab-small-disabled-state-container-color: $disabled-container, + fab-small-disabled-state-foreground-color: $disabled, + fab-small-disabled-state-layer-color: map.get($system, on-surface-variant), + fab-small-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), + fab-small-foreground-color: map.get($system, on-surface), + fab-small-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), + fab-small-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), + fab-small-ripple-color: m3-utils.color-with-opacity( + map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), + fab-small-state-layer-color: map.get($system, on-surface), + fab-state-layer-color: map.get($system, on-surface), + ), + typography: ( + fab-extended-label-text-font: map.get($system, label-small-font), + fab-extended-label-text-size: map.get($system, label-small-size), + fab-extended-label-text-tracking: map.get($system, label-small-tracking), + fab-extended-label-text-weight: map.get($system, label-small-weight) + ), + density: ( + fab-small-touch-target-display: if($density-scale < -1, none, block), + fab-touch-target-display: if($density-scale < -1, none, block), + ), ); } @@ -79,25 +91,3 @@ fab-state-layer-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); - @return ( - fab-extended-label-text-font: map.get($system, label-small-font), - fab-extended-label-text-size: map.get($system, label-small-size), - fab-extended-label-text-tracking: map.get($system, label-small-tracking), - fab-extended-label-text-weight: map.get($system, label-small-weight) - ); -} - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { - $system: m2-utils.get-system($theme); - $density-scale: theming.clamp-density(map.get($system, density-scale), -3); - - @return ( - fab-small-touch-target-display: if($density-scale < -1, none, block), - fab-touch-target-display: if($density-scale < -1, none, block), - ); -} diff --git a/src/material/button/_m2-icon-button.scss b/src/material/button/_m2-icon-button.scss index 10e1262e32d7..0e0465c6eb34 100644 --- a/src/material/button/_m2-icon-button.scss +++ b/src/material/button/_m2-icon-button.scss @@ -1,33 +1,41 @@ @use 'sass:map'; @use '../core/theming/theming'; -@use '../core/theming/inspection'; @use '../core/tokens/m2-utils'; @use '../core/tokens/m3-utils'; -// 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 ( - icon-button-icon-size: 24px, - icon-button-container-shape: 50%, - ); -} - -// 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); - $is-dark: inspection.get-theme-type($theme) == dark; + $density-scale: theming.clamp-density(map.get($system, density-scale), -3); @return ( - icon-button-disabled-icon-color: m3-utils.color-with-opacity(map.get($system, on-surface), 38%), - icon-button-disabled-state-layer-color: map.get($system, on-surface-variant), - icon-button-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), - icon-button-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), - icon-button-icon-color: inherit, - icon-button-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), - icon-button-ripple-color: m3-utils.color-with-opacity( - map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), - icon-button-state-layer-color: map.get($system, on-surface), + base: ( + icon-button-icon-size: 24px, + icon-button-container-shape: 50%, + ), + color: ( + icon-button-disabled-icon-color: + m3-utils.color-with-opacity(map.get($system, on-surface), 38%), + icon-button-disabled-state-layer-color: map.get($system, on-surface-variant), + icon-button-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), + icon-button-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), + icon-button-icon-color: inherit, + icon-button-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), + icon-button-ripple-color: m3-utils.color-with-opacity( + map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), + icon-button-state-layer-color: map.get($system, on-surface), + ), + typography: (), + density: ( + icon-button-touch-target-display: if($density-scale < -1, none, block), + icon-button-state-layer-size: map.get(( + 0: 48px, + -1: 44px, + -2: 40px, + -3: 36px, + -4: 32px, + -5: 28px, + ), $density-scale) + ), ); } @@ -43,32 +51,3 @@ map.get($system, primary), map.get($system, pressed-state-layer-opacity)), ); } - -// 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, $exclude: ()) { - $system: m2-utils.get-system($theme); - $density-scale: theming.clamp-density(map.get($system, density-scale), -3); - - $tokens: ( - icon-button-touch-target-display: if($density-scale < -1, none, block), - icon-button-state-layer-size: map.get(( - 0: 48px, - -1: 44px, - -2: 40px, - -3: 36px, - -4: 32px, - -5: 28px, - ), $density-scale) - ); - - @each $token in $exclude { - $tokens: map.remove($tokens, $token); - } - - @return $tokens; -} diff --git a/src/material/card/_card-theme.scss b/src/material/card/_card-theme.scss index 3213b5eeb7bc..2b3c594e1e32 100644 --- a/src/material/card/_card-theme.scss +++ b/src/material/card/_card-theme.scss @@ -6,7 +6,7 @@ @use './m3-card'; @mixin base($theme) { - $tokens: m2-card.get-unthemable-tokens(); + $tokens: map.get(m2-card.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-card.get-tokens($theme), base); } @@ -15,7 +15,7 @@ } @mixin color($theme) { - $tokens: m2-card.get-color-tokens($theme); + $tokens: map.get(m2-card.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-card.get-tokens($theme), color); } @@ -24,7 +24,7 @@ } @mixin typography($theme) { - $tokens: m2-card.get-typography-tokens($theme); + $tokens: map.get(m2-card.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-card.get-tokens($theme), typography); } @@ -33,7 +33,7 @@ } @mixin density($theme) { - $tokens: m2-card.get-density-tokens($theme); + $tokens: map.get(m2-card.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-card.get-tokens($theme), density); } diff --git a/src/material/card/_m2-card.scss b/src/material/card/_m2-card.scss index 028826975e88..d73e6b181720 100644 --- a/src/material/card/_m2-card.scss +++ b/src/material/card/_m2-card.scss @@ -2,51 +2,38 @@ @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 ( - card-elevated-container-shape: 4px, - card-outlined-container-shape: 4px, - card-filled-container-shape: 4px, - card-outlined-outline-width: 1px, - ); -} - -// 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 ( - card-elevated-container-color: map.get($system, surface), - card-elevated-container-elevation: elevation.get-box-shadow(1), - card-outlined-container-color: map.get($system, surface), - card-outlined-container-elevation: elevation.get-box-shadow(0), - card-outlined-outline-color: map.get($system, outline), - card-subtitle-text-color: map.get($system, on-surface-variant), - card-filled-container-color: map.get($system, surface), - card-filled-container-elevation: elevation.get-box-shadow(0) + base: ( + card-elevated-container-shape: 4px, + card-outlined-container-shape: 4px, + card-filled-container-shape: 4px, + card-outlined-outline-width: 1px, + ), + color: ( + card-elevated-container-color: map.get($system, surface), + card-elevated-container-elevation: elevation.get-box-shadow(1), + card-outlined-container-color: map.get($system, surface), + card-outlined-container-elevation: elevation.get-box-shadow(0), + card-outlined-outline-color: map.get($system, outline), + card-subtitle-text-color: map.get($system, on-surface-variant), + card-filled-container-color: map.get($system, surface), + card-filled-container-elevation: elevation.get-box-shadow(0) + ), + typography: ( + card-title-text-font: map.get($system, title-small-font), + card-title-text-line-height: map.get($system, title-small-line-height), + card-title-text-size: map.get($system, title-small-size), + card-title-text-tracking: map.get($system, title-small-tracking), + card-title-text-weight: map.get($system, title-small-weight), + card-subtitle-text-font: map.get($system, label-medium-font), + card-subtitle-text-line-height: map.get($system, label-medium-line-height), + card-subtitle-text-size: map.get($system, label-medium-size), + card-subtitle-text-tracking: map.get($system, label-medium-tracking), + card-subtitle-text-weight: map.get($system, label-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 ( - card-title-text-font: map.get($system, title-small-font), - card-title-text-line-height: map.get($system, title-small-line-height), - card-title-text-size: map.get($system, title-small-size), - card-title-text-tracking: map.get($system, title-small-tracking), - card-title-text-weight: map.get($system, title-small-weight), - card-subtitle-text-font: map.get($system, label-medium-font), - card-subtitle-text-line-height: map.get($system, label-medium-line-height), - card-subtitle-text-size: map.get($system, label-medium-size), - card-subtitle-text-tracking: map.get($system, label-medium-tracking), - card-subtitle-text-weight: map.get($system, label-medium-weight), - ); -} - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { - @return (); -} diff --git a/src/material/checkbox/_checkbox-theme.scss b/src/material/checkbox/_checkbox-theme.scss index fba588210515..f889041b1d86 100644 --- a/src/material/checkbox/_checkbox-theme.scss +++ b/src/material/checkbox/_checkbox-theme.scss @@ -9,7 +9,7 @@ /// for the mat-checkbox. /// @param {Map} $theme The theme to generate base styles for. @mixin base($theme) { - $tokens: m2-checkbox.get-unthemable-tokens($theme); + $tokens: map.get(m2-checkbox.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-checkbox.get-tokens($theme), base); } @@ -21,7 +21,7 @@ /// @param {Map} $theme The theme to generate color styles for. /// @param {String} $color-variant The color variant to use for the component @mixin color($theme, $color-variant: null) { - $tokens: m2-checkbox.get-color-tokens($theme, secondary); + $tokens: map.get(m2-checkbox.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-checkbox.get-tokens($theme, $color-variant), color); } @@ -31,14 +31,16 @@ @if inspection.get-theme-version($theme) != 1 { .mat-mdc-checkbox { &.mat-primary { - @include token-utils.values(m2-checkbox.get-color-tokens($theme, primary, - $exclude: (checkbox-disabled-label-color, checkbox-label-text-color)) + @include token-utils.values(m2-checkbox.private-get-color-palette-color-tokens( + $theme, primary, + $exclude: (checkbox-disabled-label-color, checkbox-label-text-color)) ); } &.mat-warn { - @include token-utils.values(m2-checkbox.get-color-tokens($theme, error, - $exclude: (checkbox-disabled-label-color, checkbox-label-text-color)) + @include token-utils.values(m2-checkbox.private-get-color-palette-color-tokens( + $theme, error, + $exclude: (checkbox-disabled-label-color, checkbox-label-text-color)) ); } } @@ -46,7 +48,7 @@ } @mixin typography($theme) { - $tokens: m2-checkbox.get-typography-tokens($theme); + $tokens: map.get(m2-checkbox.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-checkbox.get-tokens($theme), typography); } @@ -55,7 +57,7 @@ } @mixin density($theme) { - $tokens: m2-checkbox.get-density-tokens($theme); + $tokens: map.get(m2-checkbox.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-checkbox.get-tokens($theme), density); } diff --git a/src/material/checkbox/_m2-checkbox.scss b/src/material/checkbox/_m2-checkbox.scss index 5a67e551e9d7..92091e704141 100644 --- a/src/material/checkbox/_m2-checkbox.scss +++ b/src/material/checkbox/_m2-checkbox.scss @@ -2,29 +2,45 @@ @use '../core/tokens/m2-utils'; @use '../core/tokens/m3-utils'; @use '../core/theming/theming'; -@use '../core/theming/inspection'; -// 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($theme) { +@function get-tokens($theme) { $system: m2-utils.get-system($theme); + $density-scale: theming.clamp-density(map.get($system, density-scale), -3); @return ( - checkbox-disabled-selected-checkmark-color: map.get($system, surface), - checkbox-selected-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), - checkbox-selected-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), - checkbox-selected-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), - checkbox-unselected-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), - checkbox-unselected-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), - checkbox-unselected-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), + base: ( + checkbox-disabled-selected-checkmark-color: map.get($system, surface), + checkbox-selected-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), + checkbox-selected-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), + checkbox-selected-pressed-state-layer-opacity: map.get($system, pressed-state-layer-opacity), + checkbox-unselected-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), + checkbox-unselected-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), + checkbox-unselected-pressed-state-layer-opacity: + map.get($system, pressed-state-layer-opacity), + ), + color: private-get-color-palette-color-tokens($theme, secondary), + typography: ( + checkbox-label-text-font: map.get($system, body-medium-font), + checkbox-label-text-line-height: map.get($system, body-medium-line-height), + checkbox-label-text-size: map.get($system, body-medium-size), + checkbox-label-text-tracking: map.get($system, body-medium-tracking), + checkbox-label-text-weight: map.get($system, body-medium-weight) + ), + density: ( + checkbox-touch-target-display: if($density-scale < -1, none, block), + checkbox-state-layer-size: map.get(( + 0: 40px, + -1: 36px, + -2: 32px, + -3: 28px, + ), $density-scale) + ), ); } -// Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme, $color-variant, $exclude: ()) { +@function private-get-color-palette-color-tokens($theme, $color-variant, $exclude: ()) { $system: m2-utils.get-system($theme); $system: m3-utils.replace-colors-with-variant($system, secondary, $color-variant); - $is-dark: inspection.get-theme-type($theme) == dark; $disabled: m3-utils.color-with-opacity(map.get($system, on-surface), 38%); $tokens: ( @@ -54,31 +70,3 @@ @return $tokens; } - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - checkbox-label-text-font: map.get($system, body-medium-font), - checkbox-label-text-line-height: map.get($system, body-medium-line-height), - checkbox-label-text-size: map.get($system, body-medium-size), - checkbox-label-text-tracking: map.get($system, body-medium-tracking), - checkbox-label-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) { - $system: m2-utils.get-system($theme); - $density-scale: theming.clamp-density(map.get($system, density-scale), -3); - - @return ( - checkbox-touch-target-display: if($density-scale < -1, none, block), - checkbox-state-layer-size: map.get(( - 0: 40px, - -1: 36px, - -2: 32px, - -3: 28px, - ), $density-scale) - ); -} diff --git a/src/material/chips/_chips-theme.scss b/src/material/chips/_chips-theme.scss index 1dcf65bf11d6..5d9c821625e7 100644 --- a/src/material/chips/_chips-theme.scss +++ b/src/material/chips/_chips-theme.scss @@ -14,7 +14,7 @@ @include token-utils.values(map.get(m3-chip.get-tokens($theme), base)); } @else { .mat-mdc-standard-chip { - @include token-utils.values(m2-chip.get-unthemable-tokens($theme)); + @include token-utils.values(map.get(m2-chip.get-tokens($theme), base)); } } } @@ -28,20 +28,23 @@ map.get(m3-chip.get-tokens($theme, $color-variant), color)); } @else { .mat-mdc-standard-chip { - @include token-utils.values(m2-chip.get-color-tokens($theme)); + @include token-utils.values(map.get(m2-chip.get-tokens($theme), color)); &.mat-mdc-chip-selected, &.mat-mdc-chip-highlighted { &.mat-primary { - @include token-utils.values(m2-chip.get-color-tokens($theme, primary)); + @include token-utils.values( + m2-chip.private-get-color-palette-color-tokens($theme, primary)); } &.mat-accent { - @include token-utils.values(m2-chip.get-color-tokens($theme, secondary)); + @include token-utils.values( + m2-chip.private-get-color-palette-color-tokens($theme, secondary)); } &.mat-warn { - @include token-utils.values(m2-chip.get-color-tokens($theme, error)); + @include token-utils.values( + m2-chip.private-get-color-palette-color-tokens($theme, error)); } } } @@ -55,7 +58,7 @@ @include token-utils.values(map.get(m3-chip.get-tokens($theme), typography)); } @else { .mat-mdc-standard-chip { - @include token-utils.values(m2-chip.get-typography-tokens($theme)); + @include token-utils.values(map.get(m2-chip.get-tokens($theme), typography)); } } } @@ -67,7 +70,7 @@ @include token-utils.values(map.get(m3-chip.get-tokens($theme), density)); } @else { .mat-mdc-chip.mat-mdc-standard-chip { - @include token-utils.values(m2-chip.get-density-tokens($theme)); + @include token-utils.values(map.get(m2-chip.get-tokens($theme), density)); } } } diff --git a/src/material/chips/_m2-chip.scss b/src/material/chips/_m2-chip.scss index 7eaae5e49bb9..2263debd5fda 100644 --- a/src/material/chips/_m2-chip.scss +++ b/src/material/chips/_m2-chip.scss @@ -3,38 +3,53 @@ @use '../core/tokens/m2-utils'; @use '../core/tokens/m3-utils'; -// 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($theme) { +@function get-tokens($theme) { $system: m2-utils.get-system($theme); + $density-scale: theming.clamp-density(map.get($system, density-scale), -2); @return ( - chip-container-shape-radius: 16px, - chip-disabled-container-opacity: 0.4, - chip-disabled-outline-color: transparent, - chip-flat-selected-outline-width: 0, - chip-focus-outline-color: transparent, - chip-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), - chip-outline-color: transparent, - chip-outline-width: 0, - chip-selected-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), - chip-selected-trailing-action-state-layer-color: transparent, - chip-trailing-action-focus-opacity: 1, - chip-trailing-action-focus-state-layer-opacity: 0, - chip-trailing-action-hover-state-layer-opacity: 0, - chip-trailing-action-opacity: 0.54, - chip-trailing-action-state-layer-color: transparent, - chip-with-avatar-avatar-shape-radius: 14px, - chip-with-avatar-avatar-size: 28px, - chip-with-avatar-disabled-avatar-opacity: 1, - chip-with-icon-disabled-icon-opacity: 1, - chip-with-icon-icon-size: 18px, - chip-with-trailing-icon-disabled-trailing-icon-opacity: 1, + base: ( + chip-container-shape-radius: 16px, + chip-disabled-container-opacity: 0.4, + chip-disabled-outline-color: transparent, + chip-flat-selected-outline-width: 0, + chip-focus-outline-color: transparent, + chip-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), + chip-outline-color: transparent, + chip-outline-width: 0, + chip-selected-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), + chip-selected-trailing-action-state-layer-color: transparent, + chip-trailing-action-focus-opacity: 1, + chip-trailing-action-focus-state-layer-opacity: 0, + chip-trailing-action-hover-state-layer-opacity: 0, + chip-trailing-action-opacity: 0.54, + chip-trailing-action-state-layer-color: transparent, + chip-with-avatar-avatar-shape-radius: 14px, + chip-with-avatar-avatar-size: 28px, + chip-with-avatar-disabled-avatar-opacity: 1, + chip-with-icon-disabled-icon-opacity: 1, + chip-with-icon-icon-size: 18px, + chip-with-trailing-icon-disabled-trailing-icon-opacity: 1, + ), + color: private-get-color-palette-color-tokens($theme, null), + typography: ( + chip-label-text-font: map.get($system, body-medium-font), + chip-label-text-line-height: map.get($system, body-medium-line-height), + chip-label-text-size: map.get($system, body-medium-size), + chip-label-text-tracking: map.get($system, body-medium-tracking), + chip-label-text-weight: map.get($system, body-medium-weight) + ), + density: ( + chip-container-height: map.get(( + 0: 32px, + -1: 28px, + -2: 24px), $density-scale) + ), ); } // Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme, $color-variant: null) { +@function private-get-color-palette-color-tokens($theme, $color-variant: null) { $system: m2-utils.get-system($theme); $background: m3-utils.color-with-opacity(map.get($system, on-surface), 12%); $foreground: map.get($system, on-surface); @@ -68,33 +83,3 @@ chip-with-trailing-icon-trailing-icon-color: $foreground, ); } - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - chip-label-text-font: map.get($system, body-medium-font), - chip-label-text-line-height: map.get($system, body-medium-line-height), - chip-label-text-size: map.get($system, body-medium-size), - chip-label-text-tracking: map.get($system, body-medium-tracking), - chip-label-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) { - $system: m2-utils.get-system($theme); - $density-scale: theming.clamp-density(map.get($system, density-scale), -2); - - @return ( - // The height of the chip. - chip-container-height: map.get( - ( - 0: 32px, - -1: 28px, - -2: 24px, - ), - $density-scale - ) - ); -} diff --git a/src/material/core/_core-theme.scss b/src/material/core/_core-theme.scss index 82915a4d4410..89b27a7cb69a 100644 --- a/src/material/core/_core-theme.scss +++ b/src/material/core/_core-theme.scss @@ -14,7 +14,7 @@ @use 'sass:map'; @mixin base($theme) { - $tokens: m2-app.get-unthemable-tokens(); + $tokens: map.get(m2-app.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-app.get-tokens($theme), base); } @@ -28,7 +28,7 @@ } @mixin color($theme) { - $tokens: m2-app.get-color-tokens($theme); + $tokens: map.get(m2-app.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-app.get-tokens($theme), color); } @@ -42,7 +42,7 @@ } @mixin typography($theme) { - $tokens: m2-app.get-typography-tokens($theme); + $tokens: map.get(m2-app.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-app.get-tokens($theme), typography); } @@ -56,7 +56,7 @@ } @mixin density($theme) { - $tokens: m2-app.get-density-tokens($theme); + $tokens: map.get(m2-app.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-app.get-tokens($theme), density); } diff --git a/src/material/core/_m2-app.scss b/src/material/core/_m2-app.scss index cf781eb6fafb..ea21f00bee97 100644 --- a/src/material/core/_m2-app.scss +++ b/src/material/core/_m2-app.scss @@ -2,35 +2,23 @@ @use './style/elevation'; @use '../core/tokens/m2-utils'; -// 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 (); -} - -// 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); - $tokens: ( + $color-tokens: ( app-background-color: map.get($system, background), - app-text-color: map.get($system, on-surface), + app-text-color: map.get($system, on-surface) ); - @for $zValue from 0 through 24 { - $shadow: elevation.get-box-shadow($zValue, map.get($system, shadow)); - $tokens: map.set($tokens, 'app-elevation-shadow-level-#{$zValue}', $shadow); + $color-tokens: map.set($color-tokens, 'app-elevation-shadow-level-#{$zValue}', + elevation.get-box-shadow($zValue, map.get($system, shadow))); } - @return $tokens; -} - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - @return (); + @return ( + base: (), + color: $color-tokens, + typography: (), + density: (), + ); } -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { - @return (); -} diff --git a/src/material/core/option/_m2-optgroup.scss b/src/material/core/option/_m2-optgroup.scss index 8aa17918cfd7..f8caf91dd36c 100644 --- a/src/material/core/option/_m2-optgroup.scss +++ b/src/material/core/option/_m2-optgroup.scss @@ -1,33 +1,21 @@ @use '../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 (); -} - -// 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 ( - optgroup-label-text-color: map.get($system, on-surface), - ); -} -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); @return ( - optgroup-label-text-font: map.get($system, body-large-font), - optgroup-label-text-line-height: map.get($system, body-large-line-height), - optgroup-label-text-size: map.get($system, body-large-size), - optgroup-label-text-tracking: map.get($system, body-large-tracking), - optgroup-label-text-weight: map.get($system, body-large-weight) + base: (), + color: ( + optgroup-label-text-color: map.get($system, on-surface), + ), + typography: ( + optgroup-label-text-font: map.get($system, body-large-font), + optgroup-label-text-line-height: map.get($system, body-large-line-height), + optgroup-label-text-size: map.get($system, body-large-size), + optgroup-label-text-tracking: map.get($system, body-large-tracking), + optgroup-label-text-weight: map.get($system, body-large-weight) + ), + density: (), ); } - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { - @return (); -} diff --git a/src/material/core/option/_m2-option.scss b/src/material/core/option/_m2-option.scss index c790f0d849e7..11414eb6dd5b 100644 --- a/src/material/core/option/_m2-option.scss +++ b/src/material/core/option/_m2-option.scss @@ -1,17 +1,26 @@ -@use '../theming/inspection'; @use 'sass:map'; @use '../tokens/m2-utils'; @use '../tokens/m3-utils'; -// 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 (); +@function get-tokens($theme) { + $system: m2-utils.get-system($theme); + + @return ( + base: (), + color: private-get-color-palette-color-tokens($theme, primary), + typography: ( + option-label-text-font: map.get($system, body-large-font), + option-label-text-line-height: map.get($system, body-large-line-height), + option-label-text-size: map.get($system, body-large-size), + option-label-text-tracking: map.get($system, body-large-tracking), + option-label-text-weight: map.get($system, body-large-weight) + ), + density: (), + ); } // Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme, $color-variant) { - $is-dark: inspection.get-theme-type($theme) == dark; +@function private-get-color-palette-color-tokens($theme, $color-variant) { $system: m2-utils.get-system($theme); $system: m3-utils.replace-colors-with-variant($system, primary, $color-variant); @@ -27,19 +36,3 @@ ); } -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - option-label-text-font: map.get($system, body-large-font), - option-label-text-line-height: map.get($system, body-large-line-height), - option-label-text-size: map.get($system, body-large-size), - option-label-text-tracking: map.get($system, body-large-tracking), - option-label-text-weight: map.get($system, body-large-weight) - ); -} - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { - @return (); -} diff --git a/src/material/core/option/_optgroup-theme.scss b/src/material/core/option/_optgroup-theme.scss index 7e73385c1740..98c885f9790e 100644 --- a/src/material/core/option/_optgroup-theme.scss +++ b/src/material/core/option/_optgroup-theme.scss @@ -6,7 +6,7 @@ @use '../typography/typography'; @mixin base($theme) { - $tokens: m2-optgroup.get-unthemable-tokens(); + $tokens: map.get(m2-optgroup.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-optgroup.get-tokens($theme), base); } @@ -15,7 +15,7 @@ } @mixin color($theme) { - $tokens: m2-optgroup.get-color-tokens($theme); + $tokens: map.get(m2-optgroup.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-optgroup.get-tokens($theme), color); } @@ -24,7 +24,7 @@ } @mixin typography($theme) { - $tokens: m2-optgroup.get-typography-tokens($theme); + $tokens: map.get(m2-optgroup.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-optgroup.get-tokens($theme), typography); } @@ -33,7 +33,7 @@ } @mixin density($theme) { - $tokens: m2-optgroup.get-density-tokens($theme); + $tokens: map.get(m2-optgroup.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-optgroup.get-tokens($theme), density); } diff --git a/src/material/core/option/_option-theme.scss b/src/material/core/option/_option-theme.scss index 252e3e5cd080..064fa5bdf313 100644 --- a/src/material/core/option/_option-theme.scss +++ b/src/material/core/option/_option-theme.scss @@ -9,7 +9,7 @@ /// for the mat-option. /// @param {Map} $theme The theme to generate base styles for. @mixin base($theme) { - $tokens: m2-option.get-unthemable-tokens(); + $tokens: map.get(m2-option.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-option.get-tokens($theme), base); } @@ -21,7 +21,7 @@ /// @param {Map} $theme The theme to generate color styles for. /// @param {String} $color-variant The color variant to use for the component (M3 only) @mixin color($theme, $color-variant: null) { - $tokens: m2-option.get-color-tokens($theme, primary); + $tokens: map.get(m2-option.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-option.get-tokens($theme, $color-variant), color); } @@ -30,12 +30,12 @@ @if inspection.get-theme-version($theme) != 1 { .mat-accent { - $tokens: m2-option.get-color-tokens($theme, secondary); + $tokens: m2-option.private-get-color-palette-color-tokens($theme, secondary); @include token-utils.values($tokens); } .mat-warn { - $tokens: m2-option.get-color-tokens($theme, error); + $tokens: m2-option.private-get-color-palette-color-tokens($theme, error); @include token-utils.values($tokens); } } @@ -44,7 +44,7 @@ /// Outputs typography theme styles for the mat-option. /// @param {Map} $theme The theme to generate typography styles for. @mixin typography($theme) { - $tokens: m2-option.get-typography-tokens($theme); + $tokens: map.get(m2-option.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-option.get-tokens($theme), typography); } @@ -55,7 +55,7 @@ /// Outputs density theme styles for the mat-option. /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { - $tokens: m2-option.get-density-tokens($theme); + $tokens: map.get(m2-option.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-option.get-tokens($theme), density); } diff --git a/src/material/core/ripple/_m2-ripple.scss b/src/material/core/ripple/_m2-ripple.scss index 725868505317..61ea2aec4799 100644 --- a/src/material/core/ripple/_m2-ripple.scss +++ b/src/material/core/ripple/_m2-ripple.scss @@ -2,28 +2,16 @@ @use '../tokens/m2-utils'; @use '../tokens/m3-utils'; -// 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 (); -} - -// 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 ( - ripple-color: m3-utils.color-with-opacity( - map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), + base: (), + color: ( + ripple-color: m3-utils.color-with-opacity( + map.get($system, on-surface), map.get($system, pressed-state-layer-opacity)), + ), + 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 (); -} diff --git a/src/material/core/ripple/_ripple-theme.scss b/src/material/core/ripple/_ripple-theme.scss index a8f97700f71c..f69a7f0cc34f 100644 --- a/src/material/core/ripple/_ripple-theme.scss +++ b/src/material/core/ripple/_ripple-theme.scss @@ -5,7 +5,7 @@ @use '../theming/inspection'; @mixin base($theme) { - $tokens: m2-ripple.get-unthemable-tokens(); + $tokens: map.get(m2-ripple.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-ripple.get-tokens($theme), base); } @@ -14,7 +14,7 @@ } @mixin color($theme) { - $tokens: m2-ripple.get-color-tokens($theme); + $tokens: map.get(m2-ripple.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-ripple.get-tokens($theme), color); } @@ -23,7 +23,7 @@ } @mixin typography($theme) { - $tokens: m2-ripple.get-typography-tokens($theme); + $tokens: map.get(m2-ripple.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-ripple.get-tokens($theme), typography); } @@ -32,7 +32,7 @@ } @mixin density($theme) { - $tokens: m2-ripple.get-density-tokens($theme); + $tokens: map.get(m2-ripple.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-ripple.get-tokens($theme), density); } diff --git a/src/material/core/selection/pseudo-checkbox/_m2-pseudo-checkbox.scss b/src/material/core/selection/pseudo-checkbox/_m2-pseudo-checkbox.scss index 756c491cca22..8c35cfea31c6 100644 --- a/src/material/core/selection/pseudo-checkbox/_m2-pseudo-checkbox.scss +++ b/src/material/core/selection/pseudo-checkbox/_m2-pseudo-checkbox.scss @@ -1,17 +1,25 @@ @use '../../theming/inspection'; @use 'sass:map'; +@use 'sass:meta'; @use '../../tokens/m2-utils'; @use '../../tokens/m3-utils'; -// 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 (); +@function get-tokens($theme) { + @return ( + base: (), + color: private-get-color-palette-color-tokens($theme, secondary), + typography: (), + density: (), + ); } // Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme, $color-variant) { - $is-dark: inspection.get-theme-type($theme) == dark; +@function private-get-color-palette-color-tokens($theme, $color-variant) { + // TODO: Use system colors instead of checking theme type + $is-dark: false; + @if (meta.type-of($theme) == map and map.get($theme, color)) { + $is-dark: inspection.get-theme-type($theme) == dark; + } $disabled-color: if($is-dark, #686868, #b0b0b0); $system: m2-utils.get-system($theme); $system: m3-utils.replace-colors-with-variant($system, secondary, $color-variant); @@ -24,16 +32,6 @@ pseudo-checkbox-full-disabled-unselected-icon-color: $disabled-color, pseudo-checkbox-full-disabled-selected-icon-color: $disabled-color, pseudo-checkbox-minimal-selected-checkmark-color: map.get($system, secondary), - pseudo-checkbox-minimal-disabled-selected-checkmark-color: if($is-dark, #686868, #b0b0b0), + pseudo-checkbox-minimal-disabled-selected-checkmark-color: $disabled-color, ); } - -// 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 (); -} diff --git a/src/material/core/selection/pseudo-checkbox/_pseudo-checkbox-theme.scss b/src/material/core/selection/pseudo-checkbox/_pseudo-checkbox-theme.scss index b8ff362f4007..bbfff2857750 100644 --- a/src/material/core/selection/pseudo-checkbox/_pseudo-checkbox-theme.scss +++ b/src/material/core/selection/pseudo-checkbox/_pseudo-checkbox-theme.scss @@ -5,12 +5,12 @@ @use 'sass:map'; @mixin _palette-styles($theme, $palette-name) { - $tokens: m2-pseudo-checkbox.get-color-tokens($theme, $palette-name); + $tokens: map.get(m2-pseudo-checkbox.get-tokens($theme), color); @include token-utils.values($tokens); } @mixin base($theme) { - $tokens: m2-pseudo-checkbox.get-unthemable-tokens(); + $tokens: map.get(m2-pseudo-checkbox.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-pseudo-checkbox.get-tokens($theme), base); } @@ -28,7 +28,7 @@ /// @param {Map} $theme The theme to generate color styles for. /// @param {String} $color-variant The color variant to use for the component (M3 only) @mixin color($theme, $color-variant: null) { - $tokens: m2-pseudo-checkbox.get-color-tokens($theme, secondary); + $tokens: map.get(m2-pseudo-checkbox.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-pseudo-checkbox.get-tokens($theme, $color-variant), color); } @@ -42,24 +42,24 @@ // in order to allow for the color to be overwritten if the checkbox is inside a parent that // has `mat-accent` and is placed inside another parent that has `mat-primary`. .mat-primary { - $tokens: m2-pseudo-checkbox.get-color-tokens($theme, primary); + $tokens: m2-pseudo-checkbox.private-get-color-palette-color-tokens($theme, primary); @include token-utils.values($tokens); } .mat-accent { - $tokens: m2-pseudo-checkbox.get-color-tokens($theme, secondary); + $tokens: m2-pseudo-checkbox.private-get-color-palette-color-tokens($theme, secondary); @include token-utils.values($tokens); } .mat-warn { - $tokens: m2-pseudo-checkbox.get-color-tokens($theme, error); + $tokens: m2-pseudo-checkbox.private-get-color-palette-color-tokens($theme, error); @include token-utils.values($tokens); } } } @mixin typography($theme) { - $tokens: m2-pseudo-checkbox.get-typography-tokens($theme); + $tokens: map.get(m2-pseudo-checkbox.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-pseudo-checkbox.get-tokens($theme), typography); } @@ -68,7 +68,7 @@ } @mixin density($theme) { - $tokens: m2-pseudo-checkbox.get-density-tokens($theme); + $tokens: map.get(m2-pseudo-checkbox.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-pseudo-checkbox.get-tokens($theme), density); } diff --git a/src/material/datepicker/_datepicker-theme.scss b/src/material/datepicker/_datepicker-theme.scss index d2972be6bf59..d961841d85d6 100644 --- a/src/material/datepicker/_datepicker-theme.scss +++ b/src/material/datepicker/_datepicker-theme.scss @@ -11,7 +11,7 @@ /// for the mat-datepicker. /// @param {Map} $theme The theme to generate base styles for. @mixin base($theme) { - $tokens: m2-datepicker.get-unthemable-tokens(); + $tokens: map.get(m2-datepicker.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-datepicker.get-tokens($theme), base); } @@ -23,7 +23,7 @@ /// @param {Map} $theme The theme to generate color styles for. /// @param {String} $color-variant The color variant to use for the component (M3 only) @mixin color($theme, $color-variant: null) { - $tokens: m2-datepicker.get-color-tokens($theme, primary); + $tokens: map.get(m2-datepicker.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-datepicker.get-tokens($theme, $color-variant), color); } @@ -33,12 +33,12 @@ @if inspection.get-theme-version($theme) != 1 { .mat-datepicker-content, .mat-datepicker-toggle-active { &.mat-accent { - $tokens: m2-datepicker.get-color-tokens($theme, secondary); + $tokens: m2-datepicker.private-get-color-palette-color-tokens($theme, secondary); @include token-utils.values($tokens); } &.mat-warn { - $tokens: m2-datepicker.get-color-tokens($theme, error); + $tokens: m2-datepicker.private-get-color-palette-color-tokens($theme, error); @include token-utils.values($tokens); } } @@ -48,7 +48,7 @@ /// Outputs typography theme styles for the mat-datepicker. /// @param {Map} $theme The theme to generate typography styles for. @mixin typography($theme) { - $tokens: m2-datepicker.get-typography-tokens($theme); + $tokens: map.get(m2-datepicker.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-datepicker.get-tokens($theme), typography); } @@ -73,7 +73,7 @@ /// Outputs density theme styles for the mat-datepicker. /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { - $tokens: m2-datepicker.get-density-tokens($theme); + $tokens: map.get(m2-datepicker.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-datepicker.get-tokens($theme), density); } diff --git a/src/material/datepicker/_m2-datepicker.scss b/src/material/datepicker/_m2-datepicker.scss index cb078b110e86..595b38d9482f 100644 --- a/src/material/datepicker/_m2-datepicker.scss +++ b/src/material/datepicker/_m2-datepicker.scss @@ -4,19 +4,37 @@ @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() { +@function get-tokens($theme) { + $system: m2-utils.get-system($theme); + @return ( - datepicker-calendar-container-shape: 4px, - datepicker-calendar-container-touch-shape: 4px, - datepicker-calendar-container-elevation-shadow: elevation.get-box-shadow(4), - datepicker-calendar-container-touch-elevation-shadow: elevation.get-box-shadow(24), + base: ( + datepicker-calendar-container-shape: 4px, + datepicker-calendar-container-touch-shape: 4px, + datepicker-calendar-container-elevation-shadow: elevation.get-box-shadow(4), + datepicker-calendar-container-touch-elevation-shadow: elevation.get-box-shadow(24), + ), + color: private-get-color-palette-color-tokens($theme, primary), + typography: ( + // TODO(crisbeto): the typography tokens for other components set every typography dimension + // of an element (e.g. size, weight, line height, letter spacing). These tokens only set the + // values that were set in the previous theming API to reduce the amount of subtle screenshot + // differences. We should look into introducing the other tokens in a follow-up. + datepicker-calendar-text-font: map.get($system, body-large-font), + datepicker-calendar-text-size: 13px, + datepicker-calendar-body-label-text-size: map.get($system, label-small-size), + datepicker-calendar-body-label-text-weight: map.get($system, label-small-weight), + datepicker-calendar-period-button-text-size: map.get($system, label-small-size), + datepicker-calendar-period-button-text-weight: map.get($system, label-small-weight), + datepicker-calendar-header-text-size: 11px, + datepicker-calendar-header-text-weight: map.get($system, body-large-weight), + ), + density: (), ); } // Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme, $color-variant) { +@function private-get-color-palette-color-tokens($theme, $color-variant) { $system: m2-utils.get-system($theme); $system: m3-utils.replace-colors-with-variant($system, primary, $color-variant); $disabled: m3-utils.color-with-opacity(map.get($system, on-surface), 38%); @@ -61,28 +79,3 @@ datepicker-calendar-container-text-color: map.get($system, on-surface), ); } - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - // TODO(crisbeto): the typography tokens for other components set every typography dimension of - // an element (e.g. size, weight, line height, letter spacing). These tokens only set the values - // that were set in the previous theming API to reduce the amount of subtle screenshot - // differences. We should look into introducing the other tokens in a follow-up. - datepicker-calendar-text-font: map.get($system, body-large-font), - datepicker-calendar-text-size: 13px, - datepicker-calendar-body-label-text-size: map.get($system, label-small-size), - datepicker-calendar-body-label-text-weight: map.get($system, label-small-weight), - datepicker-calendar-period-button-text-size: map.get($system, label-small-size), - datepicker-calendar-period-button-text-weight: map.get($system, label-small-weight), - datepicker-calendar-header-text-size: 11px, - datepicker-calendar-header-text-weight: - map.get($system, body-large-weight), - ); -} - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { - @return (); -} diff --git a/src/material/dialog/_dialog-theme.scss b/src/material/dialog/_dialog-theme.scss index 9c6cbb9ed00a..2e0d8f88918f 100644 --- a/src/material/dialog/_dialog-theme.scss +++ b/src/material/dialog/_dialog-theme.scss @@ -6,7 +6,7 @@ @use '../core/typography/typography'; @mixin base($theme) { - $tokens: m2-dialog.get-unthemable-tokens(); + $tokens: map.get(m2-dialog.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-dialog.get-tokens($theme), base); } @@ -15,7 +15,7 @@ } @mixin color($theme) { - $tokens: m2-dialog.get-color-tokens($theme); + $tokens: map.get(m2-dialog.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-dialog.get-tokens($theme), color); } @@ -24,7 +24,7 @@ } @mixin typography($theme) { - $tokens: m2-dialog.get-typography-tokens($theme); + $tokens: map.get(m2-dialog.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-dialog.get-tokens($theme), typography); } @@ -33,7 +33,7 @@ } @mixin density($theme) { - $tokens: m2-dialog.get-density-tokens($theme); + $tokens: map.get(m2-dialog.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-dialog.get-tokens($theme), density); } diff --git a/src/material/dialog/_m2-dialog.scss b/src/material/dialog/_m2-dialog.scss index e5a8a8aacc5f..0aefeccbaefb 100644 --- a/src/material/dialog/_m2-dialog.scss +++ b/src/material/dialog/_m2-dialog.scss @@ -2,54 +2,42 @@ @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 ( - dialog-container-shape: 4px, - dialog-container-elevation-shadow: elevation.get-box-shadow(24), - dialog-container-max-width: 80vw, - dialog-container-small-max-width: 80vw, - dialog-container-min-width: 0, - dialog-actions-alignment: start, - dialog-actions-padding: 8px, - dialog-content-padding: 20px 24px, - dialog-with-actions-content-padding: 20px 24px, - - // Note: the CSS class is `title` while the M2 tokens call it `subhead`. - // M3 calls it `headline` which is what we're aligning with. - dialog-headline-padding: 0 24px 9px, - ); -} - -// 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 ( - dialog-container-color: map.get($system, surface), - dialog-subhead-color: map.get($system, on-surface), - dialog-supporting-text-color: map.get($system, on-surface-variant), - ); -} -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); @return ( - dialog-subhead-font: map.get($system, title-small-font), - dialog-subhead-line-height: map.get($system, title-small-line-height), - dialog-subhead-size: map.get($system, title-small-size), - dialog-subhead-weight: map.get($system, title-small-weight), - dialog-subhead-tracking: map.get($system, title-small-tracking), - dialog-supporting-text-font: map.get($system, body-large-font), - dialog-supporting-text-line-height: map.get($system, body-large-line-height), - dialog-supporting-text-size: map.get($system, body-large-size), - dialog-supporting-text-weight: map.get($system, body-large-weight), - dialog-supporting-text-tracking: map.get($system, body-large-tracking), - ); -} + base: ( + dialog-container-shape: 4px, + dialog-container-elevation-shadow: elevation.get-box-shadow(24), + dialog-container-max-width: 80vw, + dialog-container-small-max-width: 80vw, + dialog-container-min-width: 0, + dialog-actions-alignment: start, + dialog-actions-padding: 8px, + dialog-content-padding: 20px 24px, + dialog-with-actions-content-padding: 20px 24px, -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { - @return (); + // Note: the CSS class is `title` while the M2 tokens call it `subhead`. + // M3 calls it `headline` which is what we're aligning with. + dialog-headline-padding: 0 24px 9px, + ), + color: ( + dialog-container-color: map.get($system, surface), + dialog-subhead-color: map.get($system, on-surface), + dialog-supporting-text-color: map.get($system, on-surface-variant), + ), + typography: ( + dialog-subhead-font: map.get($system, title-small-font), + dialog-subhead-line-height: map.get($system, title-small-line-height), + dialog-subhead-size: map.get($system, title-small-size), + dialog-subhead-weight: map.get($system, title-small-weight), + dialog-subhead-tracking: map.get($system, title-small-tracking), + dialog-supporting-text-font: map.get($system, body-large-font), + dialog-supporting-text-line-height: map.get($system, body-large-line-height), + dialog-supporting-text-size: map.get($system, body-large-size), + dialog-supporting-text-weight: map.get($system, body-large-weight), + dialog-supporting-text-tracking: map.get($system, body-large-tracking), + ), + density: (), + ); } diff --git a/src/material/divider/_divider-theme.scss b/src/material/divider/_divider-theme.scss index 8583c131428e..3aac3203cf31 100644 --- a/src/material/divider/_divider-theme.scss +++ b/src/material/divider/_divider-theme.scss @@ -5,7 +5,7 @@ @use './m3-divider'; @mixin base($theme) { - $tokens: m2-divider.get-unthemable-tokens(); + $tokens: map.get(m2-divider.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-divider.get-tokens($theme), base); } @@ -14,7 +14,7 @@ } @mixin color($theme) { - $tokens: m2-divider.get-color-tokens($theme); + $tokens: map.get(m2-divider.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-divider.get-tokens($theme), color); } @@ -23,7 +23,7 @@ } @mixin typography($theme) { - $tokens: m2-divider.get-typography-tokens($theme); + $tokens: map.get(m2-divider.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-divider.get-tokens($theme), typography); } @@ -32,7 +32,7 @@ } @mixin density($theme) { - $tokens: m2-divider.get-density-tokens($theme); + $tokens: map.get(m2-divider.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-divider.get-tokens($theme), density); } diff --git a/src/material/divider/_m2-divider.scss b/src/material/divider/_m2-divider.scss index 5f8dabad9cbe..045fcba92606 100644 --- a/src/material/divider/_m2-divider.scss +++ b/src/material/divider/_m2-divider.scss @@ -1,28 +1,17 @@ @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 ( - divider-width: 1px - ); -} - -// 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 ( - divider-color: map.get($system, outline) + base: ( + divider-width: 1px + ), + color: ( + divider-color: map.get($system, outline) + ), + 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 (); -} diff --git a/src/material/expansion/_expansion-theme.scss b/src/material/expansion/_expansion-theme.scss index 0a435e6142e7..086e8789bde3 100644 --- a/src/material/expansion/_expansion-theme.scss +++ b/src/material/expansion/_expansion-theme.scss @@ -6,7 +6,7 @@ @use './m3-expansion'; @mixin base($theme) { - $tokens: m2-expansion.get-unthemable-tokens(); + $tokens: map.get(m2-expansion.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-expansion.get-tokens($theme), base); } @@ -15,7 +15,7 @@ } @mixin color($theme) { - $tokens: m2-expansion.get-color-tokens($theme); + $tokens: map.get(m2-expansion.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-expansion.get-tokens($theme), color); } @@ -24,7 +24,7 @@ } @mixin typography($theme) { - $tokens: m2-expansion.get-typography-tokens($theme); + $tokens: map.get(m2-expansion.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-expansion.get-tokens($theme), typography); } @@ -33,7 +33,7 @@ } @mixin density($theme) { - $tokens: m2-expansion.get-density-tokens($theme); + $tokens: map.get(m2-expansion.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-expansion.get-tokens($theme), density); } diff --git a/src/material/expansion/_m2-expansion.scss b/src/material/expansion/_m2-expansion.scss index feb5427f5ce5..4224d7ddc353 100644 --- a/src/material/expansion/_m2-expansion.scss +++ b/src/material/expansion/_m2-expansion.scss @@ -4,77 +4,61 @@ @use '../core/tokens/m3-utils'; @use '../core/style/elevation'; -// 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 ( - expansion-container-shape: 4px, - expansion-container-elevation-shadow: elevation.get-box-shadow(2), - expansion-legacy-header-indicator-display: inline-block, - expansion-header-indicator-display: none, - ); -} - -// 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 ( - expansion-container-background-color: map.get($system, surface), - expansion-container-text-color: map.get($system, on-surface), - expansion-actions-divider-color: map.get($system, outline), - expansion-header-hover-state-layer-color: m3-utils.color-with-opacity( - map.get($system, on-surface), map.get($system, hover-state-layer-opacity)), - expansion-header-focus-state-layer-color: m3-utils.color-with-opacity( - map.get($system, on-surface), map.get($system, focus-state-layer-opacity)), - expansion-header-disabled-state-text-color: - m3-utils.color-with-opacity(map.get($system, on-surface), 38%), - expansion-header-text-color: map.get($system, on-surface), - expansion-header-description-color: map.get($system, on-surface-variant), - expansion-header-indicator-color: map.get($system, on-surface-variant), - ); -} + $density-scale: theming.clamp-density(map.get($system, density-scale), -3); -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); @return ( - expansion-header-text-font: map.get($system, label-medium-font), - expansion-header-text-size: map.get($system, label-medium-size), - expansion-header-text-weight: map.get($system, label-medium-weight), + base: ( + expansion-container-shape: 4px, + expansion-container-elevation-shadow: elevation.get-box-shadow(2), + expansion-legacy-header-indicator-display: inline-block, + expansion-header-indicator-display: none, + ), + color: ( + expansion-container-background-color: map.get($system, surface), + expansion-container-text-color: map.get($system, on-surface), + expansion-actions-divider-color: map.get($system, outline), + expansion-header-hover-state-layer-color: m3-utils.color-with-opacity( + map.get($system, on-surface), map.get($system, hover-state-layer-opacity)), + expansion-header-focus-state-layer-color: m3-utils.color-with-opacity( + map.get($system, on-surface), map.get($system, focus-state-layer-opacity)), + expansion-header-disabled-state-text-color: + m3-utils.color-with-opacity(map.get($system, on-surface), 38%), + expansion-header-text-color: map.get($system, on-surface), + expansion-header-description-color: map.get($system, on-surface-variant), + expansion-header-indicator-color: map.get($system, on-surface-variant), + ), + typography: ( + expansion-header-text-font: map.get($system, label-medium-font), + expansion-header-text-size: map.get($system, label-medium-size), + expansion-header-text-weight: map.get($system, label-medium-weight), - // TODO(crisbeto): these two properties weren't set at all before the introduction of tokens, - // but it's inconsistent not to provide them since the container sets all of them. Eventually - // we should change the values to use come from `subtitle-2`. - expansion-header-text-line-height: inherit, - expansion-header-text-tracking: inherit, + // TODO(crisbeto): these two properties weren't set at all before the introduction of tokens, + // but it's inconsistent not to provide them since the container sets all of them. Eventually + // we should change the values to use come from `subtitle-2`. + expansion-header-text-line-height: inherit, + expansion-header-text-tracking: inherit, - expansion-container-text-font: map.get($system, body-medium-font), - expansion-container-text-line-height: map.get($system, body-medium-line-height), - expansion-container-text-size: map.get($system, body-medium-size), - expansion-container-text-tracking: map.get($system, body-medium-tracking), - expansion-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) { - $system: m2-utils.get-system($theme); - $density-scale: theming.clamp-density(map.get($system, density-scale), -3); - $collapsed-scale: ( - 0: 48px, - -1: 44px, - -2: 40px, - -3: 36px, - ); - $expanded-scale: ( - 0: 64px, - -1: 60px, - -2: 56px, - -3: 48px, - ); - - @return ( - expansion-header-collapsed-state-height: map.get($collapsed-scale, $density-scale), - expansion-header-expanded-state-height: map.get($expanded-scale, $density-scale), + expansion-container-text-font: map.get($system, body-medium-font), + expansion-container-text-line-height: map.get($system, body-medium-line-height), + expansion-container-text-size: map.get($system, body-medium-size), + expansion-container-text-tracking: map.get($system, body-medium-tracking), + expansion-container-text-weight: map.get($system, body-medium-weight), + ), + density: ( + expansion-header-collapsed-state-height: map.get(( + 0: 48px, + -1: 44px, + -2: 40px, + -3: 36px, + ), $density-scale), + expansion-header-expanded-state-height: map.get(( + 0: 64px, + -1: 60px, + -2: 56px, + -3: 48px, + ), $density-scale), + ), ); } diff --git a/src/material/form-field/_form-field-theme.scss b/src/material/form-field/_form-field-theme.scss index 9a757e594f71..fc272690e6f4 100644 --- a/src/material/form-field/_form-field-theme.scss +++ b/src/material/form-field/_form-field-theme.scss @@ -6,7 +6,7 @@ @use 'sass:map'; @mixin base($theme) { - $tokens: m2-form-field.get-unthemable-tokens(); + $tokens: map.get(m2-form-field.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-form-field.get-tokens($theme), base); } @@ -18,7 +18,7 @@ /// @param {Map} $theme The theme to generate color styles for. /// @param {String} $color-variant The color variant to use for the component (M3 only) @mixin color($theme, $color-variant: null) { - $tokens: m2-form-field.get-color-tokens($theme); + $tokens: map.get(m2-form-field.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-form-field.get-tokens($theme, $color-variant), color); } @@ -39,7 +39,7 @@ } @mixin typography($theme) { - $tokens: m2-form-field.get-typography-tokens($theme); + $tokens: map.get(m2-form-field.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-form-field.get-tokens($theme), typography); } @@ -48,7 +48,7 @@ } @mixin density($theme) { - $tokens: m2-form-field.get-density-tokens($theme); + $tokens: map.get(m2-form-field.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-form-field.get-tokens($theme), density); } diff --git a/src/material/form-field/_m2-form-field.scss b/src/material/form-field/_m2-form-field.scss index 0afb982dc228..1a3731bd8aee 100644 --- a/src/material/form-field/_m2-form-field.scss +++ b/src/material/form-field/_m2-form-field.scss @@ -8,107 +8,133 @@ @use 'sass:math'; @use 'sass:meta'; -// 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 ( - form-field-filled-active-indicator-height: 1px, - form-field-filled-focus-active-indicator-height: 2px, - form-field-filled-container-shape: 4px, - form-field-outlined-outline-width: 1px, - form-field-outlined-focus-outline-width: 2px, - form-field-outlined-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); - - $is-dark: inspection.get-theme-type($theme) == dark; - $surface: map.get($system, surface); - $color-tokens: private-get-color-palette-color-tokens($theme, primary); $disabled: m3-utils.color-with-opacity(map.get($system, on-surface), 38%); - @return map.merge($color-tokens, ( - // MDC has a token for the enabled placeholder, but not for the disabled one. - form-field-disabled-input-text-placeholder-color: $disabled, - form-field-state-layer-color: map.get($system, on-surface), - form-field-error-text-color: map.get($system, error), - - // On dark themes we set the native `select` color to some shade of white, - // however the color propagates to all of the `option` elements, which are - // always on a white background inside the dropdown, causing them to blend in. - // Since we can't change background of the dropdown, we need to explicitly - // reset the color of the options to something dark. - form-field-select-option-text-color: if($is-dark, m2-palette.$dark-primary-text, inherit), - // Note the spelling of the `GrayText` here which is a system color. See: - // https://developer.mozilla.org/en-US/docs/Web/CSS/system-color - form-field-select-disabled-option-text-color: - if($is-dark, m2-palette.$dark-disabled-text, GrayText), - - // These tokens are necessary for M3. MDC has them built in already, but: - // 1. They are too specific, breaking a lot of internal clients. - // 2. The larger selectors result in a larger bundle. - // Note: MDC has tokens for all the various states of the icons. Some of them are ommitted, - // because they resolve to the same value (e.g. focus and base states for the leading icon - // are the same). - form-field-leading-icon-color: unset, - form-field-disabled-leading-icon-color: unset, - form-field-trailing-icon-color: unset, - form-field-disabled-trailing-icon-color: unset, - form-field-error-focus-trailing-icon-color: unset, - form-field-error-hover-trailing-icon-color: unset, - form-field-error-trailing-icon-color: unset, - form-field-enabled-select-arrow-color: map.get($system, on-surface-variant), - form-field-disabled-select-arrow-color: $disabled, - form-field-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), - form-field-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), - form-field-filled-container-color: map.get($system, surface-variant), - form-field-filled-disabled-container-color: - m3-utils.color-with-opacity(map.get($system, on-surface), 4%), - form-field-filled-label-text-color: map.get($system, on-surface-variant), - form-field-filled-hover-label-text-color: map.get($system, on-surface-variant), - form-field-filled-disabled-label-text-color: $disabled, - form-field-filled-input-text-color: map.get($system, on-surface), - form-field-filled-disabled-input-text-color: $disabled, - form-field-filled-input-text-placeholder-color: map.get($system, on-surface-variant), - form-field-filled-error-hover-label-text-color: map.get($system, error), - form-field-filled-error-focus-label-text-color: map.get($system, error), - form-field-filled-error-label-text-color: map.get($system, error), - form-field-filled-error-caret-color: map.get($system, error), - form-field-filled-active-indicator-color: map.get($system, on-surface-variant), - form-field-filled-disabled-active-indicator-color: - m3-utils.color-with-opacity(map.get($system, on-surface), 12%), - form-field-filled-hover-active-indicator-color: map.get($system, on-surface), - form-field-filled-error-active-indicator-color: map.get($system, error), - form-field-filled-error-focus-active-indicator-color: map.get($system, error), - form-field-filled-error-hover-active-indicator-color: map.get($system, error), - form-field-outlined-label-text-color: map.get($system, on-surface-variant), - form-field-outlined-hover-label-text-color: map.get($system, on-surface), - form-field-outlined-disabled-label-text-color: $disabled, - form-field-outlined-input-text-color: map.get($system, on-surface), - form-field-outlined-disabled-input-text-color: $disabled, - form-field-outlined-input-text-placeholder-color: map.get($system, on-surface-variant), - form-field-outlined-error-caret-color: map.get($system, error), - form-field-outlined-error-focus-label-text-color: map.get($system, error), - form-field-outlined-error-label-text-color: map.get($system, error), - form-field-outlined-error-hover-label-text-color: map.get($system, error), - form-field-outlined-outline-color: map.get($system, outline-variant), - form-field-outlined-disabled-outline-color: - m3-utils.color-with-opacity(map.get($system, on-surface), 12%), - form-field-outlined-hover-outline-color: map.get($system, on-surface), - form-field-outlined-error-focus-outline-color: map.get($system, error), - form-field-outlined-error-hover-outline-color: map.get($system, error), - form-field-outlined-error-outline-color: map.get($system, error), - )); -} - -@function _variable-safe-mix($first-color, $second-color, $amount) { - @if (meta.type-of($first-color) == color and meta.type-of($second-color) == color) { - @return color.mix($first-color, $second-color, $amount); + // TODO: Use system colors instead of checking theme type + $is-dark: false; + @if (meta.type-of($theme) == map and map.get($theme, color)) { + $is-dark: inspection.get-theme-type($theme) == dark; } - @return $first-color; + + @return ( + base: ( + form-field-filled-active-indicator-height: 1px, + form-field-filled-focus-active-indicator-height: 2px, + form-field-filled-container-shape: 4px, + form-field-outlined-outline-width: 1px, + form-field-outlined-focus-outline-width: 2px, + form-field-outlined-container-shape: 4px, + ), + color: map.merge(private-get-color-palette-color-tokens($theme, primary), ( + // MDC has a token for the enabled placeholder, but not for the disabled one. + form-field-disabled-input-text-placeholder-color: $disabled, + form-field-state-layer-color: map.get($system, on-surface), + form-field-error-text-color: map.get($system, error), + + // On dark themes we set the native `select` color to some shade of white, + // however the color propagates to all of the `option` elements, which are + // always on a white background inside the dropdown, causing them to blend in. + // Since we can't change background of the dropdown, we need to explicitly + // reset the color of the options to something dark. + form-field-select-option-text-color: if($is-dark, m2-palette.$dark-primary-text, inherit), + // Note the spelling of the `GrayText` here which is a system color. See: + // https://developer.mozilla.org/en-US/docs/Web/CSS/system-color + form-field-select-disabled-option-text-color: + if($is-dark, m2-palette.$dark-disabled-text, GrayText), + + // These tokens are necessary for M3. MDC has them built in already, but: + // 1. They are too specific, breaking a lot of internal clients. + // 2. The larger selectors result in a larger bundle. + // Note: MDC has tokens for all the various states of the icons. Some of them are ommitted, + // because they resolve to the same value (e.g. focus and base states for the leading icon + // are the same). + form-field-leading-icon-color: unset, + form-field-disabled-leading-icon-color: unset, + form-field-trailing-icon-color: unset, + form-field-disabled-trailing-icon-color: unset, + form-field-error-focus-trailing-icon-color: unset, + form-field-error-hover-trailing-icon-color: unset, + form-field-error-trailing-icon-color: unset, + form-field-enabled-select-arrow-color: map.get($system, on-surface-variant), + form-field-disabled-select-arrow-color: $disabled, + form-field-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), + form-field-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), + form-field-filled-container-color: map.get($system, surface-variant), + form-field-filled-disabled-container-color: + m3-utils.color-with-opacity(map.get($system, on-surface), 4%), + form-field-filled-label-text-color: map.get($system, on-surface-variant), + form-field-filled-hover-label-text-color: map.get($system, on-surface-variant), + form-field-filled-disabled-label-text-color: $disabled, + form-field-filled-input-text-color: map.get($system, on-surface), + form-field-filled-disabled-input-text-color: $disabled, + form-field-filled-input-text-placeholder-color: map.get($system, on-surface-variant), + form-field-filled-error-hover-label-text-color: map.get($system, error), + form-field-filled-error-focus-label-text-color: map.get($system, error), + form-field-filled-error-label-text-color: map.get($system, error), + form-field-filled-error-caret-color: map.get($system, error), + form-field-filled-active-indicator-color: map.get($system, on-surface-variant), + form-field-filled-disabled-active-indicator-color: + m3-utils.color-with-opacity(map.get($system, on-surface), 12%), + form-field-filled-hover-active-indicator-color: map.get($system, on-surface), + form-field-filled-error-active-indicator-color: map.get($system, error), + form-field-filled-error-focus-active-indicator-color: map.get($system, error), + form-field-filled-error-hover-active-indicator-color: map.get($system, error), + form-field-outlined-label-text-color: map.get($system, on-surface-variant), + form-field-outlined-hover-label-text-color: map.get($system, on-surface), + form-field-outlined-disabled-label-text-color: $disabled, + form-field-outlined-input-text-color: map.get($system, on-surface), + form-field-outlined-disabled-input-text-color: $disabled, + form-field-outlined-input-text-placeholder-color: map.get($system, on-surface-variant), + form-field-outlined-error-caret-color: map.get($system, error), + form-field-outlined-error-focus-label-text-color: map.get($system, error), + form-field-outlined-error-label-text-color: map.get($system, error), + form-field-outlined-error-hover-label-text-color: map.get($system, error), + form-field-outlined-outline-color: map.get($system, outline-variant), + form-field-outlined-disabled-outline-color: + m3-utils.color-with-opacity(map.get($system, on-surface), 12%), + form-field-outlined-hover-outline-color: map.get($system, on-surface), + form-field-outlined-error-focus-outline-color: map.get($system, error), + form-field-outlined-error-hover-outline-color: map.get($system, error), + form-field-outlined-error-outline-color: map.get($system, error), + )), + typography: ( + // MDC uses `subtitle1` for the input value, placeholder and floating label. The spec + // shows `body1` for text fields though, so we manually override the typography. + // Note: Form controls inherit the typography from the parent form field. + form-field-container-text-font: map.get($system, body-large-font), + form-field-container-text-line-height: map.get($system, body-large-line-height), + form-field-container-text-size: map.get($system, body-large-size), + form-field-container-text-tracking: map.get($system, body-large-tracking), + form-field-container-text-weight: map.get($system, body-large-weight), + + // In container styles, we updated the floating label to use the `body-1` typography level. + // The MDC notched outline overrides this accidentally (only when the label floats) to a + // `rem`-based value. This results in different label widths when floated/docked and then + // breaks the notch width as it has been measured in the docked state (where `body-1` is + // applied). We try to unset these styles set by the `mdc-notched-outline`: + // https://github.com/material-components/material-components-web/blob/master/packages/mdc-notched-outline/_mixins.scss#L272-L292. + // This is why we can't use their `label-text-populated-size` token and we have to declare + // our own version of it. + form-field-outlined-label-text-populated-size: map.get($system, body-large-size), + + form-field-subscript-text-font: map.get($system, body-small-font), + form-field-subscript-text-line-height: map.get($system, body-small-line-height), + form-field-subscript-text-size: map.get($system, body-small-size), + form-field-subscript-text-tracking: map.get($system, body-small-tracking), + form-field-subscript-text-weight: map.get($system, body-small-weight), + form-field-filled-label-text-font: map.get($system, body-large-font), + form-field-filled-label-text-size: map.get($system, body-large-size), + form-field-filled-label-text-tracking: map.get($system, body-large-tracking), + form-field-filled-label-text-weight: map.get($system, body-large-weight), + form-field-outlined-label-text-font: map.get($system, body-large-font), + form-field-outlined-label-text-size: map.get($system, body-large-size), + form-field-outlined-label-text-tracking: map.get($system, body-large-tracking), + form-field-outlined-label-text-weight: map.get($system, body-large-weight), + ), + density: get-density-tokens($theme), + ); } // Generates the mapping for the properties that change based on the form field color. @@ -130,46 +156,6 @@ ); } -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - // MDC uses `subtitle1` for the input value, placeholder and floating label. The spec - // shows `body1` for text fields though, so we manually override the typography. - // Note: Form controls inherit the typography from the parent form field. - form-field-container-text-font: map.get($system, body-large-font), - form-field-container-text-line-height: map.get($system, body-large-line-height), - form-field-container-text-size: map.get($system, body-large-size), - form-field-container-text-tracking: map.get($system, body-large-tracking), - form-field-container-text-weight: map.get($system, body-large-weight), - - // In the container styles, we updated the floating label to use the `body-1` typography level. - // The MDC notched outline overrides this accidentally (only when the label floats) to a - // `rem`-based value. This results in different label widths when floated/docked and ultimately - // breaks the notch width as it has been measured in the docked state (where `body-1` is - // applied). We try to unset these styles set by the `mdc-notched-outline`: - // https://github.com/material-components/material-components-web/blob/master/packages/mdc-notched-outline/_mixins.scss#L272-L292. - // This is why we can't use their `label-text-populated-size` token and we have to declare - // our own version of it. - form-field-outlined-label-text-populated-size: - map.get($system, body-large-size), - - form-field-subscript-text-font: map.get($system, body-small-font), - form-field-subscript-text-line-height: map.get($system, body-small-line-height), - form-field-subscript-text-size: map.get($system, body-small-size), - form-field-subscript-text-tracking: map.get($system, body-small-tracking), - form-field-subscript-text-weight: map.get($system, body-small-weight), - form-field-filled-label-text-font: map.get($system, body-large-font), - form-field-filled-label-text-size: map.get($system, body-large-size), - form-field-filled-label-text-tracking: map.get($system, body-large-tracking), - form-field-filled-label-text-weight: map.get($system, body-large-weight), - form-field-outlined-label-text-font: map.get($system, body-large-font), - form-field-outlined-label-text-size: map.get($system, body-large-size), - form-field-outlined-label-text-tracking: map.get($system, body-large-tracking), - form-field-outlined-label-text-weight: map.get($system, body-large-weight), - ); -} - // Tokens that can be configured through Angular Material's density theming API. @function get-density-tokens($theme) { $system: m2-utils.get-system($theme); diff --git a/src/material/grid-list/_grid-list-theme.scss b/src/material/grid-list/_grid-list-theme.scss index 930d84ba2aab..4f1fb0e90a5c 100644 --- a/src/material/grid-list/_grid-list-theme.scss +++ b/src/material/grid-list/_grid-list-theme.scss @@ -6,7 +6,7 @@ @use '../core/tokens/token-utils'; @mixin base($theme) { - $tokens: m2-grid-list.get-unthemable-tokens(); + $tokens: map.get(m2-grid-list.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-grid-list.get-tokens($theme), base); } @@ -15,7 +15,7 @@ } @mixin color($theme) { - $tokens: m2-grid-list.get-color-tokens($theme); + $tokens: map.get(m2-grid-list.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-grid-list.get-tokens($theme), color); } @@ -24,7 +24,7 @@ } @mixin typography($theme) { - $tokens: m2-grid-list.get-typography-tokens($theme); + $tokens: map.get(m2-grid-list.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-grid-list.get-tokens($theme), typography); } @@ -33,7 +33,7 @@ } @mixin density($theme) { - $tokens: m2-grid-list.get-density-tokens($theme); + $tokens: map.get(m2-grid-list.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-grid-list.get-tokens($theme), density); } diff --git a/src/material/grid-list/_m2-grid-list.scss b/src/material/grid-list/_m2-grid-list.scss index ca0a737c1e4c..02206ec0a245 100644 --- a/src/material/grid-list/_m2-grid-list.scss +++ b/src/material/grid-list/_m2-grid-list.scss @@ -1,32 +1,21 @@ @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 (); -} - -// Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme) { - @return (); -} - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { +@function get-tokens($theme) { $system: m2-utils.get-system($theme); + @return ( - // TODO(crisbeto): other components have tokens for all typography dimensions. - // Here we only set the font size to maintain the same appearance as the pre-tokens - // theming API. Consider adding more tokens for letter spacing, font weight etc. - grid-list-tile-header-primary-text-size: map.get($system, body-medium-size), - grid-list-tile-header-secondary-text-size: map.get($system, body-small-size), - grid-list-tile-footer-primary-text-size: map.get($system, body-medium-size), - grid-list-tile-footer-secondary-text-size: map.get($system, body-small-size), + base: (), + color: (), + typography: ( + // TODO(crisbeto): other components have tokens for all typography dimensions. + // Here we only set the font size to maintain the same appearance as the pre-tokens + // theming API. Consider adding more tokens for letter spacing, font weight etc. + grid-list-tile-header-primary-text-size: map.get($system, body-medium-size), + grid-list-tile-header-secondary-text-size: map.get($system, body-small-size), + grid-list-tile-footer-primary-text-size: map.get($system, body-medium-size), + grid-list-tile-footer-secondary-text-size: map.get($system, body-small-size), + ), + density: (), ); } - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { - @return (); -} diff --git a/src/material/icon/_icon-theme.scss b/src/material/icon/_icon-theme.scss index 89a101d9b585..c0d08b503a39 100644 --- a/src/material/icon/_icon-theme.scss +++ b/src/material/icon/_icon-theme.scss @@ -5,7 +5,7 @@ @use 'sass:map'; @mixin base($theme) { - $tokens: m2-icon.get-unthemable-tokens(); + $tokens: map.get(m2-icon.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-icon.get-tokens($theme), base); } @@ -17,7 +17,7 @@ /// @param {Map} $theme The theme to generate color styles for. /// @param {String} $color-variant The color variant to use for the component (M3 only) @mixin color($theme, $color-variant: null) { - $tokens: m2-icon.get-color-tokens($theme); + $tokens: map.get(m2-icon.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-icon.get-tokens($theme, $color-variant), color); } @@ -50,7 +50,7 @@ /// Outputs typography theme styles for the mat-icon. /// @param {Map} $theme The theme to generate typography styles for. @mixin typography($theme) { - $tokens: m2-icon.get-typography-tokens($theme); + $tokens: map.get(m2-icon.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-icon.get-tokens($theme), typography); } @@ -61,7 +61,7 @@ /// Outputs density theme styles for the mat-icon. /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { - $tokens: m2-icon.get-density-tokens($theme); + $tokens: map.get(m2-icon.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-icon.get-tokens($theme), density); } diff --git a/src/material/icon/_m2-icon.scss b/src/material/icon/_m2-icon.scss index 4732a4b07a7e..f381e03e0c85 100644 --- a/src/material/icon/_m2-icon.scss +++ b/src/material/icon/_m2-icon.scss @@ -1,24 +1,10 @@ - -// 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 (); -} - -// Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme) { - // Default the icon to `inherit` so it matches the text around it. - @return private-get-icon-color-tokens(inherit); -} - -// 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 (); +@function get-tokens($theme) { + @return ( + base: (), + color: private-get-icon-color-tokens(inherit), + typography: (), + density: (), + ); } // Mixin used to set a specific color on an icon. diff --git a/src/material/list/_list-theme.scss b/src/material/list/_list-theme.scss index 63fcc239faed..8816f45fbb11 100644 --- a/src/material/list/_list-theme.scss +++ b/src/material/list/_list-theme.scss @@ -11,7 +11,7 @@ @use '../core/theming/theming'; @mixin base($theme) { - $tokens: m2-list.get-unthemable-tokens(); + $tokens: map.get(m2-list.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-list.get-tokens($theme), base); } @@ -20,7 +20,7 @@ } @mixin color($theme) { - $tokens: m2-list.get-color-tokens($theme); + $tokens: map.get(m2-list.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-list.get-tokens($theme), color); } @@ -30,14 +30,14 @@ @if inspection.get-theme-version($theme) != 1 { .mdc-list-item__start, .mdc-list-item__end { - $tokens: m2-radio.get-color-tokens($theme, primary); + $tokens: m2-radio.private-get-color-palette-color-tokens($theme, primary); @include token-utils.values($tokens); } .mat-accent { .mdc-list-item__start, .mdc-list-item__end { - $tokens: m2-radio.get-color-tokens($theme, secondary); + $tokens: m2-radio.private-get-color-palette-color-tokens($theme, secondary); @include token-utils.values($tokens); } } @@ -45,23 +45,23 @@ .mat-warn { .mdc-list-item__start, .mdc-list-item__end { - $tokens: m2-radio.get-color-tokens($theme, error); + $tokens: m2-radio.private-get-color-palette-color-tokens($theme, error); @include token-utils.values($tokens); } } .mat-mdc-list-option { - $tokens: m2-checkbox.get-color-tokens($theme, primary); + $tokens: m2-checkbox.private-get-color-palette-color-tokens($theme, primary); @include token-utils.values($tokens); } .mat-mdc-list-option.mat-accent { - $tokens: m2-checkbox.get-color-tokens($theme, secondary); + $tokens: m2-checkbox.private-get-color-palette-color-tokens($theme, secondary); @include token-utils.values($tokens); } .mat-mdc-list-option.mat-warn { - $tokens: m2-checkbox.get-color-tokens($theme, error); + $tokens: m2-checkbox.private-get-color-palette-color-tokens($theme, error); @include token-utils.values($tokens); } @@ -91,7 +91,7 @@ } @mixin density($theme) { - $tokens: m2-list.get-density-tokens($theme); + $tokens: map.get(m2-list.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-list.get-tokens($theme), density); } @@ -104,7 +104,7 @@ .mdc-list-item__start, .mdc-list-item__end { - $tokens: m2-radio.get-density-tokens($theme); + $tokens: map.get(m2-radio.get-tokens($theme), density); @include token-utils.values($tokens); } @@ -148,7 +148,7 @@ } @mixin typography($theme) { - $tokens: m2-list.get-typography-tokens($theme); + $tokens: map.get(m2-list.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-list.get-tokens($theme), typography); } diff --git a/src/material/list/_m2-list.scss b/src/material/list/_m2-list.scss index 1a8086592fca..23cf35f212ce 100644 --- a/src/material/list/_m2-list.scss +++ b/src/material/list/_m2-list.scss @@ -2,106 +2,91 @@ @use '../core/tokens/m2-utils'; @use '../core/theming/theming'; -// 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 ( - list-active-indicator-color: transparent, - list-active-indicator-shape: 4px, - list-list-item-container-shape: 0, - list-list-item-leading-avatar-shape: 50%, - list-list-item-container-color: transparent, - list-list-item-selected-container-color: transparent, - list-list-item-leading-avatar-color: transparent, - list-list-item-leading-icon-size: 24px, - list-list-item-leading-avatar-size: 40px, - list-list-item-trailing-icon-size: 24px, - list-list-item-disabled-state-layer-color: transparent, - list-list-item-disabled-state-layer-opacity: 0, - list-list-item-disabled-label-text-opacity: 0.38, - list-list-item-disabled-leading-icon-opacity: 0.38, - list-list-item-disabled-trailing-icon-opacity: 0.38, - ); -} - -// Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme) { - $system: m2-utils.get-system($theme); - - @return ( - list-list-item-label-text-color: map.get($system, on-surface), - list-list-item-supporting-text-color: map.get($system, on-surface-variant), - list-list-item-leading-icon-color: map.get($system, on-surface-variant), - list-list-item-trailing-supporting-text-color: map.get($system, on-surface-variant), - list-list-item-trailing-icon-color: map.get($system, on-surface-variant), - list-list-item-selected-trailing-icon-color: map.get($system, on-surface-variant), - list-list-item-disabled-label-text-color: map.get($system, on-surface), - list-list-item-disabled-leading-icon-color: map.get($system, on-surface), - list-list-item-disabled-trailing-icon-color: map.get($system, on-surface), - list-list-item-hover-label-text-color: map.get($system, on-surface), - list-list-item-hover-leading-icon-color: map.get($system, on-surface-variant), - list-list-item-hover-state-layer-color: map.get($system, on-surface), - list-list-item-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), - list-list-item-hover-trailing-icon-color: map.get($system, on-surface-variant), - list-list-item-focus-label-text-color: map.get($system, on-surface), - list-list-item-focus-state-layer-color: map.get($system, on-surface), - list-list-item-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), - ); -} - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - list-list-item-label-text-font: map.get($system, body-large-font), - list-list-item-label-text-line-height: map.get($system, body-large-line-height), - list-list-item-label-text-size: map.get($system, body-large-size), - list-list-item-label-text-tracking: map.get($system, body-large-tracking), - list-list-item-label-text-weight: map.get($system, body-large-weight), - list-list-item-supporting-text-font: map.get($system, body-medium-font), - list-list-item-supporting-text-line-height: map.get($system, body-medium-line-height), - list-list-item-supporting-text-size: map.get($system, body-medium-size), - list-list-item-supporting-text-tracking: map.get($system, body-medium-tracking), - list-list-item-supporting-text-weight: map.get($system, body-medium-weight), - list-list-item-trailing-supporting-text-font: map.get($system, body-small-font), - list-list-item-trailing-supporting-text-line-height: map.get($system, body-small-line-height), - list-list-item-trailing-supporting-text-size: map.get($system, body-small-size), - list-list-item-trailing-supporting-text-tracking: map.get($system, body-small-tracking), - list-list-item-trailing-supporting-text-weight: map.get($system, body-small-weight), - ); -} - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { +@function get-tokens($theme) { $system: m2-utils.get-system($theme); $density-scale: theming.clamp-density(map.get($system, density-scale), -5); @return ( - list-list-item-leading-icon-start-space: 16px, - list-list-item-leading-icon-end-space: 32px, - list-list-item-one-line-container-height: map.get(( - 0: 48px, - -1: 44px, - -2: 40px, - -3: 36px, - -4: 32px, - -5: 24px, - ), $density-scale), - list-list-item-two-line-container-height: map.get(( - 0: 64px, - -1: 60px, - -2: 56px, - -3: 52px, - -4: 48px, - -5: 48px, - ), $density-scale), - list-list-item-three-line-container-height: map.get(( - 0: 88px, - -1: 84px, - -2: 80px, - -3: 76px, - -4: 72px, - -5: 56px, - ), $density-scale), + base: ( + list-active-indicator-color: transparent, + list-active-indicator-shape: 4px, + list-list-item-container-shape: 0, + list-list-item-leading-avatar-shape: 50%, + list-list-item-container-color: transparent, + list-list-item-selected-container-color: transparent, + list-list-item-leading-avatar-color: transparent, + list-list-item-leading-icon-size: 24px, + list-list-item-leading-avatar-size: 40px, + list-list-item-trailing-icon-size: 24px, + list-list-item-disabled-state-layer-color: transparent, + list-list-item-disabled-state-layer-opacity: 0, + list-list-item-disabled-label-text-opacity: 0.38, + list-list-item-disabled-leading-icon-opacity: 0.38, + list-list-item-disabled-trailing-icon-opacity: 0.38, + ), + color: ( + list-list-item-label-text-color: map.get($system, on-surface), + list-list-item-supporting-text-color: map.get($system, on-surface-variant), + list-list-item-leading-icon-color: map.get($system, on-surface-variant), + list-list-item-trailing-supporting-text-color: map.get($system, on-surface-variant), + list-list-item-trailing-icon-color: map.get($system, on-surface-variant), + list-list-item-selected-trailing-icon-color: map.get($system, on-surface-variant), + list-list-item-disabled-label-text-color: map.get($system, on-surface), + list-list-item-disabled-leading-icon-color: map.get($system, on-surface), + list-list-item-disabled-trailing-icon-color: map.get($system, on-surface), + list-list-item-hover-label-text-color: map.get($system, on-surface), + list-list-item-hover-leading-icon-color: map.get($system, on-surface-variant), + list-list-item-hover-state-layer-color: map.get($system, on-surface), + list-list-item-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), + list-list-item-hover-trailing-icon-color: map.get($system, on-surface-variant), + list-list-item-focus-label-text-color: map.get($system, on-surface), + list-list-item-focus-state-layer-color: map.get($system, on-surface), + list-list-item-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), + ), + typography: ( + list-list-item-label-text-font: map.get($system, body-large-font), + list-list-item-label-text-line-height: map.get($system, body-large-line-height), + list-list-item-label-text-size: map.get($system, body-large-size), + list-list-item-label-text-tracking: map.get($system, body-large-tracking), + list-list-item-label-text-weight: map.get($system, body-large-weight), + list-list-item-supporting-text-font: map.get($system, body-medium-font), + list-list-item-supporting-text-line-height: map.get($system, body-medium-line-height), + list-list-item-supporting-text-size: map.get($system, body-medium-size), + list-list-item-supporting-text-tracking: map.get($system, body-medium-tracking), + list-list-item-supporting-text-weight: map.get($system, body-medium-weight), + list-list-item-trailing-supporting-text-font: map.get($system, body-small-font), + list-list-item-trailing-supporting-text-line-height: map.get($system, body-small-line-height), + list-list-item-trailing-supporting-text-size: map.get($system, body-small-size), + list-list-item-trailing-supporting-text-tracking: map.get($system, body-small-tracking), + list-list-item-trailing-supporting-text-weight: map.get($system, body-small-weight), + ), + density: ( + list-list-item-leading-icon-start-space: 16px, + list-list-item-leading-icon-end-space: 32px, + list-list-item-one-line-container-height: map.get(( + 0: 48px, + -1: 44px, + -2: 40px, + -3: 36px, + -4: 32px, + -5: 24px, + ), $density-scale), + list-list-item-two-line-container-height: map.get(( + 0: 64px, + -1: 60px, + -2: 56px, + -3: 52px, + -4: 48px, + -5: 48px, + ), $density-scale), + list-list-item-three-line-container-height: map.get(( + 0: 88px, + -1: 84px, + -2: 80px, + -3: 76px, + -4: 72px, + -5: 56px, + ), $density-scale), + ), ); } diff --git a/src/material/menu/_m2-menu.scss b/src/material/menu/_m2-menu.scss index 8f74535940ff..80d8b990afe2 100644 --- a/src/material/menu/_m2-menu.scss +++ b/src/material/menu/_m2-menu.scss @@ -3,55 +3,42 @@ @use '../core/tokens/m2-utils'; @use '../core/tokens/m3-utils'; -// 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 ( - menu-container-shape: 4px, - menu-divider-bottom-spacing: 0, - menu-divider-top-spacing: 0, - menu-item-spacing: 16px, - menu-item-icon-size: 24px, - menu-item-leading-spacing: 16px, - menu-item-trailing-spacing: 16px, - menu-item-with-icon-leading-spacing: 16px, - menu-item-with-icon-trailing-spacing: 16px, - menu-container-elevation-shadow: elevation.get-box-shadow(8), - - // Unused - menu-base-elevation-level: null, - ); -} - -// 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 ( - menu-item-label-text-color: map.get($system, on-surface), - menu-item-icon-color: map.get($system, on-surface), - menu-item-hover-state-layer-color: m3-utils.color-with-opacity( - map.get($system, on-surface), map.get($system, hover-state-layer-opacity)), - menu-item-focus-state-layer-color: m3-utils.color-with-opacity( - map.get($system, on-surface), map.get($system, focus-state-layer-opacity)), - menu-container-color: map.get($system, surface), - menu-divider-color: map.get($system, outline), - ); -} + base: ( + menu-container-shape: 4px, + menu-divider-bottom-spacing: 0, + menu-divider-top-spacing: 0, + menu-item-spacing: 16px, + menu-item-icon-size: 24px, + menu-item-leading-spacing: 16px, + menu-item-trailing-spacing: 16px, + menu-item-with-icon-leading-spacing: 16px, + menu-item-with-icon-trailing-spacing: 16px, + menu-container-elevation-shadow: elevation.get-box-shadow(8), -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - menu-item-label-text-font: map.get($system, body-large-font), - menu-item-label-text-size: map.get($system, body-large-size), - menu-item-label-text-tracking: map.get($system, body-large-tracking), - menu-item-label-text-line-height: map.get($system, body-large-line-height), - menu-item-label-text-weight: map.get($system, body-large-weight), + // Unused + menu-base-elevation-level: null, + ), + color: ( + menu-item-label-text-color: map.get($system, on-surface), + menu-item-icon-color: map.get($system, on-surface), + menu-item-hover-state-layer-color: m3-utils.color-with-opacity( + map.get($system, on-surface), map.get($system, hover-state-layer-opacity)), + menu-item-focus-state-layer-color: m3-utils.color-with-opacity( + map.get($system, on-surface), map.get($system, focus-state-layer-opacity)), + menu-container-color: map.get($system, surface), + menu-divider-color: map.get($system, outline), + ), + typography: ( + menu-item-label-text-font: map.get($system, body-large-font), + menu-item-label-text-size: map.get($system, body-large-size), + menu-item-label-text-tracking: map.get($system, body-large-tracking), + menu-item-label-text-line-height: map.get($system, body-large-line-height), + menu-item-label-text-weight: map.get($system, body-large-weight), + ), + density: (), ); } - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { - @return (); -} diff --git a/src/material/menu/_menu-theme.scss b/src/material/menu/_menu-theme.scss index 6fa1d6eec0f5..aefbf7611b95 100644 --- a/src/material/menu/_menu-theme.scss +++ b/src/material/menu/_menu-theme.scss @@ -6,7 +6,7 @@ @use '../core/typography/typography'; @mixin base($theme) { - $tokens: m2-menu.get-unthemable-tokens(); + $tokens: map.get(m2-menu.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-menu.get-tokens($theme), base); } @@ -15,7 +15,7 @@ } @mixin color($theme) { - $tokens: m2-menu.get-color-tokens($theme); + $tokens: map.get(m2-menu.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-menu.get-tokens($theme), color); } @@ -24,7 +24,7 @@ } @mixin typography($theme) { - $tokens: m2-menu.get-typography-tokens($theme); + $tokens: map.get(m2-menu.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-menu.get-tokens($theme), typography); } @@ -33,7 +33,7 @@ } @mixin density($theme) { - $tokens: m2-menu.get-density-tokens($theme); + $tokens: map.get(m2-menu.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-menu.get-tokens($theme), density); } diff --git a/src/material/paginator/_m2-paginator.scss b/src/material/paginator/_m2-paginator.scss index e4d114a6b040..1223c3675f15 100644 --- a/src/material/paginator/_m2-paginator.scss +++ b/src/material/paginator/_m2-paginator.scss @@ -4,72 +4,53 @@ @use '../core/tokens/m2-utils'; @use '../core/tokens/m3-utils'; -// 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 (); -} - -// Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme) { - $system: m2-utils.get-system($theme); - - @return ( - paginator-container-text-color: map.get($system, on-surface), - paginator-container-background-color: map.get($system, surface), - paginator-enabled-icon-color: map.get($system, on-surface-variant), - paginator-disabled-icon-color: m3-utils.color-with-opacity(map.get($system, on-surface), 38%), - ); -} - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - paginator-container-text-font: map.get($system, body-small-font), - paginator-container-text-line-height: map.get($system, body-small-line-height), - paginator-container-text-size: map.get($system, body-small-size), - paginator-container-text-tracking: map.get($system, body-small-tracking), - paginator-container-text-weight: map.get($system, body-small-weight), - paginator-select-trigger-text-size: map.get($system, body-small-size), - ); -} - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { +@function get-tokens($theme) { $system: m2-utils.get-system($theme); $density-scale: theming.clamp-density(map.get($system, density-scale), -5); - $size-scale: ( - 0: 56px, - -1: 52px, - -2: 48px, - -3: 40px, - -4: 40px, - -5: 40px, - ); - $form-field-size-scale: ( + + $form-field-height: map.get(( 0: 56px, -1: 52px, -2: 48px, -3: 44px, -4: 40px, -5: 36px, - ); - $form-field-density-scale: if($density-scale > -4, -4, $density-scale); - $form-field-height: map.get($form-field-size-scale, $form-field-density-scale); - - // We computed the desired height of the form-field using the density configuration. The - // spec only describes vertical spacing/alignment in non-dense mode. This means that we - // cannot update the spacing to explicit numbers based on the density scale. Instead, we - // determine the height reduction and equally subtract it from the default `top` and `bottom` - // padding that is provided by the Material Design specification. - $form-field-vertical-deduction: math.div(56px - $form-field-height, 2); - $form-field-vertical-padding: 16px - $form-field-vertical-deduction; + ), if($density-scale > -4, -4, $density-scale)); @return ( - paginator-container-size: map.get($size-scale, $density-scale), - paginator-form-field-container-height: $form-field-height, - paginator-form-field-container-vertical-padding: $form-field-vertical-padding, - paginator-touch-target-display: if($density-scale < -2, none, block), + base: (), + color: ( + paginator-container-text-color: map.get($system, on-surface), + paginator-container-background-color: map.get($system, surface), + paginator-enabled-icon-color: map.get($system, on-surface-variant), + paginator-disabled-icon-color: m3-utils.color-with-opacity(map.get($system, on-surface), 38%), + ), + typography: ( + paginator-container-text-font: map.get($system, body-small-font), + paginator-container-text-line-height: map.get($system, body-small-line-height), + paginator-container-text-size: map.get($system, body-small-size), + paginator-container-text-tracking: map.get($system, body-small-tracking), + paginator-container-text-weight: map.get($system, body-small-weight), + paginator-select-trigger-text-size: map.get($system, body-small-size), + ), + density: ( + paginator-container-size: map.get(( + 0: 56px, + -1: 52px, + -2: 48px, + -3: 40px, + -4: 40px, + -5: 40px, + ), $density-scale), + paginator-form-field-container-height: $form-field-height, + // We computed the desired height of the form-field using the density configuration. The + // spec only describes vertical spacing/alignment in non-dense mode. This means that we + // cannot update the spacing to explicit numbers based on the density scale. Instead, we + // determine the height reduction and equally subtract it from the default `top` and `bottom` + // padding that is provided by the Material Design specification. + paginator-form-field-container-vertical-padding: + 16px - math.div(56px - $form-field-height, 2), + paginator-touch-target-display: if($density-scale < -2, none, block), + ), ); } diff --git a/src/material/paginator/_paginator-theme.scss b/src/material/paginator/_paginator-theme.scss index 02789a5d4199..6934d7b76134 100644 --- a/src/material/paginator/_paginator-theme.scss +++ b/src/material/paginator/_paginator-theme.scss @@ -6,7 +6,7 @@ @use '../core/tokens/token-utils'; @mixin base($theme) { - $tokens: m2-paginator.get-unthemable-tokens(); + $tokens: map.get(m2-paginator.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-paginator.get-tokens($theme), base); } @@ -15,7 +15,7 @@ } @mixin color($theme) { - $tokens: m2-paginator.get-color-tokens($theme); + $tokens: map.get(m2-paginator.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-paginator.get-tokens($theme), color); } @@ -24,7 +24,7 @@ } @mixin typography($theme) { - $tokens: m2-paginator.get-typography-tokens($theme); + $tokens: map.get(m2-paginator.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-paginator.get-tokens($theme), typography); } @@ -33,7 +33,7 @@ } @mixin density($theme) { - $tokens: m2-paginator.get-density-tokens($theme); + $tokens: map.get(m2-paginator.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-paginator.get-tokens($theme), density); } diff --git a/src/material/progress-bar/_m2-progress-bar.scss b/src/material/progress-bar/_m2-progress-bar.scss index 8db4d77eaed9..c14c9fdbc1b8 100644 --- a/src/material/progress-bar/_m2-progress-bar.scss +++ b/src/material/progress-bar/_m2-progress-bar.scss @@ -4,26 +4,23 @@ @use '../core/tokens/m2-utils'; @use '../core/tokens/m3-utils'; -// Tokens that can't be configured through Angular Material's current theming API, -// but may be in a future version of the theming API. -// -// Tokens that are available in MDC, but not used in Angular Material should be mapped to `null`. -// `null` indicates that we are intentionally choosing not to emit a slot or value for the token in -// our CSS. -@function get-unthemable-tokens() { - $height: 4px; +@function get-tokens($theme) { + $system: m2-utils.get-system($theme); @return ( - // The height of the progress bar. `active-indicator-height` applies to the - // bar and `track-height` applies to the track. - progress-bar-active-indicator-height: $height, - progress-bar-track-height: $height, - progress-bar-track-shape: 0, + base: ( + progress-bar-active-indicator-height: 4px, + progress-bar-track-height: 4px, + progress-bar-track-shape: 0, + ), + color: private-get-color-palette-color-tokens($theme, primary), + typography: (), + density: (), ); } // Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme, $color-variant) { +@function private-get-color-palette-color-tokens($theme, $color-variant) { $system: m2-utils.get-system($theme); $system: m3-utils.replace-colors-with-variant($system, primary, $color-variant); @@ -36,13 +33,3 @@ ) ); } - -// 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 (); -} diff --git a/src/material/progress-bar/_progress-bar-theme.scss b/src/material/progress-bar/_progress-bar-theme.scss index 58c76823e99d..cdb71f71be1c 100644 --- a/src/material/progress-bar/_progress-bar-theme.scss +++ b/src/material/progress-bar/_progress-bar-theme.scss @@ -5,7 +5,7 @@ @use 'sass:map'; @mixin base($theme) { - $tokens: m2-progress-bar.get-unthemable-tokens(); + $tokens: map.get(m2-progress-bar.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-progress-bar.get-tokens($theme), base); } @@ -19,16 +19,16 @@ map.get(m3-progress-bar.get-tokens($theme, $color-variant), color)); } @else { .mat-mdc-progress-bar { - $tokens: m2-progress-bar.get-color-tokens($theme, primary); + $tokens: m2-progress-bar.private-get-color-palette-color-tokens($theme, primary); @include token-utils.values($tokens); &.mat-accent { - $tokens: m2-progress-bar.get-color-tokens($theme, secondary); + $tokens: m2-progress-bar.private-get-color-palette-color-tokens($theme, secondary); @include token-utils.values($tokens); } &.mat-warn { - $tokens: m2-progress-bar.get-color-tokens($theme, error); + $tokens: m2-progress-bar.private-get-color-palette-color-tokens($theme, error); @include token-utils.values($tokens); } } @@ -36,7 +36,7 @@ } @mixin typography($theme) { - $tokens: m2-progress-bar.get-typography-tokens($theme); + $tokens: map.get(m2-progress-bar.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-progress-bar.get-tokens($theme), typography); } @@ -45,7 +45,7 @@ } @mixin density($theme) { - $tokens: m2-progress-bar.get-density-tokens($theme); + $tokens: map.get(m2-progress-bar.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-progress-bar.get-tokens($theme), density); } diff --git a/src/material/progress-spinner/_m2-progress-spinner.scss b/src/material/progress-spinner/_m2-progress-spinner.scss index c5360f828ac6..50700466394c 100644 --- a/src/material/progress-spinner/_m2-progress-spinner.scss +++ b/src/material/progress-spinner/_m2-progress-spinner.scss @@ -2,21 +2,20 @@ @use '../core/tokens/m3-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. -// -// Tokens that are available in MDC, but not used in Angular Material should be mapped to `null`. -// `null` indicates that we are intentionally choosing not to emit a slot or value for the token in -// our CSS. -@function get-unthemable-tokens() { +@function get-tokens($theme) { @return ( - progress-spinner-active-indicator-width: 4px, - progress-spinner-size: 48px, + base: ( + progress-spinner-active-indicator-width: 4px, + progress-spinner-size: 48px, + ), + color: private-get-color-palette-color-tokens($theme, primary), + typography: (), + density: (), ); } // Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme, $color-variant) { +@function private-get-color-palette-color-tokens($theme, $color-variant) { $system: m2-utils.get-system($theme); $system: m3-utils.replace-colors-with-variant($system, primary, $color-variant); @@ -24,13 +23,3 @@ progress-spinner-active-indicator-color: map.get($system, primary) ); } - -// 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 (); -} diff --git a/src/material/progress-spinner/_progress-spinner-theme.scss b/src/material/progress-spinner/_progress-spinner-theme.scss index d5486410e0e0..cfcca702132f 100644 --- a/src/material/progress-spinner/_progress-spinner-theme.scss +++ b/src/material/progress-spinner/_progress-spinner-theme.scss @@ -5,7 +5,7 @@ @use 'sass:map'; @mixin base($theme) { - $tokens: m2-progress-spinner.get-unthemable-tokens(); + $tokens: map.get(m2-progress-spinner.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-progress-spinner.get-tokens($theme), base); } @@ -17,7 +17,7 @@ /// @param {Map} $theme The theme to generate color styles for. /// @param {String} $color-variant The color variant to use for the component (M3 only) @mixin color($theme, $color-variant: null) { - $tokens: m2-progress-spinner.get-color-tokens($theme, primary); + $tokens: map.get(m2-progress-spinner.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-progress-spinner.get-tokens($theme, $color-variant), color); } @@ -26,19 +26,19 @@ @if inspection.get-theme-version($theme) != 1 { .mat-accent { - $tokens: m2-progress-spinner.get-color-tokens($theme, secondary); + $tokens: m2-progress-spinner.private-get-color-palette-color-tokens($theme, secondary); @include token-utils.values($tokens); } .mat-warn { - $tokens: m2-progress-spinner.get-color-tokens($theme, error); + $tokens: m2-progress-spinner.private-get-color-palette-color-tokens($theme, error); @include token-utils.values($tokens); } } } @mixin typography($theme) { - $tokens: m2-progress-spinner.get-typography-tokens($theme); + $tokens: map.get(m2-progress-spinner.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-progress-spinner.get-tokens($theme), typography); } @@ -47,7 +47,7 @@ } @mixin density($theme) { - $tokens: m2-progress-spinner.get-density-tokens($theme); + $tokens: map.get(m2-progress-spinner.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-progress-spinner.get-tokens($theme), density); } diff --git a/src/material/radio/_m2-radio.scss b/src/material/radio/_m2-radio.scss index f8c0bb5bd262..807e55255f58 100644 --- a/src/material/radio/_m2-radio.scss +++ b/src/material/radio/_m2-radio.scss @@ -1,26 +1,43 @@ @use 'sass:map'; @use '../core/theming/theming'; -@use '../core/theming/inspection'; @use '../core/tokens/m2-utils'; @use '../core/tokens/m3-utils'; -// 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() { +@function get-tokens($theme) { + $system: m2-utils.get-system($theme); + $density-scale: theming.clamp-density(map.get($system, density-scale), -3); + @return ( - radio-disabled-selected-icon-opacity: 0.38, - radio-disabled-unselected-icon-opacity: 0.38, - // This is specified both here and in the density tokens, because it - // determines the size of the radio button itself and there are internal - // tests who don't configure the theme correctly. - radio-state-layer-size: 40px, + base: ( + radio-disabled-selected-icon-opacity: 0.38, + radio-disabled-unselected-icon-opacity: 0.38, + // This is specified both here and in the density tokens, because it + // determines the size of the radio button itself and there are internal + // tests who don't configure the theme correctly. + radio-state-layer-size: 40px, + ), + color: private-get-color-palette-color-tokens($theme, secondary), + typography: ( + radio-label-text-font: map.get($system, body-medium-font), + radio-label-text-line-height: map.get($system, body-medium-line-height), + radio-label-text-size: map.get($system, body-medium-size), + radio-label-text-tracking: map.get($system, body-medium-tracking), + radio-label-text-weight: map.get($system, body-medium-weight) + ), + density: ( + radio-state-layer-size: map.get(( + 0: 40px, + -1: 36px, + -2: 32px, + -3: 28px, + ), $density-scale), + radio-touch-target-display: if($density-scale < -1, none, block) + ), ); } // Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme, $color-variant) { - $system: m2-utils.get-system($theme); - $is-dark: inspection.get-theme-type($theme) == dark; +@function private-get-color-palette-color-tokens($theme, $color-variant) { $system: m2-utils.get-system($theme); $system: m3-utils.replace-colors-with-variant($system, secondary, $color-variant); $disabled: m3-utils.color-with-opacity(map.get($system, on-surface), 38%); @@ -42,32 +59,3 @@ radio-unselected-pressed-icon-color: map.get($system, on-surface), ); } - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - radio-label-text-font: map.get($system, body-medium-font), - radio-label-text-line-height: map.get($system, body-medium-line-height), - radio-label-text-size: map.get($system, body-medium-size), - radio-label-text-tracking: map.get($system, body-medium-tracking), - radio-label-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) { - $system: m2-utils.get-system($theme); - $density-scale: theming.clamp-density(map.get($system, density-scale), -3); - - @return ( - // The diameter of the radio's ripple. - radio-state-layer-size: map.get(( - 0: 40px, - -1: 36px, - -2: 32px, - -3: 28px, - ), $density-scale), - radio-touch-target-display: if($density-scale < -1, none, block) - ); -} diff --git a/src/material/radio/_radio-theme.scss b/src/material/radio/_radio-theme.scss index 5e4eb887f201..3afa42163e4c 100644 --- a/src/material/radio/_radio-theme.scss +++ b/src/material/radio/_radio-theme.scss @@ -9,7 +9,7 @@ /// for the mat-radio. /// @param {Map} $theme The theme to generate base styles for. @mixin base($theme) { - $tokens: m2-radio.get-unthemable-tokens(); + $tokens: map.get(m2-radio.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-radio.get-tokens($theme), base); } @@ -27,17 +27,17 @@ } @else { .mat-mdc-radio-button { &.mat-primary { - $tokens: m2-radio.get-color-tokens($theme, primary); + $tokens: m2-radio.private-get-color-palette-color-tokens($theme, primary); @include token-utils.values($tokens); } &.mat-accent { - $tokens: m2-radio.get-color-tokens($theme, secondary); + $tokens: m2-radio.private-get-color-palette-color-tokens($theme, secondary); @include token-utils.values($tokens); } &.mat-warn { - $tokens: m2-radio.get-color-tokens($theme, error); + $tokens: m2-radio.private-get-color-palette-color-tokens($theme, error); @include token-utils.values($tokens); } } @@ -45,7 +45,7 @@ } @mixin typography($theme) { - $tokens: m2-radio.get-typography-tokens($theme); + $tokens: map.get(m2-radio.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-radio.get-tokens($theme), typography); } @@ -54,7 +54,7 @@ } @mixin density($theme) { - $tokens: m2-radio.get-density-tokens($theme); + $tokens: map.get(m2-radio.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-radio.get-tokens($theme), density); } diff --git a/src/material/select/_m2-select.scss b/src/material/select/_m2-select.scss index e94b7ee2214e..c485ee3bd603 100644 --- a/src/material/select/_m2-select.scss +++ b/src/material/select/_m2-select.scss @@ -4,16 +4,34 @@ @use '../core/tokens/m2-utils'; @use '../core/tokens/m3-utils'; -// 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() { +@function get-tokens($theme) { + $system: m2-utils.get-system($theme); + $density-scale: theming.clamp-density(map.get($system, density-scale), -2); + @return ( - select-container-elevation-shadow: elevation.get-box-shadow(8), + base: ( + select-container-elevation-shadow: elevation.get-box-shadow(8), + ), + color: private-get-color-palette-color-tokens($theme, primary), + typography: ( + select-trigger-text-font: map.get($system, body-large-font), + select-trigger-text-line-height: map.get($system, body-large-line-height), + select-trigger-text-size: map.get($system, body-large-size), + select-trigger-text-tracking: map.get($system, body-large-tracking), + select-trigger-text-weight: map.get($system, body-large-weight) + ), + density: ( + select-arrow-transform: map.get(( + 0: translateY(-8px), + -1: translateY(-8px), + -2: none, + ), $density-scale), + ), ); } // Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme, $color-variant) { +@function private-get-color-palette-color-tokens($theme, $color-variant) { $system: m2-utils.get-system($theme); $system: m3-utils.replace-colors-with-variant($system, primary, $color-variant); $disabled: m3-utils.color-with-opacity(map.get($system, on-surface), 38%); @@ -29,29 +47,3 @@ select-invalid-arrow-color: map.get($system, error), ); } - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - select-trigger-text-font: map.get($system, body-large-font), - select-trigger-text-line-height: map.get($system, body-large-line-height), - select-trigger-text-size: map.get($system, body-large-size), - select-trigger-text-tracking: map.get($system, body-large-tracking), - select-trigger-text-weight: map.get($system, body-large-weight) - ); -} - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { - $system: m2-utils.get-system($theme); - $density-scale: theming.clamp-density(map.get($system, density-scale), -2); - - @return ( - select-arrow-transform: map.get(( - 0: translateY(-8px), - -1: translateY(-8px), - -2: none, - ), $density-scale), - ); -} diff --git a/src/material/select/_select-theme.scss b/src/material/select/_select-theme.scss index 16347bd71103..0e842a4e4f8f 100644 --- a/src/material/select/_select-theme.scss +++ b/src/material/select/_select-theme.scss @@ -9,7 +9,7 @@ /// for the mat-select. /// @param {Map} $theme The theme to generate base styles for. @mixin base($theme) { - $tokens: m2-select.get-unthemable-tokens(); + $tokens: map.get(m2-select.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-select.get-tokens($theme), base); } @@ -21,7 +21,7 @@ /// @param {Map} $theme The theme to generate color styles for. /// @param {String} $color-variant The color variant to use for the component (M3 only) @mixin color($theme, $color-variant: null) { - $tokens: m2-select.get-color-tokens($theme, primary); + $tokens: map.get(m2-select.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-select.get-tokens($theme, $color-variant), color); } @@ -30,19 +30,19 @@ @if inspection.get-theme-version($theme) != 1 { .mat-mdc-form-field.mat-accent { - $tokens: m2-select.get-color-tokens($theme, secondary); + $tokens: m2-select.private-get-color-palette-color-tokens($theme, secondary); @include token-utils.values($tokens); } .mat-mdc-form-field.mat-warn { - $tokens: m2-select.get-color-tokens($theme, error); + $tokens: m2-select.private-get-color-palette-color-tokens($theme, error); @include token-utils.values($tokens); } } } @mixin typography($theme) { - $tokens: m2-select.get-typography-tokens($theme); + $tokens: map.get(m2-select.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-select.get-tokens($theme), typography); } @@ -51,7 +51,7 @@ } @mixin density($theme) { - $tokens: m2-select.get-density-tokens($theme); + $tokens: map.get(m2-select.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-select.get-tokens($theme), density); } diff --git a/src/material/sidenav/_m2-sidenav.scss b/src/material/sidenav/_m2-sidenav.scss index 563964daf433..b4efaccfa671 100644 --- a/src/material/sidenav/_m2-sidenav.scss +++ b/src/material/sidenav/_m2-sidenav.scss @@ -6,48 +6,38 @@ @use '../core/tokens/m2-utils'; @use '../core/tokens/m3-utils'; -// 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 ( - // Currently zero, but it appears to be relevant for M3. - // See: https://m3.material.io/components/navigation-drawer/overview - sidenav-container-shape: 0, - sidenav-container-elevation-shadow: elevation.get-box-shadow(16), - sidenav-container-width: auto, - ); -} - -// 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); - $is-dark: inspection.get-theme-type($theme) == dark; + // TODO: Use system colors instead of checking theme type + $is-dark: false; + @if (meta.type-of($theme) == map and map.get($theme, color)) { + $is-dark: inspection.get-theme-type($theme) == dark; + } $scrim-opacity: 0.6; $scrim-color: m3-utils.color-with-opacity(map.get($system, surface), 60%); $fallback-scrim-color: if($is-dark, rgba(#fff, $scrim-opacity), rgba(#000, $scrim-opacity)); @return ( - sidenav-container-divider-color: map.get($system, outline), - sidenav-container-background-color: map.get($system, surface), - sidenav-container-text-color: map.get($system, on-surface), - sidenav-content-background-color: map.get($system, background), - sidenav-content-text-color: map.get($system, on-surface), + base: ( + sidenav-container-shape: 0, + sidenav-container-elevation-shadow: elevation.get-box-shadow(16), + sidenav-container-width: auto, + ), + color: ( + sidenav-container-divider-color: map.get($system, outline), + sidenav-container-background-color: map.get($system, surface), + sidenav-container-text-color: map.get($system, on-surface), + sidenav-content-background-color: map.get($system, background), + sidenav-content-text-color: map.get($system, on-surface), - // We use invert() here to have the darken the background color expected to be used. - // If the background is light, we use a dark backdrop. If the background is dark, we - // use a light backdrop. If the value isn't a color, Sass will throw an error so we - // fall back to something generic. - sidenav-scrim-color: if(meta.type-of($scrim-color) == color, - color.invert($scrim-color), $fallback-scrim-color), + // We use invert() here to have the darken the background color expected to be used. + // If the background is light, we use a dark backdrop. If the background is dark, we + // use a light backdrop. If the value isn't a color, Sass will throw an error so we + // fall back to something generic. + sidenav-scrim-color: if(meta.type-of($scrim-color) == color, + color.invert($scrim-color), $fallback-scrim-color), + ), + 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 (); -} diff --git a/src/material/sidenav/_sidenav-theme.scss b/src/material/sidenav/_sidenav-theme.scss index 54589a006f02..602f22f4024d 100644 --- a/src/material/sidenav/_sidenav-theme.scss +++ b/src/material/sidenav/_sidenav-theme.scss @@ -5,7 +5,7 @@ @use './m3-sidenav'; @mixin base($theme) { - $tokens: m2-sidenav.get-unthemable-tokens(); + $tokens: map.get(m2-sidenav.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-sidenav.get-tokens($theme), base); } @@ -14,7 +14,7 @@ } @mixin color($theme) { - $tokens: m2-sidenav.get-color-tokens($theme); + $tokens: map.get(m2-sidenav.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-sidenav.get-tokens($theme), color); } @@ -23,7 +23,7 @@ } @mixin typography($theme) { - $tokens: m2-sidenav.get-typography-tokens($theme); + $tokens: map.get(m2-sidenav.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-sidenav.get-tokens($theme), typography); } @@ -32,7 +32,7 @@ } @mixin density($theme) { - $tokens: m2-sidenav.get-density-tokens($theme); + $tokens: map.get(m2-sidenav.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-sidenav.get-tokens($theme), density); } diff --git a/src/material/slide-toggle/_m2-slide-toggle.scss b/src/material/slide-toggle/_m2-slide-toggle.scss index 999114984aab..d7d374c60075 100644 --- a/src/material/slide-toggle/_m2-slide-toggle.scss +++ b/src/material/slide-toggle/_m2-slide-toggle.scss @@ -4,94 +4,103 @@ @use '../core/tokens/m2-utils'; @use '../core/tokens/m3-utils'; -// 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($theme) { +@function get-tokens($theme) { $system: m2-utils.get-system($theme); + $density-scale: theming.clamp-density(map.get($system, density-scale), -3); - // visible-track-opacity and hidden-track-opacity: - // The hidden and visible track represent whichever track is visible or - // hidden in the ui. This could be the .mdc-switch__track :before or - // :after depending on whether the switch is selected or unselected. - // - // The m2 slide-toggle uses transforms to hide & show the tracks while - // the m3 slide-toggle uses opacity. @return ( - slide-toggle-disabled-handle-opacity: 0.38, - slide-toggle-disabled-selected-handle-opacity: 0.38, - slide-toggle-disabled-selected-icon-opacity: 0.38, - slide-toggle-disabled-track-opacity: 0.12, - slide-toggle-disabled-unselected-handle-opacity: 0.38, - slide-toggle-disabled-unselected-icon-opacity: 0.38, - slide-toggle-disabled-unselected-track-outline-color: transparent, - slide-toggle-disabled-unselected-track-outline-width: 1px, - slide-toggle-handle-height: 20px, - slide-toggle-handle-shape: 10px, - slide-toggle-handle-width: 20px, - slide-toggle-hidden-track-opacity: 1, - slide-toggle-hidden-track-transition: transform 75ms 0ms cubic-bezier(0.4, 0, 0.6, 1), - slide-toggle-pressed-handle-size: 20px, - slide-toggle-selected-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), - slide-toggle-selected-handle-horizontal-margin: 0, - slide-toggle-selected-handle-size: 20px, - slide-toggle-selected-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), - slide-toggle-selected-icon-size: 18px, - slide-toggle-selected-pressed-handle-horizontal-margin: 0, - slide-toggle-selected-pressed-state-layer-opacity: - map.get($system, pressed-state-layer-opacity), - slide-toggle-selected-track-outline-color: transparent, - slide-toggle-selected-track-outline-width: 1px, - slide-toggle-selected-with-icon-handle-horizontal-margin: 0, - slide-toggle-track-height: 14px, - slide-toggle-track-outline-color: transparent, - slide-toggle-track-outline-width: 1px, - slide-toggle-track-shape: 7px, - slide-toggle-track-width: 36px, - slide-toggle-unselected-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), - slide-toggle-unselected-handle-horizontal-margin: 0, - slide-toggle-unselected-handle-size: 20px, - slide-toggle-unselected-hover-state-layer-opacity: map.get($system, focus-state-layer-opacity), - slide-toggle-unselected-icon-size: 18px, - slide-toggle-unselected-pressed-handle-horizontal-margin: 0, - slide-toggle-unselected-pressed-state-layer-opacity: 0.1, - slide-toggle-unselected-with-icon-handle-horizontal-margin: 0, - slide-toggle-visible-track-opacity: 1, - slide-toggle-visible-track-transition: transform 75ms 0ms cubic-bezier(0, 0, 0.2, 1), - slide-toggle-with-icon-handle-size: 20px, - ); -} - -// Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme) { - $system: m2-utils.get-system($theme); - - @return map.merge( - private-get-color-palette-color-tokens($theme, primary), - ( - slide-toggle-disabled-label-text-color: - m3-utils.color-with-opacity(map.get($system, on-surface), 38%), - slide-toggle-disabled-handle-elevation-shadow: elevation.get-box-shadow(0), - slide-toggle-disabled-selected-handle-color: map.get($system, on-surface), - slide-toggle-disabled-selected-track-color: map.get($system, on-surface), - slide-toggle-disabled-unselected-handle-color: map.get($system, on-surface), - slide-toggle-disabled-unselected-icon-color: map.get($system, surface-variant), - slide-toggle-disabled-unselected-track-color: map.get($system, on-surface), - slide-toggle-handle-elevation-shadow: elevation.get-box-shadow(1), - slide-toggle-handle-surface-color: map.get($system, surface), - slide-toggle-label-text-color: map.get($system, on-surface), - slide-toggle-unselected-hover-handle-color: map.get($system, inverse-surface), - slide-toggle-unselected-focus-handle-color: map.get($system, inverse-surface), - slide-toggle-unselected-focus-state-layer-color: map.get($system, on-surface), - slide-toggle-unselected-focus-track-color: map.get($system, outline), - slide-toggle-unselected-icon-color: map.get($system, surface-variant), - slide-toggle-unselected-handle-color: map.get($system, on-surface-variant), - slide-toggle-unselected-hover-state-layer-color: map.get($system, on-surface), - slide-toggle-unselected-hover-track-color: map.get($system, outline), - slide-toggle-unselected-pressed-handle-color: map.get($system, inverse-surface), - slide-toggle-unselected-pressed-track-color: map.get($system, outline), - slide-toggle-unselected-pressed-state-layer-color: map.get($system, on-surface), - slide-toggle-unselected-track-color: map.get($system, outline), - ) + base: ( + // visible-track-opacity and hidden-track-opacity: + // The hidden and visible track represent whichever track is visible or + // hidden in the ui. This could be the .mdc-switch__track :before or + // :after depending on whether the switch is selected or unselected. + // + // The m2 slide-toggle uses transforms to hide & show the tracks while + // the m3 slide-toggle uses opacity. + slide-toggle-disabled-handle-opacity: 0.38, + slide-toggle-disabled-selected-handle-opacity: 0.38, + slide-toggle-disabled-selected-icon-opacity: 0.38, + slide-toggle-disabled-track-opacity: 0.12, + slide-toggle-disabled-unselected-handle-opacity: 0.38, + slide-toggle-disabled-unselected-icon-opacity: 0.38, + slide-toggle-disabled-unselected-track-outline-color: transparent, + slide-toggle-disabled-unselected-track-outline-width: 1px, + slide-toggle-handle-height: 20px, + slide-toggle-handle-shape: 10px, + slide-toggle-handle-width: 20px, + slide-toggle-hidden-track-opacity: 1, + slide-toggle-hidden-track-transition: transform 75ms 0ms cubic-bezier(0.4, 0, 0.6, 1), + slide-toggle-pressed-handle-size: 20px, + slide-toggle-selected-focus-state-layer-opacity: map.get($system, focus-state-layer-opacity), + slide-toggle-selected-handle-horizontal-margin: 0, + slide-toggle-selected-handle-size: 20px, + slide-toggle-selected-hover-state-layer-opacity: map.get($system, hover-state-layer-opacity), + slide-toggle-selected-icon-size: 18px, + slide-toggle-selected-pressed-handle-horizontal-margin: 0, + slide-toggle-selected-pressed-state-layer-opacity: + map.get($system, pressed-state-layer-opacity), + slide-toggle-selected-track-outline-color: transparent, + slide-toggle-selected-track-outline-width: 1px, + slide-toggle-selected-with-icon-handle-horizontal-margin: 0, + slide-toggle-track-height: 14px, + slide-toggle-track-outline-color: transparent, + slide-toggle-track-outline-width: 1px, + slide-toggle-track-shape: 7px, + slide-toggle-track-width: 36px, + slide-toggle-unselected-focus-state-layer-opacity: + map.get($system, focus-state-layer-opacity), + slide-toggle-unselected-handle-horizontal-margin: 0, + slide-toggle-unselected-handle-size: 20px, + slide-toggle-unselected-hover-state-layer-opacity: + map.get($system, focus-state-layer-opacity), + slide-toggle-unselected-icon-size: 18px, + slide-toggle-unselected-pressed-handle-horizontal-margin: 0, + slide-toggle-unselected-pressed-state-layer-opacity: 0.1, + slide-toggle-unselected-with-icon-handle-horizontal-margin: 0, + slide-toggle-visible-track-opacity: 1, + slide-toggle-visible-track-transition: transform 75ms 0ms cubic-bezier(0, 0, 0.2, 1), + slide-toggle-with-icon-handle-size: 20px, + ), + color: map.merge(private-get-color-palette-color-tokens($theme, primary), ( + slide-toggle-disabled-label-text-color: + m3-utils.color-with-opacity(map.get($system, on-surface), 38%), + slide-toggle-disabled-handle-elevation-shadow: elevation.get-box-shadow(0), + slide-toggle-disabled-selected-handle-color: map.get($system, on-surface), + slide-toggle-disabled-selected-track-color: map.get($system, on-surface), + slide-toggle-disabled-unselected-handle-color: map.get($system, on-surface), + slide-toggle-disabled-unselected-icon-color: map.get($system, surface-variant), + slide-toggle-disabled-unselected-track-color: map.get($system, on-surface), + slide-toggle-handle-elevation-shadow: elevation.get-box-shadow(1), + slide-toggle-handle-surface-color: map.get($system, surface), + slide-toggle-label-text-color: map.get($system, on-surface), + slide-toggle-unselected-hover-handle-color: map.get($system, inverse-surface), + slide-toggle-unselected-focus-handle-color: map.get($system, inverse-surface), + slide-toggle-unselected-focus-state-layer-color: map.get($system, on-surface), + slide-toggle-unselected-focus-track-color: map.get($system, outline), + slide-toggle-unselected-icon-color: map.get($system, surface-variant), + slide-toggle-unselected-handle-color: map.get($system, on-surface-variant), + slide-toggle-unselected-hover-state-layer-color: map.get($system, on-surface), + slide-toggle-unselected-hover-track-color: map.get($system, outline), + slide-toggle-unselected-pressed-handle-color: map.get($system, inverse-surface), + slide-toggle-unselected-pressed-track-color: map.get($system, outline), + slide-toggle-unselected-pressed-state-layer-color: map.get($system, on-surface), + slide-toggle-unselected-track-color: map.get($system, outline)) + ), + typography: ( + slide-toggle-label-text-font: map.get($system, body-medium-font), + slide-toggle-label-text-line-height: map.get($system, body-medium-line-height), + slide-toggle-label-text-size: map.get($system, body-medium-size), + slide-toggle-label-text-tracking: map.get($system, body-medium-tracking), + slide-toggle-label-text-weight: map.get($system, body-medium-weight) + ), + density: ( + slide-toggle-state-layer-size: map.get(( + 0: 40px, + -1: 36px, + -2: 32px, + -3: 28px, + ), $density-scale) + ), ); } @@ -116,31 +125,3 @@ slide-toggle-selected-track-color: map.get($system, inverse-primary), ); } - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - slide-toggle-label-text-font: map.get($system, body-medium-font), - slide-toggle-label-text-line-height: map.get($system, body-medium-line-height), - slide-toggle-label-text-size: map.get($system, body-medium-size), - slide-toggle-label-text-tracking: map.get($system, body-medium-tracking), - slide-toggle-label-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) { - $system: m2-utils.get-system($theme); - $density-scale: theming.clamp-density(map.get($system, density-scale), -3); - - @return ( - // The diameter of the handle ripple. - slide-toggle-state-layer-size: map.get(( - 0: 40px, - -1: 36px, - -2: 32px, - -3: 28px, - ), $density-scale) - ); -} diff --git a/src/material/slide-toggle/_slide-toggle-theme.scss b/src/material/slide-toggle/_slide-toggle-theme.scss index e3835b9eed06..8fbbeab6bc21 100644 --- a/src/material/slide-toggle/_slide-toggle-theme.scss +++ b/src/material/slide-toggle/_slide-toggle-theme.scss @@ -11,7 +11,7 @@ /// for the mat-slide-toggle. /// @param {Map} $theme The theme to generate base styles for. @mixin base($theme) { - $tokens: m2-slide-toggle.get-unthemable-tokens($theme); + $tokens: map.get(m2-slide-toggle.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-slide-toggle.get-tokens($theme), base); } @@ -23,7 +23,7 @@ /// @param {Map} $theme The theme to generate color styles for. /// @param {String} $color-variant The color variant to use for the component (M3 only) @mixin color($theme, $color-variant: null) { - $tokens: m2-slide-toggle.get-color-tokens($theme); + $tokens: map.get(m2-slide-toggle.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-slide-toggle.get-tokens($theme, $color-variant), color); } @@ -31,7 +31,7 @@ @include token-utils.values($tokens); @if inspection.get-theme-version($theme) != 1 { - $mat-tokens: m2-slide-toggle.get-color-tokens($theme); + $mat-tokens: map.get(m2-slide-toggle.get-tokens($theme), color); $system: m2-utils.get-system($theme); .mat-mdc-slide-toggle { @@ -58,11 +58,11 @@ } @else { @include sass-utils.current-selector-or-root() { // TODO: See if this can be removed - @include token-utils.values(m2-slide-toggle.get-typography-tokens($theme)); + @include token-utils.values(map.get(m2-slide-toggle.get-tokens($theme), typography)); .mat-mdc-slide-toggle { @include token-utils.values( - m2-slide-toggle.get-typography-tokens($theme)); + map.get(m2-slide-toggle.get-tokens($theme), typography)); } } } @@ -71,7 +71,7 @@ /// Outputs density theme styles for the mat-slide-toggle. /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { - $tokens: m2-slide-toggle.get-density-tokens($theme); + $tokens: map.get(m2-slide-toggle.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-slide-toggle.get-tokens($theme), density); } diff --git a/src/material/slider/_m2-slider.scss b/src/material/slider/_m2-slider.scss index d12b0e41d67c..bdb16a22ed1b 100644 --- a/src/material/slider/_m2-slider.scss +++ b/src/material/slider/_m2-slider.scss @@ -3,41 +3,33 @@ @use '../core/tokens/m2-utils'; @use '../core/tokens/m3-utils'; -// 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 ( - slider-active-track-height: 6px, - slider-active-track-shape: 9999px, - slider-handle-elevation: elevation.get-box-shadow(1), - slider-handle-height: 20px, - slider-handle-shape: 50%, - slider-handle-width: 20px, - slider-inactive-track-height: 4px, - slider-inactive-track-shape: 9999px, - slider-value-indicator-border-radius: 4px, - slider-value-indicator-caret-display: block, - slider-value-indicator-container-transform: translateX(-50%), - slider-value-indicator-height: 32px, - slider-value-indicator-padding: 0 12px, - slider-value-indicator-text-transform: none, - slider-value-indicator-width: auto, - slider-with-overlap-handle-outline-width: 1px, - slider-with-tick-marks-active-container-opacity: 0.6, - slider-with-tick-marks-container-shape: 50%, - slider-with-tick-marks-container-size: 2px, - slider-with-tick-marks-inactive-container-opacity: 0.6, - ); -} - -// 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); - $theme-color-tokens: private-get-color-palette-color-tokens($theme, primary); - @return map.merge( - $theme-color-tokens, - ( + @return ( + base: ( + slider-active-track-height: 6px, + slider-active-track-shape: 9999px, + slider-handle-elevation: elevation.get-box-shadow(1), + slider-handle-height: 20px, + slider-handle-shape: 50%, + slider-handle-width: 20px, + slider-inactive-track-height: 4px, + slider-inactive-track-shape: 9999px, + slider-value-indicator-border-radius: 4px, + slider-value-indicator-caret-display: block, + slider-value-indicator-container-transform: translateX(-50%), + slider-value-indicator-height: 32px, + slider-value-indicator-padding: 0 12px, + slider-value-indicator-text-transform: none, + slider-value-indicator-width: auto, + slider-with-overlap-handle-outline-width: 1px, + slider-with-tick-marks-active-container-opacity: 0.6, + slider-with-tick-marks-container-shape: 50%, + slider-with-tick-marks-container-size: 2px, + slider-with-tick-marks-inactive-container-opacity: 0.6, + ), + color: map.merge(private-get-color-palette-color-tokens($theme, primary), ( slider-disabled-active-track-color: map.get($system, on-surface), slider-disabled-handle-color: map.get($system, on-surface), slider-disabled-inactive-track-color: map.get($system, on-surface), @@ -45,8 +37,16 @@ slider-label-label-text-color: map.get($system, inverse-on-surface), slider-value-indicator-opacity: 1, slider-with-overlap-handle-outline-color: map.get($system, on-surface), - slider-with-tick-marks-disabled-container-color: map.get($system, on-surface), + slider-with-tick-marks-disabled-container-color: map.get($system, on-surface)), + ), + typography: ( + slider-label-label-text-font: map.get($system, label-medium-font), + slider-label-label-text-size: map.get($system, label-medium-size), + slider-label-label-text-line-height: map.get($system, label-medium-line-height), + slider-label-label-text-tracking: map.get($system, label-medium-tracking), + slider-label-label-text-weight: map.get($system, label-medium-weight), ), + density: (), ); } @@ -54,7 +54,6 @@ @function private-get-color-palette-color-tokens($theme, $color-variant) { $system: m2-utils.get-system($theme); $system: m3-utils.replace-colors-with-variant($system, primary, $color-variant); - $color: map.get($system, primary); @return ( slider-active-track-color: map.get($system, primary), @@ -71,20 +70,3 @@ slider-with-tick-marks-inactive-container-color: map.get($system, primary), ); } - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - slider-label-label-text-font: map.get($system, label-medium-font), - slider-label-label-text-size: map.get($system, label-medium-size), - slider-label-label-text-line-height: map.get($system, label-medium-line-height), - slider-label-label-text-tracking: map.get($system, label-medium-tracking), - slider-label-label-text-weight: map.get($system, label-medium-weight), - ); -} - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { - @return (); -} diff --git a/src/material/slider/_slider-theme.scss b/src/material/slider/_slider-theme.scss index 6c36654cb78b..5a2bc794003a 100644 --- a/src/material/slider/_slider-theme.scss +++ b/src/material/slider/_slider-theme.scss @@ -9,7 +9,7 @@ /// for the mat-slider. /// @param {Map} $theme The theme to generate base styles for. @mixin base($theme) { - $tokens: m2-slider.get-unthemable-tokens(); + $tokens: map.get(m2-slider.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-slider.get-tokens($theme), base); } @@ -21,7 +21,7 @@ /// @param {Map} $theme The theme to generate color styles for. /// @param {String} $color-variant The color variant to use for the component (M3 only) @mixin color($theme, $color-variant: null) { - $tokens: m2-slider.get-color-tokens($theme); + $tokens: map.get(m2-slider.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-slider.get-tokens($theme, $color-variant), color); } @@ -44,7 +44,7 @@ /// Outputs typography theme styles for the mat-slider. /// @param {Map} $theme The theme to generate typography styles for. @mixin typography($theme) { - $tokens: m2-slider.get-typography-tokens($theme); + $tokens: map.get(m2-slider.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-slider.get-tokens($theme), typography); } @@ -55,7 +55,7 @@ /// Outputs density theme styles for the mat-slider. /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { - $tokens: m2-slider.get-density-tokens($theme); + $tokens: map.get(m2-slider.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-slider.get-tokens($theme), density); } diff --git a/src/material/snack-bar/_m2-snack-bar.scss b/src/material/snack-bar/_m2-snack-bar.scss index e109df5e4fe1..e65c58565d77 100644 --- a/src/material/snack-bar/_m2-snack-bar.scss +++ b/src/material/snack-bar/_m2-snack-bar.scss @@ -1,44 +1,37 @@ @use '../core/theming/inspection'; @use '../core/tokens/m2-utils'; @use 'sass:map'; +@use 'sass:meta'; -// 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 ( - snack-bar-container-shape: 4px, - ); -} - -// Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme) { - $is-dark: inspection.get-theme-type($theme) == dark; +@function get-tokens($theme) { $system: m2-utils.get-system($theme); - @return ( - snack-bar-container-color: map.get($system, inverse-surface), - snack-bar-supporting-text-color: map.get($system, inverse-on-surface), - snack-bar-button-color: - if( + // TODO: Use system colors instead of checking theme type and using primary hues + $snack-bar-button-color: map.get($system, inverse-primary); + @if (meta.type-of($theme) == map and map.get($theme, color)) { + $is-dark: inspection.get-theme-type($theme) == dark; + $snack-bar-button-color: if( $is-dark, inspection.get-theme-color($theme, primary, 500), inspection.get-theme-color($theme, primary, 100) - ) - ); -} + ); + } -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); @return ( - snack-bar-supporting-text-font: map.get($system, body-medium-font), - snack-bar-supporting-text-line-height: map.get($system, body-medium-line-height), - snack-bar-supporting-text-size: map.get($system, body-medium-size), - snack-bar-supporting-text-weight: map.get($system, body-medium-weight), + base: ( + snack-bar-container-shape: 4px, + ), + color: ( + snack-bar-container-color: map.get($system, inverse-surface), + snack-bar-supporting-text-color: map.get($system, inverse-on-surface), + snack-bar-button-color: $snack-bar-button-color + ), + typography: ( + snack-bar-supporting-text-font: map.get($system, body-medium-font), + snack-bar-supporting-text-line-height: map.get($system, body-medium-line-height), + snack-bar-supporting-text-size: map.get($system, body-medium-size), + snack-bar-supporting-text-weight: map.get($system, body-medium-weight), + ), + density: (), ); } - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { - @return (); -} diff --git a/src/material/snack-bar/_snack-bar-theme.scss b/src/material/snack-bar/_snack-bar-theme.scss index 791d5f708d13..64eb6e231376 100644 --- a/src/material/snack-bar/_snack-bar-theme.scss +++ b/src/material/snack-bar/_snack-bar-theme.scss @@ -6,7 +6,7 @@ @use './m3-snack-bar'; @mixin base($theme) { - $tokens: m2-snack-bar.get-unthemable-tokens(); + $tokens: map.get(m2-snack-bar.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-snack-bar.get-tokens($theme), base); } @@ -18,12 +18,12 @@ @if inspection.get-theme-version($theme) == 1 { @include token-utils.values(map.get(m3-snack-bar.get-tokens($theme), color)); } @else { - @include token-utils.values(m2-snack-bar.get-color-tokens($theme)); + @include token-utils.values(map.get(m2-snack-bar.get-tokens($theme), color)); } } @mixin typography($theme) { - $tokens: m2-snack-bar.get-typography-tokens($theme); + $tokens: map.get(m2-snack-bar.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-snack-bar.get-tokens($theme), typography); } @@ -32,7 +32,7 @@ } @mixin density($theme) { - $tokens: m2-snack-bar.get-density-tokens($theme); + $tokens: map.get(m2-snack-bar.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-snack-bar.get-tokens($theme), density); } diff --git a/src/material/sort/_m2-sort.scss b/src/material/sort/_m2-sort.scss index 1b3ebd714a29..d3483b3d5b18 100644 --- a/src/material/sort/_m2-sort.scss +++ b/src/material/sort/_m2-sort.scss @@ -1,27 +1,16 @@ @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 (); -} - -// 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 ( - sort-arrow-color: map.get($system, on-surface), + base: (), + color: ( + sort-arrow-color: map.get($system, on-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 (); -} diff --git a/src/material/sort/_sort-theme.scss b/src/material/sort/_sort-theme.scss index 0e30441cd28c..99797f12190b 100644 --- a/src/material/sort/_sort-theme.scss +++ b/src/material/sort/_sort-theme.scss @@ -6,7 +6,7 @@ @use '../core/tokens/token-utils'; @mixin base($theme) { - $tokens: m2-sort.get-unthemable-tokens(); + $tokens: map.get(m2-sort.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-sort.get-tokens($theme), base); } @@ -15,7 +15,7 @@ } @mixin color($theme) { - $tokens: m2-sort.get-color-tokens($theme); + $tokens: map.get(m2-sort.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-sort.get-tokens($theme), color); } @@ -24,7 +24,7 @@ } @mixin typography($theme) { - $tokens: m2-sort.get-typography-tokens($theme); + $tokens: map.get(m2-sort.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-sort.get-tokens($theme), typography); } @@ -33,7 +33,7 @@ } @mixin density($theme) { - $tokens: m2-sort.get-density-tokens($theme); + $tokens: map.get(m2-sort.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-sort.get-tokens($theme), density); } diff --git a/src/material/stepper/_m2-stepper.scss b/src/material/stepper/_m2-stepper.scss index 4fd95c5b19e1..c2fb62f9faff 100644 --- a/src/material/stepper/_m2-stepper.scss +++ b/src/material/stepper/_m2-stepper.scss @@ -3,63 +3,48 @@ @use '../core/tokens/m2-utils'; @use '../core/tokens/m3-utils'; -// 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 ( - stepper-header-focus-state-layer-shape: 0, - stepper-header-hover-state-layer-shape: 0, - ); -} - -// Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme) { - $system: m2-utils.get-system($theme); - @return map.merge(private-get-color-palette-color-tokens($theme, primary), ( - stepper-container-color: map.get($system, surface), - stepper-line-color: map.get($system, outline), - stepper-header-hover-state-layer-color: m3-utils.color-with-opacity( - map.get($system, on-surface), map.get($system, hover-state-layer-opacity)), - stepper-header-focus-state-layer-color: m3-utils.color-with-opacity( - map.get($system, on-surface), map.get($system, focus-state-layer-opacity)), - stepper-header-label-text-color: map.get($system, on-surface-variant), - stepper-header-optional-label-text-color: map.get($system, on-surface-variant), - stepper-header-selected-state-label-text-color: map.get($system, on-surface), - stepper-header-error-state-label-text-color: map.get($system, error), - stepper-header-icon-background-color: map.get($system, on-surface-variant), - stepper-header-error-state-icon-foreground-color: map.get($system, error), - stepper-header-error-state-icon-background-color: transparent, - )); -} - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - stepper-container-text-font: map.get($system, body-medium-font), - stepper-header-label-text-font: map.get($system, body-medium-font), - stepper-header-label-text-size: map.get($system, body-medium-size), - stepper-header-label-text-weight: map.get($system, body-medium-weight), - stepper-header-error-state-label-text-size: map.get($system, body-large-size), - stepper-header-selected-state-label-text-size: map.get($system, body-large-size), - stepper-header-selected-state-label-text-weight: map.get($system, body-large-weight), - ); -} - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { +@function get-tokens($theme) { $system: m2-utils.get-system($theme); $density-scale: theming.clamp-density(map.get($system, density-scale), -4); - $height-config: ( - 0: 72px, - -1: 68px, - -2: 64px, - -3: 60px, - -4: 42px, - ); @return ( - stepper-header-height: map.get($height-config, $density-scale), + base: ( + stepper-header-focus-state-layer-shape: 0, + stepper-header-hover-state-layer-shape: 0, + ), + color: map.merge(private-get-color-palette-color-tokens($theme, primary), ( + stepper-container-color: map.get($system, surface), + stepper-line-color: map.get($system, outline), + stepper-header-hover-state-layer-color: m3-utils.color-with-opacity( + map.get($system, on-surface), map.get($system, hover-state-layer-opacity)), + stepper-header-focus-state-layer-color: m3-utils.color-with-opacity( + map.get($system, on-surface), map.get($system, focus-state-layer-opacity)), + stepper-header-label-text-color: map.get($system, on-surface-variant), + stepper-header-optional-label-text-color: map.get($system, on-surface-variant), + stepper-header-selected-state-label-text-color: map.get($system, on-surface), + stepper-header-error-state-label-text-color: map.get($system, error), + stepper-header-icon-background-color: map.get($system, on-surface-variant), + stepper-header-error-state-icon-foreground-color: map.get($system, error), + stepper-header-error-state-icon-background-color: transparent) + ), + typography: ( + stepper-container-text-font: map.get($system, body-medium-font), + stepper-header-label-text-font: map.get($system, body-medium-font), + stepper-header-label-text-size: map.get($system, body-medium-size), + stepper-header-label-text-weight: map.get($system, body-medium-weight), + stepper-header-error-state-label-text-size: map.get($system, body-large-size), + stepper-header-selected-state-label-text-size: map.get($system, body-large-size), + stepper-header-selected-state-label-text-weight: map.get($system, body-large-weight), + ), + density: ( + stepper-header-height: map.get(( + 0: 72px, + -1: 68px, + -2: 64px, + -3: 60px, + -4: 42px, + ), $density-scale), + ), ); } diff --git a/src/material/stepper/_stepper-theme.scss b/src/material/stepper/_stepper-theme.scss index 9c14d341c6fc..326be2bf2040 100644 --- a/src/material/stepper/_stepper-theme.scss +++ b/src/material/stepper/_stepper-theme.scss @@ -9,7 +9,7 @@ /// for mat-stepper. /// @param {Map} $theme The theme to generate base styles for. @mixin base($theme) { - $tokens: m2-stepper.get-unthemable-tokens(); + $tokens: map.get(m2-stepper.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-stepper.get-tokens($theme), base); } @@ -21,7 +21,7 @@ /// @param {Map} $theme The theme to generate color styles for. /// @param {String} $color-variant The color variant to use for the component (M3 only) @mixin color($theme, $color-variant: null) { - $tokens: m2-stepper.get-color-tokens($theme); + $tokens: map.get(m2-stepper.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-stepper.get-tokens($theme, $color-variant), color); } @@ -42,7 +42,7 @@ } @mixin typography($theme) { - $tokens: m2-stepper.get-typography-tokens($theme); + $tokens: map.get(m2-stepper.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-stepper.get-tokens($theme), typography); } @@ -51,7 +51,7 @@ } @mixin density($theme) { - $tokens: m2-stepper.get-density-tokens($theme); + $tokens: map.get(m2-stepper.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-stepper.get-tokens($theme), density); } diff --git a/src/material/table/_m2-table.scss b/src/material/table/_m2-table.scss index 389c28768548..da8afdcbcf7b 100644 --- a/src/material/table/_m2-table.scss +++ b/src/material/table/_m2-table.scss @@ -2,73 +2,62 @@ @use '../core/theming/theming'; @use '../core/tokens/m2-utils'; -// 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 ( - table-row-item-outline-width: 1px, - ); -} - -// Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme) { - $system: m2-utils.get-system($theme); - - @return ( - table-background-color: map.get($system, surface), - table-header-headline-color: map.get($system, on-surface), - table-row-item-label-text-color: map.get($system, on-surface), - table-row-item-outline-color: map.get($system, outline), - ); -} - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - table-header-headline-font: map.get($system, label-medium-font), - table-header-headline-line-height: map.get($system, label-medium-line-height), - table-header-headline-size: map.get($system, label-medium-size), - table-header-headline-weight: map.get($system, label-medium-weight), - table-header-headline-tracking: map.get($system, label-medium-tracking), - - // Plain cells and footer cells have the same typography. - table-row-item-label-text-font: map.get($system, body-medium-font), - table-row-item-label-text-line-height: map.get($system, body-medium-line-height), - table-row-item-label-text-size: map.get($system, body-medium-size), - table-row-item-label-text-weight: map.get($system, body-medium-weight), - table-row-item-label-text-tracking: map.get($system, body-medium-tracking), - - table-footer-supporting-text-font: map.get($system, body-medium-font), - table-footer-supporting-text-line-height: map.get($system, body-medium-line-height), - table-footer-supporting-text-size: map.get($system, body-medium-size), - table-footer-supporting-text-weight: map.get($system, body-medium-weight), - table-footer-supporting-text-tracking: map.get($system, body-medium-tracking), - ); -} - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { +@function get-tokens($theme) { $system: m2-utils.get-system($theme); $density-scale: theming.clamp-density(map.get($system, density-scale), -4); - $header-scale: ( - 0: 56px, - -1: 52px, - -2: 48px, - -3: 44px, - -4: 40px - ); - $cell-scale: ( - 0: 52px, - -1: 48px, - -2: 44px, - -3: 40px, - -4: 36px - ); @return ( - table-header-container-height: map.get($header-scale, $density-scale), - table-footer-container-height: map.get($cell-scale, $density-scale), - table-row-item-container-height: map.get($cell-scale, $density-scale), + base: ( + table-row-item-outline-width: 1px, + ), + color: ( + table-background-color: map.get($system, surface), + table-header-headline-color: map.get($system, on-surface), + table-row-item-label-text-color: map.get($system, on-surface), + table-row-item-outline-color: map.get($system, outline), + ), + typography: ( + table-header-headline-font: map.get($system, label-medium-font), + table-header-headline-line-height: map.get($system, label-medium-line-height), + table-header-headline-size: map.get($system, label-medium-size), + table-header-headline-weight: map.get($system, label-medium-weight), + table-header-headline-tracking: map.get($system, label-medium-tracking), + + // Plain cells and footer cells have the same typography. + table-row-item-label-text-font: map.get($system, body-medium-font), + table-row-item-label-text-line-height: map.get($system, body-medium-line-height), + table-row-item-label-text-size: map.get($system, body-medium-size), + table-row-item-label-text-weight: map.get($system, body-medium-weight), + table-row-item-label-text-tracking: map.get($system, body-medium-tracking), + + table-footer-supporting-text-font: map.get($system, body-medium-font), + table-footer-supporting-text-line-height: map.get($system, body-medium-line-height), + table-footer-supporting-text-size: map.get($system, body-medium-size), + table-footer-supporting-text-weight: map.get($system, body-medium-weight), + table-footer-supporting-text-tracking: map.get($system, body-medium-tracking), + ), + density: ( + table-header-container-height: map.get(( + 0: 56px, + -1: 52px, + -2: 48px, + -3: 44px, + -4: 40px + ), $density-scale), + table-footer-container-height: map.get(( + 0: 52px, + -1: 48px, + -2: 44px, + -3: 40px, + -4: 36px + ), $density-scale), + table-row-item-container-height: map.get(( + 0: 52px, + -1: 48px, + -2: 44px, + -3: 40px, + -4: 36px + ), $density-scale), + ), ); } diff --git a/src/material/table/_table-theme.scss b/src/material/table/_table-theme.scss index d807bba45996..226241daa096 100644 --- a/src/material/table/_table-theme.scss +++ b/src/material/table/_table-theme.scss @@ -6,7 +6,7 @@ @use '../core/tokens/token-utils'; @mixin base($theme) { - $tokens: m2-table.get-unthemable-tokens(); + $tokens: map.get(m2-table.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-table.get-tokens($theme), base); } @@ -15,7 +15,7 @@ } @mixin color($theme) { - $tokens: m2-table.get-color-tokens($theme); + $tokens: map.get(m2-table.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-table.get-tokens($theme), color); } @@ -24,7 +24,7 @@ } @mixin typography($theme) { - $tokens: m2-table.get-typography-tokens($theme); + $tokens: map.get(m2-table.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-table.get-tokens($theme), typography); } @@ -33,7 +33,7 @@ } @mixin density($theme) { - $tokens: m2-table.get-density-tokens($theme); + $tokens: map.get(m2-table.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-table.get-tokens($theme), density); } diff --git a/src/material/tabs/_m2-tabs.scss b/src/material/tabs/_m2-tabs.scss index 93dcf4961781..85d392439a7a 100644 --- a/src/material/tabs/_m2-tabs.scss +++ b/src/material/tabs/_m2-tabs.scss @@ -3,29 +3,42 @@ @use '../core/tokens/m2-utils'; @use '../core/tokens/m3-utils'; -// Tokens that can't be configured through Angular Material's current theming API, -// but may be in a future version of the theming API. -// -// Tokens that are available in MDC, but not used in Angular Material should be mapped to `null`. -// `null` indicates that we are intentionally choosing not to emit a slot or value for the token in -// our CSS. -@function get-unthemable-tokens() { +@function get-tokens($theme) { + $system: m2-utils.get-system($theme); + $density-scale: theming.clamp-density(map.get($system, density-scale), -4); + @return ( - // This is specified both here and in the density tokens, because it determines the size of the - // tab itself and there are internal tests who don't configure the theme correctly. - tab-container-height: 48px, - // For some period of time, the MDC tabs removed the divider. This has been added back in - // and will be present in M3. - tab-divider-color: transparent, - tab-divider-height: 0, - tab-active-indicator-height: 2px, - // Currently set to zero, but used by the gmat styles to make the indicator rounded. - tab-active-indicator-shape: 0, + base: ( + // This is specified both here and in the density tokens, because it determines the size of + // the tab itself and there are internal tests who don't configure the theme correctly. + tab-container-height: 48px, + tab-divider-color: transparent, + tab-divider-height: 0, + tab-active-indicator-height: 2px, + tab-active-indicator-shape: 0, + ), + color: private-get-color-palette-color-tokens($theme, primary), + typography: ( + tab-label-text-font: map.get($system, label-small-font), + tab-label-text-size: map.get($system, label-small-size), + tab-label-text-tracking: map.get($system, label-small-tracking), + tab-label-text-line-height: map.get($system, label-small-line-height), + tab-label-text-weight: map.get($system, label-small-weight), + ), + density: ( + tab-container-height: map.get(( + 0: 48px, + -1: 44px, + -2: 40px, + -3: 36px, + -4: 32px, + ), $density-scale), + ), ); } // Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme, $color-variant, $exclude: ()) { +@function private-get-color-palette-color-tokens($theme, $color-variant, $exclude: ()) { $system: m2-utils.get-system($theme); $system: m3-utils.replace-colors-with-variant($system, primary, $color-variant); @@ -53,32 +66,3 @@ @return $tokens; } - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - // Note: MDC has equivalents of these tokens, but they lead to much higher selector specificity. - tab-label-text-font: map.get($system, label-small-font), - tab-label-text-size: map.get($system, label-small-size), - tab-label-text-tracking: map.get($system, label-small-tracking), - tab-label-text-line-height: map.get($system, label-small-line-height), - tab-label-text-weight: map.get($system, label-small-weight), - ); -} - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { - $system: m2-utils.get-system($theme); - $density-scale: theming.clamp-density(map.get($system, density-scale), -4); - - @return ( - tab-container-height: map.get(( - 0: 48px, - -1: 44px, - -2: 40px, - -3: 36px, - -4: 32px, - ), $density-scale), - ); -} diff --git a/src/material/tabs/_tabs-theme.scss b/src/material/tabs/_tabs-theme.scss index c2301d360a2c..1c3afa5f42d3 100644 --- a/src/material/tabs/_tabs-theme.scss +++ b/src/material/tabs/_tabs-theme.scss @@ -6,7 +6,7 @@ @use 'sass:map'; @mixin base($theme) { - $tokens: m2-tabs.get-unthemable-tokens(); + $tokens: map.get(m2-tabs.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-tabs.get-tokens($theme), base); } @@ -25,23 +25,23 @@ .mat-mdc-tab-group, .mat-mdc-tab-nav-bar { @include token-utils.values( - m2-tabs.get-color-tokens($theme, primary, + m2-tabs.private-get-color-palette-color-tokens($theme, primary, $exclude: (tab-background-color, tab-foreground-color))); &.mat-accent { @include token-utils.values( - m2-tabs.get-color-tokens($theme, secondary, + m2-tabs.private-get-color-palette-color-tokens($theme, secondary, $exclude: (tab-background-color, tab-foreground-color))); } &.mat-warn { @include token-utils.values( - m2-tabs.get-color-tokens($theme, error, + m2-tabs.private-get-color-palette-color-tokens($theme, error, $exclude: (tab-background-color, tab-foreground-color))); } &.mat-background-primary { - $tokens: m2-tabs.get-color-tokens($theme, primary); + $tokens: m2-tabs.private-get-color-palette-color-tokens($theme, primary); @include token-utils.values(( tab-background-color: map.get($tokens, tab-background-color), tab-foreground-color: map.get($tokens, tab-foreground-color) @@ -49,7 +49,7 @@ } &.mat-background-accent { - $tokens: m2-tabs.get-color-tokens($theme, secondary); + $tokens: m2-tabs.private-get-color-palette-color-tokens($theme, secondary); @include token-utils.values(( tab-background-color: map.get($tokens, tab-background-color), tab-foreground-color: map.get($tokens, tab-foreground-color), @@ -57,7 +57,7 @@ } &.mat-background-warn { - $tokens: m2-tabs.get-color-tokens($theme, error); + $tokens: m2-tabs.private-get-color-palette-color-tokens($theme, error); @include token-utils.values(( tab-background-color: map.get($tokens, tab-background-color), tab-foreground-color: map.get($tokens, tab-foreground-color), @@ -74,7 +74,7 @@ @include token-utils.values(map.get(m3-tabs.get-tokens($theme), typography)); } @else { .mat-mdc-tab-header { - @include token-utils.values(m2-tabs.get-typography-tokens($theme)); + @include token-utils.values(map.get(m2-tabs.get-tokens($theme), typography)); } } } @@ -86,7 +86,7 @@ @include token-utils.values(map.get(m3-tabs.get-tokens($theme), density)); } @else { .mat-mdc-tab-header { - @include token-utils.values(m2-tabs.get-density-tokens($theme)); + @include token-utils.values(map.get(m2-tabs.get-tokens($theme), density)); } } } diff --git a/src/material/timepicker/_m2-timepicker.scss b/src/material/timepicker/_m2-timepicker.scss index 5f8653081cca..d7da794d6e25 100644 --- a/src/material/timepicker/_m2-timepicker.scss +++ b/src/material/timepicker/_m2-timepicker.scss @@ -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 ( - timepicker-container-shape: 4px, - timepicker-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 ( - timepicker-container-background-color: map.get($system, surface) + base: ( + timepicker-container-shape: 4px, + timepicker-container-elevation-shadow: elevation.get-box-shadow(8), + ), + color: ( + timepicker-container-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 (); -} diff --git a/src/material/timepicker/_timepicker-theme.scss b/src/material/timepicker/_timepicker-theme.scss index 32b041b472ad..29fc4dc7348d 100644 --- a/src/material/timepicker/_timepicker-theme.scss +++ b/src/material/timepicker/_timepicker-theme.scss @@ -6,7 +6,7 @@ @use '../core/tokens/token-utils'; @mixin base($theme) { - $tokens: m2-timepicker.get-unthemable-tokens(); + $tokens: map.get(m2-timepicker.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-timepicker.get-tokens($theme), base); } @@ -15,7 +15,7 @@ } @mixin color($theme) { - $tokens: m2-timepicker.get-color-tokens($theme); + $tokens: map.get(m2-timepicker.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-timepicker.get-tokens($theme), color); } @@ -24,7 +24,7 @@ } @mixin typography($theme) { - $tokens: m2-timepicker.get-typography-tokens($theme); + $tokens: map.get(m2-timepicker.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-timepicker.get-tokens($theme), typography); } @@ -33,7 +33,7 @@ } @mixin density($theme) { - $tokens: m2-timepicker.get-density-tokens($theme); + $tokens: map.get(m2-timepicker.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-timepicker.get-tokens($theme), density); } diff --git a/src/material/toolbar/_m2-toolbar.scss b/src/material/toolbar/_m2-toolbar.scss index f877b02e63f1..cffbceff1cb6 100644 --- a/src/material/toolbar/_m2-toolbar.scss +++ b/src/material/toolbar/_m2-toolbar.scss @@ -2,54 +2,35 @@ @use '../core/theming/theming'; @use '../core/tokens/m2-utils'; -// 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 (); -} - -// Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme) { - $system: m2-utils.get-system($theme); - @return private-get-color-palette-color-tokens( - $background-color: map.get($system, surface), - $text-color: map.get($system, on-surface), - ); -} - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - toolbar-title-text-font: map.get($system, title-small-font), - toolbar-title-text-line-height: map.get($system, title-small-line-height), - toolbar-title-text-size: map.get($system, title-small-size), - toolbar-title-text-tracking: map.get($system, title-small-tracking), - toolbar-title-text-weight: map.get($system, title-small-weight), - ); -} - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { +@function get-tokens($theme) { $system: m2-utils.get-system($theme); $density-scale: theming.clamp-density(map.get($system, density-scale), -3); - $standard-scale: ( - 0: 64px, - -1: 60px, - -2: 56px, - -3: 52px, - ); - - $mobile-scale: ( - 0: 56px, - -1: 52px, - -2: 48px, - -3: 44px, - ); @return ( - toolbar-standard-height: map.get($standard-scale, $density-scale), - toolbar-mobile-height: map.get($mobile-scale, $density-scale), + base: (), + color: private-get-color-palette-color-tokens( + map.get($system, surface), map.get($system, on-surface)), + typography: ( + toolbar-title-text-font: map.get($system, title-small-font), + toolbar-title-text-line-height: map.get($system, title-small-line-height), + toolbar-title-text-size: map.get($system, title-small-size), + toolbar-title-text-tracking: map.get($system, title-small-tracking), + toolbar-title-text-weight: map.get($system, title-small-weight), + ), + density: ( + toolbar-standard-height: map.get(( + 0: 64px, + -1: 60px, + -2: 56px, + -3: 52px, + ), $density-scale), + toolbar-mobile-height: map.get(( + 0: 56px, + -1: 52px, + -2: 48px, + -3: 44px, + ), $density-scale), + ), ); } diff --git a/src/material/toolbar/_toolbar-theme.scss b/src/material/toolbar/_toolbar-theme.scss index 3ce01ac0b32d..a9663c6ba958 100644 --- a/src/material/toolbar/_toolbar-theme.scss +++ b/src/material/toolbar/_toolbar-theme.scss @@ -14,7 +14,7 @@ } @mixin base($theme) { - $tokens: m2-toolbar.get-unthemable-tokens(); + $tokens: map.get(m2-toolbar.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-toolbar.get-tokens($theme), base); } @@ -23,7 +23,7 @@ } @mixin color($theme) { - $tokens: m2-toolbar.get-color-tokens($theme); + $tokens: map.get(m2-toolbar.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-toolbar.get-tokens($theme), color); } @@ -60,7 +60,7 @@ } @mixin typography($theme) { - $tokens: m2-toolbar.get-typography-tokens($theme); + $tokens: map.get(m2-toolbar.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-toolbar.get-tokens($theme), typography); } @@ -69,7 +69,7 @@ } @mixin density($theme) { - $tokens: m2-toolbar.get-density-tokens($theme); + $tokens: map.get(m2-toolbar.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-toolbar.get-tokens($theme), density); } diff --git a/src/material/tooltip/_m2-tooltip.scss b/src/material/tooltip/_m2-tooltip.scss index 38ad2632908b..03f4822efe36 100644 --- a/src/material/tooltip/_m2-tooltip.scss +++ b/src/material/tooltip/_m2-tooltip.scss @@ -1,41 +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. -// -// Tokens that are available in MDC, but not used in Angular Material should be mapped to `null`. -// `null` indicates that we are intentionally choosing not to emit a slot or value for the token in -// our CSS. -@function get-unthemable-tokens() { - @return ( - tooltip-container-shape: 4px, - tooltip-supporting-text-line-height: 16px, - ); -} - -// 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 ( - tooltip-container-color: map.get($system, inverse-surface), - tooltip-supporting-text-color: map.get($system, inverse-on-surface), + base: ( + tooltip-container-shape: 4px, + tooltip-supporting-text-line-height: 16px, + ), + color: ( + tooltip-container-color: map.get($system, inverse-surface), + tooltip-supporting-text-color: map.get($system, inverse-on-surface), + ), + typography: ( + tooltip-supporting-text-font: map.get($system, body-small-font), + tooltip-supporting-text-size: map.get($system, body-small-size), + tooltip-supporting-text-weight: map.get($system, body-small-weight), + tooltip-supporting-text-tracking: map.get($system, body-small-tracking), + ), + 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 ( - tooltip-supporting-text-font: map.get($system, body-small-font), - tooltip-supporting-text-size: map.get($system, body-small-size), - tooltip-supporting-text-weight: map.get($system, body-small-weight), - tooltip-supporting-text-tracking: map.get($system, body-small-tracking), - ); -} - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { - @return (); -} diff --git a/src/material/tooltip/_tooltip-theme.scss b/src/material/tooltip/_tooltip-theme.scss index 9ebd3bf38370..513c292be536 100644 --- a/src/material/tooltip/_tooltip-theme.scss +++ b/src/material/tooltip/_tooltip-theme.scss @@ -6,7 +6,7 @@ @use 'sass:map'; @mixin base($theme) { - $tokens: m2-tooltip.get-unthemable-tokens(); + $tokens: map.get(m2-tooltip.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-tooltip.get-tokens($theme), base); } @@ -15,7 +15,7 @@ } @mixin color($theme) { - $tokens: m2-tooltip.get-color-tokens($theme); + $tokens: map.get(m2-tooltip.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-tooltip.get-tokens($theme), color); } @@ -24,7 +24,7 @@ } @mixin typography($theme) { - $tokens: m2-tooltip.get-typography-tokens($theme); + $tokens: map.get(m2-tooltip.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-tooltip.get-tokens($theme), typography); } @@ -33,7 +33,7 @@ } @mixin density($theme) { - $tokens: m2-tooltip.get-density-tokens($theme); + $tokens: map.get(m2-tooltip.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-tooltip.get-tokens($theme), density); } diff --git a/src/material/tree/_m2-tree.scss b/src/material/tree/_m2-tree.scss index e0944b29da4f..6d657165a5ad 100644 --- a/src/material/tree/_m2-tree.scss +++ b/src/material/tree/_m2-tree.scss @@ -2,47 +2,29 @@ @use '../core/theming/theming'; @use '../core/tokens/m2-utils'; -// 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 (); -} - -// Tokens that can be configured through Angular Material's color theming API. -@function get-color-tokens($theme) { - $system: m2-utils.get-system($theme); - - @return ( - tree-container-background-color: map.get($system, surface), - tree-node-text-color: map.get($system, on-surface), - ); -} - -// Tokens that can be configured through Angular Material's typography theming API. -@function get-typography-tokens($theme) { - $system: m2-utils.get-system($theme); - @return ( - tree-node-text-font: map.get($system, body-medium-font), - tree-node-text-size: map.get($system, body-medium-size), - tree-node-text-weight: map.get($system, body-medium-weight), - - // TODO(crisbeto): provide tokens for line height and letter spacing to match other components. - ); -} - -// Tokens that can be configured through Angular Material's density theming API. -@function get-density-tokens($theme) { +@function get-tokens($theme) { $system: m2-utils.get-system($theme); $density-scale: theming.clamp-density(map.get($system, density-scale), -4); - $min-height-scale: ( - 0: 48px, - -1: 44px, - -2: 40px, - -3: 36px, - -4: 28px, - ); @return ( - tree-node-min-height: map.get($min-height-scale, $density-scale) + base: (), + color: ( + tree-container-background-color: map.get($system, surface), + tree-node-text-color: map.get($system, on-surface), + ), + typography: ( + // TODO(crisbeto): provide tokens for line height and letter spacing + tree-node-text-font: map.get($system, body-medium-font), + tree-node-text-size: map.get($system, body-medium-size), + tree-node-text-weight: map.get($system, body-medium-weight),), + density: ( + tree-node-min-height: map.get(( + 0: 48px, + -1: 44px, + -2: 40px, + -3: 36px, + -4: 28px, + ), $density-scale) + ), ); } diff --git a/src/material/tree/_tree-theme.scss b/src/material/tree/_tree-theme.scss index 1985be922307..e17db37b896c 100644 --- a/src/material/tree/_tree-theme.scss +++ b/src/material/tree/_tree-theme.scss @@ -6,7 +6,7 @@ @use './m3-tree'; @mixin base($theme) { - $tokens: m2-tree.get-unthemable-tokens(); + $tokens: map.get(m2-tree.get-tokens($theme), base); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-tree.get-tokens($theme), base); } @@ -15,7 +15,7 @@ } @mixin color($theme) { - $tokens: m2-tree.get-color-tokens($theme); + $tokens: map.get(m2-tree.get-tokens($theme), color); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-tree.get-tokens($theme), color); } @@ -24,7 +24,7 @@ } @mixin typography($theme) { - $tokens: m2-tree.get-typography-tokens($theme); + $tokens: map.get(m2-tree.get-tokens($theme), typography); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-tree.get-tokens($theme), typography); } @@ -33,7 +33,7 @@ } @mixin density($theme) { - $tokens: m2-tree.get-density-tokens($theme); + $tokens: map.get(m2-tree.get-tokens($theme), density); @if inspection.get-theme-version($theme) == 1 { $tokens: map.get(m3-tree.get-tokens($theme), density); }