Skip to content

Commit 6b623b8

Browse files
committed
fix(button-toggle): use solid border color
Usually the theme divider color is rgba, which means that it can look differently, depending on the color behind it. As a result, the border of a selected button toggle is different from a deselected one, because its background color is darker. These changes switch to using a solid color to ensure that we have always have a consistent border. These changes also add a new theming utility function that converts an rgba color to hex, if the consumer knows the background. We've been using it in a couple of places already, but now it's being moved out into a reusable function.
1 parent aff565a commit 6b623b8

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

src/lib/badge/_badge-theme.scss

+4-5
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,16 @@ $mat-badge-large-size: $mat-badge-default-size + 6;
130130

131131
.mat-badge-disabled {
132132
.mat-badge-content {
133-
$app-background: mat-color($background, 'background');
134-
$badge-color: mat-color($foreground, disabled-button);
135-
136133
// The disabled color usually has some kind of opacity, but because the badge is overlayed
137134
// on top of something else, it won't look good if it's opaque. If it is a color *type*,
138135
// we convert it into a solid color by taking the opacity from the rgba value and using
139136
// the value to determine the percentage of the background to put into foreground when
140137
// mixing the colors together.
138+
$badge-color: mat-color($foreground, disabled-button);
139+
$app-background: mat-color($background, 'background');
140+
141141
@if (type-of($badge-color) == color and type-of($app-background) == color) {
142-
$badge-opacity: opacity($badge-color);
143-
background: mix($app-background, rgba($badge-color, 1), (1 - $badge-opacity) * 100%);
142+
background: mat-rgba-to-hex($badge-color, $app-background);
144143
}
145144
@else {
146145
background: $badge-color;

src/lib/button-toggle/_button-toggle-theme.scss

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
@mixin mat-button-toggle-theme($theme) {
77
$foreground: map-get($theme, foreground);
88
$background: map-get($theme, background);
9-
$divider-color: mat-color($foreground, divider);
9+
$theme-divider-color: mat-color($foreground, divider);
10+
11+
// By default the theme usually has an rgba color for the dividers, which can
12+
// stack up with the background of a button toggle. This can cause the border
13+
// of a selected toggle to look different from an deselected one. We use a solid
14+
// color to ensure that the border always stays the same.
15+
$divider-color: if(type-of($theme-divider-color) == color,
16+
mat-rgba-to-hex($theme-divider-color, mat-color($background, card)),
17+
$theme-divider-color
18+
);
1019

1120
.mat-button-toggle-standalone,
1221
.mat-button-toggle-group {

src/lib/core/theming/_theming.scss

+8
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,11 @@
8888
background: $mat-dark-theme-background,
8989
);
9090
}
91+
92+
// Approximates an rgba color into a solid hex color, given a background color.
93+
@function mat-rgba-to-hex($color, $background-color) {
94+
// We convert the rgba color into a solid one by taking the opacity from the rgba
95+
// value and using it to determine the percentage of the background to put
96+
// into foreground when mixing the colors together.
97+
@return mix($background-color, rgba($color, 1), (1 - opacity($color)) * 100%);
98+
}

src/lib/sort/_sort-theme.scss

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1+
@import '../core/theming/theming';
2+
13
@mixin mat-sort-theme($theme) {
24
$background: map-get($theme, background);
35
$foreground: map-get($theme, foreground);
46

57
.mat-sort-header-arrow {
6-
$table-background: mat-color($background, 'card');
7-
$text-color: mat-color($foreground, secondary-text);
8-
98
// Because the arrow is made up of multiple elements that are stacked on top of each other,
109
// we can't use the semi-trasparent color from the theme directly. If the value is a color
1110
// *type*, we convert it into a solid color by taking the opacity from the rgba value and
1211
// using the value to determine the percentage of the background to put into foreground
1312
// when mixing the colors together. Otherwise, if it resolves to something different
1413
// (e.g. it resolves to a CSS variable), we use the color directly.
14+
$text-color: mat-color($foreground, secondary-text);
15+
$table-background: mat-color($background, 'card');
16+
1517
@if (type-of($table-background) == color and type-of($text-color) == color) {
16-
$text-opacity: opacity($text-color);
17-
color: mix($table-background, rgba($text-color, 1), (1 - $text-opacity) * 100%);
18+
color: mat-rgba-to-hex($text-color, $table-background);
1819
}
1920
@else {
2021
color: $text-color;
2122
}
2223
}
2324
}
2425

25-
@mixin mat-sort-typography($config) { }
26+
@mixin mat-sort-typography($config) {}

0 commit comments

Comments
 (0)