Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): draw chat text in the accent text token

Yudhi Armyndhariscfd6d279e82a
diff --git a/dashboard/src/contrast-pairs.test.ts b/dashboard/src/contrast-pairs.test.ts
index 3d98493d6..fe569a0d5 100644
--- a/dashboard/src/contrast-pairs.test.ts
+++ b/dashboard/src/contrast-pairs.test.ts
@@ -7,7 +7,8 @@ import ts from 'typescript';
// The brand green (#25d366) and the amber warning fill are light colours: white on them is 1.98:1 and 2.15:1,
// far under the 4.5:1 AA needs, and the green as text on white is the same 1.98:1. Text and icons on those fills are
-// dark (#0f172a, 9.0:1 on the green, as .btn-primary has it), and the brand green as text is --primary-text.
+// dark (#0f172a, 9.0:1 on the green, as .btn-primary has it), and the brand green as text is --primary-text. The chat
+// page's accent (#00a884, 3.03:1 against white either way) follows the same rule, with --chat-accent-text as its text.
const SRC = dirname(fileURLToPath(import.meta.url));
@@ -39,7 +40,7 @@ function rules(): Rule[] {
const WHITE = /^(?:#fff|#ffffff|white)$/i;
// Solid fills only: a translucent tint (rgba, color-mix) is a different pair and is checked by its own ratio.
const LIGHT_FILL =
- /^(?:var\(--primary(?:-hover)?(?:,[^)]*)?\)|var\(--warning(?:,[^)]*)?\)|#25d366|#1da851|#16a34a|#f59e0b|#d97706)$/i;
+ /^(?:var\(--(?:primary|chat-accent)(?:-hover)?(?:,[^)]*)?\)|var\(--warning(?:,[^)]*)?\)|#25d366|#1da851|#16a34a|#f59e0b|#d97706|#00a884|#008f6f)$/i;
test('no rule sets white text on the brand green or amber fill', () => {
const offenders = rules()
@@ -90,13 +91,15 @@ test('the inline scan sees white on a light fill and leaves dark text alone', ()
test('the brand green is never used as a text colour', () => {
const css = rules()
- .filter(r => /^(?:var\(--primary(?:,[^)]*)?\)|#25d366)$/i.test(r.decl.color ?? ''))
+ .filter(r => /^(?:var\(--(?:primary|chat-accent)(?:,[^)]*)?\)|#25d366|#00a884)$/i.test(r.decl.color ?? ''))
.map(r => `${r.at}: ${r.selectors}`);
const inline = filesUnder(SRC, ['.tsx']).flatMap(full =>
readFileSync(full, 'utf8')
.split('\n')
.map((line, i) => ({ line, at: `${full.slice(SRC.length + 1)}:${i + 1}` }))
- .filter(({ line }) => /(?<![\w-])color:\s*['"](?:var\(--primary\)|#25d366)['"]/.test(line))
+ .filter(({ line }) =>
+ /(?<![\w-])color:\s*['"](?:var\(--(?:primary|chat-accent)\)|#25d366|#00a884)['"]/.test(line),
+ )
.map(({ at }) => at),
);
assert.deepEqual([...css, ...inline], []);
diff --git a/dashboard/src/pages/Chats.css b/dashboard/src/pages/Chats.css
index 730694268..086b51913 100644
--- a/dashboard/src/pages/Chats.css
+++ b/dashboard/src/pages/Chats.css
@@ -192,7 +192,7 @@
border-radius: 50%;
background: color-mix(in srgb, var(--chat-accent) 12%, var(--chat-panel));
border: 1px solid color-mix(in srgb, var(--chat-accent) 25%, transparent);
- color: var(--chat-accent);
+ color: var(--chat-accent-text);
font-weight: 600;
font-size: 1rem;
display: flex;
@@ -414,7 +414,7 @@
.chats-page .session-check {
margin-inline-start: auto;
- color: var(--chat-accent);
+ color: var(--chat-accent-text);
flex-shrink: 0;
}
@@ -750,7 +750,7 @@
.chats-page .action-avatar {
background: var(--chat-accent);
- color: #fff;
+ color: #0f172a;
}
.chats-page .chat-item-info {
@@ -1041,7 +1041,7 @@
}
.chats-page .chat-archive-entry svg {
- color: var(--chat-accent);
+ color: var(--chat-accent-text);
}
.chats-page .chat-archive-entry:hover {
@@ -1052,7 +1052,7 @@
margin-inline-start: auto;
font-size: 0.8125rem;
font-weight: 600;
- color: var(--chat-accent);
+ color: var(--chat-accent-text);
}
/* The room's menu lists the row's actions too: its groups stack, and dividers part them. */
@@ -1462,7 +1462,7 @@
padding-inline: 0.75rem;
font-size: 0.8125rem;
font-weight: 600;
- color: var(--chat-accent);
+ color: var(--chat-accent-text);
text-transform: uppercase;
letter-spacing: 0.04em;
}
@@ -1832,7 +1832,7 @@
}
.chats-page .scroll-to-bottom-btn:hover {
- color: var(--chat-accent);
+ color: var(--chat-accent-text);
}
.chats-page .scroll-to-bottom-btn:active {
@@ -2798,7 +2798,7 @@
}
.chats-page .btn-input-accessory.active {
- color: var(--chat-accent);
+ color: var(--chat-accent-text);
}
.chats-page .btn-input-accessory:disabled {
@@ -2862,7 +2862,7 @@
background: var(--chat-accent);
border: none;
border-radius: 50%;
- color: #fff;
+ color: #0f172a;
cursor: pointer;
flex-shrink: 0;
transition:
diff --git a/dashboard/src/theme-contrast.test.ts b/dashboard/src/theme-contrast.test.ts
index 04b451fbc..004128d12 100644
--- a/dashboard/src/theme-contrast.test.ts
+++ b/dashboard/src/theme-contrast.test.ts
@@ -113,24 +113,32 @@ const PILL_TEXT_FILLS = [
'.chats-page .message-prompt-button.selected',
];
+// The accent text is drawn on a tint the same way, in the session switcher's avatar.
+const TEXT_FILLS: Array<[string, string[]]> = [
+ ['--chat-pill-active-text', PILL_TEXT_FILLS],
+ ['--chat-accent-text', ['.chats-page .session-avatar']],
+];
+
for (const anchor of CHAT_ANCHORS) {
- test(`the pill green clears AA on every fill it is drawn on (${anchor})`, () => {
+ test(`chat text clears AA on every tinted fill it is drawn on (${anchor})`, () => {
const block = chatBlock(anchor);
- const text = rgb(chatToken(block, '--chat-pill-active-text'));
- for (const selector of PILL_TEXT_FILLS) {
- const fill = /(?:^|;)\s*background:\s*([^;]+)/.exec(chatRule(selector))?.[1].trim();
- assert.ok(fill, `${selector} paints no background`);
- const plain = /^var\((--[\w-]+)\)$/.exec(fill);
- const mixed = /^color-mix\(in srgb, var\((--[\w-]+)\) (\d+)%, var\((--[\w-]+)\)\)$/.exec(fill);
- assert.ok(plain || mixed, `${selector} paints ${fill}, which this test cannot resolve`);
- const surface = plain
- ? rgb(chatToken(block, plain[1]))
- : rgb(chatToken(block, mixed![1])).map(
- (c, i) =>
- c * (Number(mixed![2]) / 100) + rgb(chatToken(block, mixed![3]))[i] * (1 - Number(mixed![2]) / 100),
- );
- const ratio = contrast(text, surface);
- assert.ok(ratio >= 4.5, `${anchor} --chat-pill-active-text is ${ratio.toFixed(2)}:1 on ${selector}`);
+ for (const [token, selectors] of TEXT_FILLS) {
+ const text = rgb(chatToken(block, token));
+ for (const selector of selectors) {
+ const fill = /(?:^|;)\s*background:\s*([^;]+)/.exec(chatRule(selector))?.[1].trim();
+ assert.ok(fill, `${selector} paints no background`);
+ const plain = /^var\((--[\w-]+)\)$/.exec(fill);
+ const mixed = /^color-mix\(in srgb, var\((--[\w-]+)\) (\d+)%, var\((--[\w-]+)\)\)$/.exec(fill);
+ assert.ok(plain || mixed, `${selector} paints ${fill}, which this test cannot resolve`);
+ const surface = plain
+ ? rgb(chatToken(block, plain[1]))
+ : rgb(chatToken(block, mixed![1])).map(
+ (c, i) =>
+ c * (Number(mixed![2]) / 100) + rgb(chatToken(block, mixed![3]))[i] * (1 - Number(mixed![2]) / 100),
+ );
+ const ratio = contrast(text, surface);
+ assert.ok(ratio >= 4.5, `${anchor} ${token} is ${ratio.toFixed(2)}:1 on ${selector}`);
+ }
}
});
}