Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
📐 fix: Draw Controls at the Theme Control Radius (#16481)
Marco Beretta5d39e0b90192
diff --git a/client/src/components/Agents/SortDropdown.tsx b/client/src/components/Agents/SortDropdown.tsxindex 5fdfb604bd..6022e207d2 100644--- a/client/src/components/Agents/SortDropdown.tsx+++ b/client/src/components/Agents/SortDropdown.tsx@@ -47,7 +47,8 @@ const SortDropdown: React.FC<SortDropdownProps> = ({ value, onChange }) => {options={options}sizeClasses="w-40"icon={<ArrowDownWideNarrow className="size-3.5 shrink-0" aria-hidden="true" />}- triggerClassName="h-8 w-40 rounded-lg px-2.5 py-0 text-xs transition-none"+ shape="default"+ triggerClassName="h-8 w-40 px-2.5 py-0 text-xs transition-none"testId="agent-sort-dropdown"aria-labelledby={labelId}/>diff --git a/client/src/components/Nav/Settings/Sidebar.tsx b/client/src/components/Nav/Settings/Sidebar.tsxindex a5d6a00b06..ce15b71501 100644--- a/client/src/components/Nav/Settings/Sidebar.tsx+++ b/client/src/components/Nav/Settings/Sidebar.tsx@@ -69,7 +69,7 @@ export default function Sidebar({value={tab.id}onClick={() => onSelectTab(tab.id)}className={cn(- 'text-text-secondary hover:bg-surface-hover hover:text-text-primary focus-visible:ring-text-primary flex items-center justify-between gap-2 rounded-xl px-3 py-2.5 text-sm transition-colors focus-visible:ring-2 focus-visible:outline-hidden focus-visible:ring-inset md:py-2',+ 'text-text-secondary hover:bg-surface-hover hover:text-text-primary focus-visible:ring-text-primary rounded-theme-control flex items-center justify-between gap-2 px-3 py-2.5 text-sm transition-colors focus-visible:ring-2 focus-visible:outline-hidden focus-visible:ring-inset md:py-2','data-[state=active]:bg-surface-tertiary data-[state=active]:text-text-primary',)}>diff --git a/client/src/components/Prompts/sidebar/FilterPrompts.tsx b/client/src/components/Prompts/sidebar/FilterPrompts.tsxindex c78b1d737c..994df2b1cb 100644--- a/client/src/components/Prompts/sidebar/FilterPrompts.tsx+++ b/client/src/components/Prompts/sidebar/FilterPrompts.tsx@@ -116,7 +116,8 @@ export default function FilterPrompts({onChange={onSelect}options={filterOptions}className={cn('shrink-0 [&>button]:size-9', dropdownClassName)}- triggerClassName="rounded-lg bg-transparent"+ shape="default"+ triggerClassName="bg-transparent"icon={<ListFilter className="h-4 w-4" />}label="Filter: "ariaLabel={localize('com_ui_filter_prompts')}diff --git a/client/src/components/SidePanel/Agents/Advanced/AdvancedButton.tsx b/client/src/components/SidePanel/Agents/Advanced/AdvancedButton.tsxindex 3846c1c976..4ca124743f 100644--- a/client/src/components/SidePanel/Agents/Advanced/AdvancedButton.tsx+++ b/client/src/components/SidePanel/Agents/Advanced/AdvancedButton.tsx@@ -14,6 +14,7 @@ const AdvancedButton: React.FC<AdvancedButtonProps> = ({ setActivePanel }) => {return (<Buttonvariant="subtle"+ shape="theme"onClick={() => setActivePanel(Panel.advanced)}aria-label={localize('com_ui_advanced')}className="h-9 w-full px-3"diff --git a/client/src/components/SidePanel/Agents/Version/VersionButton.tsx b/client/src/components/SidePanel/Agents/Version/VersionButton.tsxindex d8856b68a7..9b3337864e 100644--- a/client/src/components/SidePanel/Agents/Version/VersionButton.tsx+++ b/client/src/components/SidePanel/Agents/Version/VersionButton.tsx@@ -13,6 +13,7 @@ const VersionButton = ({ setActivePanel }: VersionButtonProps) => {return (<Buttonvariant="subtle"+ shape="theme"onClick={() => setActivePanel(Panel.version)}aria-label={localize('com_ui_agent_version')}className="h-9 w-full px-3"diff --git a/client/src/components/SidePanel/Agents/Version/VersionPanel.tsx b/client/src/components/SidePanel/Agents/Version/VersionPanel.tsxindex dcfb8389ca..e4ffdceded 100644--- a/client/src/components/SidePanel/Agents/Version/VersionPanel.tsx+++ b/client/src/components/SidePanel/Agents/Version/VersionPanel.tsx@@ -145,6 +145,7 @@ export default function VersionPanel() {<Buttonvariant="subtle"size="icon"+ shape="theme"onClick={() => setActivePanel(Panel.builder)}aria-label={localize('com_ui_back_to_builder')}className="text-text-secondary hover:text-text-primary shrink-0"diff --git a/client/src/components/SidePanel/Builder/ActionsAuth.tsx b/client/src/components/SidePanel/Builder/ActionsAuth.tsxindex d8cda066b1..db33654be8 100644--- a/client/src/components/SidePanel/Builder/ActionsAuth.tsx+++ b/client/src/components/SidePanel/Builder/ActionsAuth.tsx@@ -80,7 +80,7 @@ export default function ActionsAuth({ disableOAuth }: { disableOAuth?: boolean }<OGDialogTrigger asChild><buttontype="button"- className="group border-border-light hover:bg-surface-secondary focus-visible:ring-text-primary flex w-full items-center gap-3 rounded-xl border bg-transparent px-3 py-2.5 text-left transition-colors focus:outline-hidden focus-visible:ring-2"+ className="group border-border-light hover:bg-surface-secondary focus-visible:ring-text-primary rounded-theme-control flex w-full items-center gap-3 border bg-transparent px-3 py-2.5 text-left transition-colors focus:outline-hidden focus-visible:ring-2"><current.icon className="text-text-secondary size-5 shrink-0" aria-hidden={true} /><span className="min-w-0 flex-1">diff --git a/client/src/components/SidePanel/Builder/ActionsPanel.tsx b/client/src/components/SidePanel/Builder/ActionsPanel.tsxindex 3fc7cdd984..7320eab1bc 100644--- a/client/src/components/SidePanel/Builder/ActionsPanel.tsx+++ b/client/src/components/SidePanel/Builder/ActionsPanel.tsx@@ -104,7 +104,7 @@ export default function ActionsPanel({setAction(undefined);}}aria-label={localize('com_ui_back_to_builder')}- className="border-border-light text-text-secondary hover:bg-surface-secondary hover:text-text-primary focus-visible:ring-ring-primary inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-xl border transition-colors focus:outline-hidden focus-visible:ring-2"+ className="border-border-light text-text-secondary hover:bg-surface-secondary hover:text-text-primary focus-visible:ring-ring-primary rounded-theme-control inline-flex h-10 w-10 shrink-0 items-center justify-center border transition-colors focus:outline-hidden focus-visible:ring-2"><ChevronLeft className="h-5 w-5" strokeWidth={1.75} aria-hidden="true" /></button>@@ -118,7 +118,7 @@ export default function ActionsPanel({type="button"disabled={!(assistant_id ?? '') || !action.action_id}aria-label={localize('com_ui_delete_action')}- className="border-border-light hover:bg-surface-secondary focus-visible:ring-ring-primary text-text-destructive inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-xl border transition-colors focus:outline-hidden focus-visible:ring-2 disabled:opacity-50"+ className="border-border-light hover:bg-surface-secondary focus-visible:ring-ring-primary text-text-destructive rounded-theme-control inline-flex h-10 w-10 shrink-0 items-center justify-center border transition-colors focus:outline-hidden focus-visible:ring-2 disabled:opacity-50"><TrashIcon className="h-4 w-4" /></button>diff --git a/e2e/specs/mock/scenarios/clickhouse-control-radius.spec.ts b/e2e/specs/mock/scenarios/clickhouse-control-radius.spec.tsnew file mode 100644index 0000000000..e203d9af93--- /dev/null+++ b/e2e/specs/mock/scenarios/clickhouse-control-radius.spec.ts@@ -0,0 +1,130 @@+import { expect, test } from '@playwright/test';+import type { Locator, Page } from '@playwright/test';+import { clickHouseTheme } from '../../../../packages/client/src/theme/themes/clickhouse';+import { NEW_CHAT_PATH } from '../helpers';+import { probeStyle } from './style.helpers';++/**+ * Controls take the theme's control radius, not a surface-sized step of the radius scale. Under+ * the ClickHouse theme `rounded-xl` is Click UI's dialog step (8px) while its controls are drawn at+ * `radii.1` (4px); in the default theme both are 12px, so the default look does not move. Every+ * expectation is resolved by the browser from a probe carrying the role, never written down here.+ */+test.describe.configure({ timeout: 120_000 });+test.use({ viewport: { width: 1280, height: 800 } });++const THEME_PARAM = 'e2eTheme';++/**+ * One init script per page: Playwright does not order several, so the theme a navigation wants+ * rides in its URL (`?e2eTheme=clickhouse`) and the script stores that definition or clears it.+ */+async function installThemeBridge(page: Page) {+ await page.addInitScript(+ ([param, definition]) => {+ const wanted = new URL(location.href).searchParams.get(param);+ if (wanted === null) {+ return;+ }+ localStorage.removeItem('theme-colors');+ localStorage.removeItem('theme-name');+ if (wanted === 'clickhouse') {+ localStorage.setItem('theme-definition', JSON.stringify(definition));+ localStorage.setItem('theme-source', 'definition');+ } else {+ localStorage.removeItem('theme-definition');+ localStorage.removeItem('theme-source');+ }+ },+ [THEME_PARAM, clickHouseTheme] as const,+ );+}++type ThemeChoice = 'clickhouse' | 'default';++const radius = (locator: Locator) =>+ locator.evaluate((node) => getComputedStyle(node).borderTopLeftRadius);++async function openGeneralSettings(page: Page, theme: ThemeChoice): Promise<Locator> {+ await page.goto(`${NEW_CHAT_PATH}?${THEME_PARAM}=${theme}`, { timeout: 15000 });+ await page.getByTestId('nav-user').click();+ await page.getByRole('menuitem', { name: 'Settings' }).click();+ const dialog = page.getByRole('dialog');+ await expect(dialog.getByRole('heading', { name: 'Settings', exact: true })).toBeVisible({+ timeout: 15000,+ });+ await dialog.getByRole('tab', { name: 'General' }).click();+ return dialog;+}++async function settingsControlRadii(page: Page, theme: ThemeChoice) {+ const dialog = await openGeneralSettings(page, theme);+ const select = dialog.getByRole('combobox').first();+ await expect(select).toBeVisible();+ return {+ tab: await radius(dialog.getByRole('tab', { name: 'General' })),+ select: await radius(select),+ };+}++async function marketplaceToolbarRadii(page: Page, theme: ThemeChoice) {+ await page.goto(`/agents/all?${THEME_PARAM}=${theme}`, { timeout: 15000 });+ const sort = page.getByTestId('agent-sort-dropdown');+ await expect(sort).toBeVisible({ timeout: 30000 });+ const controls: Locator[] = [+ sort,+ page.getByRole('button', { name: 'My agents' }),+ page.getByRole('textbox', { name: 'Search agents' }),+ ];+ const admin = page.getByRole('button', { name: 'Admin Settings' });+ if (await admin.isVisible()) {+ controls.push(admin);+ }+ return Promise.all(controls.map(radius));+}++test.describe('control radius', () => {+ test('settings selects and tabs take the ClickHouse control radius @scenario:clickhouse-settings-controls-take-control-radius', async ({+ page,+ }) => {+ await installThemeBridge(page);++ const radii = await settingsControlRadii(page, 'clickhouse');+ await expect(page.locator('html')).toHaveAttribute('data-theme', 'clickhouse');+ const control = await probeStyle(page, 'rounded-theme-control', 'border-top-left-radius');+ const dialogStep = await probeStyle(page, 'rounded-xl', 'border-top-left-radius');++ /** `border.radii.1`, and not the dialog step these controls used to borrow. */+ expect(control).toBe('4px');+ expect(dialogStep).not.toBe(control);+ expect(radii).toEqual({ tab: control, select: control });+ });++ test('the default theme keeps its settings control corners @scenario:default-theme-settings-controls-keep-radius', async ({+ page,+ }) => {+ await installThemeBridge(page);++ const radii = await settingsControlRadii(page, 'default');+ await expect(page.locator('html')).not.toHaveAttribute('data-theme', 'clickhouse');+ const previous = await probeStyle(page, 'rounded-xl', 'border-top-left-radius');++ expect(previous).toBe('12px');+ expect(radii).toEqual({ tab: previous, select: previous });+ });++ test('the marketplace toolbar controls share one corner in every theme @scenario:marketplace-toolbar-shares-one-radius', async ({+ page,+ }) => {+ await installThemeBridge(page);+ for (const theme of ['default', 'clickhouse'] as ThemeChoice[]) {+ const radii = await marketplaceToolbarRadii(page, theme);+ const html = expect(page.locator('html'));+ await (theme === 'clickhouse' ? html : html.not).toHaveAttribute('data-theme', 'clickhouse');+ const button = await probeStyle(page, 'rounded-lg', 'border-top-left-radius');++ expect(radii.length).toBeGreaterThanOrEqual(3);+ expect(new Set(radii)).toEqual(new Set([button]));+ }+ });+});diff --git a/eslint-suppressions.json b/eslint-suppressions.jsonindex 113c82a61d..0bae62134c 100644--- a/eslint-suppressions.json+++ b/eslint-suppressions.json@@ -62,7 +62,7 @@},"client/src/components/Agents/SortDropdown.tsx": {"shadcn/no-restyle": {- "count": 5+ "count": 4}},"client/src/components/Agents/VirtualizedAgentGrid.tsx": {@@ -1491,7 +1491,7 @@},"client/src/components/Prompts/sidebar/FilterPrompts.tsx": {"shadcn/no-restyle": {- "count": 2+ "count": 1},"shadcn/require-static-classes": {"count": 1diff --git a/packages/client/src/components/Dropdown.spec.tsx b/packages/client/src/components/Dropdown.spec.tsxindex e9e0b82e45..e4646e4ef0 100644--- a/packages/client/src/components/Dropdown.spec.tsx+++ b/packages/client/src/components/Dropdown.spec.tsx@@ -47,3 +47,41 @@ describe('Dropdown accessible name', () => {expect(screen.getByRole('combobox', { name: 'Clock Format' })).toBeInTheDocument();});});++describe('Dropdown shape', () => {+ const trigger = () => screen.getByRole('combobox', { name: 'Clock Format' });++ it('draws the trigger at the theme control radius when no shape is given', () => {+ render(<Dropdown value="12h" options={OPTIONS} ariaLabel="Clock Format" />);++ expect(trigger()).toHaveClass('rounded-theme-control');+ expect(trigger()).not.toHaveClass('rounded-xl');+ });++ it.each([+ ['default', 'rounded-lg'],+ ['theme', 'rounded-theme-control'],+ ['round', 'rounded-theme-control-round'],+ ] as const)('maps shape="%s" to %s, as Button does', (shape, radius) => {+ render(+ <Dropdown value="12h" options={OPTIONS} ariaLabel="Clock Format" shape={shape} disabled />,+ );++ expect(trigger()).toHaveClass(radius);+ });++ it('keeps the field radius on a field trigger whatever the shape', () => {+ render(+ <Dropdown+ value="12h"+ options={OPTIONS}+ ariaLabel="Clock Format"+ variant="field"+ shape="round"+ />,+ );++ expect(trigger()).toHaveClass('rounded-lg');+ expect(trigger()).not.toHaveClass('rounded-theme-control-round');+ });+});diff --git a/packages/client/src/components/Dropdown.tsx b/packages/client/src/components/Dropdown.tsxindex ca9d909c7d..05884af1da 100644--- a/packages/client/src/components/Dropdown.tsx+++ b/packages/client/src/components/Dropdown.tsx@@ -8,6 +8,8 @@ import { cn, disabledFillClasses } from '~/utils';import { fieldControl } from './Field';import './Dropdown.css';+type DropdownShape = 'default' | 'theme' | 'round';+interface DropdownProps {value?: string;label?: string;@@ -28,6 +30,13 @@ interface DropdownProps {portal?: boolean;/** `field` matches the `Input` primitive so this can sit in a form row. */variant?: 'default' | 'field';+ /**+ * The trigger's corner, in `Button`'s vocabulary: `default` is `Button`'s own+ * `rounded-lg`, `theme` the theme's control radius, `round` its pill. Omitted,+ * the trigger takes the control radius, which is what it drew before the prop+ * existed in the default theme. A `field` trigger keeps the field's corner.+ */+ shape?: DropdownShape;/** Renders the popover into this element instead of document.body */portalElement?: ((element: HTMLElement) => HTMLElement | null) | HTMLElement | null;disabled?: boolean;@@ -36,6 +45,12 @@ interface DropdownProps {searchEmptyText?: string;}+const shapeClasses: Record<DropdownShape, string> = {+ default: 'rounded-lg',+ theme: 'rounded-theme-control',+ round: 'rounded-theme-control-round',+};+const isDivider = (item: string | Option | { divider: true }): item is { divider: true } =>typeof item === 'object' && 'divider' in item;@@ -61,6 +76,7 @@ const Dropdown: React.FC<DropdownProps> = ({'aria-labelledby': ariaLabelledBy,portal = true,variant = 'default',+ shape = 'theme',portalElement,disabled = false,searchable = false,@@ -150,7 +166,8 @@ const Dropdown: React.FC<DropdownProps> = ({store={selectProps}disabled={disabled}className={cn(- 'border-border-control text-text-primary hover:bg-surface-hover hover:text-text-primary relative inline-flex items-center justify-between rounded-xl border bg-transparent py-2 text-sm transition-all duration-200 ease-in-out',+ 'border-border-control text-text-primary hover:bg-surface-hover hover:text-text-primary relative inline-flex items-center justify-between border bg-transparent py-2 text-sm transition-all duration-200 ease-in-out',+ variant !== 'field' && shapeClasses[shape],'disabled:hover:text-text-primary disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-transparent',disabledFillClasses,/** Horizontal padding would squeeze the icon, which flex-shrinks to fit */diff --git a/packages/client/src/theme/themes/clickui.json b/packages/client/src/theme/themes/clickui.jsonindex 49a119cab5..a70285b835 100644--- a/packages/client/src/theme/themes/clickui.json+++ b/packages/client/src/theme/themes/clickui.json@@ -11,16 +11,38 @@"border.radii.2": "0.5rem","border.radii.3": "0.75rem","border.radii.full": "9999px",+ "click.badge.opaque.color.background.default": "#f6f7fa",+ "click.badge.opaque.color.stroke.default": "#e6e7e9",+ "click.badge.opaque.color.text.default": "#696e79",+ "click.badge.radii.all": "9999px","click.button.basic.color.primary.background.active": "#161517",+ "click.button.basic.color.primary.background.default": "#302e32","click.button.basic.color.primary.background.disabled": "#dfdfdf",+ "click.button.basic.color.primary.text.default": "#ffffff",+ "click.button.basic.color.secondary.stroke.default": "#e6e7e9","click.button.iconButton.color.primary.background.active": "rgb(86.824% 87.176% 88.235%)","click.codeblock.lightMode.color.background.default": "#f6f7fa","click.codeblock.lightMode.color.text.default": "#282828",+ "click.dialog.color.background.default": "#ffffff","click.dialog.color.opaqueBackground.default": "lch(6.7738 0 none / 0.75)",+ "click.dialog.color.title.default": "lch(11.126 1.374 305.43)",+ "click.dialog.radii.all": "0.5rem",+ "click.dialog.stroke.default": "1px solid #e6e7e9",+ "click.field.color.background.default": "#fbfcff",+ "click.field.color.stroke.default": "#e6e7e9","click.field.color.stroke.disabled": "#dfdfdf",+ "click.field.color.text.default": "#302e32","click.genericMenu.panel.size.height": "2rem","click.global.color.text.danger": "#c10000","click.global.color.text.warning": "#a33c00",+ "click.switch.color.background.active": "#151515",+ "click.switch.color.background.default": "#cccfd3",+ "click.switch.color.indicator.default": "#ffffff",+ "click.switch.radii.all": "9999px",+ "click.table.header.color.background.default": "#f6f7fa",+ "click.table.header.color.title.default": "#161517",+ "click.table.radii.all": "0.25rem",+ "click.table.row.color.stroke.default": "#e6e7e9","global.color.accent.default": "#151515","global.color.background.default": "#ffffff","global.color.background.muted": "#f6f7fa",@@ -90,19 +112,39 @@"border.radii.2": "0.5rem","border.radii.3": "0.75rem","border.radii.full": "9999px",+ "click.badge.opaque.color.background.default": "#1f1f1c",+ "click.badge.opaque.color.stroke.default": "#323232",+ "click.badge.opaque.color.text.default": "#b3b6bd",+ "click.badge.radii.all": "9999px","click.button.basic.color.primary.background.active": "rgb(90.686% 92.5% 38.088%)","click.button.basic.color.primary.background.default": "#faff69","click.button.basic.color.primary.background.disabled": "#414141","click.button.basic.color.primary.background.hover": "rgb(98.627% 100% 58.824%)","click.button.basic.color.primary.text.default": "#1f1f1c",+ "click.button.basic.color.secondary.stroke.default": "#414141","click.button.iconButton.color.primary.background.active": "rgb(14.118% 14.118% 14.118%)","click.codeblock.darkMode.color.background.default": "#282828","click.codeblock.darkMode.color.text.default": "#ffffff",+ "click.dialog.color.background.default": "#1f1f1c","click.dialog.color.opaqueBackground.default": "lch(40.731 0 none / 0.75)",+ "click.dialog.color.title.default": "rgb(97.5% 97.5% 97.5%)",+ "click.dialog.radii.all": "0.5rem",+ "click.dialog.stroke.default": "1px solid #323232",+ "click.field.color.background.default": "rgb(17.794% 17.794% 17.794%)",+ "click.field.color.stroke.default": "rgb(23.627% 23.627% 23.627%)","click.field.color.stroke.disabled": "#414141",+ "click.field.color.text.default": "#e6e7e9","click.genericMenu.panel.size.height": "2rem","click.global.color.text.danger": "#ffbaba","click.global.color.text.warning": "#ffb88f",+ "click.switch.color.background.active": "#faff69",+ "click.switch.color.background.default": "#606060",+ "click.switch.color.indicator.default": "#151515",+ "click.switch.radii.all": "9999px",+ "click.table.header.color.background.default": "#282828",+ "click.table.header.color.title.default": "rgb(97.5% 97.5% 97.5%)",+ "click.table.radii.all": "0.25rem",+ "click.table.row.color.stroke.default": "#323232","global.color.accent.default": "#faff69","global.color.background.default": "#1f1f1c","global.color.background.muted": "#282828",diff --git a/packages/client/src/theme/themes/clickui.spec.ts b/packages/client/src/theme/themes/clickui.spec.tsindex cec71b0204..ee63ac5773 100644--- a/packages/client/src/theme/themes/clickui.spec.ts+++ b/packages/client/src/theme/themes/clickui.spec.ts@@ -1,7 +1,29 @@+import { createElement } from 'react';+import { cleanup, render } from '@testing-library/react';+import type { ReactElement } from 'react';import type { IThemeAppearance, IThemeRGB, ThemeMode } from '../types';+import {+ Table,+ TableBody,+ TableCell,+ TableHead,+ TableHeader,+ TableRow,+} from '../../components/Table';+import { OGDialog, OGDialogContent, OGDialogTitle } from '../../components/OriginalDialog';+import { Button } from '../../components/Button';+import { Switch } from '../../components/Switch';+import Dropdown from '../../components/Dropdown';+import { Input } from '../../components/Input';import { clickHouseTheme } from './clickhouse';+import Badge from '../../components/Badge';+import { resolveTheme } from '../registry';import snapshot from './clickui.json';+jest.mock('react-i18next', () => ({+ useTranslation: () => ({ t: (key: string) => key }),+}));+/*** Drift guard for the ClickHouse theme. `clickui.json` is a snapshot of the Click UI tokens the* theme cites, copied verbatim from the tag it records; the maps below name the token behind each@@ -300,6 +322,36 @@ function lchGray(lightness: number): number {return srgb * 255;}+/**+ * A chromatic CSS `lch()` (D50) converted to sRGB channels: Lab to XYZ, Bradford to D65, then the+ * sRGB matrix and transfer curve. Click UI writes a few component colors this way, such as the+ * light dialog title.+ */+function lchColor(lightness: number, chroma: number, hue: number): [number, number, number] {+ const radians = (hue * Math.PI) / 180;+ const fy = (lightness + 16) / 116;+ const fx = fy + (chroma * Math.cos(radians)) / 500;+ const fz = fy - (chroma * Math.sin(radians)) / 200;+ const epsilon = 216 / 24389;+ const kappa = 24389 / 27;+ const inverse = (t: number) => (t ** 3 > epsilon ? t ** 3 : (116 * t - 16) / kappa);+ const x50 = 0.96422 * inverse(fx);+ const y50 = lightness > kappa * epsilon ? fy ** 3 : lightness / kappa;+ const z50 = 0.82521 * inverse(fz);+ const x = 0.9554734527 * x50 - 0.0230985369 * y50 + 0.0632593087 * z50;+ const y = -0.028369707 * x50 + 1.009995458 * y50 + 0.021041399 * z50;+ const z = 0.0123140017 * x50 - 0.0205076964 * y50 + 1.3303659366 * z50;+ const linear = [+ 3.2409699419 * x - 1.5373831776 * y - 0.4986107603 * z,+ -0.9692436363 * x + 1.8759675015 * y + 0.0415550574 * z,+ 0.0556300797 * x - 0.2039769589 * y + 1.0569715142 * z,+ ];+ const [r, g, b] = linear.map(+ (v) => 255 * (v <= 0.0031308 ? 12.92 * v : 1.055 * v ** (1 / 2.4) - 0.055),+ );+ return [r, g, b];+}+function channel(value: string): number {return value.endsWith('%') ? (parseFloat(value) / 100) * 255 : Number(value);}@@ -320,7 +372,7 @@ function parseColor(value: string): Rgba {return [channel(parts[0]), channel(parts[1]), channel(parts[2]), a];}if (Number(parts[1]) !== 0) {- throw new Error(`Only achromatic lch() is supported: ${value}`);+ return [...lchColor(Number(parts[0]), Number(parts[1]), Number(parts[2])), a];}const gray = lchGray(Number(parts[0]));return [gray, gray, gray, a];@@ -374,6 +426,368 @@ function comparable(key: keyof IThemeAppearance, raw: string | number): string {return value.replace(/;$/, '').trim();}+/**+ * Color and shape parity of the shared primitives against Click UI's own components. Each probe+ * renders a primitive, reads the utility it paints for one decision (`bg-*`, `text-*`, a+ * `border-*` color on an element that draws a border, `rounded-*`), resolves that role under the+ * ClickHouse theme, and compares it with the Click UI component token. A primitive that paints+ * nothing for a decision reads as transparent, no border or square, and text with no color of its+ * own inherits the body copy (`text-primary`).+ *+ * The score is how many decisions match, per mode. Run with `CLICKUI_PARITY_REPORT=1` to print+ * every decision; the floors below only move up.+ */+type ParityKind = 'color' | 'shape';+type Utility = 'bg' | 'text' | 'border' | 'rounded';++interface ParityProbe {+ /** The Click UI component token the primitive should reproduce. */+ token: string;+ kind: ParityKind;+ utility: Utility;+ /** A state the utility is written under, such as `data-[state=checked]:`. */+ variant?: string;+ /** Renders the primitive and returns the element that paints the decision. */+ element: () => Element;+ /** Why the theme departs from Click UI on purpose, when it does. */+ deviation?: string;+}++function mount(tree: ReactElement, selector: string): Element {+ const { baseElement } = render(tree);+ const element = baseElement.querySelector(selector);+ if (!element) {+ throw new Error(`Parity probe found no ${selector}`);+ }+ return element;+}++const switchProbe = (checked: boolean) => () =>+ mount(createElement(Switch, { 'aria-label': 'probe', checked }), '[role="switch"]');++const tableProbe = (selector: string) => () =>+ mount(+ createElement(+ Table,+ null,+ createElement(+ TableHeader,+ null,+ createElement(TableRow, null, createElement(TableHead, null, 'Name')),+ ),+ createElement(+ TableBody,+ null,+ createElement(TableRow, null, createElement(TableCell, null, 'Row')),+ ),+ ),+ selector,+ );++const dialogProbe = (selector: string) => () =>+ mount(+ createElement(+ OGDialog,+ { open: true },+ createElement(OGDialogContent, null, createElement(OGDialogTitle, null, 'Title')),+ ),+ selector,+ );++const badgeProbe = () =>+ mount(createElement(Badge, { label: 'Tools', isAvailable: true }), 'button');++const inputProbe = () => mount(createElement(Input, { 'aria-label': 'probe' }), 'input');++const dropdownProbe = () =>+ mount(+ createElement(Dropdown, {+ value: 'a',+ options: [{ value: 'a', label: 'A' }],+ ariaLabel: 'probe',+ onChange: () => undefined,+ }),+ '[role="combobox"]',+ );++const buttonProbe = (variant: 'default' | 'outline') => () =>+ mount(createElement(Button, { variant }, 'Save'), 'button');++const parityProbes: Record<string, ParityProbe> = {+ 'Button primary fill': {+ token: 'click.button.basic.color.primary.background.default',+ kind: 'color',+ utility: 'bg',+ element: buttonProbe('default'),+ },+ 'Button primary label': {+ token: 'click.button.basic.color.primary.text.default',+ kind: 'color',+ utility: 'text',+ element: buttonProbe('default'),+ },+ 'Button secondary stroke': {+ token: 'click.button.basic.color.secondary.stroke.default',+ kind: 'color',+ utility: 'border',+ element: buttonProbe('outline'),+ },+ 'Button corner': {+ token: 'border.radii.1',+ kind: 'shape',+ utility: 'rounded',+ element: buttonProbe('default'),+ },+ 'Field fill': {+ token: 'click.field.color.background.default',+ kind: 'color',+ utility: 'bg',+ element: inputProbe,+ },+ 'Field stroke': {+ token: 'click.field.color.stroke.default',+ kind: 'color',+ utility: 'border',+ element: inputProbe,+ deviation: 'border-control holds form controls to the 3:1 non-text floor stroke.default misses',+ },+ 'Field text': {+ token: 'click.field.color.text.default',+ kind: 'color',+ utility: 'text',+ element: inputProbe,+ },+ 'Field corner': {+ token: 'border.radii.1',+ kind: 'shape',+ utility: 'rounded',+ element: inputProbe,+ },+ 'Dropdown trigger stroke': {+ token: 'click.field.color.stroke.default',+ kind: 'color',+ utility: 'border',+ element: dropdownProbe,+ deviation: 'border-control holds form controls to the 3:1 non-text floor stroke.default misses',+ },+ 'Dropdown trigger corner': {+ token: 'border.radii.1',+ kind: 'shape',+ utility: 'rounded',+ element: dropdownProbe,+ },+ 'Dialog surface': {+ token: 'click.dialog.color.background.default',+ kind: 'color',+ utility: 'bg',+ element: dialogProbe('[role="dialog"]'),+ },+ 'Dialog stroke': {+ token: 'click.dialog.stroke.default',+ kind: 'color',+ utility: 'border',+ element: dialogProbe('[role="dialog"]'),+ },+ 'Dialog title': {+ token: 'click.dialog.color.title.default',+ kind: 'color',+ utility: 'text',+ element: dialogProbe('h2'),+ },+ 'Dialog scrim': {+ token: 'click.dialog.color.opaqueBackground.default',+ kind: 'color',+ utility: 'bg',+ element: dialogProbe('.inset-0'),+ },+ 'Dialog corner': {+ token: 'click.dialog.radii.all',+ kind: 'shape',+ utility: 'rounded',+ element: dialogProbe('[role="dialog"]'),+ },+ 'Switch track, on': {+ token: 'click.switch.color.background.active',+ kind: 'color',+ utility: 'bg',+ variant: 'data-[state=checked]:',+ element: switchProbe(true),+ },+ 'Switch track, off': {+ token: 'click.switch.color.background.default',+ kind: 'color',+ utility: 'bg',+ variant: 'data-[state=unchecked]:',+ element: switchProbe(false),+ deviation: 'switch-unchecked holds the off track to the 3:1 non-text floor #cccfd3 misses',+ },+ 'Switch thumb': {+ token: 'click.switch.color.indicator.default',+ kind: 'color',+ utility: 'bg',+ element: () => switchProbe(false)().firstElementChild ?? document.body,+ },+ 'Switch corner': {+ token: 'click.switch.radii.all',+ kind: 'shape',+ utility: 'rounded',+ element: switchProbe(false),+ },+ 'Table header fill': {+ token: 'click.table.header.color.background.default',+ kind: 'color',+ utility: 'bg',+ element: tableProbe('thead'),+ },+ 'Table header title': {+ token: 'click.table.header.color.title.default',+ kind: 'color',+ utility: 'text',+ element: tableProbe('th'),+ },+ 'Table row stroke': {+ token: 'click.table.row.color.stroke.default',+ kind: 'color',+ utility: 'border',+ element: tableProbe('tbody tr'),+ },+ 'Table corner': {+ token: 'click.table.radii.all',+ kind: 'shape',+ utility: 'rounded',+ element: tableProbe('div'),+ },+ 'Badge fill': {+ token: 'click.badge.opaque.color.background.default',+ kind: 'color',+ utility: 'bg',+ element: badgeProbe,+ },+ 'Badge label': {+ token: 'click.badge.opaque.color.text.default',+ kind: 'color',+ utility: 'text',+ element: badgeProbe,+ },+ 'Badge stroke': {+ token: 'click.badge.opaque.color.stroke.default',+ kind: 'color',+ utility: 'border',+ element: badgeProbe,+ },+ 'Badge corner': {+ token: 'click.badge.radii.all',+ kind: 'shape',+ utility: 'rounded',+ element: badgeProbe,+ },+};++/** The fewest decisions per mode that must match; raise a floor when a change closes a gap. */+const parityFloors: Record<ThemeMode, Record<ParityKind, number>> = {+ light: { color: 6, shape: 6 },+ dark: { color: 6, shape: 6 },+};++const radiusRoles: Record<string, keyof IThemeAppearance> = {+ sm: 'radiusSm',+ md: 'radiusMd',+ lg: 'radiusLg',+ xl: 'radiusXl',+ '2xl': 'radius2xl',+ '3xl': 'radius3xl',+ 'theme-control': 'controlRadius',+ 'theme-control-round': 'roundControlRadius',+ 'theme-surface': 'surfaceRadius',+ 'theme-surface-lg': 'largeSurfaceRadius',+};++const fixedRadii: Record<string, string> = { full: '9999px', none: '0px' };++/** A `border`, `border-2` or one-sided `border-b` class, the width a border color needs to show. */+const drawsBorder = (classes: string[]) =>+ classes.some((name) => /^border(-[0-9]+|-[xytblrse](-[0-9]+)?)?$/.test(name));++type Resolved = ReturnType<typeof resolveTheme>;++function roleColor(resolved: Resolved, name: string): Rgba | undefined {+ const [role, alpha] = name.split('/');+ if (role === 'transparent') {+ return [0, 0, 0, 0];+ }+ const triplet = resolved.colors[`rgb-${role}` as keyof IThemeRGB];+ if (triplet === undefined) {+ return undefined;+ }+ const [r, g, b] = triplet.split(' ').map(Number);+ return [r, g, b, alpha === undefined ? 1 : Number(alpha) / 100];+}++/** The role a probe paints, or `undefined` when the primitive paints nothing for it. */+function paintedRole(element: Element, probe: ParityProbe, resolved: Resolved): string | undefined {+ const prefix = `${probe.variant ?? ''}${probe.utility}-`;+ const classes = (element.getAttribute('class') ?? '').split(/\s+/);+ const names = classes+ .filter((name) => name.startsWith(prefix))+ .map((name) => name.slice(prefix.length));+ if (probe.utility === 'rounded') {+ return names.find((name) => name in radiusRoles || name in fixedRadii);+ }+ if (probe.utility === 'border' && !drawsBorder(classes)) {+ return undefined;+ }+ return names.find((name) => roleColor(resolved, name) !== undefined);+}++function inheritedTextRole(element: Element, probe: ParityProbe, resolved: Resolved): string {+ for (let node: Element | null = element; node; node = node.parentElement) {+ const role = paintedRole(node, probe, resolved);+ if (role !== undefined) {+ return role;+ }+ }+ return 'text-primary';+}++const clickColor = (value: string): Rgba =>+ parseColor(/(#[0-9a-f]{6}|(?:rgba?|lch)\([^)]*\))\s*;?$/i.exec(value.trim())?.[1] ?? value);++const sameColor = (a: Rgba, b: Rgba) =>+ (a[3] === 0 && b[3] === 0) ||+ (a.slice(0, 3).every((value, index) => Math.abs(value - b[index]) < 1) &&+ Math.abs(a[3] - b[3]) < 0.01);++interface ParityResult {+ decision: string;+ kind: ParityKind;+ match: boolean;+ theme: string;+ clickUi: string;+ deviation?: string;+}++function measure(mode: ThemeMode, decision: string, probe: ParityProbe): ParityResult {+ const resolved = resolveTheme(clickHouseTheme, mode);+ const element = probe.element();+ const source = tokens[mode][probe.token];+ const role =+ probe.utility === 'text'+ ? inheritedTextRole(element, probe, resolved)+ : paintedRole(element, probe, resolved);+ cleanup();+ const base = { decision, kind: probe.kind, clickUi: source, deviation: probe.deviation };+ if (probe.kind === 'shape') {+ const theme =+ role === undefined ? '0px' : (fixedRadii[role] ?? resolved.appearance[radiusRoles[role]]);+ const painted = role === undefined ? 'unpainted' : `${probe.utility}-${role}`;+ return { ...base, theme: `${painted} = ${theme}`, match: theme === source };+ }+ const color = role === undefined ? ([0, 0, 0, 0] as Rgba) : roleColor(resolved, role);+ const painted = role === undefined ? 'unpainted' : `${probe.utility}-${role}`;+ const theme = `${painted} = ${color ? formatRgba(color) : 'unresolved'}`;+ return { ...base, theme, match: color !== undefined && sameColor(color, clickColor(source)) };+}+describe('ClickHouse theme drift against Click UI', () => {it('records the Click UI tag and commit the snapshot was taken from', () => {expect(snapshot.source).toBe('https://github.com/ClickHouse/click-ui');@@ -441,8 +855,44 @@ describe('ClickHouse theme drift against Click UI', () => {const cited = new Set([...Object.values(colorSources[mode]),...Object.values(appearanceSources),+ ...Object.values(parityProbes).map((probe) => probe.token),]);expect(Object.keys(tokens[mode]).filter((token) => !cited.has(token))).toEqual([]);});});++describe('ClickHouse primitive parity against Click UI components', () => {+ it.each(modes)('matches at least the recorded number of %s decisions', (mode) => {+ const results = Object.entries(parityProbes).map(([decision, probe]) =>+ measure(mode, decision, probe),+ );+ const score = (kind: ParityKind) => {+ const scoped = results.filter((result) => result.kind === kind);+ const matched = scoped.filter((result) => result.match).length;+ return { matched, total: scoped.length };+ };+ const color = score('color');+ const shape = score('shape');++ if (process.env.CLICKUI_PARITY_REPORT) {+ const verdict = ({ match, deviation }: ParityResult) => {+ if (match) {+ return 'match';+ }+ return deviation ? 'deviation' : 'gap';+ };+ const rows = results.map(+ (result) => `${verdict(result)}\t${result.decision}\t${result.theme}\t${result.clickUi}`,+ );+ const percent = ({ matched, total }: { matched: number; total: number }) =>+ `${matched}/${total} (${((matched / total) * 100).toFixed(1)}%)`;+ console.info(+ [`${mode}: color ${percent(color)}, shape ${percent(shape)}`, ...rows].join('\n'),+ );+ }++ expect(color.matched).toBeGreaterThanOrEqual(parityFloors[mode].color);+ expect(shape.matched).toBeGreaterThanOrEqual(parityFloors[mode].shape);+ });+});