diff --git a/src/material/autocomplete/_autocomplete-theme.scss b/src/material/autocomplete/_autocomplete-theme.scss index 9e4fb8da3acb..bc05192ced75 100644 --- a/src/material/autocomplete/_autocomplete-theme.scss +++ b/src/material/autocomplete/_autocomplete-theme.scss @@ -48,7 +48,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( diff --git a/src/material/badge/_badge-theme.scss b/src/material/badge/_badge-theme.scss index 94ebf7753fcd..5b99eca35535 100644 --- a/src/material/badge/_badge-theme.scss +++ b/src/material/badge/_badge-theme.scss @@ -74,7 +74,7 @@ /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { } } diff --git a/src/material/bottom-sheet/_bottom-sheet-theme.scss b/src/material/bottom-sheet/_bottom-sheet-theme.scss index 0923513f62d8..3fc593944d06 100644 --- a/src/material/bottom-sheet/_bottom-sheet-theme.scss +++ b/src/material/bottom-sheet/_bottom-sheet-theme.scss @@ -48,7 +48,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { } } diff --git a/src/material/button-toggle/_button-toggle-theme.scss b/src/material/button-toggle/_button-toggle-theme.scss index 5313c3a1adc6..6ea99840bf34 100644 --- a/src/material/button-toggle/_button-toggle-theme.scss +++ b/src/material/button-toggle/_button-toggle-theme.scss @@ -5,6 +5,7 @@ @use '../core/tokens/token-utils'; @use '../core/typography/typography'; @use './m2-button-toggle'; +@use './m3-button-toggle'; /// Outputs base theme styles (styles not dependent on the color, typography, or density settings) /// for the mat-button-toggle. @@ -59,7 +60,8 @@ /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values( + m3-button-toggle.$prefix, m3-button-toggle.get-density-tokens($theme)); } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( @@ -97,6 +99,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-button-toggle') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/src/material/button-toggle/_m3-button-toggle.scss b/src/material/button-toggle/_m3-button-toggle.scss index cdffa5214e78..935455ef4abb 100644 --- a/src/material/button-toggle/_m3-button-toggle.scss +++ b/src/material/button-toggle/_m3-button-toggle.scss @@ -1,6 +1,9 @@ @use 'sass:map'; +@use 'sass:list'; @use '../core/style/sass-utils'; @use '../core/tokens/m3-utils'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, button-toggle); @@ -58,3 +61,13 @@ $prefix: (mat, button-toggle); @return m3-utils.namespace($prefix, ($tokens, $color-variants), $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -4); + $index: ($scale * -1) + 1; + + @return ( + height: list.nth((40px, 40px, 40px, 36px, 24px), $index), + ); +} diff --git a/src/material/button/_button-theme.scss b/src/material/button/_button-theme.scss index db74995ac807..a88abbd91180 100644 --- a/src/material/button/_button-theme.scss +++ b/src/material/button/_button-theme.scss @@ -5,6 +5,7 @@ @use '../core/tokens/token-utils'; @use '../core/typography/typography'; @use './m2-button'; +@use './m3-button'; @mixin _button-variant($theme, $palette) { $mat-tokens: if( @@ -91,7 +92,8 @@ /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values( + m3-button.$prefix, m3-button.get-density-tokens($theme)); } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( @@ -127,6 +129,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-button') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/src/material/button/_fab-theme.scss b/src/material/button/_fab-theme.scss index cf271dd93e51..a4a8e8eec768 100644 --- a/src/material/button/_fab-theme.scss +++ b/src/material/button/_fab-theme.scss @@ -3,6 +3,7 @@ @use '../core/theming/inspection'; @use '../core/theming/validation'; @use './m2-fab'; +@use './m3-fab'; @use '../core/tokens/token-utils'; @use '../core/typography/typography'; @@ -80,7 +81,7 @@ /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values(m3-fab.$prefix, m3-fab.get-density-tokens($theme)); } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( @@ -116,6 +117,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-fab') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/src/material/button/_icon-button-theme.scss b/src/material/button/_icon-button-theme.scss index 74e3470ac591..963d568b9706 100644 --- a/src/material/button/_icon-button-theme.scss +++ b/src/material/button/_icon-button-theme.scss @@ -1,6 +1,7 @@ @use 'sass:map'; @use 'sass:math'; @use './m2-icon-button'; +@use './m3-icon-button'; @use '../core/style/sass-utils'; @use '../core/tokens/token-utils'; @use '../core/theming/theming'; @@ -74,7 +75,8 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values( + m3-icon-button.$prefix, m3-icon-button.get-density-tokens($theme)); } @else { $icon-size: 24px; $density-scale: inspection.get-theme-density($theme); @@ -137,6 +139,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-icon-button') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/src/material/button/_m3-button.scss b/src/material/button/_m3-button.scss index 3dbd92645e7d..3ed296652edd 100644 --- a/src/material/button/_m3-button.scss +++ b/src/material/button/_m3-button.scss @@ -1,7 +1,10 @@ @use 'sass:map'; +@use 'sass:list'; @use '../core/tokens/m3-utils'; @use '../core/style/sass-utils'; @use '../core/style/elevation'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, button); @@ -14,7 +17,6 @@ $prefix: (mat, button); @function get-tokens($systems, $exclude-hardcoded, $token-slots) { $tokens: ( filled-container-color: map.get($systems, md-sys-color, primary), - filled-container-height: if($exclude-hardcoded, null, 40px), filled-container-shape: map.get($systems, md-sys-shape, corner-full), filled-disabled-container-color: sass-utils.safe-color-change( map.get($systems, md-sys-color, on-surface), $alpha: 0.12), @@ -37,7 +39,6 @@ $prefix: (mat, button); map.get($systems, md-sys-color, on-primary), $alpha: map.get($systems, md-sys-state, pressed-state-layer-opacity) ), filled-state-layer-color: map.get($systems, md-sys-color, on-primary), - outlined-container-height: if($exclude-hardcoded, null, 40px), outlined-container-shape: map.get($systems, md-sys-shape, corner-full), outlined-disabled-label-text-color: sass-utils.safe-color-change( map.get($systems, md-sys-color, on-surface), $alpha: 0.38), @@ -64,7 +65,6 @@ $prefix: (mat, button); outlined-state-layer-color: map.get($systems, md-sys-color, primary), protected-container-color: map.get($systems, md-sys-color, surface), protected-container-elevation-shadow: map.get($systems, md-sys-elevation, level1), - protected-container-height: if($exclude-hardcoded, null, 40px), protected-container-shape: map.get($systems, md-sys-shape, corner-full), protected-disabled-container-color: sass-utils.safe-color-change( map.get($systems, md-sys-color, on-surface), $alpha: 0.12), @@ -91,7 +91,6 @@ $prefix: (mat, button); map.get($systems, md-sys-color, primary), $alpha: map.get($systems, md-sys-state, pressed-state-layer-opacity)), protected-state-layer-color: map.get($systems, md-sys-color, primary), - text-container-height: if($exclude-hardcoded, null, 40px), text-container-shape: map.get($systems, md-sys-shape, corner-full), text-disabled-label-text-color: sass-utils.safe-color-change( map.get($systems, md-sys-color, on-surface), $alpha: 0.38), @@ -113,7 +112,6 @@ $prefix: (mat, button); text-state-layer-color: map.get($systems, md-sys-color, primary), text-with-icon-horizontal-padding: m3-utils.hardcode(16px, $exclude-hardcoded), tonal-container-color: map.get($systems, md-sys-color, secondary-container), - tonal-container-height: if($exclude-hardcoded, null, 40px), tonal-container-shape: map.get($systems, md-sys-shape, corner-full), tonal-disabled-container-color: sass-utils.safe-color-change( map.get($systems, md-sys-color, on-surface), $alpha: 0.12), @@ -241,3 +239,22 @@ $prefix: (mat, button); @return m3-utils.namespace($prefix, ($tokens, $variant-tokens), $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -3); + $index: ($scale * -1) + 1; + + @return ( + filled-touch-target-display: list.nth((block, block, none, none), $index), + filled-container-height: list.nth((40px, 36px, 32px, 28px), $index), + outlined-container-height: list.nth((40px, 36px, 32px, 28px), $index), + outlined-touch-target-display: list.nth((block, block, none, none), $index), + protected-touch-target-display: list.nth((block, block, none, none), $index), + protected-container-height: list.nth((40px, 36px, 32px, 28px), $index), + text-touch-target-display: list.nth((block, block, none, none), $index), + text-container-height: list.nth((40px, 36px, 32px, 28px), $index), + tonal-container-height: list.nth((40px, 36px, 32px, 28px), $index), + tonal-touch-target-display: list.nth((block, block, none, none), $index), + ); +} diff --git a/src/material/button/_m3-fab.scss b/src/material/button/_m3-fab.scss index e7a62c86518a..a6fd7df59006 100644 --- a/src/material/button/_m3-fab.scss +++ b/src/material/button/_m3-fab.scss @@ -1,7 +1,10 @@ @use 'sass:map'; +@use 'sass:list'; @use '../core/style/sass-utils'; @use '../core/tokens/m3-utils'; @use '../core/style/elevation'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, fab); @@ -172,3 +175,13 @@ $prefix: (mat, fab); @return m3-utils.namespace($prefix, ($tokens, $variant-tokens), $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -3); + $index: ($scale * -1) + 1; + + @return ( + touch-target-display: list.nth((block, block, none, none), $index), + ); +} diff --git a/src/material/button/_m3-icon-button.scss b/src/material/button/_m3-icon-button.scss index 18f6c89f4c09..18747ac78c7d 100644 --- a/src/material/button/_m3-icon-button.scss +++ b/src/material/button/_m3-icon-button.scss @@ -1,6 +1,9 @@ @use 'sass:map'; +@use 'sass:list'; @use '../core/tokens/m3-utils'; @use '../core/style/sass-utils'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, icon-button); @@ -24,7 +27,6 @@ $prefix: (mat, icon-button); disabled-icon-color: sass-utils.safe-color-change( map.get($systems, md-sys-color, on-surface), $alpha: 0.38), icon-size: if($exclude-hardcoded, null, 24px), - state-layer-size: if($exclude-hardcoded, null, 40px), icon-color: map.get($systems, md-sys-color, on-surface-variant), ); @@ -65,3 +67,15 @@ $prefix: (mat, icon-button); @return m3-utils.namespace($prefix, ($tokens, $variant-tokens), $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -5); + $index: ($scale * -1) + 1; + + @return ( + touch-target-display: list.nth((block, block, none, none, none, none), $index), + // The size caps out at 24px, because anything lower will be smaller than the icon. + state-layer-size: list.nth((40px, 36px, 32px, 28px, 24px, 24px), $index), + ); +} diff --git a/src/material/card/_card-theme.scss b/src/material/card/_card-theme.scss index 76551e5f7a4a..d0453b1f647c 100644 --- a/src/material/card/_card-theme.scss +++ b/src/material/card/_card-theme.scss @@ -48,7 +48,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( diff --git a/src/material/checkbox/_checkbox-theme.scss b/src/material/checkbox/_checkbox-theme.scss index 46af1b611953..f22043ff80f1 100644 --- a/src/material/checkbox/_checkbox-theme.scss +++ b/src/material/checkbox/_checkbox-theme.scss @@ -5,6 +5,7 @@ @use '../core/tokens/token-utils'; @use '../core/typography/typography'; @use './m2-checkbox'; +@use './m3-checkbox'; /// Outputs base theme styles (styles not dependent on the color, typography, or density settings) /// for the mat-checkbox. @@ -75,7 +76,8 @@ $density-scale: inspection.get-theme-density($theme); @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values( + m3-checkbox.$prefix, m3-checkbox.get-density-tokens($theme)); } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( @@ -111,6 +113,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-checkbox') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/src/material/checkbox/_m3-checkbox.scss b/src/material/checkbox/_m3-checkbox.scss index ec22a932d94b..fa1acdada71e 100644 --- a/src/material/checkbox/_m3-checkbox.scss +++ b/src/material/checkbox/_m3-checkbox.scss @@ -1,6 +1,9 @@ @use 'sass:map'; +@use 'sass:list'; @use '../core/style/sass-utils'; @use '../core/tokens/m3-utils'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, checkbox); @@ -37,7 +40,6 @@ $prefix: (mat, checkbox); selected-pressed-state-layer-color: map.get($systems, md-sys-color, on-surface), selected-pressed-state-layer-opacity: map.get($systems, md-sys-state, pressed-state-layer-opacity), - state-layer-size: if($exclude-hardcoded, null, 40px), unselected-focus-icon-color: map.get($systems, md-sys-color, on-surface), unselected-focus-state-layer-color: map.get($systems, md-sys-color, on-surface), unselected-focus-state-layer-opacity: @@ -88,3 +90,14 @@ $prefix: (mat, checkbox); @return m3-utils.namespace($prefix, ($tokens, $variant-tokens), $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -3); + $index: ($scale * -1) + 1; + + @return ( + touch-target-display: list.nth((block, block, none, none), $index), + state-layer-size: list.nth((40px, 36px, 32px, 28px), $index) + ); +} diff --git a/src/material/chips/_chips-theme.scss b/src/material/chips/_chips-theme.scss index 91ef757a0558..07b8c6f61641 100644 --- a/src/material/chips/_chips-theme.scss +++ b/src/material/chips/_chips-theme.scss @@ -1,5 +1,6 @@ @use 'sass:color'; @use './m2-chip'; +@use './m3-chip'; @use '../core/tokens/token-utils'; @use '../core/theming/theming'; @use '../core/theming/inspection'; @@ -72,7 +73,7 @@ /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values(m3-chip.$prefix, m3-chip.get-density-tokens($theme)); } @else { .mat-mdc-chip.mat-mdc-standard-chip { @include token-utils.create-token-values-mixed( @@ -107,6 +108,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-chips') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/src/material/chips/_m3-chip.scss b/src/material/chips/_m3-chip.scss index 8a460788c478..fb1344099c46 100644 --- a/src/material/chips/_m3-chip.scss +++ b/src/material/chips/_m3-chip.scss @@ -1,6 +1,9 @@ @use 'sass:map'; +@use 'sass:list'; @use '../core/style/sass-utils'; @use '../core/tokens/m3-utils'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, chip); @@ -114,3 +117,13 @@ $prefix: (mat, chip); @return m3-utils.namespace($prefix, ($tokens, $variant-tokens), $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -2); + $index: ($scale * -1) + 1; + + @return ( + container-height: list.nth((32px, 28px, 24px), $index), + ); +} diff --git a/src/material/core/_core-theme.scss b/src/material/core/_core-theme.scss index 2f425744ea24..aace526523e1 100644 --- a/src/material/core/_core-theme.scss +++ b/src/material/core/_core-theme.scss @@ -57,7 +57,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { @include option-theme.density($theme); @include optgroup-theme.density($theme); diff --git a/src/material/core/density/private/_all-density.scss b/src/material/core/density/private/_all-density.scss index d05f73adc38d..0b615d687ac1 100644 --- a/src/material/core/density/private/_all-density.scss +++ b/src/material/core/density/private/_all-density.scss @@ -1,33 +1,33 @@ -@use '../../theming/inspection'; +@use '../../../autocomplete/autocomplete-theme'; +@use '../../../button-toggle/button-toggle-theme'; @use '../../../button/button-theme'; -@use '../../../button/icon-button-theme'; @use '../../../button/fab-theme'; +@use '../../../button/icon-button-theme'; +@use '../../../card/card-theme'; +@use '../../../checkbox/checkbox-theme'; +@use '../../../chips/chips-theme'; +@use '../../../core/core-theme'; +@use '../../../dialog/dialog-theme'; @use '../../../expansion/expansion-theme'; -@use '../../../stepper/stepper-theme'; -@use '../../../toolbar/toolbar-theme'; -@use '../../../tree/tree-theme'; -@use '../../../paginator/paginator-theme'; @use '../../../form-field/form-field-theme'; -@use '../../../button-toggle/button-toggle-theme'; -@use '../../../card/card-theme'; +@use '../../../input/input-theme'; +@use '../../../list/list-theme'; +@use '../../../menu/menu-theme'; +@use '../../../paginator/paginator-theme'; @use '../../../progress-bar/progress-bar-theme'; @use '../../../progress-spinner/progress-spinner-theme'; -@use '../../../tooltip/tooltip-theme'; -@use '../../../input/input-theme'; -@use '../../../autocomplete/autocomplete-theme'; -@use '../../../checkbox/checkbox-theme'; -@use '../../../core/core-theme'; +@use '../../../radio/radio-theme'; @use '../../../select/select-theme'; -@use '../../../dialog/dialog-theme'; -@use '../../../chips/chips-theme'; @use '../../../slide-toggle/slide-toggle-theme'; -@use '../../../radio/radio-theme'; @use '../../../slider/slider-theme'; -@use '../../../menu/menu-theme'; -@use '../../../list/list-theme'; -@use '../../../tabs/tabs-theme'; @use '../../../snack-bar/snack-bar-theme'; +@use '../../../stepper/stepper-theme'; @use '../../../table/table-theme'; +@use '../../../tabs/tabs-theme'; +@use '../../../toolbar/toolbar-theme'; +@use '../../../tooltip/tooltip-theme'; +@use '../../../tree/tree-theme'; +@use '../../theming/inspection'; // Includes all of the density styles. @mixin all-component-densities($theme) { @@ -40,35 +40,35 @@ // not possible as it would introduce a circular dependency for density because the `mat-core` // mixin that is transitively loaded by the `all-theme` file, imports `all-density` which // would then load `all-theme` again. This ultimately results a circular dependency. - @include form-field-theme.density($theme); + @include autocomplete-theme.density($theme); + @include button-theme.density($theme); + @include button-toggle-theme.density($theme); @include card-theme.density($theme); + @include checkbox-theme.density($theme); + @include chips-theme.density($theme); + @include core-theme.density($theme); + @include dialog-theme.density($theme); + @include expansion-theme.density($theme); + @include fab-theme.density($theme); + @include form-field-theme.density($theme); + @include icon-button-theme.density($theme); + @include input-theme.density($theme); + @include list-theme.density($theme); + @include menu-theme.density($theme); + @include paginator-theme.density($theme); @include progress-bar-theme.density($theme); @include progress-spinner-theme.density($theme); - @include tooltip-theme.density($theme); - @include input-theme.density($theme); - @include core-theme.density($theme); + @include radio-theme.density($theme); @include select-theme.density($theme); - @include checkbox-theme.density($theme); - @include autocomplete-theme.density($theme); - @include dialog-theme.density($theme); - @include chips-theme.density($theme); @include slide-toggle-theme.density($theme); - @include radio-theme.density($theme); @include slider-theme.density($theme); - @include menu-theme.density($theme); - @include list-theme.density($theme); - @include paginator-theme.density($theme); - @include tabs-theme.density($theme); @include snack-bar-theme.density($theme); - @include button-theme.density($theme); - @include icon-button-theme.density($theme); - @include fab-theme.density($theme); - @include table-theme.density($theme); - @include expansion-theme.density($theme); @include stepper-theme.density($theme); + @include table-theme.density($theme); + @include tabs-theme.density($theme); @include toolbar-theme.density($theme); + @include tooltip-theme.density($theme); @include tree-theme.density($theme); - @include button-toggle-theme.density($theme); } diff --git a/src/material/core/option/_optgroup-theme.scss b/src/material/core/option/_optgroup-theme.scss index a0e52362f694..f0ae5befefe3 100644 --- a/src/material/core/option/_optgroup-theme.scss +++ b/src/material/core/option/_optgroup-theme.scss @@ -38,7 +38,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { } } diff --git a/src/material/core/option/_option-theme.scss b/src/material/core/option/_option-theme.scss index 564f53a681c2..edc3250c6ef4 100644 --- a/src/material/core/option/_option-theme.scss +++ b/src/material/core/option/_option-theme.scss @@ -59,7 +59,7 @@ /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { } } diff --git a/src/material/core/ripple/_ripple-theme.scss b/src/material/core/ripple/_ripple-theme.scss index 2525dda3c74a..b9def167b960 100644 --- a/src/material/core/ripple/_ripple-theme.scss +++ b/src/material/core/ripple/_ripple-theme.scss @@ -41,7 +41,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( diff --git a/src/material/core/theming/_definition.scss b/src/material/core/theming/_definition.scss index 511786869338..5b75b9faf8f2 100644 --- a/src/material/core/theming/_definition.scss +++ b/src/material/core/theming/_definition.scss @@ -121,7 +121,6 @@ $theme-version: 1; $internals: ( theme-version: $theme-version, density-scale: $density-scale, - density-tokens: m3-tokens.generate-density-tokens($density-scale) ) ); } diff --git a/src/material/core/theming/_inspection.scss b/src/material/core/theming/_inspection.scss index e0d5f57639e5..900ba77f8e06 100644 --- a/src/material/core/theming/_inspection.scss +++ b/src/material/core/theming/_inspection.scss @@ -299,6 +299,7 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac @each $system in $systems { $result: map.deep-merge($result, map.get($theme, $_internals, '#{$system}-tokens') or ()); } + @return $result; } diff --git a/src/material/core/theming/tests/theming-definition-api.spec.ts b/src/material/core/theming/tests/theming-definition-api.spec.ts index 12d95f842ddd..512fa7f8655f 100644 --- a/src/material/core/theming/tests/theming-definition-api.spec.ts +++ b/src/material/core/theming/tests/theming-definition-api.spec.ts @@ -78,7 +78,6 @@ describe('theming definition api', () => { 'typography-system-variables-prefix', 'typography-tokens', 'density-scale', - 'density-tokens', 'base-tokens', ]); expect(vars['version']).toBe('1'); @@ -169,13 +168,13 @@ describe('theming definition api', () => { scale: -2 ) )); - $data: map.get($theme, $internals); :root { - --size: #{map.get($data, density-tokens, (mat, checkbox), state-layer-size)}; + @include mat.checkbox-density($theme); } `); const vars = getRootVars(css); - expect(vars['size']).toBe('32px'); + expect(vars['mat-checkbox-touch-target-display']).toBe('none'); + expect(vars['mat-checkbox-state-layer-size']).toBe('32px'); }); it('should throw for invalid system config', () => { @@ -294,11 +293,7 @@ describe('theming definition api', () => { } `); const vars = getRootVars(css); - expect(vars['keys'].split(', ')).toEqual([ - 'theme-version', - 'density-scale', - 'density-tokens', - ]); + expect(vars['keys'].split(', ')).toEqual(['theme-version', 'density-scale']); }); }); }); diff --git a/src/material/core/tokens/BUILD.bazel b/src/material/core/tokens/BUILD.bazel index d1c472a31aff..7e91512f1b42 100644 --- a/src/material/core/tokens/BUILD.bazel +++ b/src/material/core/tokens/BUILD.bazel @@ -43,17 +43,10 @@ sass_library( deps = ["//src/material/core/m2:m2_sass"], ) -sass_library( - name = "density", - srcs = ["_density.scss"], - deps = ["//src/material/core/theming"], -) - sass_library( name = "m3_tokens", srcs = ["_m3-tokens.scss"], deps = [ - ":density", ":format_tokens", ":m2_tokens", "//src/material/autocomplete:m3", @@ -105,7 +98,6 @@ sass_library( name = "m2_tokens", srcs = ["_m2-tokens.scss"], deps = [ - ":density", ":format_tokens", "//src/material/autocomplete:m2", "//src/material/badge:m2", diff --git a/src/material/core/tokens/_density.scss b/src/material/core/tokens/_density.scss deleted file mode 100644 index 2dfa4533a6ff..000000000000 --- a/src/material/core/tokens/_density.scss +++ /dev/null @@ -1,151 +0,0 @@ -@use 'sass:list'; -@use 'sass:map'; -@use '../theming/theming'; - -/// Maps namespaced tokens to per-density-scale values. -/// This is used as a temporary solution for density, since Material Design currently does not have -/// systemized density. -/// Format: -/// ( -/// (mat, comp): ( -/// token: (, , , ...), -/// ... -/// ), -/// ... -/// ) -// TODO(mmalerba): Add density tokens for remaining components. -$_density-tokens: ( - (mat, autocomplete): (), - (mat, badge): (), - (mat, bottom-sheet): (), - (mat, card): (), - (mat, checkbox): ( - state-layer-size: (40px, 36px, 32px, 28px), - touch-target-display: (block, block, none, none), - ), - (mat, chip): ( - container-height: (32px, 28px, 24px), - ), - (mat, progress-spinner): (), - (mat, datepicker): (), - (mat, dialog): (), - (mat, divider): (), - (mat, expansion): ( - header-collapsed-state-height: (48px, 44px, 40px, 36px), - header-expanded-state-height: (64px, 60px, 56px, 48px), - ), - (mat, fab): ( - touch-target-display: (block, block, none, none), - ), - (mat, button): ( - filled-touch-target-display: (block, block, none, none), - filled-container-height: (40px, 36px, 32px, 28px), - outlined-container-height: (40px, 36px, 32px, 28px), - outlined-touch-target-display: (block, block, none, none), - protected-touch-target-display: (block, block, none, none), - protected-container-height: (40px, 36px, 32px, 28px), - text-touch-target-display: (block, block, none, none), - text-container-height: (40px, 36px, 32px, 28px), - tonal-container-height: (40px, 36px, 32px, 28px), - tonal-touch-target-display: (block, block, none, none), - ), - (mat, form-field): ( - container-height: (56px, 52px, 48px, 44px, 40px, 36px), - filled-label-display: (block, block, none, none, none, none), - container-vertical-padding: (16px, 14px, 12px, 10px, 8px, 6px), - filled-with-label-container-padding-top: (24px, 22px, 12px, 10px, 8px, 6px), - filled-with-label-container-padding-bottom: (8px, 6px, 12px, 10px, 8px, 6px), - ), - (mat, grid-list): (), - (mat, icon): (), - (mat, icon-button): ( - touch-target-display: (block, block, none, none), - // The size caps out at 24px, because anything lower will be smaller than the icon. - state-layer-size: (40px, 36px, 32px, 28px, 24px, 24px), - ), - (mat, progress-bar): (), - (mat, list): ( - list-item-leading-icon-start-space: (16px, 12px, 8px, 4px), - list-item-leading-icon-end-space: (16px, 12px, 8px, 4px), - list-item-one-line-container-height: (48px, 44px, 40px, 36px, 32px, 24px), - list-item-two-line-container-height: (64px, 60px, 56px, 52px, 48px, 48px), - list-item-three-line-container-height: (88px, 84px, 80px, 76px, 72px, 56px), - ), - (mat, menu): (), - (mat, optgroup): (), - (mat, option): (), - (mat, paginator): ( - container-size: (56px, 52px, 48px, 40px), - form-field-container-height: (40px, 40px, 40px, 40px, 40px, 36px), - form-field-container-vertical-padding: (8px, 8px, 8px, 8px, 8px, 6px), - touch-target-display: (block, block, none, none), - ), - (mat, tooltip): (), - (mat, radio): ( - touch-target-display: (block, block, none, none), - state-layer-size: (40px, 36px, 32px, 28px), - ), - (mat, ripple): (), - (mat, tab): ( - container-height: (48px, 44px, 40px, 36px, 32px), - ), - (mat, select): ( - arrow-transform: (translateY(-8px), translateY(-8px), none), - ), - (mat, sidenav): (), - (mat, slider): (), - (mat, snack-bar): (), - (mat, sort): (), - (mat, button-toggle): ( - height: (40px, 40px, 40px, 36px, 24px), - ), - (mat, stepper): ( - header-height: (72px, 68px, 64px, 60px, 42px), - ), - (mat, slide-toggle): (), - (mat, table): ( - header-container-height: (56px, 52px, 48px, 44px, 40px), - footer-container-height: (52px, 48px, 44px, 40px, 36px), - row-item-container-height: (52px, 48px, 44px, 40px, 36px), - ), - (mat, timepicker): (), - (mat, toolbar): ( - standard-height: (64px, 60px, 56px, 52px), - mobile-height: (56px, 52px, 48px, 44px), - ), - (mat, tree): ( - node-min-height: (48px, 44px, 40px, 36px, 28px), - ), -); - -/// Gets the value for the given density scale from the given set of density values. -/// @param {List} $density-values The list of values for each density scale. -/// @param {Number} $scale The density scale to get the value for. -/// @return {*} The value for the given scale. -@function _get-value-for-scale($density-values, $scale) { - $scale: theming.clamp-density($scale, -1 * list.length($density-values) + 1); - $index: -$scale + 1; - @return list.nth($density-values, $index); -} - -/// Gets a map of all density tokens for the given scale -/// @param {Number} $scale The density scale -/// @return {Map} Map of all fully qualified density tokens for the given scale. -@function get-tokens-for-scale($scale) { - $result: (); - @each $namespace, $tokens in $_density-tokens { - @each $token, $density-values in $tokens { - $tokens: map.set($tokens, $token, _get-value-for-scale($density-values, $scale)); - } - $result: map.set($result, $namespace, $tokens); - } - @return $result; -} - -/// Checks whether the given token is systemized by Angular Material's made up density system. -/// @param {List} $namespace The namespace of the token -/// @param {String} $token The name of the token -/// @return {Boolean} Whether the token is systemized by the density system -@function is-systemized($namespace, $token) { - @return map.get($_density-tokens, $namespace, $token) != null; -} diff --git a/src/material/core/tokens/_m3-system.scss b/src/material/core/tokens/_m3-system.scss index b06f76611bc9..6eb9a86c9902 100644 --- a/src/material/core/tokens/_m3-system.scss +++ b/src/material/core/tokens/_m3-system.scss @@ -1,12 +1,29 @@ +@use '../../button-toggle/m3-button-toggle'; +@use '../../button/m3-button'; +@use '../../button/m3-fab'; +@use '../../button/m3-icon-button'; +@use '../../checkbox/m3-checkbox'; +@use '../../chips/m3-chip'; +@use '../../expansion/m3-expansion'; +@use '../../form-field/m3-form-field'; +@use '../../list/m3-list'; +@use '../../paginator/m3-paginator'; +@use '../../radio/m3-radio'; +@use '../../select/m3-select'; +@use '../../stepper/m3-stepper'; +@use '../../table/m3-table'; +@use '../../tabs/m3-tabs'; +@use '../../toolbar/m3-toolbar'; +@use '../../tree/m3-tree'; @use '../style/elevation'; @use '../style/sass-utils'; @use '../theming/config-validation'; @use '../theming/definition'; @use './m3'; +@use './m3-tokens'; +@use 'sass:list'; @use 'sass:map'; @use 'sass:meta'; -@use 'sass:list'; -@use './m3-tokens'; /// Emits necessary CSS variables for Material's system level values for the values defined in the /// config map. The config map can have values color, typography, and/or density. @@ -71,12 +88,12 @@ definition.define-density((scale: $density))); $scale: map.get($density-config, _mat-theming-internals-do-not-access, density-scale); @if ($scale != 0) { - $all-tokens: m3-tokens.generate-density-tokens($scale); - @each $component-tokens in $all-tokens { - $namespace: list.nth($component-tokens, 1); - @each $tokens in list.nth($component-tokens, 2) { - --#{list.nth($namespace, 1)}-#{list.nth($namespace, 2)}-#{ - list.nth($tokens, 1)}: #{list.nth($tokens, 2)}; + // Emit component-level density tokens if the scale is lower than 0. The density tokens + // do not fallback to any system-level values and must be defined if the scale is different. + $density-tokens: get-density-tokens($scale); + @each $prefix, $tokens in $density-tokens { + @each $token-name, $token-value in $tokens { + --#{list.nth($prefix, 1)}-#{list.nth($prefix, 2)}-#{$token-name}: #{$token-value}; } } } @@ -86,6 +103,29 @@ @include system-level-state($overrides: $overrides, $prefix: definition.$system-fallback-prefix); } +// Gets all density-related tokens from the components. +@function get-density-tokens($scale) { + @return ( + m3-checkbox.$prefix: m3-checkbox.get-density-tokens($scale), + m3-chip.$prefix: m3-chip.get-density-tokens($scale), + m3-expansion.$prefix: m3-expansion.get-density-tokens($scale), + m3-fab.$prefix: m3-fab.get-density-tokens($scale), + m3-button.$prefix: m3-button.get-density-tokens($scale), + m3-form-field.$prefix: m3-form-field.get-density-tokens($scale), + m3-icon-button.$prefix: m3-icon-button.get-density-tokens($scale), + m3-list.$prefix: m3-list.get-density-tokens($scale), + m3-paginator.$prefix: m3-paginator.get-density-tokens($scale), + m3-radio.$prefix: m3-radio.get-density-tokens($scale), + m3-tabs.$prefix: m3-tabs.get-density-tokens($scale), + m3-select.$prefix: m3-select.get-density-tokens($scale), + m3-button-toggle.$prefix: m3-button-toggle.get-density-tokens($scale), + m3-stepper.$prefix: m3-stepper.get-density-tokens($scale), + m3-table.$prefix: m3-table.get-density-tokens($scale), + m3-toolbar.$prefix: m3-toolbar.get-density-tokens($scale), + m3-tree.$prefix: m3-tree.get-density-tokens($scale), + ); +} + /// Emits the system-level CSS variables for each of the provided override values. E.g. to /// change the primary color to red, use `mat.theme-overrides((primary: red));` @mixin theme-overrides($overrides, $prefix: definition.$system-fallback-prefix) { @@ -258,7 +298,6 @@ @return sass-utils.deep-merge-all( m3-tokens.generate-tokens($app-vars, true, true), - m3-tokens.generate-density-tokens(0) ); } diff --git a/src/material/core/tokens/_m3-tokens.scss b/src/material/core/tokens/_m3-tokens.scss index 69c892f21211..8ad6d8e81bf8 100644 --- a/src/material/core/tokens/_m3-tokens.scss +++ b/src/material/core/tokens/_m3-tokens.scss @@ -41,7 +41,6 @@ @use '../ripple/m3-ripple'; @use '../selection/pseudo-checkbox/m3-pseudo-checkbox'; @use '../style/sass-utils'; -@use './density'; @use './format-tokens'; @use './m2-tokens'; @use './m3'; @@ -154,16 +153,6 @@ $_cached-token-slots: null; get-m3-tokens($systems, $exclude-hardcoded, $token-slots), ); - // Strip out tokens that are systemized by our made up density system. - @each $namespace, $tokens in $result { - @each $token, $value in $tokens { - @if density.is-systemized($namespace, $token) and not $include-density { - $tokens: map.remove($tokens, $token); - } - } - $result: map.set($result, $namespace, $tokens); - } - @return $result; } @@ -387,13 +376,6 @@ $system-variables-prefix) { )); } -/// Generates a set of namespaced density tokens for all components. -/// @param {String|Number} $scale The regular font-weight -/// @return {Map} A map of namespaced density tokens -@function generate-density-tokens($scale) { - @return density.get-tokens-for-scale($scale); -} - /// Generates a set of namespaced tokens not related to color, typography, or density for all /// components. /// @return {Map} A map of namespaced tokens not related to color, typography, or density diff --git a/src/material/core/tokens/_token-utils.scss b/src/material/core/tokens/_token-utils.scss index 351c4889469e..f18ddc7123bf 100644 --- a/src/material/core/tokens/_token-utils.scss +++ b/src/material/core/tokens/_token-utils.scss @@ -198,6 +198,10 @@ $_system-fallbacks: m3-system.create-system-fallbacks(); @return (); } $values: map.get($tokens, $prefix); + @if ($values == null) { + @return (); + } + $color-variant: map.get($options, color-variant); $emit-overrides-only: map.get($options, emit-overrides-only); @if $color-variant == null { @@ -214,6 +218,7 @@ $_system-fallbacks: m3-system.create-system-fallbacks(); @error 'Invalid color variant: #{$color-variant}. #{$secondary-message}.'; } + @return if($emit-overrides-only, $overrides, map.merge($values, $overrides)); } diff --git a/src/material/datepicker/_datepicker-theme.scss b/src/material/datepicker/_datepicker-theme.scss index eba19985d1c8..fd817b98c68a 100644 --- a/src/material/datepicker/_datepicker-theme.scss +++ b/src/material/datepicker/_datepicker-theme.scss @@ -120,7 +120,7 @@ $calendar-weekday-table-font-size: 11px !default; /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { // TODO(crisbeto): move this into the structural styles // once the icon button density is switched to tokens. diff --git a/src/material/dialog/_dialog-theme.scss b/src/material/dialog/_dialog-theme.scss index 76914ee51706..fd28b6990657 100644 --- a/src/material/dialog/_dialog-theme.scss +++ b/src/material/dialog/_dialog-theme.scss @@ -43,7 +43,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { } } diff --git a/src/material/divider/_divider-theme.scss b/src/material/divider/_divider-theme.scss index 2193c1ec468c..fb079fabc028 100644 --- a/src/material/divider/_divider-theme.scss +++ b/src/material/divider/_divider-theme.scss @@ -37,7 +37,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { } } diff --git a/src/material/expansion/_expansion-theme.scss b/src/material/expansion/_expansion-theme.scss index 13d21e537a81..251fc806e543 100644 --- a/src/material/expansion/_expansion-theme.scss +++ b/src/material/expansion/_expansion-theme.scss @@ -6,6 +6,7 @@ @use '../core/style/sass-utils'; @use '../core/tokens/token-utils'; @use './m2-expansion'; +@use './m3-expansion'; @mixin base($theme) { @if inspection.get-theme-version($theme) == 1 { @@ -45,7 +46,8 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values( + m3-expansion.$prefix, m3-expansion.get-density-tokens($theme)); } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( @@ -72,6 +74,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-expansion') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme)); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/src/material/expansion/_m3-expansion.scss b/src/material/expansion/_m3-expansion.scss index 35df80c355da..f0299de8eab4 100644 --- a/src/material/expansion/_m3-expansion.scss +++ b/src/material/expansion/_m3-expansion.scss @@ -1,6 +1,9 @@ @use 'sass:map'; +@use 'sass:list'; @use '../core/style/sass-utils'; @use '../core/tokens/m3-utils'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, expansion); @@ -39,3 +42,14 @@ $prefix: (mat, expansion); @return m3-utils.namespace($prefix, $tokens, $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -3); + $index: ($scale * -1) + 1; + + @return ( + header-collapsed-state-height: list.nth((48px, 44px, 40px, 36px), $index), + header-expanded-state-height: list.nth((64px, 60px, 56px, 48px), $index), + ); +} diff --git a/src/material/form-field/_form-field-theme.scss b/src/material/form-field/_form-field-theme.scss index 0144c00b9248..bedb1810841d 100644 --- a/src/material/form-field/_form-field-theme.scss +++ b/src/material/form-field/_form-field-theme.scss @@ -1,4 +1,5 @@ @use './m2-form-field'; +@use './m3-form-field'; @use '../core/theming/theming'; @use '../core/theming/inspection'; @use '../core/theming/validation'; @@ -73,7 +74,8 @@ /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values( + m3-form-field.$prefix, m3-form-field.get-density-tokens($theme)); } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( @@ -111,6 +113,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-form-field') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/src/material/form-field/_m3-form-field.scss b/src/material/form-field/_m3-form-field.scss index c06a11b5acd6..7cc6e124feb2 100644 --- a/src/material/form-field/_m3-form-field.scss +++ b/src/material/form-field/_m3-form-field.scss @@ -1,6 +1,9 @@ @use 'sass:map'; +@use 'sass:list'; @use '../core/style/sass-utils'; @use '../core/tokens/m3-utils'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, form-field); @@ -134,3 +137,17 @@ $prefix: (mat, form-field); @return m3-utils.namespace($prefix, ($tokens, $variant-tokens), $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -5); + $index: ($scale * -1) + 1; + + @return ( + container-height: list.nth((56px, 52px, 48px, 44px, 40px, 36px), $index), + filled-label-display: list.nth((block, block, none, none, none, none), $index), + container-vertical-padding: list.nth((16px, 14px, 12px, 10px, 8px, 6px), $index), + filled-with-label-container-padding-top: list.nth((24px, 22px, 12px, 10px, 8px, 6px), $index), + filled-with-label-container-padding-bottom: list.nth((8px, 6px, 12px, 10px, 8px, 6px), $index), + ); +} diff --git a/src/material/grid-list/_grid-list-theme.scss b/src/material/grid-list/_grid-list-theme.scss index 57ecae1c983f..dfee81821281 100644 --- a/src/material/grid-list/_grid-list-theme.scss +++ b/src/material/grid-list/_grid-list-theme.scss @@ -35,7 +35,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { } } diff --git a/src/material/icon/_icon-theme.scss b/src/material/icon/_icon-theme.scss index 5c4f1a213da3..bce7c9fafa57 100644 --- a/src/material/icon/_icon-theme.scss +++ b/src/material/icon/_icon-theme.scss @@ -66,7 +66,7 @@ /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { } } diff --git a/src/material/input/_input-theme.scss b/src/material/input/_input-theme.scss index 89ea988a140c..e3448faab96d 100644 --- a/src/material/input/_input-theme.scss +++ b/src/material/input/_input-theme.scss @@ -27,7 +27,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { } } diff --git a/src/material/list/_list-theme.scss b/src/material/list/_list-theme.scss index 2f3e8ea78a34..86fcbb4f05d4 100644 --- a/src/material/list/_list-theme.scss +++ b/src/material/list/_list-theme.scss @@ -9,6 +9,7 @@ @use '../core/typography/typography'; @use '../radio/m2-radio'; @use './m2-list'; +@use './m3-list'; @mixin base($theme) { // Add default values for tokens not related to color, typography, or density. @@ -103,7 +104,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values(m3-list.$prefix, m3-list.get-density-tokens($theme)); } @else { $density-scale: inspection.get-theme-density($theme); @@ -194,6 +195,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-list') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme)); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/src/material/list/_m3-list.scss b/src/material/list/_m3-list.scss index fcd37d1aac15..4fc1ab936c2b 100644 --- a/src/material/list/_m3-list.scss +++ b/src/material/list/_m3-list.scss @@ -1,5 +1,8 @@ @use 'sass:map'; +@use 'sass:list'; @use '../core/tokens/m3-utils'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, list); @@ -50,7 +53,6 @@ $prefix: (mat, list); list-item-leading-avatar-size: if($exclude-hardcoded, null, 40px), list-item-leading-icon-color: map.get($systems, md-sys-color, on-surface-variant), list-item-leading-icon-size: if($exclude-hardcoded, null, 24px), - list-item-one-line-container-height: if($exclude-hardcoded, null, 56px), list-item-selected-trailing-icon-color: map.get($systems, md-sys-color, primary), list-item-supporting-text-color: map.get($systems, md-sys-color, on-surface-variant), list-item-supporting-text-font: map.get($systems, md-sys-typescale, body-medium-font), @@ -59,7 +61,6 @@ $prefix: (mat, list); list-item-supporting-text-size: map.get($systems, md-sys-typescale, body-medium-size), list-item-supporting-text-tracking: map.get($systems, md-sys-typescale, body-medium-tracking), list-item-supporting-text-weight: map.get($systems, md-sys-typescale, body-medium-weight), - list-item-three-line-container-height: if($exclude-hardcoded, null, 88px), list-item-trailing-icon-color: map.get($systems, md-sys-color, on-surface-variant), list-item-trailing-icon-size: if($exclude-hardcoded, null, 24px), list-item-trailing-supporting-text-color: map.get($systems, md-sys-color, on-surface-variant), @@ -71,8 +72,21 @@ $prefix: (mat, list); map.get($systems, md-sys-typescale, label-small-tracking), list-item-trailing-supporting-text-weight: map.get($systems, md-sys-typescale, label-small-weight), - list-item-two-line-container-height: if($exclude-hardcoded, null, 72px), ); @return m3-utils.namespace($prefix, $tokens, $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -5); + $index: ($scale * -1) + 1; + + @return ( + list-item-leading-icon-start-space: list.nth((16px, 12px, 8px, 4px, 4px, 4px), $index), + list-item-leading-icon-end-space: list.nth((16px, 12px, 8px, 4px, 4px, 4px), $index), + list-item-one-line-container-height: list.nth((48px, 44px, 40px, 36px, 32px, 24px), $index), + list-item-two-line-container-height: list.nth((64px, 60px, 56px, 52px, 48px, 48px), $index), + list-item-three-line-container-height: list.nth((88px, 84px, 80px, 76px, 72px, 56px), $index), + ); +} diff --git a/src/material/menu/_menu-theme.scss b/src/material/menu/_menu-theme.scss index 68c8d8c1a56d..70666842a876 100644 --- a/src/material/menu/_menu-theme.scss +++ b/src/material/menu/_menu-theme.scss @@ -42,7 +42,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { } } diff --git a/src/material/paginator/_m3-paginator.scss b/src/material/paginator/_m3-paginator.scss index ca2ad1e85995..8abc6fd5102e 100644 --- a/src/material/paginator/_m3-paginator.scss +++ b/src/material/paginator/_m3-paginator.scss @@ -1,6 +1,9 @@ @use 'sass:map'; +@use 'sass:list'; @use '../core/style/sass-utils'; @use '../core/tokens/m3-utils'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, paginator); @@ -25,3 +28,16 @@ $prefix: (mat, paginator); @return m3-utils.namespace($prefix, $tokens, $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -5); + $index: ($scale * -1) + 1; + + @return ( + container-size: list.nth((56px, 52px, 48px, 40px, 40px, 40px), $index), + form-field-container-height: list.nth((40px, 40px, 40px, 40px, 40px, 36px), $index), + form-field-container-vertical-padding: list.nth((8px, 8px, 8px, 8px, 8px, 6px), $index), + touch-target-display: list.nth((block, block, none, none, none, none), $index), + ); +} diff --git a/src/material/paginator/_paginator-theme.scss b/src/material/paginator/_paginator-theme.scss index 887ddd382ad3..af9dd4817270 100644 --- a/src/material/paginator/_paginator-theme.scss +++ b/src/material/paginator/_paginator-theme.scss @@ -1,6 +1,7 @@ @use 'sass:map'; @use 'sass:meta'; @use './m2-paginator'; +@use './m3-paginator'; @use '../core/style/sass-utils'; @use '../core/typography/typography'; @use '../core/theming/theming'; @@ -47,7 +48,8 @@ ); @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values( + m3-paginator.$prefix, m3-paginator.get-density-tokens($theme)); } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( @@ -74,6 +76,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-paginator') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme)); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/src/material/radio/_m3-radio.scss b/src/material/radio/_m3-radio.scss index b1f01204edf8..243ebfa469c7 100644 --- a/src/material/radio/_m3-radio.scss +++ b/src/material/radio/_m3-radio.scss @@ -1,6 +1,9 @@ @use 'sass:map'; +@use 'sass:list'; @use '../core/style/sass-utils'; @use '../core/tokens/m3-utils'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, radio); @@ -30,7 +33,6 @@ $prefix: (mat, radio); selected-hover-icon-color: map.get($systems, md-sys-color, primary), selected-icon-color: map.get($systems, md-sys-color, primary), selected-pressed-icon-color: map.get($systems, md-sys-color, primary), - state-layer-size: if($exclude-hardcoded, null, 40px), unselected-focus-icon-color: map.get($systems, md-sys-color, on-surface), unselected-hover-icon-color: map.get($systems, md-sys-color, on-surface), unselected-icon-color: map.get($systems, md-sys-color, on-surface-variant), @@ -64,3 +66,14 @@ $prefix: (mat, radio); @return m3-utils.namespace($prefix, ($tokens, $variant-tokens), $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -3); + $index: ($scale * -1) + 1; + + @return ( + touch-target-display: list.nth((block, block, none, none), $index), + state-layer-size: list.nth((40px, 36px, 32px, 28px), $index), + ); +} diff --git a/src/material/radio/_radio-theme.scss b/src/material/radio/_radio-theme.scss index ac4d40e166b0..ea6be9874ee7 100644 --- a/src/material/radio/_radio-theme.scss +++ b/src/material/radio/_radio-theme.scss @@ -5,6 +5,7 @@ @use '../core/tokens/token-utils'; @use '../core/typography/typography'; @use './m2-radio'; +@use './m3-radio'; /// Outputs base theme styles (styles not dependent on the color, typography, or density settings) /// for the mat-radio. @@ -73,7 +74,7 @@ /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values(m3-radio.$prefix, m3-radio.get-density-tokens($theme)); } @else { $density-scale: inspection.get-theme-density($theme); @@ -111,6 +112,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-radio') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/src/material/select/_m3-select.scss b/src/material/select/_m3-select.scss index 263364b013dd..3f760aaedd15 100644 --- a/src/material/select/_m3-select.scss +++ b/src/material/select/_m3-select.scss @@ -1,7 +1,10 @@ @use 'sass:map'; +@use 'sass:list'; @use '../core/style/sass-utils'; @use '../core/style/elevation'; @use '../core/tokens/m3-utils'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, select); @@ -46,3 +49,13 @@ $prefix: (mat, select); @return m3-utils.namespace($prefix, ($tokens, $variant-tokens), $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -2); + $index: ($scale * -1) + 1; + + @return ( + arrow-transform: list.nth((translateY(-8px), translateY(-8px), none), $index), + ); +} diff --git a/src/material/select/_select-theme.scss b/src/material/select/_select-theme.scss index 096973d132ea..9f8f091425cb 100644 --- a/src/material/select/_select-theme.scss +++ b/src/material/select/_select-theme.scss @@ -5,6 +5,7 @@ @use '../core/tokens/token-utils'; @use '../core/typography/typography'; @use './m2-select'; +@use './m3-select'; /// Outputs base theme styles (styles not dependent on the color, typography, or density settings) /// for the mat-select. @@ -71,7 +72,8 @@ /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values( + m3-select.$prefix, m3-select.get-density-tokens($theme)); } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( @@ -107,6 +109,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-select') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/src/material/sidenav/_sidenav-theme.scss b/src/material/sidenav/_sidenav-theme.scss index ad5872fb778b..46cc171b42a0 100644 --- a/src/material/sidenav/_sidenav-theme.scss +++ b/src/material/sidenav/_sidenav-theme.scss @@ -37,7 +37,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { } } diff --git a/src/material/slide-toggle/_slide-toggle-theme.scss b/src/material/slide-toggle/_slide-toggle-theme.scss index a01513c3ea57..e590d8f52fb2 100644 --- a/src/material/slide-toggle/_slide-toggle-theme.scss +++ b/src/material/slide-toggle/_slide-toggle-theme.scss @@ -119,7 +119,7 @@ /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { @include sass-utils.current-selector-or-root() { // TODO: See if this can be removed diff --git a/src/material/slider/_slider-theme.scss b/src/material/slider/_slider-theme.scss index 9c500dcca421..98d1b686b8ac 100644 --- a/src/material/slider/_slider-theme.scss +++ b/src/material/slider/_slider-theme.scss @@ -63,7 +63,7 @@ /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( diff --git a/src/material/sort/_sort-theme.scss b/src/material/sort/_sort-theme.scss index 8ba1b069eac4..b27aa8722189 100644 --- a/src/material/sort/_sort-theme.scss +++ b/src/material/sort/_sort-theme.scss @@ -38,7 +38,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( diff --git a/src/material/stepper/_m3-stepper.scss b/src/material/stepper/_m3-stepper.scss index 09ecd961e1d8..1bb9f5595d79 100644 --- a/src/material/stepper/_m3-stepper.scss +++ b/src/material/stepper/_m3-stepper.scss @@ -1,6 +1,9 @@ @use 'sass:map'; +@use 'sass:list'; @use '../core/style/sass-utils'; @use '../core/tokens/m3-utils'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, stepper); @@ -77,3 +80,13 @@ $prefix: (mat, stepper); @return m3-utils.namespace($prefix, ($tokens, $variant-tokens), $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -4); + $index: ($scale * -1) + 1; + + @return ( + header-height: list.nth((72px, 68px, 64px, 60px, 42px), $index), + ); +} diff --git a/src/material/stepper/_stepper-theme.scss b/src/material/stepper/_stepper-theme.scss index 3bc2d3f53fda..924facb0acd2 100644 --- a/src/material/stepper/_stepper-theme.scss +++ b/src/material/stepper/_stepper-theme.scss @@ -5,6 +5,7 @@ @use '../core/style/sass-utils'; @use '../core/tokens/token-utils'; @use './m2-stepper'; +@use './m3-stepper'; /// Outputs base theme styles (styles not dependent on the color, typography, or density settings) /// for mat-stepper. @@ -67,7 +68,8 @@ /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values( + m3-stepper.$prefix, m3-stepper.get-density-tokens($theme)); } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( @@ -103,6 +105,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-stepper') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/src/material/table/_m3-table.scss b/src/material/table/_m3-table.scss index cec7d081f7e6..8d22e8722170 100644 --- a/src/material/table/_m3-table.scss +++ b/src/material/table/_m3-table.scss @@ -1,6 +1,9 @@ @use 'sass:map'; +@use 'sass:list'; @use '../core/style/sass-utils'; @use '../core/tokens/m3-utils'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, table); @@ -27,3 +30,15 @@ $prefix: (mat, table); @return m3-utils.namespace($prefix, $tokens, $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -4); + $index: ($scale * -1) + 1; + + @return ( + header-container-height: list.nth((56px, 52px, 48px, 44px, 40px), $index), + footer-container-height: list.nth((52px, 48px, 44px, 40px, 36px), $index), + row-item-container-height: list.nth((52px, 48px, 44px, 40px, 36px), $index), + ); +} diff --git a/src/material/table/_table-theme.scss b/src/material/table/_table-theme.scss index 3189a304ec57..29c2cfa6a738 100644 --- a/src/material/table/_table-theme.scss +++ b/src/material/table/_table-theme.scss @@ -1,5 +1,6 @@ @use 'sass:map'; @use './m2-table'; +@use './m3-table'; @use '../core/theming/theming'; @use '../core/theming/inspection'; @use '../core/theming/validation'; @@ -42,7 +43,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values(m3-table.$prefix, m3-table.get-density-tokens($theme)); } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( @@ -69,6 +70,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-table') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme)); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/src/material/tabs/_m3-tabs.scss b/src/material/tabs/_m3-tabs.scss index 3f277bba4961..db91da546ea8 100644 --- a/src/material/tabs/_m3-tabs.scss +++ b/src/material/tabs/_m3-tabs.scss @@ -1,6 +1,9 @@ @use '../core/tokens/m3-utils'; @use '../core/style/sass-utils'; @use 'sass:map'; +@use 'sass:list'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, tab); @@ -23,7 +26,6 @@ $prefix: (mat, tab); active-indicator-shape: m3-utils.hardcode(0, $exclude-hardcoded), active-label-text-color: map.get($systems, md-sys-color, on-surface), active-ripple-color: map.get($systems, md-sys-color, on-surface), - container-height: if($exclude-hardcoded, null, 48px), divider-color: map.get($systems, md-sys-color, surface-variant), divider-height: m3-utils.hardcode(1px, $exclude-hardcoded), inactive-focus-label-text-color: map.get($systems, md-sys-color, on-surface), @@ -56,3 +58,13 @@ $prefix: (mat, tab); @return m3-utils.namespace($prefix, ($tokens, $variant-tokens), $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -4); + $index: ($scale * -1) + 1; + + @return ( + container-height: list.nth((48px, 44px, 40px, 36px, 32px), $index), + ); +} diff --git a/src/material/tabs/_tabs-theme.scss b/src/material/tabs/_tabs-theme.scss index b612d72b438a..dd87a7bcc104 100644 --- a/src/material/tabs/_tabs-theme.scss +++ b/src/material/tabs/_tabs-theme.scss @@ -1,5 +1,6 @@ @use '../core/style/sass-utils'; @use './m2-tabs'; +@use './m3-tabs'; @use '../core/theming/theming'; @use '../core/theming/inspection'; @use '../core/theming/validation'; @@ -95,7 +96,7 @@ /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values(m3-tabs.$prefix, m3-tabs.get-density-tokens($theme)); } @else { .mat-mdc-tab-header { @include token-utils.create-token-values-mixed( @@ -129,6 +130,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-tabs') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme), $options...); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/src/material/timepicker/_timepicker-theme.scss b/src/material/timepicker/_timepicker-theme.scss index b9df0d896fd8..ae76f7aba02e 100644 --- a/src/material/timepicker/_timepicker-theme.scss +++ b/src/material/timepicker/_timepicker-theme.scss @@ -60,7 +60,7 @@ /// @param {Map} $theme The theme to generate density styles for. @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( diff --git a/src/material/toolbar/_m3-toolbar.scss b/src/material/toolbar/_m3-toolbar.scss index e1d58cf3b394..08ab80368650 100644 --- a/src/material/toolbar/_m3-toolbar.scss +++ b/src/material/toolbar/_m3-toolbar.scss @@ -1,6 +1,9 @@ @use 'sass:map'; +@use 'sass:list'; @use '../core/style/sass-utils'; @use '../core/tokens/m3-utils'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, toolbar); @@ -21,3 +24,14 @@ $prefix: (mat, toolbar); @return m3-utils.namespace($prefix, $tokens, $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -3); + $index: ($scale * -1) + 1; + + @return ( + standard-height: list.nth((64px, 60px, 56px, 52px), $index), + mobile-height: list.nth((56px, 52px, 48px, 44px), $index), + ); +} diff --git a/src/material/toolbar/_toolbar-theme.scss b/src/material/toolbar/_toolbar-theme.scss index 73d992afb2eb..cca9e3c9e26a 100644 --- a/src/material/toolbar/_toolbar-theme.scss +++ b/src/material/toolbar/_toolbar-theme.scss @@ -6,6 +6,7 @@ @use '../core/tokens/token-utils'; @use '../core/typography/typography'; @use './m2-toolbar'; +@use './m3-toolbar'; @mixin _palette-styles($theme, $palette-name) { @include token-utils.create-token-values-mixed( @@ -65,7 +66,8 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values( + m3-toolbar.$prefix, m3-toolbar.get-density-tokens($theme)); } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( @@ -96,6 +98,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-toolbar') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme)); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/src/material/tooltip/_tooltip-theme.scss b/src/material/tooltip/_tooltip-theme.scss index 70a0a9de6a51..df629ea41c40 100644 --- a/src/material/tooltip/_tooltip-theme.scss +++ b/src/material/tooltip/_tooltip-theme.scss @@ -48,7 +48,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + // There are no M3 density tokens for this component } @else { @include sass-utils.current-selector-or-root() { @include token-utils.create-token-values-mixed( diff --git a/src/material/tree/_m3-tree.scss b/src/material/tree/_m3-tree.scss index 3fc9221b3faf..7fb28ab600c7 100644 --- a/src/material/tree/_m3-tree.scss +++ b/src/material/tree/_m3-tree.scss @@ -1,5 +1,8 @@ @use 'sass:map'; +@use 'sass:list'; @use '../core/tokens/m3-utils'; +@use '../core/theming/theming'; +@use '../core/theming/inspection'; // The prefix used to generate the fully qualified name for tokens in this file. $prefix: (mat, tree); @@ -20,3 +23,13 @@ $prefix: (mat, tree); @return m3-utils.namespace($prefix, $tokens, $token-slots); } + +// Tokens that can be configured through Angular Material's density theming API. +@function get-density-tokens($theme) { + $scale: theming.clamp-density(inspection.get-theme-density($theme), -4); + $index: ($scale * -1) + 1; + + @return ( + node-min-height: list.nth((48px, 44px, 40px, 36px, 28px), $index), + ); +} diff --git a/src/material/tree/_tree-theme.scss b/src/material/tree/_tree-theme.scss index 0a53ce4d4870..70671db570c1 100644 --- a/src/material/tree/_tree-theme.scss +++ b/src/material/tree/_tree-theme.scss @@ -6,6 +6,7 @@ @use '../core/style/sass-utils'; @use '../core/tokens/token-utils'; @use './m2-tree'; +@use './m3-tree'; @mixin base($theme) { @if inspection.get-theme-version($theme) == 1 { @@ -45,7 +46,7 @@ @mixin density($theme) { @if inspection.get-theme-version($theme) == 1 { - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); + @include token-utils.create-token-values(m3-tree.$prefix, m3-tree.get-density-tokens($theme)); } @else { $density-scale: inspection.get-theme-density($theme); @@ -76,6 +77,9 @@ @include theming.private-check-duplicate-theme-styles($theme, 'mat-tree') { @if inspection.get-theme-version($theme) == 1 { @include _theme-from-tokens(inspection.get-theme-tokens($theme)); + @if inspection.theme-has($theme, density) { + @include density($theme); + } } @else { @include base($theme); @if inspection.theme-has($theme, color) { diff --git a/tools/extract-tokens/extract-tokens.ts b/tools/extract-tokens/extract-tokens.ts index 7611a0851e55..8ada0a9fd7bb 100644 --- a/tools/extract-tokens/extract-tokens.ts +++ b/tools/extract-tokens/extract-tokens.ts @@ -203,6 +203,7 @@ function getTokenExtractionCode( const str = '__privateSassString'; const stringJoin = '__privateStringJoin'; const m3Tokens = '___privateM3Tokens'; + const m3System = '___privateM3System'; const palettes = '___privatePalettes'; const sassUtils = '__privateSassUtils'; const inferTokenType = '__privateInferFromValue'; @@ -216,6 +217,7 @@ function getTokenExtractionCode( @use 'sass:math' as ${math}; @use 'sass:string' as ${str}; @use '${join(corePath, 'tokens/m3-tokens')}' as ${m3Tokens}; + @use '${join(corePath, 'tokens/m3-system')}' as ${m3System}; @use '${join(corePath, 'theming/palettes')}' as ${palettes}; @use '${join(corePath, 'style/sass-utils')}' as ${sassUtils}; @@ -233,7 +235,7 @@ function getTokenExtractionCode( $__all-color: ${m3Tokens}.generate-color-tokens(light, ${palettes}.$azure-palette, ${palettes}.$azure-palette, ${palettes}.$azure-palette, 'mat-sys'); $__all-typography: ${m3Tokens}.generate-typography-tokens(font, 100, 100, 100, 100, 'mat-sys'); - $__all-density: ${m3Tokens}.generate-density-tokens(0); + $__all-density: ${m3System}.get-density-tokens(0); $__all-base: ${m3Tokens}.generate-base-tokens(); $__results: (); $__override-tokens: ${defineOverrides}(); @@ -290,7 +292,7 @@ function getTokenExtractionCode( $color: ${map}.get($__all-color, $namespace) or (); $base: ${map}.get($__all-base, $namespace) or (); $typography: ${map}.get($__all-typography, $namespace) or (); - $density: ${map}.get($__all-density, $namespace) or (); + $density: ${map}.get($__all-density, $namespace) or ();\ @each $name, $resolved-value in $tokens { $color-value: ${map}.get($color, $name); @@ -301,18 +303,18 @@ function getTokenExtractionCode( $type: ''; $value: null; - @if ($base-value) { - $type: base; - $value: $base-value; + @if ($density-value) { + $type: density; + $value: $density-value; } @else if ($typography-value) { $type: typography; $value: $typography-value; - } @else if ($density-value) { - $type: density; - $value: $density-value; - } @else { + } @else if ($color-value) { $type: color; $value: $color-value; + } @else { + $type: base; + $value: $base-value; } // If the token has a value, but could not be found in the token maps, try to infer its type