From 32d781e58a48bd06cb3c0bb1d039fe3bad333e41 Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Sat, 10 Oct 2026 17:23:17 +0200 Subject: [PATCH] =?UTF-8?q?=E2=98=91=EF=B8=8F=20feat:=20Give=20the=20Check?= =?UTF-8?q?box=20Theme=20Roles=20for=20Its=20Fill=20and=20Corner=20(#16958?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Give the Checkbox Theme Roles for Its Fill and Corner The shared checkbox painted no fill when unchecked and drew the rounded-sm corner every small control shares, so the ClickHouse theme could not reach Click UI's checkbox.color.background.default fill or its 0.125rem checkbox.radii.all corner. A checkboxRadius appearance role sets the corner and follows radiusSm, the corner it drew before, when a theme names that and not this. A checkbox-fill color role paints an unchecked box only when the new checkboxFillStyle role is fill; the default transparent style keeps every default theme pixel-identical, and the fill follows surface-primary when a theme omits it. Checkbox and CheckboxGlyph read both roles. The ClickHouse theme sets Click UI's fill and corner, and both entries leave the drift guard's not-expressible list with their probes pinned to match. * test: Spell Each Checkbox Scenario Tag Literally * test: Pin the Theme Cache Digest Built From the New Resolver --- .../Providers/__tests__/themeCache.spec.ts | 2 +- .../scenarios/clickhouse-checkbox.spec.ts | 196 ++++++++++++++++++ .../client/src/components/Checkbox.spec.tsx | 40 ++++ packages/client/src/components/Checkbox.tsx | 6 +- packages/client/src/theme/README.md | 8 + packages/client/src/theme/defaults.css | 4 + packages/client/src/theme/defaults.spec.ts | 4 +- packages/client/src/theme/registry.spec.ts | 63 ++++++ packages/client/src/theme/registry.ts | 15 +- packages/client/src/theme/tailwind.spec.js | 2 + .../client/src/theme/themes/clickhouse.ts | 5 + .../client/src/theme/themes/clickui.spec.ts | 23 +- packages/client/src/theme/themes/dark.ts | 1 + packages/client/src/theme/themes/default.ts | 1 + .../client/src/theme/themes/highContrast.ts | 2 + packages/client/src/theme/tokens.css | 11 + packages/client/src/theme/tokens.spec.ts | 2 + packages/client/src/theme/types/index.ts | 10 + .../client/src/theme/utils/applyTheme.spec.ts | 8 + packages/client/src/theme/utils/applyTheme.ts | 5 + packages/client/src/utils/utils.ts | 2 +- packages/client/tailwind.preset.cjs | 1 + packages/data-provider/specs/theme.spec.ts | 34 +++ packages/data-provider/src/theme.ts | 5 + 24 files changed, 431 insertions(+), 19 deletions(-) create mode 100644 e2e/specs/mock/scenarios/clickhouse-checkbox.spec.ts create mode 100644 packages/client/src/components/Checkbox.spec.tsx diff --git a/client/src/Providers/__tests__/themeCache.spec.ts b/client/src/Providers/__tests__/themeCache.spec.ts index 6d3ce1c28b..14387ce1a8 100644 --- a/client/src/Providers/__tests__/themeCache.spec.ts +++ b/client/src/Providers/__tests__/themeCache.spec.ts @@ -182,7 +182,7 @@ describe('theme cache storage', () => { * - definitions with one or both mode blocks absent. * A new role, or a new fallback, joins by construction. */ -const PIN = { fingerprint: '1.3.yila83', digest: '1lhfc04' }; +const PIN = { fingerprint: '1.3.dxwdxg', digest: 'aepelz' }; const digestOf = (text: string): string => { let hash = 5381; diff --git a/e2e/specs/mock/scenarios/clickhouse-checkbox.spec.ts b/e2e/specs/mock/scenarios/clickhouse-checkbox.spec.ts new file mode 100644 index 0000000000..e053f3ad05 --- /dev/null +++ b/e2e/specs/mock/scenarios/clickhouse-checkbox.spec.ts @@ -0,0 +1,196 @@ +import { expect, test } from '@playwright/test'; +import { FileSources } from 'librechat-data-provider'; +import type { TFile } from 'librechat-data-provider'; +import type { Locator, Page } from '@playwright/test'; +import { clickHouseTheme } from '../../../../packages/client/src/theme/themes/clickhouse'; + +/** + * The shared checkbox reads its corner from `checkboxRadius` and, under `checkboxFillStyle: + * 'fill'`, paints an unchecked box in `checkbox-fill`. Click UI fills the box with + * `checkbox.color.background.default` and rounds it at `checkbox.radii.all` (0.125rem); LibreChat's + * own checkbox stays clear on the `rounded-sm` corner without a theme. The My Files table's row + * selection is a real consumer of the primitive, with a routed file list. + */ +test.describe.configure({ timeout: 120_000 }); +test.use({ viewport: { width: 1280, height: 800 } }); + +type Mode = 'light' | 'dark'; +type ThemeChoice = 'clickhouse' | 'default' | 'small-corner' | 'fill-canvas'; + +/** Names only the small corner, as a theme written before the checkbox had a role of its own. */ +const smallCornerTheme = { + version: 1, + name: 'e2e-small-corner', + modes: { light: { appearance: { radiusSm: '6px' } }, dark: { appearance: { radiusSm: '6px' } } }, +}; + +/** Fills the checkbox without naming its fill, so the box takes the theme's own canvas. */ +const fillCanvasTheme = { + version: 1, + name: 'e2e-checkbox-fill-canvas', + modes: { + light: { + colors: { 'rgb-surface-primary': '10 20 30' }, + appearance: { checkboxFillStyle: 'fill' }, + }, + }, +}; + +const files: TFile[] = Array.from({ length: 2 }, (_, index) => ({ + file_id: `checkbox-theme-file-${index}`, + filename: `Checkbox theme fixture ${index}.txt`, + filepath: `/files/checkbox-theme-file-${index}.txt`, + user: 'checkbox-theme-user', + bytes: 100, + object: 'file', + source: FileSources.local, + type: 'text/plain', + usage: 0, + embedded: false, + createdAt: '2026-09-01T00:00:00.000Z', + updatedAt: '2026-09-01T00:00:00.000Z', +})); + +/** One init script per page; the theme and mode each navigation wants ride in its URL. */ +async function installThemeBridge(page: Page) { + await page.addInitScript( + (definitions) => { + const params = new URL(location.href).searchParams; + const theme = params.get('e2eTheme'); + const mode = params.get('e2eThemeMode'); + if (theme === null || mode === null) { + return; + } + localStorage.setItem('color-theme', mode); + localStorage.removeItem('theme-colors'); + localStorage.removeItem('theme-name'); + const definition = (definitions as Record)[theme]; + if (definition) { + localStorage.setItem('theme-definition', JSON.stringify(definition)); + localStorage.setItem('theme-source', 'definition'); + } else { + localStorage.removeItem('theme-definition'); + localStorage.removeItem('theme-source'); + } + }, + { + clickhouse: clickHouseTheme, + 'small-corner': smallCornerTheme, + 'fill-canvas': fillCanvasTheme, + }, + ); +} + +async function openFiles(page: Page, theme: ThemeChoice, mode: Mode) { + await page.goto(`/c/new?e2eTheme=${theme}&e2eThemeMode=${mode}`, { timeout: 15000 }); + await expect(page.locator('html')).toHaveClass(mode === 'dark' ? /\bdark\b/ : /\blight\b/); + await page.getByTestId('nav-user').click(); + await page.getByRole('menu').getByRole('menuitem', { name: 'My Files', exact: true }).click(); + const dialog = page.getByRole('dialog', { name: 'My Files' }); + await expect(dialog.getByText(files[0].filename)).toBeVisible(); + return dialog; +} + +const paint = (box: Locator) => + box.evaluate((node) => { + const style = getComputedStyle(node); + return { fill: style.backgroundColor, corner: style.borderTopLeftRadius }; + }); + +/** The fill a probe painted with `bg-` resolves to on this page. */ +const roleFill = (page: Page, role: string) => + page.evaluate((name) => { + const probe = document.createElement('div'); + probe.className = `bg-${name}`; + document.body.append(probe); + const fill = getComputedStyle(probe).backgroundColor; + probe.remove(); + return fill; + }, role); + +async function attachShot(dialog: Locator, name: string) { + const path = test.info().outputPath(`${name}.png`); + await dialog.locator('table').screenshot({ path, animations: 'disabled' }); + await test.info().attach(name, { path, contentType: 'image/png' }); +} + +/** Titles are literal so each `@scenario` tag is findable in the source. */ +const CASES: Array<{ mode: Mode; clickhouse: string; unchanged: string }> = [ + { + mode: 'light', + clickhouse: + 'ClickHouse light checkboxes take the Click UI fill and corner @scenario:clickhouse-checkbox-light', + unchanged: + 'default light checkboxes stay clear on the small corner @scenario:default-checkbox-light-unchanged', + }, + { + mode: 'dark', + clickhouse: + 'ClickHouse dark checkboxes take the Click UI fill and corner @scenario:clickhouse-checkbox-dark', + unchanged: + 'default dark checkboxes stay clear on the small corner @scenario:default-checkbox-dark-unchanged', + }, +]; + +const rgb = (triplet: string | undefined) => `rgb(${(triplet ?? '').split(' ').join(', ')})`; + +test.describe('theme checkbox', () => { + test.beforeEach(async ({ page }) => { + await page.route('**/api/files', (route) => route.fulfill({ json: files })); + await installThemeBridge(page); + }); + + for (const { mode, clickhouse, unchanged } of CASES) { + test(clickhouse, async ({ page }) => { + const dialog = await openFiles(page, 'clickhouse', mode); + await expect(page.locator('html')).toHaveAttribute('data-theme', 'clickhouse'); + const colors = clickHouseTheme.modes[mode]?.colors ?? {}; + const row = dialog.locator('tbody').getByRole('checkbox').first(); + + expect(await paint(row)).toEqual({ fill: rgb(colors['rgb-checkbox-fill']), corner: '2px' }); + await attachShot(dialog, `clickhouse-${mode}-unchecked`); + + await row.click(); + await expect(row).toHaveAttribute('data-state', 'checked'); + expect(await paint(row)).toEqual({ + fill: rgb(colors['rgb-surface-inverted']), + corner: '2px', + }); + await attachShot(dialog, `clickhouse-${mode}-checked`); + }); + + test(unchanged, async ({ page }) => { + const dialog = await openFiles(page, 'default', mode); + const row = dialog.locator('tbody').getByRole('checkbox').first(); + + expect(await paint(row)).toEqual({ fill: 'rgba(0, 0, 0, 0)', corner: '4px' }); + + await row.click(); + await expect(row).toHaveAttribute('data-state', 'checked'); + expect((await paint(row)).fill).toBe(await roleFill(page, 'surface-inverted')); + }); + } + + test('a theme that names only the small corner rounds the checkbox with it @scenario:checkbox-corner-follows-radius-sm', async ({ + page, + }) => { + const dialog = await openFiles(page, 'small-corner', 'light'); + await expect(page.locator('html')).toHaveAttribute('data-theme', smallCornerTheme.name); + + expect(await paint(dialog.locator('tbody').getByRole('checkbox').first())).toEqual({ + fill: 'rgba(0, 0, 0, 0)', + corner: '6px', + }); + }); + + test('a filled theme that names no checkbox fill paints its own canvas @scenario:checkbox-fill-follows-canvas', async ({ + page, + }) => { + const dialog = await openFiles(page, 'fill-canvas', 'light'); + await expect(page.locator('html')).toHaveAttribute('data-theme', fillCanvasTheme.name); + + expect((await paint(dialog.locator('tbody').getByRole('checkbox').first())).fill).toBe( + 'rgb(10, 20, 30)', + ); + }); +}); diff --git a/packages/client/src/components/Checkbox.spec.tsx b/packages/client/src/components/Checkbox.spec.tsx new file mode 100644 index 0000000000..943d6398fc --- /dev/null +++ b/packages/client/src/components/Checkbox.spec.tsx @@ -0,0 +1,40 @@ +import '@testing-library/jest-dom'; +import { render, screen } from '@testing-library/react'; +import { Checkbox, CheckboxGlyph } from './Checkbox'; + +describe('Checkbox', () => { + it('reads its corner and unchecked fill from the checkbox roles', () => { + render(); + + const box = screen.getByRole('checkbox', { name: 'Probe' }); + expect(box).toHaveClass( + 'rounded-theme-checkbox', + 'theme-checkbox-fill:bg-checkbox-fill', + 'data-[state=checked]:bg-surface-inverted', + ); + expect(box).not.toHaveClass('rounded-sm'); + }); + + it("lets a caller's corner replace the checkbox role", () => { + render(); + + const box = screen.getByRole('checkbox', { name: 'Probe' }); + expect(box).toHaveClass('rounded-full'); + expect(box).not.toHaveClass('rounded-theme-checkbox'); + }); +}); + +describe('CheckboxGlyph', () => { + it('paints the unchecked fill role only while unchecked', () => { + const { container, rerender } = render(); + const glyph = container.firstElementChild; + + expect(glyph).toHaveClass('rounded-theme-checkbox', 'theme-checkbox-fill:bg-checkbox-fill'); + expect(glyph).not.toHaveClass('bg-surface-inverted'); + + rerender(); + + expect(glyph).toHaveClass('rounded-theme-checkbox', 'bg-surface-inverted'); + expect(glyph).not.toHaveClass('theme-checkbox-fill:bg-checkbox-fill'); + }); +}); diff --git a/packages/client/src/components/Checkbox.tsx b/packages/client/src/components/Checkbox.tsx index 53e080904a..e60c264c28 100644 --- a/packages/client/src/components/Checkbox.tsx +++ b/packages/client/src/components/Checkbox.tsx @@ -27,7 +27,7 @@ const Checkbox: React.ForwardRefExoticComponent< = ({