diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d6b730..cff953b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,24 @@ All notable changes to this project will be documented in this file. +## 1.20.2 - 2026-09-30 + +Changes since 1.20.1: + +### Fixed + +- Text contrast now meets WCAG AA (4.5:1) in both themes: + - the "Live" refresh label and the table sort icon use a new `--color-primary-text` token (dark lime in the light theme) instead of the light lime brand color; + - the idle refresh label is no longer dimmed with opacity; + - the light theme's danger button is a little darker, and the dark theme's danger hover is lighter so its dark text stays readable; + - syntax highlighting colors are defined per theme (`--hl-*` tokens), darker in the light theme; + - muted text is slightly darker in the light theme. + +### Added + +- A Storybook "Accessibility / Contrast" page that measures the contrast of the most contrast-prone components in both themes. +- Storybook accessibility checks now fail the tests on violations (`a11y.test: 'error'`). The Colors story shows each token's current value per theme and includes the syntax colors. + ## 1.20.1 - 2026-09-30 Changes since 1.20.0: diff --git a/client/.storybook/preview.tsx b/client/.storybook/preview.tsx index a1cc1ce..6f51c9a 100644 --- a/client/.storybook/preview.tsx +++ b/client/.storybook/preview.tsx @@ -37,7 +37,8 @@ const preview: Preview = { }, }, a11y: { - test: 'todo', + // Accessibility violations (e.g. color contrast) fail the story's test + test: 'error', }, }, }; diff --git a/client/.storybook/stories/Colors.stories.tsx b/client/.storybook/stories/Colors.stories.tsx index 1b428c4..1bf23ec 100644 --- a/client/.storybook/stories/Colors.stories.tsx +++ b/client/.storybook/stories/Colors.stories.tsx @@ -1,10 +1,16 @@ -import React from 'react'; +import React, { useLayoutEffect, useRef, useState } from 'react'; import type { Meta, StoryObj } from '@storybook/react-vite'; const palette = [ { name: 'Atlantis', token: '--color-primary', hex: '#9DD341', role: 'Primary / Action' }, + { + name: 'Atlantis text', + token: '--color-primary-text', + hex: '#496904', + role: 'Primary as text / icon', + }, { name: 'Outer Space', token: '--color-text', hex: '#2D3339', role: 'Text / Surface' }, - { name: 'Kimberly', token: '--color-text-muted', hex: '#6650C0', role: 'Muted text / Info' }, + { name: 'Kimberly', token: '--color-text-muted', hex: '#634DBD', role: 'Muted text / Info' }, { name: 'Powder Ash', token: '--color-border', hex: '#AFBFB9', role: 'Border / Neutral' }, ]; @@ -23,12 +29,23 @@ const semanticColors = [ { name: 'Running fg', token: '--color-running-fg', hex: '#6B4A00' }, ]; +const syntaxColors = [ + { name: 'Comment', token: '--hl-comment', hex: '#4F6557' }, + { name: 'Keyword', token: '--hl-keyword', hex: '#764E99' }, + { name: 'String / title', token: '--hl-string', hex: '#4F6821' }, + { name: 'Number', token: '--hl-number', hex: '#895403' }, + { name: 'Function', token: '--hl-function', hex: '#056980' }, + { name: 'Variable / params', token: '--hl-variable', hex: '#815354' }, + { name: 'Property', token: '--hl-property', hex: '#1D6971' }, + { name: 'Meta', token: '--hl-meta', hex: '#615B7E' }, +]; + const surfaceColors = [ { name: 'Background', token: '--color-bg', hex: '#E6EDEA' }, { name: 'Background subtle', token: '--color-bg-subtle', hex: '#D8E2DE' }, { name: 'Secondary', token: '--color-secondary', hex: '#EDF1EF' }, { name: 'Secondary hover', token: '--color-secondary-hover', hex: '#DFE6E3' }, - { name: 'Danger', token: '--color-danger', hex: '#D94F4F' }, + { name: 'Danger', token: '--color-danger', hex: '#CE4546' }, { name: 'Primary fg', token: '--color-primary-fg', hex: '#2D3339' }, ]; @@ -43,8 +60,27 @@ function Swatch({ hex: string; role?: string; }) { + // Show the token's current value (per theme) rather than a hard-coded copy + const ref = useRef(null); + const [value, setValue] = useState(hex); + useLayoutEffect(() => { + const read = () => { + if (!ref.current) return; + const resolved = getComputedStyle(ref.current).getPropertyValue(token).trim(); + if (resolved) setValue(resolved.toUpperCase()); + }; + read(); + // Re-read when the theme toolbar switches data-theme on + const observer = new MutationObserver(read); + observer.observe(document.documentElement, { + attributes: true, + attributeFilter: ['data-theme'], + }); + return () => observer.disconnect(); + }, [token]); return (
)}
- {hex} + {value}
{token} @@ -128,6 +164,11 @@ function ColorPalette() { ))} +
+ {syntaxColors.map((c) => ( + + ))} +
); } diff --git a/client/.storybook/stories/ContextMenu.stories.tsx b/client/.storybook/stories/ContextMenu.stories.tsx index 158f47f..26e7f03 100644 --- a/client/.storybook/stories/ContextMenu.stories.tsx +++ b/client/.storybook/stories/ContextMenu.stories.tsx @@ -13,7 +13,7 @@ export default meta; type Story = StoryObj; const trigger = ( - ); diff --git a/client/.storybook/stories/Contrast.stories.tsx b/client/.storybook/stories/Contrast.stories.tsx new file mode 100644 index 0000000..0e25791 --- /dev/null +++ b/client/.storybook/stories/Contrast.stories.tsx @@ -0,0 +1,330 @@ +import React, { useLayoutEffect, useRef, useState } from 'react'; +import type { Meta, StoryObj } from '@storybook/react-vite'; +import { AutoRefreshIndicator } from '../../src/ui/AutoRefreshIndicator/AutoRefreshIndicator'; +import { Button } from '../../src/ui/Button/Button'; +import { CodeBlock } from '../../src/ui/CodeBlock/CodeBlock'; + +/* + * Text contrast review page (WCAG AA: 4.5:1 for normal text, 3:1 for large + * text) for the components where contrast is easiest to get wrong: light + * brand colors used as text, dimmed labels, colored buttons and syntax + * highlighting. Every sample is the real component, shown in both themes, and + * the contrast of each piece of text is measured live from the rendered + * colors - so this page stays accurate as the design tokens change. + */ + +// ── Contrast measurement ───────────────────────────────────────────────────── + +type Rgba = [number, number, number, number]; + +function parseColor(value: string): Rgba { + const parts = value.match(/[\d.]+/g)?.map(Number) ?? [0, 0, 0]; + return [parts[0], parts[1], parts[2], parts[3] ?? 1]; +} + +function luminance([r, g, b]: Rgba): number { + const channel = (c: number) => { + const s = c / 255; + return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4; + }; + return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b); +} + +function contrast(a: Rgba, b: Rgba): number { + const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x); + return (hi + 0.05) / (lo + 0.05); +} + +/** Blends `top` over an opaque `bottom`. */ +function blend(top: Rgba, bottom: Rgba): Rgba { + const a = top[3]; + return [0, 1, 2].map((i) => top[i] * a + bottom[i] * (1 - a)).concat(1) as Rgba; +} + +/** Product of the `opacity` of `el` and its ancestors (e.g. a dimmed idle label). */ +function opacityChain(el: Element): number { + let opacity = 1; + for (let node: Element | null = el; node; node = node.parentElement) { + opacity *= parseFloat(getComputedStyle(node).opacity); + } + return opacity; +} + +/** The opaque color behind `el`, from its own and its ancestors' backgrounds. */ +function effectiveBackground(el: Element): Rgba { + const layers: Rgba[] = []; + for (let node: Element | null = el; node; node = node.parentElement) { + const bg = parseColor(getComputedStyle(node).backgroundColor); + bg[3] *= opacityChain(node); + if (bg[3] > 0) layers.push(bg); + if (bg[3] >= 1) break; + } + return layers.reduceRight((under, layer) => blend(layer, under), [255, 255, 255, 1]); +} + +const hex = ([r, g, b]: Rgba) => + '#' + [r, g, b].map((c) => Math.round(c).toString(16).padStart(2, '0')).join(''); + +interface Measurement { + text: string; + fg: string; + bg: string; + ratio: number; + required: number; +} + +/** Measures every element that directly contains visible text. */ +function measure(root: HTMLElement): Measurement[] { + const seen = new Set(); + const results: Measurement[] = []; + for (const el of Array.from(root.querySelectorAll('*'))) { + const text = Array.from(el.childNodes) + .filter((n) => n.nodeType === Node.TEXT_NODE) + .map((n) => n.textContent ?? '') + .join('') + .trim(); + if (!text || el.closest('[aria-hidden="true"]')) continue; + const style = getComputedStyle(el); + const fontSize = parseFloat(style.fontSize); + const bold = Number(style.fontWeight) >= 700; + // WCAG "large text": at least 24px, or 18.66px bold + const required = fontSize >= 24 || (bold && fontSize >= 18.66) ? 3 : 4.5; + const bgColor = effectiveBackground(el); + const fg = parseColor(style.color); + fg[3] *= opacityChain(el); + const fgColor = blend(fg, bgColor); + const key = `${hex(fgColor)}|${hex(bgColor)}|${required}`; + if (seen.has(key)) continue; + seen.add(key); + results.push({ + text: text.length > 28 ? `${text.slice(0, 28)}…` : text, + fg: hex(fgColor), + bg: hex(bgColor), + ratio: contrast(fgColor, bgColor), + required, + }); + } + return results.sort((a, b) => a.ratio / a.required - b.ratio / b.required); +} + +function Readout({ items }: { items: Measurement[] }) { + return ( + + + {items.map((m) => { + const pass = m.ratio >= m.required; + return ( + + + + + + ); + })} + +
+ + {m.text} + + + {m.fg} on {m.bg} + + {m.ratio.toFixed(2)}:1 {pass ? '✓' : `✗ needs ${m.required}:1`} +
+ ); +} + +/** Renders a sample and measures its text contrast after layout. */ +function Sample({ children }: { children: React.ReactNode }) { + const ref = useRef(null); + const [items, setItems] = useState([]); + useLayoutEffect(() => { + const el = ref.current; + if (!el) return; + // Measure after the theme/styles have applied + const frame = requestAnimationFrame(() => setItems(measure(el))); + return () => cancelAnimationFrame(frame); + }, []); + return ( +
+
{children}
+ +
+ ); +} + +// ── Page ───────────────────────────────────────────────────────────────────── + +// Covers every syntax color: comment, keyword, string, number, function +// (title), params, property +const JS_CODE = [ + '// Open the app and wait for the dashboard', + 'async function openDashboard(context, timeoutMs) {', + " const url = context.getEnv('BASE_URL');", + ' await context.page.goto(url, { timeout: timeoutMs ?? 30000 });', + ' return context.page.title();', + '}', +].join('\n'); +const JSON_CODE = JSON.stringify( + { status: 'pass', attempts: 2, cached: false, output: { title: 'Dashboard' } }, + null, + 2, +); + +interface Issue { + title: string; + note: string; + render: () => React.ReactNode; +} + +const ISSUES: Issue[] = [ + { + title: 'AutoRefreshIndicator label', + note: 'Active ("Live", --color-primary-text), idle and error labels (runs pages).', + render: () => ( +
+ + + +
+ ), + }, + { + title: 'Danger button', + note: 'Danger, primary and secondary buttons (text on colored backgrounds).', + render: () => ( +
+ + + + +
+ ), + }, + { + title: 'Code highlighting - JavaScript', + note: 'All --hl-* syntax colors on the page background (step code, snippets).', + render: () => , + }, + { + title: 'Code highlighting - JSON', + note: 'Keys, strings, numbers and literals in JSON step outputs.', + render: () => , + }, + { + title: 'Muted text', + note: '--color-text-muted on both background shades (hints, table headers, descriptions).', + render: () => ( +
+ {['var(--color-bg)', 'var(--color-bg-subtle)'].map((bg) => ( + + Last run 2 minutes ago + + ))} +
+ ), + }, +]; + +function Panel({ theme }: { theme: 'light' | 'dark' }) { + return ( +
+

+ {theme === 'dark' ? 'Dark theme' : 'Light theme'} +

+ {ISSUES.map((issue) => ( +
+

{issue.title}

+

+ {issue.note} +

+ {issue.render()} +
+ ))} +
+ ); +} + +function ContrastPage() { + return ( +
+

+ Text contrast of the components where it's easiest to get wrong (WCAG AA: 4.5:1 for normal + text, 3:1 for large text). Each row is a piece of text in the sample, measured from its + rendered colors, worst first. +

+
+ + +
+
+ ); +} + +const meta: Meta = { + title: 'Accessibility/Contrast', + component: ContrastPage, + // a11y checks use the project default ('error' in preview.tsx) + parameters: { layout: 'fullscreen' }, + // The light panel relies on the page default (light) theme + globals: { theme: 'light' }, +}; +export default meta; +type Story = StoryObj; + +export const Overview: Story = {}; diff --git a/client/src/ui/AutoRefreshIndicator/AutoRefreshIndicator.module.css b/client/src/ui/AutoRefreshIndicator/AutoRefreshIndicator.module.css index b31ecc6..4d830c9 100644 --- a/client/src/ui/AutoRefreshIndicator/AutoRefreshIndicator.module.css +++ b/client/src/ui/AutoRefreshIndicator/AutoRefreshIndicator.module.css @@ -71,7 +71,7 @@ } .active .label { - color: var(--color-primary); + color: var(--color-primary-text); font-weight: 600; } @@ -83,8 +83,8 @@ } .inactive .label { + /* Not dimmed with opacity: muted text already reads as inactive and keeps 4.5:1 */ color: var(--color-text-muted); - opacity: 0.5; } /* ── Error state ──────────────────────────────────────────── */ diff --git a/client/src/ui/CodeBlock/CodeBlock.module.css b/client/src/ui/CodeBlock/CodeBlock.module.css index 6a04ed4..c984ebf 100644 --- a/client/src/ui/CodeBlock/CodeBlock.module.css +++ b/client/src/ui/CodeBlock/CodeBlock.module.css @@ -18,7 +18,7 @@ .code :global(.hljs-comment), .code :global(.hljs-quote) { - color: var(--hl-comment, #6A8072); + color: var(--hl-comment); font-style: italic; } @@ -27,7 +27,7 @@ .code :global(.hljs-built_in), .code :global(.hljs-name), .code :global(.hljs-tag) { - color: var(--hl-keyword, #A67DCC); + color: var(--hl-keyword); } .code :global(.hljs-string), @@ -39,32 +39,32 @@ .code :global(.hljs-template-variable), .code :global(.hljs-type), .code :global(.hljs-addition) { - color: var(--hl-string, #9BB870); + color: var(--hl-string); } .code :global(.hljs-number), .code :global(.hljs-regexp), .code :global(.hljs-link) { - color: var(--hl-number, #E8A85F); + color: var(--hl-number); } .code :global(.hljs-function), .code :global(.hljs-title.hljs-function_) { - color: var(--hl-function, #5BB8D4); + color: var(--hl-function); } .code :global(.hljs-variable), .code :global(.hljs-params) { - color: var(--hl-variable, #D4A0A0); + color: var(--hl-variable); } .code :global(.hljs-property) { - color: var(--hl-property, #79C0C8); + color: var(--hl-property); } .code :global(.hljs-deletion), .code :global(.hljs-meta) { - color: var(--hl-meta, #A9A3C9); + color: var(--hl-meta); } .code :global(.hljs-emphasis) { diff --git a/client/src/ui/Table/Table.module.css b/client/src/ui/Table/Table.module.css index ff09134..96b640e 100644 --- a/client/src/ui/Table/Table.module.css +++ b/client/src/ui/Table/Table.module.css @@ -49,7 +49,7 @@ .sortIconActive { opacity: 1; - color: var(--color-primary); + color: var(--color-primary-text); } [data-theme="dark"] .th { diff --git a/client/src/ui/tokens.css b/client/src/ui/tokens.css index 50a1aa4..51eda38 100644 --- a/client/src/ui/tokens.css +++ b/client/src/ui/tokens.css @@ -11,6 +11,8 @@ --color-primary-hover: #8ABD2E; --color-primary-active: #77A320; --color-primary-fg: #2D3339; /* Outer Space on bright green */ + /* Primary as text/icon color on light surfaces (Atlantis is too light for text) */ + --color-primary-text: #496904; /* Secondary — Kimberly tint */ --color-secondary: #EDEAF8; @@ -19,8 +21,8 @@ --color-secondary-fg: #6650C0; /* Kimberly */ --color-secondary-border: #B8B0E0; - /* Danger */ - --color-danger: #D94F4F; + /* Danger (white text needs >= 4.5:1) */ + --color-danger: #CE4546; --color-danger-hover: #C03A3A; --color-danger-fg: #ffffff; @@ -43,11 +45,21 @@ --color-link-hover: #3D2F80; --color-text: #2D3339; - --color-text-muted: #6650C0; /* Kimberly */ + --color-text-muted: #634DBD; /* Kimberly, a touch darker for 4.5:1 on bg-subtle */ --color-border: #AFBFB9; /* Powder Ash */ --color-bg: #E6EDEA; /* Powder Ash tint */ --color-bg-subtle: #D8E2DE; /* Powder Ash tint, 1 step darker */ + /* Syntax highlighting (CodeBlock); each >= 4.5:1 on bg and bg-subtle */ + --hl-comment: #4F6557; + --hl-keyword: #764E99; + --hl-string: #4F6821; + --hl-number: #895403; + --hl-function: #056980; + --hl-variable: #815354; + --hl-property: #1D6971; + --hl-meta: #615B7E; + /* Spacing */ --space-1: 4px; --space-2: 8px; @@ -112,6 +124,7 @@ a:hover { --color-primary-hover: #AEDE55; --color-primary-active: #8ABD2E; --color-primary-fg: #1A1F24; + --color-primary-text: #9DD341; /* Secondary — dark Kimberly tint */ --color-secondary: #2A2548; @@ -122,7 +135,7 @@ a:hover { /* Danger */ --color-danger: #E06060; - --color-danger-hover: #CC4A4A; + --color-danger-hover: #F06E6D; /* lighter, so the dark text keeps >= 4.5:1 */ --color-danger-fg: #1A1F24; /* Semantic */ @@ -148,4 +161,14 @@ a:hover { --color-border: #3D4850; --color-bg: #1A1F24; /* deeper than Outer Space */ --color-bg-subtle: #2D3339; /* Outer Space */ + + /* Syntax highlighting (CodeBlock); each >= 4.5:1 on bg and bg-subtle */ + --hl-comment: #8AA192; + --hl-keyword: #B38ADA; + --hl-string: #9BB870; + --hl-number: #E8A85F; + --hl-function: #5BB8D4; + --hl-variable: #D4A0A0; + --hl-property: #79C0C8; + --hl-meta: #A9A3C9; } diff --git a/package-lock.json b/package-lock.json index e7e7821..2a15caa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "liqa", - "version": "1.20.1", + "version": "1.20.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "liqa", - "version": "1.20.1", + "version": "1.20.2", "workspaces": [ "server", "client" diff --git a/package.json b/package.json index e636acc..e569aa4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "liqa", - "version": "1.20.1", + "version": "1.20.2", "private": true, "engines": { "node": ">=24"