diff --git a/e2e/specs/mock/scenarios/clickhouse-theme-shape.spec.ts b/e2e/specs/mock/scenarios/clickhouse-theme-shape.spec.ts new file mode 100644 index 0000000000..bc58e56bf3 --- /dev/null +++ b/e2e/specs/mock/scenarios/clickhouse-theme-shape.spec.ts @@ -0,0 +1,107 @@ +import { expect, test } from '@playwright/test'; +import type { Locator, Page } from '@playwright/test'; +import { NEW_CHAT_PATH } from '../helpers'; +import { clickHouseTheme } from '../../../../packages/client/src/theme/themes/clickhouse'; +import { probeStyle } from './style.helpers'; + +/** + * The ClickHouse theme sets the radius, mono and shadow scales as well as its colours, so the + * plain `rounded-*`, `font-mono` and `shadow-*` utilities take Click UI's shape. The mention menu + * carries `rounded-2xl` and `shadow-lg` and opens from the composer, which makes it one real + * element on both scales. The mode comes from the project, and every expectation is read for the + * mode the page actually resolved. + */ +test.describe.configure({ timeout: 120_000 }); + +type Mode = 'light' | 'dark'; + +const SHADOW_ALPHA: Record = { light: 0.15, dark: 0.6 }; + +async function storeClickHouse(page: Page) { + await page.addInitScript((theme) => { + localStorage.removeItem('theme-colors'); + localStorage.removeItem('theme-name'); + localStorage.setItem('theme-definition', JSON.stringify(theme)); + localStorage.setItem('theme-source', 'definition'); + }, clickHouseTheme); +} + +/** Serves `interface.theme: clickhouse` on `/api/config`, the way librechat.yaml delivers it. */ +async function serveClickHouse(page: Page) { + await page.route( + (url) => url.pathname === '/api/config', + async (route) => { + const response = await route.fetch(); + const body = await response.json(); + await route.fulfill({ + response, + json: { ...body, interface: { ...body.interface, theme: 'clickhouse' } }, + }); + }, + ); +} + +async function openMentionMenu(page: Page): Promise { + await page.goto(NEW_CHAT_PATH, { timeout: 15000 }); + const composer = page.getByRole('textbox', { name: 'Message input' }); + await expect(composer).toBeVisible({ timeout: 30000 }); + await composer.click(); + await composer.pressSequentially('@'); + const search = page.getByPlaceholder('Mention an endpoint'); + await expect(search).toBeVisible({ timeout: 15000 }); + const menu = page.locator('div.popover').filter({ has: search }); + await expect(menu).toBeVisible(); + return menu; +} + +async function resolvedMode(page: Page): Promise { + const dark = await page.evaluate(() => document.documentElement.classList.contains('dark')); + return dark ? 'dark' : 'light'; +} + +async function expectClickUiShape(page: Page, menu: Locator) { + await expect(page.locator('html')).toHaveAttribute('data-theme', 'clickhouse'); + const alpha = SHADOW_ALPHA[await resolvedMode(page)]; + + /** Click UI's `radii.2`; LibreChat's own `rounded-2xl` is twice that. */ + await expect(menu).toHaveCSS('border-radius', '8px'); + const shadow = await menu.evaluate((node) => getComputedStyle(node).boxShadow); + expect(shadow).toContain(`rgba(21, 21, 21, ${alpha}) 0px 4px 6px -1px`); + expect(shadow).toContain(`rgba(21, 21, 21, ${alpha}) 0px 2px 4px -1px`); +} + +test.describe('ClickHouse theme shape', () => { + test('the ClickHouse theme draws the mention menu with Click UI corners and elevation @scenario:clickhouse-theme-reshapes-mention-menu', async ({ + page, + }) => { + await storeClickHouse(page); + + const menu = await openMentionMenu(page); + + await expectClickUiShape(page, menu); + }); + + test('interface.theme clickhouse reshapes the mention menu without a stored theme @scenario:clickhouse-deployment-theme-reshapes-mention-menu', async ({ + page, + }) => { + await serveClickHouse(page); + + const menu = await openMentionMenu(page); + + await expectClickUiShape(page, menu); + expect(await page.evaluate(() => localStorage.getItem('theme-definition'))).toBeNull(); + }); + + test('monospace text under the ClickHouse theme leads with Inconsolata @scenario:clickhouse-mono-font-leads-with-inconsolata', async ({ + page, + }) => { + await storeClickHouse(page); + + await openMentionMenu(page); + await expect(page.locator('html')).toHaveAttribute('data-theme', 'clickhouse'); + + const family = await probeStyle(page, 'font-mono', 'font-family'); + expect(family.replace(/"/g, '').startsWith('Inconsolata')).toBe(true); + expect(family).toContain('monospace'); + }); +}); diff --git a/packages/client/src/theme/README.md b/packages/client/src/theme/README.md index cf785bf3d0..a5e80ca7f8 100644 --- a/packages/client/src/theme/README.md +++ b/packages/client/src/theme/README.md @@ -44,6 +44,12 @@ The defaults reproduce the scale those utilities had before, so a theme that nam changes nothing. The mapping lives in the app stylesheet (`client/src/style.css`), not the published `theme.css`, whose preset keeps its own `rounded-sm`. +The bundled ClickHouse theme (`themes/clickhouse.ts`) is the reference for a theme that changes +shape as well as color: it tightens the radius scale to Click UI's `border.radii` steps, sets the +mono family to Inconsolata over a real fallback stack, and raises every surface with Click UI's +`shadow.1`, at 0.15 alpha in light mode and 0.6 in dark. Select it for a deployment with +`interface.theme: clickhouse` in `librechat.yaml`. + `themeRGB`, `REACT_APP_THEME_*`, and the existing localStorage keys remain supported through legacy adapters. Theme application removes only variables owned by the theme module when a theme is reset. diff --git a/packages/client/src/theme/themes/clickhouse.spec.tsx b/packages/client/src/theme/themes/clickhouse.spec.tsx index 749484c44e..cfbce8060f 100644 --- a/packages/client/src/theme/themes/clickhouse.spec.tsx +++ b/packages/client/src/theme/themes/clickhouse.spec.tsx @@ -308,6 +308,24 @@ describe('clickhouse theme definition', () => { roundControlRadius: '9999px', }); expect(resolved.appearance.fontFamily).toMatch(/^"Inter", "SF Pro Display"/); + expect(resolved.appearance.monoFontFamily).toMatch( + /^"Inconsolata", ui-monospace, .*monospace$/, + ); + /** Click UI's `border.radii` 1, 2 and 3. */ + expect(resolved.appearance).toMatchObject({ + radiusSm: '0.25rem', + radiusMd: '0.25rem', + radiusLg: '0.25rem', + radiusXl: '0.5rem', + radius2xl: '0.5rem', + radius3xl: '0.75rem', + }); + /** Click UI's `shadow.1`, deeper in dark mode, raises every surface. */ + const alpha = mode === 'light' ? '0.15' : '0.6'; + expect(resolved.appearance.shadowLg).toBe( + `0 4px 6px -1px rgb(21 21 21 / ${alpha}), 0 2px 4px -1px rgb(21 21 21 / ${alpha})`, + ); + expect(resolved.appearance.elevationSurface).toBe(resolved.appearance.shadowLg); }); it.each(modes)('repaints the %s canvas, text, border and accent roles', (mode) => { @@ -321,6 +339,28 @@ describe('clickhouse theme definition', () => { expect(clickHouse.appearance.controlRadius).not.toBe(defaultAppearance.controlRadius); expect(clickHouse.appearance.surfaceRadius).not.toBe(defaultAppearance.surfaceRadius); expect(clickHouse.appearance.largeSurfaceRadius).not.toBe(defaultAppearance.largeSurfaceRadius); + + /** The plain utilities' scales move too, not only the `theme-*` roles. `rounded-sm` is left + * out: Click UI's `radii.1` (0.25rem) renders the same as LibreChat's `calc(0.5rem - 4px)` + * on a 16px root. */ + const shapeTokens = [ + 'radiusMd', + 'radiusLg', + 'radiusXl', + 'radius2xl', + 'radius3xl', + 'monoFontFamily', + 'shadowXs', + 'shadowSm', + 'shadowMd', + 'shadowLg', + 'shadowXl', + 'shadow2xl', + 'elevationSurface', + ] as const; + expect( + shapeTokens.filter((token) => clickHouse.appearance[token] === libreChat.appearance[token]), + ).toEqual([]); }); it('keeps the brand yellow as the dark-mode accent and link', () => { @@ -381,6 +421,8 @@ describe('clickhouse theme at runtime', () => { expect(property('--surface-primary')).toBe(clickHouseDarkTheme['rgb-surface-primary']); expect(property('--text-primary')).toBe(clickHouseDarkTheme['rgb-text-primary']); expect(property('--theme-control-radius')).toBe('0.25rem'); + expect(property('--theme-radius-lg')).toBe('0.25rem'); + expect(property('--theme-shadow-lg')).toContain('rgb(21 21 21 / 0.6)'); rerender(renderProvider('dark', libreChatTheme)); @@ -391,5 +433,7 @@ describe('clickhouse theme at runtime', () => { expect(property('--surface-primary')).toBe(libreChatDark.colors['rgb-surface-primary']); expect(property('--text-primary')).toBe(libreChatDark.colors['rgb-text-primary']); expect(property('--theme-control-radius')).toBe(defaultAppearance.controlRadius); + expect(property('--theme-radius-lg')).toBe(defaultAppearance.radiusLg); + expect(property('--theme-shadow-lg')).toBe(defaultAppearance.shadowLg); }); }); diff --git a/packages/client/src/theme/themes/clickhouse.ts b/packages/client/src/theme/themes/clickhouse.ts index 0acaf2cff0..bd4197a383 100644 --- a/packages/client/src/theme/themes/clickhouse.ts +++ b/packages/client/src/theme/themes/clickhouse.ts @@ -1,4 +1,4 @@ -import type { ThemeDefinition, IThemeRGB } from '../types'; +import type { IThemeAppearance, ThemeDefinition, IThemeRGB } from '../types'; /** * ClickHouse reference theme, built from Click UI's design tokens @@ -265,22 +265,69 @@ export const clickHouseDarkTheme: IThemeRGB = { 'rgb-presentation': '31 31 28', // #1f1f1c (background.default) }; -/** Click UI's radius scale (`border.radii` 1, 2, 3 and full) and its regular - * family (`typography.font.families.regular`). */ -const clickHouseAppearance = { +/** + * Click UI's shape, from `border.radii`, `typography.font.families` and `shadow`. + * + * Nearly every Click UI component (button, field, card, menu, popover, table, toast) is drawn at + * `radii.1`, and the dialog at `radii.2`, so the small and medium steps collapse onto `radii.1`, + * the dialog-sized steps onto `radii.2`, and the largest onto `radii.3`. `rounded-sm` takes + * `radii.1`, which LibreChat's `sm` also renders at on a 16px root; every larger step tightens. + * + * Click UI's mono family is Inconsolata. The app does not bundle it, so the tail is the same + * metric-matched stack the default theme uses (Click UI's own tail names `"SFMono Regular"`, + * which no platform installs). + * + * Click UI raises every elevated surface (card, dialog, menu, panel, popover, toast) with + * `shadow.1`, and its only lighter step is the hairline `shadow.5`. Steps 2 to 4 are the flyout's + * inset and directional edges, which do not belong on a general scale. `shadow.1` darkens from + * 0.15 to 0.6 alpha in dark mode; its colour is `#151515` in both (written `lch(6.7738 0 none)` + * in the light tokens and as percentages in the dark). + */ +const clickHouseShape = { controlRadius: '0.25rem', surfaceRadius: '0.5rem', largeSurfaceRadius: '0.75rem', roundControlRadius: '9999px', + radiusSm: '0.25rem', // border.radii.1 + radiusMd: '0.25rem', // border.radii.1 + radiusLg: '0.25rem', // border.radii.1 + radiusXl: '0.5rem', // border.radii.2 + radius2xl: '0.5rem', // border.radii.2 + radius3xl: '0.75rem', // border.radii.3 fontFamily: '"Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif', + monoFontFamily: + '"Inconsolata", ui-monospace, SFMono-Regular, Menlo, "Cascadia Mono", "Liberation Mono", Consolas, monospace', + shadowXs: '0 2px 2px 0 rgb(0 0 0 / 0.03)', // shadow.5 + shadowSm: '0 2px 2px 0 rgb(0 0 0 / 0.03)', // shadow.5 +}; + +const elevation = (alpha: number): string => + `0 4px 6px -1px rgb(21 21 21 / ${alpha}), 0 2px 4px -1px rgb(21 21 21 / ${alpha})`; + +const clickHouseElevation = (alpha: number): Partial => ({ + shadowMd: elevation(alpha), // shadow.1 + shadowLg: elevation(alpha), // shadow.1 + shadowXl: elevation(alpha), // shadow.1 + shadow2xl: elevation(alpha), // shadow.1 + elevationSurface: elevation(alpha), // shadow.1 +}); + +const clickHouseLightAppearance: Partial = { + ...clickHouseShape, + ...clickHouseElevation(0.15), +}; + +const clickHouseDarkAppearance: Partial = { + ...clickHouseShape, + ...clickHouseElevation(0.6), }; export const clickHouseTheme: ThemeDefinition = Object.freeze({ version: 1, name: 'clickhouse', modes: { - light: { colors: clickHouseLightTheme, appearance: clickHouseAppearance }, - dark: { colors: clickHouseDarkTheme, appearance: clickHouseAppearance }, + light: { colors: clickHouseLightTheme, appearance: clickHouseLightAppearance }, + dark: { colors: clickHouseDarkTheme, appearance: clickHouseDarkAppearance }, }, });