From cfeaee13ab8b4366708f32f3a8d5e6a53af5118f Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Thu, 1 Oct 2026 12:12:02 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=97=20feat:=20Per-Mode=20Appearance=20?= =?UTF-8?q?Defaults=20for=20Menu=20and=20Tooltip=20Shadows=20(#16602)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/style.css | 14 ++- e2e/specs/mock/scenarios/menu-shadow.spec.ts | 105 ++++++++++++------ packages/client/src/components/Dropdown.css | 10 +- packages/client/src/components/Tooltip.css | 4 +- packages/client/src/theme/README.md | 6 + packages/client/src/theme/defaults.css | 9 ++ packages/client/src/theme/defaults.spec.ts | 23 +++- packages/client/src/theme/index.ts | 2 + packages/client/src/theme/registry.spec.ts | 75 ++++++++++++- packages/client/src/theme/registry.ts | 45 +++++++- packages/client/src/theme/tailwind.spec.js | 6 +- .../client/src/theme/themes/clickhouse.ts | 3 + .../client/src/theme/themes/clickui.spec.ts | 57 ++++------ packages/client/src/theme/types/index.ts | 4 + packages/data-provider/specs/theme.spec.ts | 49 ++++++++ packages/data-provider/src/theme.ts | 3 + 16 files changed, 324 insertions(+), 91 deletions(-) create mode 100644 packages/data-provider/specs/theme.spec.ts diff --git a/client/src/style.css b/client/src/style.css index 296bd6cc0f..5f9e32cc90 100644 --- a/client/src/style.css +++ b/client/src/style.css @@ -1982,11 +1982,11 @@ html { font-size: 1rem; line-height: 1.5rem; color: rgb(var(--text-primary)); - box-shadow: 0 2px 4px 0 rgb(0 0 0 / 0.25); + box-shadow: var(--theme-tooltip-shadow, 0 2px 4px 0 rgb(0 0 0 / 0.25)); } .tooltip:where(.dark, .dark *) { - box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.35); + box-shadow: var(--theme-tooltip-shadow, 0 1px 2px 0 rgb(0 0 0 / 0.35)); } @layer base { @@ -2071,9 +2071,9 @@ html[data-input-modality='keyboard'] background-color: rgb(var(--surface-primary)); padding: 0.5rem; color: rgb(var(--text-primary)); - /* The `shadowLg` role, whose default is this literal. */ + /* The `menuShadow` role, whose light default is this literal. */ box-shadow: var( - --theme-shadow-lg, + --theme-menu-shadow, 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1) ); @@ -2108,9 +2108,11 @@ html[data-input-modality='keyboard'] .popover-ui:where(.dark, .dark *) { background-color: rgb(var(--surface-secondary)); color: rgb(var(--text-secondary)); - box-shadow: + box-shadow: var( + --theme-menu-shadow, 0 10px 15px -3px rgb(0 0 0 / 0.25), - 0 4px 6px -4px rgb(0 0 0 / 0.1); + 0 4px 6px -4px rgb(0 0 0 / 0.1) + ); } .select-item { diff --git a/e2e/specs/mock/scenarios/menu-shadow.spec.ts b/e2e/specs/mock/scenarios/menu-shadow.spec.ts index f05f6b8e9a..a303b403e9 100644 --- a/e2e/specs/mock/scenarios/menu-shadow.spec.ts +++ b/e2e/specs/mock/scenarios/menu-shadow.spec.ts @@ -5,10 +5,11 @@ import { NEW_CHAT_PATH } from '../helpers'; import { probeStyle } from './style.helpers'; /** - * The shared menu panel (`.popover-ui`) draws its light shadow from the `shadowLg` role, whose - * default is the literal it drew before, so the default theme is unchanged and the ClickHouse - * theme takes Click UI's `genericMenu.panel.shadow.default`. The dark panel keeps the app's own - * literal in every theme (berry-13/LibreChat#217). + * The shared menu panel (`.popover-ui`) and tooltip (`.tooltip`) draw their shadows from the + * `menuShadow` and `tooltipShadow` roles, whose light and dark defaults are the literals each mode + * drew before, so the default theme is unchanged. The ClickHouse theme takes Click UI's + * `genericMenu.panel.shadow.default` in each mode and draws tooltips with no shadow, and a theme + * that names only `shadowLg` keeps shading its light menus with it, as it did before the role. */ type Mode = 'light' | 'dark'; @@ -17,6 +18,20 @@ const DEFAULT_LIGHT = 'rgba(0, 0, 0, 0.1) 0px 10px 15px -3px, rgba(0, 0, 0, 0.1) const DARK = 'rgba(0, 0, 0, 0.25) 0px 10px 15px -3px, rgba(0, 0, 0, 0.1) 0px 4px 6px -4px'; const CLICKHOUSE_LIGHT = 'rgba(21, 21, 21, 0.15) 0px 4px 6px -1px, rgba(21, 21, 21, 0.15) 0px 2px 4px -1px'; +const CLICKHOUSE_DARK = + 'rgba(21, 21, 21, 0.6) 0px 4px 6px -1px, rgba(21, 21, 21, 0.6) 0px 2px 4px -1px'; +const TOOLTIP_LIGHT = 'rgba(0, 0, 0, 0.25) 0px 2px 4px 0px'; +const TOOLTIP_DARK = 'rgba(0, 0, 0, 0.35) 0px 1px 2px 0px'; + +/** Names only the general large shadow, the way a theme written before the menu role would. */ +const LG_ONLY_THEME = { + version: 1, + name: 'e2e-shadow-lg-only', + modes: { + light: { appearance: { shadowLg: '0 1px 2px 0 rgb(10 20 30 / 0.5)' } }, + dark: { appearance: { shadowLg: '0 1px 2px 0 rgb(10 20 30 / 0.5)' } }, + }, +} as const; async function openChat(page: Page, mode: Mode, definition?: { name: string }) { await page.addInitScript( @@ -44,41 +59,61 @@ async function openChat(page: Page, mode: Mode, definition?: { name: string }) { } } -const CASES: Array<{ title: string; mode: Mode; definition?: { name: string }; shadow: string }> = [ - { - title: - 'the default light menu panel keeps its shadow @scenario:menu-shadow-default-light-unchanged', - mode: 'light', - shadow: DEFAULT_LIGHT, - }, - { - title: - 'the default dark menu panel keeps its shadow @scenario:menu-shadow-default-dark-unchanged', - mode: 'dark', - shadow: DARK, - }, - { - title: - 'the ClickHouse light menu panel takes the Click UI menu shadow @scenario:menu-shadow-clickhouse-light', - mode: 'light', - definition: clickHouseTheme, - shadow: CLICKHOUSE_LIGHT, - }, - { - title: - 'the ClickHouse dark menu panel keeps the app dark shadow @scenario:menu-shadow-clickhouse-dark-unchanged', - mode: 'dark', - definition: clickHouseTheme, - shadow: DARK, - }, -]; +type Shadows = { menu: string; tooltip: string }; -test.describe('menu panel shadow', () => { - for (const { title, mode, definition, shadow } of CASES) { +const CASES: Array<{ title: string; mode: Mode; definition?: { name: string }; shadows: Shadows }> = + [ + { + title: + 'the default light menu panel and tooltip keep their shadows @scenario:menu-shadow-default-light-unchanged', + mode: 'light', + shadows: { menu: DEFAULT_LIGHT, tooltip: TOOLTIP_LIGHT }, + }, + { + title: + 'the default dark menu panel and tooltip keep their shadows @scenario:menu-shadow-default-dark-unchanged', + mode: 'dark', + shadows: { menu: DARK, tooltip: TOOLTIP_DARK }, + }, + { + title: + 'the ClickHouse light theme takes the Click UI menu shadow and drops the tooltip shadow @scenario:menu-shadow-clickhouse-light', + mode: 'light', + definition: clickHouseTheme, + shadows: { menu: CLICKHOUSE_LIGHT, tooltip: 'none' }, + }, + { + title: + 'the ClickHouse dark theme takes the Click UI menu shadow and drops the tooltip shadow @scenario:menu-shadow-clickhouse-dark', + mode: 'dark', + definition: clickHouseTheme, + shadows: { menu: CLICKHOUSE_DARK, tooltip: 'none' }, + }, + { + title: + 'a light theme that names only shadowLg still shades its menus with it @scenario:menu-shadow-follows-shadow-lg-light', + mode: 'light', + definition: LG_ONLY_THEME, + shadows: { menu: 'rgba(10, 20, 30, 0.5) 0px 1px 2px 0px', tooltip: TOOLTIP_LIGHT }, + }, + { + title: + 'a dark theme that names only shadowLg keeps the dark menu literal @scenario:menu-shadow-shadow-lg-dark-unchanged', + mode: 'dark', + definition: LG_ONLY_THEME, + shadows: { menu: DARK, tooltip: TOOLTIP_DARK }, + }, + ]; + +test.describe('menu panel and tooltip shadows', () => { + for (const { title, mode, definition, shadows } of CASES) { test(title, async ({ page }) => { await openChat(page, mode, definition); - expect(await probeStyle(page, 'popover-ui', 'box-shadow')).toBe(shadow); + expect({ + menu: await probeStyle(page, 'popover-ui', 'box-shadow'), + tooltip: await probeStyle(page, 'tooltip', 'box-shadow'), + }).toEqual(shadows); }); } }); diff --git a/packages/client/src/components/Dropdown.css b/packages/client/src/components/Dropdown.css index 3d140f89ec..e427137c6d 100644 --- a/packages/client/src/components/Dropdown.css +++ b/packages/client/src/components/Dropdown.css @@ -11,9 +11,9 @@ background-color: rgb(var(--surface-primary)); padding: 0.5rem; color: rgb(var(--text-primary)); - /* The `shadowLg` role, whose default is this literal. */ + /* The `menuShadow` role, whose light default is this literal. */ box-shadow: var( - --theme-shadow-lg, + --theme-menu-shadow, 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1) ); @@ -56,9 +56,11 @@ html.high-contrast .popover-ui { .popover-ui:where(.dark, .dark *) { background-color: rgb(var(--surface-secondary)); color: rgb(var(--text-secondary)); - box-shadow: + box-shadow: var( + --theme-menu-shadow, 0 10px 15px -3px rgb(0 0 0 / 0.25), - 0 4px 6px -4px rgb(0 0 0 / 0.1); + 0 4px 6px -4px rgb(0 0 0 / 0.1) + ); } .select-item { diff --git a/packages/client/src/components/Tooltip.css b/packages/client/src/components/Tooltip.css index 89a71d95cc..d8db905f24 100644 --- a/packages/client/src/components/Tooltip.css +++ b/packages/client/src/components/Tooltip.css @@ -11,7 +11,7 @@ font-size: 1rem; line-height: 1.5rem; color: rgb(var(--text-primary)); - box-shadow: 0 2px 4px 0 rgb(0 0 0 / 0.25); + box-shadow: var(--theme-tooltip-shadow, 0 2px 4px 0 rgb(0 0 0 / 0.25)); /* Enhanced layout for longer descriptions */ max-width: 320px; word-wrap: break-word; @@ -25,7 +25,7 @@ } .tooltip:where(.dark, .dark *) { - box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.35); + box-shadow: var(--theme-tooltip-shadow, 0 1px 2px 0 rgb(0 0 0 / 0.35)); } /* The contrast edge ships with the primitive: the app stylesheet is not part of diff --git a/packages/client/src/theme/README.md b/packages/client/src/theme/README.md index 83d5bbb5b0..e5bbcecce3 100644 --- a/packages/client/src/theme/README.md +++ b/packages/client/src/theme/README.md @@ -63,6 +63,12 @@ Three primitives keep corners of their own outside that scale: the menu panel (` `menuRadius` (0.7rem), the tooltip reads `tooltipRadius` (0.275rem) and the tab trigger reads `tabRadius` (0.185rem, through `rounded-theme-tab`). The defaults are the corners they always drew. +Most appearance defaults hold in both modes. `darkAppearanceDefaults` lists the ones that differ in +dark mode, and `defaultAppearanceFor(mode)` returns the full set for a mode: the menu panel's +`menuShadow` and the tooltip's `tooltipShadow` are heavier on a dark page, as they always were. A +theme that names a role in one mode replaces that mode's default only, and a theme that names +`shadowLg` but not `menuShadow` keeps shading its light menus with `shadowLg`. + 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 diff --git a/packages/client/src/theme/defaults.css b/packages/client/src/theme/defaults.css index ccdc465903..90c4695089 100644 --- a/packages/client/src/theme/defaults.css +++ b/packages/client/src/theme/defaults.css @@ -269,6 +269,12 @@ html { --theme-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1); --theme-shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1); --theme-shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.25); + --theme-menu-shadow: var( + --theme-shadow-lg, + 0 10px 15px -3px rgb(0 0 0 / 0.1), + 0 4px 6px -4px rgb(0 0 0 / 0.1) + ); + --theme-tooltip-shadow: 0 2px 4px 0 rgb(0 0 0 / 0.25); --theme-motion-fast: 150ms; --theme-motion-normal: 200ms; --switch-unchecked: 148 148 148; @@ -412,6 +418,9 @@ html { --provider-azure: linear-gradient(0.375turn, #61bde2, #4389d0); --provider-bedrock: #268672; --provider-foreground: #ffffff; + /* The appearance defaults that differ in dark mode (`darkAppearanceDefaults`). */ + --theme-menu-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.25), 0 4px 6px -4px rgb(0 0 0 / 0.1); + --theme-tooltip-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.35); } /* A root other than the document one that a legacy palette themes (`THEME_SCOPE_ATTRIBUTE` in diff --git a/packages/client/src/theme/defaults.spec.ts b/packages/client/src/theme/defaults.spec.ts index dc7b21afb3..3427b7c98e 100644 --- a/packages/client/src/theme/defaults.spec.ts +++ b/packages/client/src/theme/defaults.spec.ts @@ -1,7 +1,12 @@ import fs from 'fs'; import path from 'path'; import type { IThemeRGB } from './types'; -import { defaultAppearance, defaultBrands, themeAppearanceProperties } from './registry'; +import { + defaultBrands, + defaultAppearance, + darkAppearanceDefaults, + themeAppearanceProperties, +} from './registry'; import { defaultTheme } from './themes/default'; import { darkTheme } from './themes/dark'; @@ -17,7 +22,7 @@ function declarations(selector: string): Map { return new Map( Array.from(withoutComments.matchAll(/(--[\w-]+):\s*([^;]+);/g), (match) => [ match[1], - match[2].replace(/\s+/g, ' ').trim(), + match[2].replace(/\s+/g, ' ').replace(/\(\s+/g, '(').replace(/\s+\)/g, ')').trim(), ]), ); } @@ -87,6 +92,7 @@ const stockAliases: Partial< labelSize: 'textSm', dialogTitleSize: 'textLg', dialogTitleFontFamily: 'displayFontFamily', + menuShadow: 'shadowLg', }; /** Color roles split out of a broader one read it in the stylesheet, in both modes, so a @@ -119,6 +125,19 @@ describe('the stock appearance and brands', () => { }); }); + it('declares the appearance defaults that differ in dark mode in the dark rule only', () => { + Object.entries(darkAppearanceDefaults).forEach(([key, value]) => { + const property = themeAppearanceProperties[key as keyof typeof defaultAppearance]; + expect([property, dark.get(property)]).toEqual([property, value?.replace(/\s+/g, ' ')]); + }); + const darkOnly = [...dark.keys()].filter((property) => property.startsWith('--theme-')); + expect(darkOnly.sort()).toEqual( + Object.keys(darkAppearanceDefaults) + .map((key) => themeAppearanceProperties[key as keyof typeof defaultAppearance]) + .sort(), + ); + }); + it.each([ ['light', false], ['dark', true], diff --git a/packages/client/src/theme/index.ts b/packages/client/src/theme/index.ts index afb5d1a891..d302676eec 100644 --- a/packages/client/src/theme/index.ts +++ b/packages/client/src/theme/index.ts @@ -23,7 +23,9 @@ export { HIGH_CONTRAST_THEME_NAME, THEME_VERSION, collectThemeWarnings, + darkAppearanceDefaults, defaultAppearance, + defaultAppearanceFor, defaultBrands, fromLegacyTheme, highContrastTheme, diff --git a/packages/client/src/theme/registry.spec.ts b/packages/client/src/theme/registry.spec.ts index 89bcad928f..f4e9dbfdef 100644 --- a/packages/client/src/theme/registry.spec.ts +++ b/packages/client/src/theme/registry.spec.ts @@ -3,6 +3,8 @@ import { readFileSync } from 'node:fs'; import type { ThemeDefinition } from './types'; import { collectThemeWarnings, + darkAppearanceDefaults, + defaultAppearanceFor, defaultAppearance, defaultBrands, fromLegacyTheme, @@ -14,6 +16,7 @@ import { import { clickHouseTheme } from './themes/clickhouse'; import { defaultTheme } from './themes/default'; import { darkTheme } from './themes/dark'; +import * as themeEntry from './index'; const compactTheme: ThemeDefinition = { version: 1, @@ -51,7 +54,7 @@ describe('theme registry', () => { expect(light.appearance.controlRadius).toBe('0.25rem'); expect(light.appearance.fontFamily).toBe(defaultAppearance.fontFamily); expect(dark.colors['rgb-text-primary']).toBe(darkTheme['rgb-text-primary']); - expect(dark.appearance).toEqual(defaultAppearance); + expect(dark.appearance).toEqual(defaultAppearanceFor('dark')); }); it('derives omitted code surfaces from the mode-specific legacy canvas', () => { @@ -948,6 +951,74 @@ describe('theme registry', () => { ].forEach((appearance) => expect(issues(appearance)).toHaveLength(1)); }); + describe('appearance defaults that differ per mode', () => { + const lightMenu = '0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)'; + const darkMenu = '0 10px 15px -3px rgb(0 0 0 / 0.25), 0 4px 6px -4px rgb(0 0 0 / 0.1)'; + const lightTooltip = '0 2px 4px 0 rgb(0 0 0 / 0.25)'; + const darkTooltip = '0 1px 2px 0 rgb(0 0 0 / 0.35)'; + const shadows = (theme: ThemeDefinition, mode: 'light' | 'dark') => { + const { menuShadow, tooltipShadow } = resolveTheme(theme, mode).appearance; + return { menuShadow, tooltipShadow }; + }; + const theme = (modes: ThemeDefinition['modes']): ThemeDefinition => ({ + version: 1, + name: 'mode-default-reference', + modes, + }); + + it('publishes the per-mode defaults from the theme entry point', () => { + expect(themeEntry.defaultAppearanceFor).toBe(defaultAppearanceFor); + expect(themeEntry.darkAppearanceDefaults).toBe(darkAppearanceDefaults); + }); + + it('keeps the menu and tooltip shadows each mode drew before they had roles', () => { + expect(shadows(theme({}), 'light')).toEqual({ + menuShadow: lightMenu, + tooltipShadow: lightTooltip, + }); + expect(shadows(theme({}), 'dark')).toEqual({ + menuShadow: darkMenu, + tooltipShadow: darkTooltip, + }); + expect(defaultAppearanceFor('light')).toBe(defaultAppearance); + expect(defaultAppearanceFor('dark')).toEqual({ + ...defaultAppearance, + ...darkAppearanceDefaults, + }); + }); + + it('shades light menus with a theme that names only shadowLg, and keeps the dark literal', () => { + const shadowLg = '0 4px 6px -1px rgb(21 21 21 / 0.15)'; + const lgOnly = theme({ + light: { appearance: { shadowLg } }, + dark: { appearance: { shadowLg } }, + }); + + expect(shadows(lgOnly, 'light').menuShadow).toBe(shadowLg); + expect(shadows(lgOnly, 'dark').menuShadow).toBe(darkMenu); + }); + + it('applies a value named in one mode to that mode only', () => { + const darkOnly = theme({ + dark: { appearance: { menuShadow: 'none', tooltipShadow: 'none' } }, + }); + + expect(shadows(darkOnly, 'light')).toEqual({ + menuShadow: lightMenu, + tooltipShadow: lightTooltip, + }); + expect(shadows(darkOnly, 'dark')).toEqual({ menuShadow: 'none', tooltipShadow: 'none' }); + }); + + it('lets a named menu shadow win over shadowLg in light', () => { + const both = theme({ + light: { appearance: { shadowLg: '0 1px 2px 0 rgb(0 0 0 / 0.5)', menuShadow: 'none' } }, + }); + + expect(shadows(both, 'light').menuShadow).toBe('none'); + }); + }); + it('keeps the menu, tooltip and tab corners on their old literals unless a theme names its own', () => { expect(defaultAppearance).toMatchObject({ menuRadius: '0.7rem', @@ -1471,7 +1542,7 @@ describe('theme registry', () => { expect(light.colors['rgb-text-primary']).toBe('1 2 3'); expect(light.appearance).toEqual({ ...defaultAppearance, controlRadius: '2px' }); expect(light.brands['provider-openai']).toBe('#123456'); - expect(resolveTheme(newerTheme, 'dark').appearance).toEqual(defaultAppearance); + expect(resolveTheme(newerTheme, 'dark').appearance).toEqual(defaultAppearanceFor('dark')); }); it('reports nothing for a definition that only uses known tokens', () => { diff --git a/packages/client/src/theme/registry.ts b/packages/client/src/theme/registry.ts index 367c28672b..fcb9e1d463 100644 --- a/packages/client/src/theme/registry.ts +++ b/packages/client/src/theme/registry.ts @@ -225,6 +225,8 @@ export const themeAppearanceProperties: Readonly< shadowLg: '--theme-shadow-lg', shadowXl: '--theme-shadow-xl', shadow2xl: '--theme-shadow-2xl', + menuShadow: '--theme-menu-shadow', + tooltipShadow: '--theme-tooltip-shadow', motionFast: '--theme-motion-fast', motionNormal: '--theme-motion-normal', }); @@ -297,10 +299,27 @@ export const defaultAppearance: IThemeAppearance = Object.freeze({ shadowLg: '0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)', shadowXl: '0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)', shadow2xl: '0 25px 50px -12px rgb(0 0 0 / 0.25)', + menuShadow: '0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)', + tooltipShadow: '0 2px 4px 0 rgb(0 0 0 / 0.25)', motionFast: '150ms', motionNormal: '200ms', }); +/** + * The defaults that differ in dark mode, over `defaultAppearance`. The menu panel and the tooltip + * always drew a heavier shadow on a dark page, so their dark defaults are those literals. A theme + * that names a role in a mode replaces the default for that mode only. + */ +export const darkAppearanceDefaults: Readonly> = Object.freeze({ + menuShadow: '0 10px 15px -3px rgb(0 0 0 / 0.25), 0 4px 6px -4px rgb(0 0 0 / 0.1)', + tooltipShadow: '0 1px 2px 0 rgb(0 0 0 / 0.35)', +}); + +/** Every appearance default in `mode`. */ +export function defaultAppearanceFor(mode: ThemeMode): IThemeAppearance { + return mode === 'dark' ? { ...defaultAppearance, ...darkAppearanceDefaults } : defaultAppearance; +} + export const themeBrandTokens: readonly (keyof IThemeBrands)[] = sharedBrandTokens; export const defaultBrands: IThemeBrands = Object.freeze({ @@ -446,16 +465,34 @@ const inheritedAppearance: ReadonlyArray<[keyof IThemeAppearance, keyof IThemeAp ['dialogTitleFontFamily', 'displayFontFamily'], ]; -function withInheritedRoles(appearance?: Partial): IThemeAppearance { +/** + * Pairs that hold in one mode only. The light menu panel read `shadowLg` before it had a role, so + * a theme that names `shadowLg` keeps shading its light menus with it; the dark panel always drew + * its own literal, which is now its dark default. + */ +const modeInheritedAppearance: Record< + ThemeMode, + ReadonlyArray<[keyof IThemeAppearance, keyof IThemeAppearance]> +> = { + light: [['menuShadow', 'shadowLg']], + dark: [], +}; + +function withInheritedRoles( + mode: ThemeMode, + appearance?: Partial, +): IThemeAppearance { const known = knownAppearance(appearance); - const resolved = inheritedAppearance.reduce>( + const resolved = [...inheritedAppearance, ...modeInheritedAppearance[mode]].reduce< + Partial + >( (roles, [role, source]) => roles[role] === undefined && roles[source] !== undefined ? { ...roles, [role]: roles[source] } : roles, known, ); - return { ...defaultAppearance, ...resolved }; + return { ...defaultAppearanceFor(mode), ...resolved }; } export function resolveTheme(theme: ThemeDefinition, mode: ThemeMode): ResolvedThemeDefinition { @@ -652,7 +689,7 @@ export function resolveTheme(theme: ThemeDefinition, mode: ThemeMode): ResolvedT ...seriesEightFallback, ...verifiedFallback, } as Required, - appearance: withComposableShadows(withInheritedRoles(definition?.appearance)), + appearance: withComposableShadows(withInheritedRoles(mode, definition?.appearance)), /** Mode last: a mode override is more specific than the theme-wide set. */ brands: { ...defaultBrands, diff --git a/packages/client/src/theme/tailwind.spec.js b/packages/client/src/theme/tailwind.spec.js index 230865d81a..1171aa5872 100644 --- a/packages/client/src/theme/tailwind.spec.js +++ b/packages/client/src/theme/tailwind.spec.js @@ -238,7 +238,10 @@ describe('LibreChat Tailwind preset', () => { const stockStyles = fs.readFileSync(path.resolve(__dirname, 'defaults.css'), 'utf8'); /** Prettier wraps a long font stack, so declarations compare with whitespace collapsed. */ - const collapsed = stockStyles.replace(/\s+/g, ' '); + const collapsed = stockStyles + .replace(/\s+/g, ' ') + .replace(/\(\s+/g, '(') + .replace(/\s+\)/g, ')'); /** Roles split out of a broader one alias the role they were split from. */ const aliases = { controlPaddingX: 'spaceNormal', @@ -246,6 +249,7 @@ describe('LibreChat Tailwind preset', () => { labelSize: 'textSm', dialogTitleSize: 'textLg', dialogTitleFontFamily: 'displayFontFamily', + menuShadow: 'shadowLg', }; Object.entries(themeAppearanceProperties).forEach(([key, property]) => { const value = aliases[key] diff --git a/packages/client/src/theme/themes/clickhouse.ts b/packages/client/src/theme/themes/clickhouse.ts index 010fafe50e..f3a44e2506 100644 --- a/packages/client/src/theme/themes/clickhouse.ts +++ b/packages/client/src/theme/themes/clickhouse.ts @@ -434,6 +434,9 @@ const clickHouseElevation = (alpha: number): Partial => ({ shadowXl: elevation(alpha), // shadow.1 shadow2xl: elevation(alpha), // shadow.1 elevationSurface: elevation(alpha), // shadow.1 + menuShadow: elevation(alpha), // genericMenu.panel.shadow.default, which is shadow.1 + /** Click UI's tooltip draws no shadow (Tooltip.module.css). */ + tooltipShadow: 'none', }); const clickHouseLightAppearance: Partial = { diff --git a/packages/client/src/theme/themes/clickui.spec.ts b/packages/client/src/theme/themes/clickui.spec.ts index fd02d3bbc4..5f8f476607 100644 --- a/packages/client/src/theme/themes/clickui.spec.ts +++ b/packages/client/src/theme/themes/clickui.spec.ts @@ -462,6 +462,12 @@ const appearanceDecisions: Partial> = { shadowXl: 'shadow.1', shadow2xl: 'shadow.1', elevationSurface: 'shadow.1', + menuShadow: 'click.genericMenu.panel.shadow.default', controlHeight: 'click.genericMenu.panel.size.height', controlPaddingX: 'click.button.basic.space.x', controlGap: 'click.button.basic.space.gap', @@ -709,7 +716,7 @@ function comparable(key: keyof IThemeAppearance, raw: string | number): string { if (scrimKeys.has(key)) { return /^[\d.]+$/.test(value) ? String(Number(value)) : String(parseColor(value)[3]); } - if (key.startsWith('shadow') || key === 'elevationSurface') { + if (/shadow/i.test(key) || key === 'elevationSurface') { return normalizeShadow(value); } /** Click UI's mono tail names `"SFMono Regular"`, which no platform installs; the theme keeps @@ -895,31 +902,24 @@ const popoverCorner = (mode: ThemeMode) => { } }; -/** - * The Dropdown menu's shadow. The package rule reads `shadowLg`; the app stylesheet repeats it in - * light and repaints it in dark with a literal, and the app's rules win, so dark reads that one. - */ -const menuShadow = (mode: ThemeMode) => { - if (mode === 'dark') { - return cssValue(APP_STYLESHEET, '.popover-ui:where(.dark, .dark *)', 'box-shadow'); - } - const own = cssValue('components/Dropdown.css', '.popover-ui', 'box-shadow'); - const app = cssValue(APP_STYLESHEET, '.popover-ui', 'box-shadow'); - if (app !== own) { - throw new Error( - `The app's .popover-ui shadow (${app}) no longer repeats Dropdown.css (${own})`, - ); - } - return resolveRoleVar(own, mode); -}; +/** The Dropdown menu's shadow, which reads `menuShadow`: `.popover-ui` in light, and its `.dark` + * rule in dark, each repeated by the app stylesheet. */ +const menuShadow = (mode: ThemeMode) => + appCopyResolved( + 'Dropdown.css', + mode === 'dark' ? '.popover-ui:where(.dark, .dark *)' : '.popover-ui', + 'box-shadow', + mode, + ); -/** The Tooltip's shadow: `.tooltip` in light, and its `.dark` rule in dark. Tooltip renders the - * bare `tooltip` class, so nothing but this stylesheet paints it. */ +/** The Tooltip's shadow, which reads `tooltipShadow`: `.tooltip` in light, and its `.dark` rule in + * dark. Tooltip renders the bare `tooltip` class, so nothing but these rules paints it. */ const tooltipShadow = (mode: ThemeMode) => - cssValue( - 'components/Tooltip.css', + appCopyResolved( + 'Tooltip.css', mode === 'dark' ? '.tooltip:where(.dark, .dark *)' : '.tooltip', 'box-shadow', + mode, ); /** The Tabs trigger, which takes its corner from a radius utility. */ @@ -1243,19 +1243,6 @@ const notExpressible: Record = { 'the field is transparent and inks with text-primary; a color role is an opaque triplet, so no role can default to no fill, and no role holds field ink apart from body copy', issue: 'https://github.com/berry-13/LibreChat/issues/206', }, - - 'Dropdown menu shadow': { - decisions: { dark: ['Dropdown menu shadow'] }, - reason: - "light reads shadowLg, but the app's dark .popover-ui rule repaints the shadow with a 0.25-alpha literal that no shadow role defaults to", - issue: 'https://github.com/berry-13/LibreChat/issues/217', - }, - 'Tooltip shadow': { - decisions: { light: ['Tooltip shadow'], dark: ['Tooltip shadow'] }, - reason: - 'Tooltip.css draws a black drop shadow, a different one in each mode, and no shadow role defaults to either, where Click UI draws none', - issue: 'https://github.com/berry-13/LibreChat/issues/220', - }, }; type Verdict = 'match' | 'near' | 'deviation' | 'not expressible'; diff --git a/packages/client/src/theme/types/index.ts b/packages/client/src/theme/types/index.ts index ead46a0ee4..9e350125f7 100644 --- a/packages/client/src/theme/types/index.ts +++ b/packages/client/src/theme/types/index.ts @@ -536,6 +536,10 @@ export interface IThemeAppearance { shadowLg: string; shadowXl: string; shadow2xl: string; + /** The menu panel's and the tooltip's shadows. Their dark defaults differ from the light ones, + * and the light menu shadow follows `shadowLg` when a theme names only that. */ + menuShadow: string; + tooltipShadow: string; motionFast: string; motionNormal: string; } diff --git a/packages/data-provider/specs/theme.spec.ts b/packages/data-provider/specs/theme.spec.ts new file mode 100644 index 0000000000..7fe311c0de --- /dev/null +++ b/packages/data-provider/specs/theme.spec.ts @@ -0,0 +1,49 @@ +import { collectThemeIssues } from '../src/theme'; +import { deploymentThemeSchema } from '../src/config'; + +/** A deployment theme as `librechat.yaml` delivers it, with appearance only in the given modes. */ +const definition = (modes: Record>) => ({ + version: 1, + name: 'mode-shadow-reference', + modes: Object.fromEntries( + Object.entries(modes).map(([mode, appearance]) => [mode, { appearance }]), + ), +}); + +const messages = (theme: unknown) => collectThemeIssues(theme).map(({ message }) => message); + +describe('menu and tooltip shadow roles in a theme definition', () => { + it('accepts a different shadow per mode, `none` included', () => { + const theme = definition({ + light: { menuShadow: '0 4px 6px -1px rgb(21 21 21 / 0.15)', tooltipShadow: 'none' }, + dark: { + menuShadow: '0 4px 6px -1px rgb(21 21 21 / 0.6), 0 2px 4px -1px rgb(21 21 21 / 0.6)', + tooltipShadow: '0 1px 2px 0 rgb(0 0 0 / 0.35)', + }, + }); + + expect(deploymentThemeSchema.safeParse(theme).success).toBe(true); + expect(messages(theme)).toEqual([]); + }); + + it('accepts a shadow named in one mode only, leaving the other to its default', () => { + const theme = definition({ dark: { tooltipShadow: 'none' } }); + + expect(deploymentThemeSchema.safeParse(theme).success).toBe(true); + expect(messages(theme)).toEqual([]); + }); + + it.each([ + ['menuShadow', 'var(--theme-shadow-lg)'], + ['menuShadow', '0 4px; color: red'], + ['menuShadow', 'big'], + ['tooltipShadow', '0 1px 2px 0 rgb(0 0 0 / 0.35),'], + ['tooltipShadow', 'url(x.png)'], + ])('rejects %s %s in either mode', (role, value) => { + for (const mode of ['light', 'dark']) { + expect(messages(definition({ [mode]: { [role]: value } }))).toEqual([ + `Invalid appearance value for ${role}: ${value}`, + ]); + } + }); +}); diff --git a/packages/data-provider/src/theme.ts b/packages/data-provider/src/theme.ts index c8489e7306..f964a5d717 100644 --- a/packages/data-provider/src/theme.ts +++ b/packages/data-provider/src/theme.ts @@ -399,6 +399,9 @@ const appearanceValidators = { shadowLg: isShadow, shadowXl: isShadow, shadow2xl: isShadow, + /** The menu panel's and the tooltip's shadows, `none` included. */ + menuShadow: isShadow, + tooltipShadow: isShadow, motionFast: isDuration, motionNormal: isDuration, } satisfies Record boolean>;