Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): lift dark error text to AA on error tints
Yudhi Armyndharis2eef87c08684
diff --git a/dashboard/src/App.css b/dashboard/src/App.cssindex 865cdef8e..8548de3d3 100644--- a/dashboard/src/App.css+++ b/dashboard/src/App.css@@ -47,8 +47,9 @@--border: #334155; /* Slate 700 */--info: #60a5fa; /* Blue 400 — lighter so it reads over the dark translucent-blue tints *//* On the dark surfaces success and warning already clear AA (6.42:1 and 6.81:1), so they- keep their base value; error is 4.06:1 there and is lightened instead. */- --error-text: #f15e5e;+ keep their base value; error is 4.06:1 there and is lightened instead, to a value that still+ clears 4.65:1 on the darkest error tint behind it (20 percent over Slate 800). */+ --error-text: #f77b7b;--success-text: var(--success);--warning-text: var(--warning);@@ -82,8 +83,9 @@--border: #334155;--info: #60a5fa;/* On the dark surfaces success and warning already clear AA (6.42:1 and 6.81:1), so they- keep their base value; error is 4.06:1 there and is lightened instead. */- --error-text: #f15e5e;+ keep their base value; error is 4.06:1 there and is lightened instead, to a value that still+ clears 4.65:1 on the darkest error tint behind it (20 percent over Slate 800). */+ --error-text: #f77b7b;--success-text: var(--success);--warning-text: var(--warning);--primary-soft: color-mix(in srgb, var(--primary) 18%, transparent);diff --git a/dashboard/src/theme-contrast.test.ts b/dashboard/src/theme-contrast.test.tsnew file mode 100644index 000000000..c81108065--- /dev/null+++ b/dashboard/src/theme-contrast.test.ts@@ -0,0 +1,44 @@+import { test } from 'node:test';+import assert from 'node:assert/strict';+import { readFileSync } from 'node:fs';+import { fileURLToPath } from 'node:url';+import { dirname, join } from 'node:path';++// Error text in dark mode lands on the card surface and on the 10 to 20 percent error tints that+// pills and danger buttons paint over it, so it has to clear WCAG AA (4.5:1) on the darkest of those.++const CSS = readFileSync(join(dirname(fileURLToPath(import.meta.url)), 'App.css'), 'utf8');++const rgb = (hex: string): number[] => [1, 3, 5].map(i => parseInt(hex.slice(i, i + 2), 16));+const luminance = (c: number[]): number => {+ const [r, g, b] = c.map(v => (v / 255 <= 0.03928 ? v / 255 / 12.92 : ((v / 255 + 0.055) / 1.055) ** 2.4));+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;+};+const contrast = (a: number[], b: number[]): number => {+ const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);+ return (hi + 0.05) / (lo + 0.05);+};+const token = (block: string, name: string): string => {+ const value = block.match(new RegExp(`${name}:\\s*(#[0-9a-f]{6})`, 'i'))?.[1];+ assert.ok(value, `${name} is not a hex colour in the block`);+ return value;+};+const blockAfter = (anchor: string): string => {+ const from = CSS.indexOf(anchor);+ assert.notEqual(from, -1, `App.css no longer contains "${anchor}"`);+ return CSS.slice(from, CSS.indexOf('}', from));+};++test('dark --error-text clears AA on every error tint it lands on, in both dark blocks', () => {+ const error = rgb(token(blockAfter(':root {'), '--error'));+ for (const anchor of ["[data-theme='dark'] {", ":root:not([data-theme='light']) {"]) {+ const block = blockAfter(anchor);+ const text = rgb(token(block, '--error-text'));+ const surface = rgb(token(block, '--bg-white'));+ for (const alpha of [0, 0.1, 0.12, 0.15, 0.18, 0.2]) {+ const bg = error.map((c, i) => c * alpha + surface[i] * (1 - alpha));+ const ratio = contrast(text, bg);+ assert.ok(ratio >= 4.5, `${anchor} --error-text is ${ratio.toFixed(2)}:1 on a ${alpha * 100}% error tint`);+ }+ }+});