From f90aab27b4fa497ab6d320b7caa4c1e569d7d00b Mon Sep 17 00:00:00 2001 From: Elizabeth Mitchell Date: Tue, 21 Mar 2023 11:22:12 -0700 Subject: [PATCH] fix(button): enable separate color and opacity tokens PiperOrigin-RevId: 518329426 --- button/lib/_elevated-button.scss | 1 - button/lib/_filled-button.scss | 1 - button/lib/_icon.scss | 1 + button/lib/_outlined-button.scss | 2 +- button/lib/_shared.scss | 46 +++++++++++++------------------- button/lib/_text-button.scss | 1 - button/lib/_tonal-button.scss | 1 - 7 files changed, 20 insertions(+), 33 deletions(-) diff --git a/button/lib/_elevated-button.scss b/button/lib/_elevated-button.scss index 16e1e4eb26..bcbe273443 100644 --- a/button/lib/_elevated-button.scss +++ b/button/lib/_elevated-button.scss @@ -49,7 +49,6 @@ $_custom-property-prefix: 'elevated-button'; } @function _resolve-tokens($tokens) { - $tokens: shared.flatten-disabled-colors($tokens); $tokens: shared.remove-unsupported-tokens($tokens); @return $tokens; } diff --git a/button/lib/_filled-button.scss b/button/lib/_filled-button.scss index 9ff325f36c..d4beb0e188 100644 --- a/button/lib/_filled-button.scss +++ b/button/lib/_filled-button.scss @@ -48,7 +48,6 @@ $_custom-property-prefix: 'filled-button'; } @function _resolve-tokens($tokens) { - $tokens: shared.flatten-disabled-colors($tokens); $tokens: shared.remove-unsupported-tokens($tokens); @return $tokens; } diff --git a/button/lib/_icon.scss b/button/lib/_icon.scss index f774760048..2ac3dc4434 100644 --- a/button/lib/_icon.scss +++ b/button/lib/_icon.scss @@ -36,6 +36,7 @@ .md3-button:disabled & { color: var(--_with-icon-disabled-icon-color); + opacity: var(--_with-icon-disabled-icon-opacity); } } } diff --git a/button/lib/_outlined-button.scss b/button/lib/_outlined-button.scss index ac025b236f..24f3f5198c 100644 --- a/button/lib/_outlined-button.scss +++ b/button/lib/_outlined-button.scss @@ -66,6 +66,7 @@ $_custom-property-prefix: 'outlined-button'; .md3-button:disabled & { border-color: var(--_disabled-outline-color); + opacity: var(--_disabled-outline-opacity); } } @@ -83,7 +84,6 @@ $_custom-property-prefix: 'outlined-button'; } @function _resolve-tokens($tokens) { - $tokens: shared.flatten-disabled-colors($tokens); $tokens: shared.remove-unsupported-tokens($tokens); @return $tokens; } diff --git a/button/lib/_shared.scss b/button/lib/_shared.scss index a99111491d..a7bc16a280 100644 --- a/button/lib/_shared.scss +++ b/button/lib/_shared.scss @@ -12,7 +12,6 @@ // go/keep-sorted start @use '../../focus/focus-ring'; @use '../../ripple/ripple'; -@use '../../sass/color'; @use '../../sass/dom'; @use '../../sass/shape'; // go/keep-sorted end @@ -70,13 +69,21 @@ z-index: 0; // Place content on top of elevation and ripple block-size: var(--_container-height); font: var(--_label-text-type); - background-color: var(--_container-color); color: var(--_label-text-color); // TODO(b/181413732): Verify token below are named correctly padding-inline-start: var(--_spacing-leading); padding-inline-end: var(--_spacing-trailing); gap: 8px; + &::before { + // Background color. Separate node for disabled opacity styles. + background-color: var(--_container-color); + border-radius: inherit; + content: ''; + inset: 0; + position: absolute; + } + &::-moz-focus-inner { padding: 0; border: 0; @@ -96,9 +103,14 @@ outline: none; } - &:disabled { - background-color: var(--_disabled-container-color); + &:disabled .md3-button__label { color: var(--_disabled-label-text-color); + opacity: var(--_disabled-label-text-opacity); + } + + &:disabled::before { + background-color: var(--_disabled-container-color); + opacity: var(--_disabled-container-opacity); } @media (forced-colors: active) { @@ -116,6 +128,8 @@ border-end-end-radius: var(--_container-shape-end-end); } + .md3-button::after, + .md3-button::before, md-elevation, .md3-button__ripple { z-index: -1; // Place behind content @@ -137,30 +151,6 @@ } } -@function flatten-disabled-colors($tokens) { - @return color.join-color-and-opacity-pairs( - $tokens, - ( - ( - color-key: 'disabled-container-color', - opacity-key: 'disabled-container-opacity' - ), - ( - color-key: 'disabled-label-text-color', - opacity-key: 'disabled-label-text-opacity' - ), - ( - color-key: 'with-icon-disabled-icon-color', - opacity-key: 'with-icon-disabled-icon-opacity' - ), - ( - color-key: 'disabled-outline-color', - opacity-key: 'disabled-outline-opacity' - ) - ) - ); -} - @function remove-unsupported-tokens($tokens) { // b/193825150: Text and Outlined Button don't have `container-shadow-color`, // leaving `container-elevation` useless. diff --git a/button/lib/_text-button.scss b/button/lib/_text-button.scss index 26aec46225..293184d413 100644 --- a/button/lib/_text-button.scss +++ b/button/lib/_text-button.scss @@ -56,7 +56,6 @@ $_custom-property-prefix: 'text-button'; 'disabled-container-color', 'disabled-container-opacity' ); - $tokens: shared.flatten-disabled-colors($tokens); $tokens: shared.remove-unsupported-tokens($tokens); @return $tokens; } diff --git a/button/lib/_tonal-button.scss b/button/lib/_tonal-button.scss index 47ec4117ae..f2cf062128 100644 --- a/button/lib/_tonal-button.scss +++ b/button/lib/_tonal-button.scss @@ -48,7 +48,6 @@ $_custom-property-prefix: 'tonal-button'; } @function _resolve-tokens($tokens) { - $tokens: shared.flatten-disabled-colors($tokens); $tokens: shared.remove-unsupported-tokens($tokens); @return $tokens; }