Skip to content

Commit

Permalink
fix(button): enable separate color and opacity tokens
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 518329426
  • Loading branch information
asyncLiz authored and copybara-github committed Mar 21, 2023
1 parent 324e856 commit f90aab2
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 33 deletions.
1 change: 0 additions & 1 deletion button/lib/_elevated-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 0 additions & 1 deletion button/lib/_filled-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions button/lib/_icon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

.md3-button:disabled & {
color: var(--_with-icon-disabled-icon-color);
opacity: var(--_with-icon-disabled-icon-opacity);
}
}
}
2 changes: 1 addition & 1 deletion button/lib/_outlined-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ $_custom-property-prefix: 'outlined-button';

.md3-button:disabled & {
border-color: var(--_disabled-outline-color);
opacity: var(--_disabled-outline-opacity);
}
}

Expand All @@ -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;
}
46 changes: 18 additions & 28 deletions button/lib/_shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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.
Expand Down
1 change: 0 additions & 1 deletion button/lib/_text-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 0 additions & 1 deletion button/lib/_tonal-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit f90aab2

Please sign in to comment.