Skip to content

Commit 33efc28

Browse files
authored
fix: maximize contrast of dark texts on light backgrounds (#150)
1 parent 6085acc commit 33efc28

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

projects/material-css-vars/src/lib/_variables.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ $text: (
4444
--light-disabled-text: rgba(var(--light-disabled-text-no-rgb)),
4545
--light-dividers: rgba(var(--light-dividers-no-rgb)),
4646
--light-focused: rgba(var(--light-focused-no-rgb)),
47+
--dark-text-contrast: #000000,
48+
--light-text-contrast: var(--light-primary-text),
4749
) !default;
4850

4951
$default-light-theme: (

projects/material-css-vars/src/lib/material-css-vars.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ interface Color {
3535
})
3636
export class MaterialCssVarsService {
3737
private static CONTRAST_PREFIX = "contrast-";
38-
private static DARK_TEXT_VAR = "--dark-primary-text";
39-
private static LIGHT_TEXT_VAR = "--light-primary-text";
38+
private static DARK_TEXT_VAR = "--dark-text-contrast";
39+
private static LIGHT_TEXT_VAR = "--light-text-contrast";
4040
// This should be readonly from the outside
4141
cfg: MaterialCssVariablesConfig;
4242
primary = "#03a9f4";

projects/material-css-vars/src/test/integration.spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ describe("integration", () => {
6060
button.color = "primary";
6161
fixture.detectChanges();
6262

63-
expect(getButtonComputedStyle(fixture).color).toEqual(
64-
"rgba(0, 0, 0, 0.87)",
65-
);
63+
expect(getButtonComputedStyle(fixture).color).toEqual("rgb(0, 0, 0)");
6664
});
6765

6866
it("should render a button in the given accent color", () => {
@@ -96,9 +94,7 @@ describe("integration", () => {
9694
button.color = "warn";
9795
fixture.detectChanges();
9896

99-
expect(getButtonComputedStyle(fixture).color).toEqual(
100-
"rgba(0, 0, 0, 0.87)",
101-
);
97+
expect(getButtonComputedStyle(fixture).color).toEqual("rgb(0, 0, 0)");
10298
});
10399
});
104100

0 commit comments

Comments
 (0)