Skip to content

refactor(material/button): switch flat-button to density tokens #27797

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/material/button/_button-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,13 @@
@include button-theme-private.touch-target-density($density-scale);
}

.mat-mdc-unelevated-button {
$density-tokens: tokens-mdc-button-filled.get-density-tokens($theme);
@include mdc-button-filled-theme.theme($density-tokens);
@include button-theme-private.touch-target-density($density-scale);
}

.mat-mdc-button,
.mat-mdc-unelevated-button,
.mat-mdc-outlined-button {
// Use `mat-mdc-button-base` to increase the specificity over the button's structural styles.
&.mat-mdc-button-base {
Expand Down
22 changes: 19 additions & 3 deletions src/material/core/tokens/m2/mdc/_button-filled.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@use 'sass:map';
@use '../../token-utils';
@use '../../../mdc-helpers/mdc-helpers';
@use '../../../style/sass-utils';
@use '../../../theming/inspection';
@use '../../../theming/theming';

// The prefix used to generate the fully qualified name for tokens in this file.
$prefix: (mdc, button-filled);
Expand All @@ -14,15 +16,16 @@ $prefix: (mdc, button-filled);
// our CSS.
@function get-unthemable-tokens() {
@return (
container-elevation: 0,
container-height: 36px,
container-shape: 4px,
container-elevation: 0,
disabled-container-elevation: 0,
focus-container-elevation: 0,
hover-container-elevation: 0,
keep-touch-target: false,
pressed-container-elevation: 0,

focus-ring-color: null,
focus-ring-offset: null,
focus-state-layer-opacity: null,
hover-state-layer-opacity: null,
pressed-state-layer-opacity: null,
Expand Down Expand Up @@ -77,7 +80,20 @@ $prefix: (mdc, button-filled);

// Tokens that can be configured through Angular Material's density theming API.
@function get-density-tokens($theme) {
@return ();
$scale: theming.clamp-density(inspection.get-theme-density($theme), -3);

@return (
container-height:
map.get(
(
0: 36px,
-1: 32px,
-2: 28px,
-3: 24px,
),
$scale
)
);
}

// Combines the tokens generated by the above functions into a single map with placeholder values.
Expand Down
6 changes: 4 additions & 2 deletions src/material/core/tokens/tests/test-validate-tokens.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@use 'sass:map';

@use '@material/button/button-protected-theme' as mdc-button-protected-theme;
@use '@material/button/button-filled-theme' as mdc-button-filled-theme;
@use '@material/card/elevated-card-theme' as mdc-elevated-card-theme;
@use '@material/card/outlined-card-theme' as mdc-outlined-card-theme;
@use '@material/checkbox/checkbox-theme' as mdc-checkbox-theme;
Expand All @@ -25,6 +26,7 @@
@use '@material/theme/validate' as mdc-validate;

@use '../m2/mdc/button-protected' as tokens-mdc-button-protected;
@use '../m2/mdc/button-filled' as tokens-mdc-button-filled;
@use '../m2/mdc/circular-progress' as tokens-mdc-circular-progress;
@use '../m2/mdc/linear-progress' as tokens-mdc-linear-progress;
@use '../m2/mdc/elevated-card' as tokens-mdc-elevated-card;
Expand Down Expand Up @@ -160,8 +162,8 @@
);
@include validate-slots(
$component: 'm2.mdc.button-filled',
$slots: tokens-mdc-extended-fab.get-token-slots(),
$reference: mdc-extended-fab-theme.$extended-light-theme
$slots: tokens-mdc-button-filled.get-token-slots(),
$reference: mdc-button-filled-theme.$light-theme
);
@include validate-slots(
$component: 'm2.mdc.button-protected',
Expand Down