From bdfd3012eaa40712221d005a80c001953e52bc6a Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Wed, 30 Sep 2026 08:58:31 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=8F=20feat:=20Give=20Theme-Sized=20Con?= =?UTF-8?q?trols=20Their=20Own=20Padding=20and=20Gap=20Roles=20(#16528)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Give Theme-Sized Controls Their Own Padding and Gap Roles The theme variants of Button and Chip, CheckboxButton and every composer control read spaceNormal and spaceCompact, which also pad message rows, steer bubbles and the composer send button, so a theme could not give its controls Click UI's button spacing without reshaping the chat. Add controlPaddingX and controlGap appearance roles, which those controls read instead. Their defaults are the shared spacing values, a theme that names only spaceNormal or spaceCompact keeps its controls on them, and the preset falls back to the shared roles for a stylesheet that predates these. The ClickHouse theme takes Click UI's button.basic.space.x and space.gap, and the drift guard pins both values and measures the themed Button's padding and gap. * test: Reach the Temporary Chat Chip Through a Sent Message The header status chip only appears once a temporary chat has its first message, so the scenarios send one, and measure the real message bubble instead of a probe for the shared spacing. * fix: Let the Control Spacing Roles Replace the Base Gap Tailwind Merge could not classify px-theme-control-x or gap-theme-control-gap, so a theme-sized Button kept the base gap-2 beside the role and a caller's own padding beside both, leaving the winner to stylesheet order. Register both utilities with their groups. * fix: Alias the Stock Control Spacing to the Shared Spacing Roles A stylesheet that set only --theme-space-normal or --theme-space-compact stopped reaching Button, Chip and the composer controls once the stock CSS declared the control roles as literals, so the preset's fallback never ran. The stock declarations now read the shared roles, with the same defaults. * test: Assert the Control Spacing Utilities Declare Their Own Properties --- .../Chat/Input/CodeApprovalMenu.tsx | 2 +- .../Chat/Input/CodeWorkspaceMenu.tsx | 2 +- .../Input/__tests__/CodeApprovalMenu.spec.tsx | 2 +- .../Input/__tests__/appearanceTokens.spec.ts | 2 +- .../mock/scenarios/control-spacing.spec.ts | 131 ++++++++++++++++++ .../client/src/components/Button.spec.tsx | 12 +- packages/client/src/components/Button.tsx | 2 +- .../src/components/CheckboxButton.spec.tsx | 4 +- .../client/src/components/CheckboxButton.tsx | 2 +- packages/client/src/components/Chip.spec.tsx | 3 +- packages/client/src/components/Chip.tsx | 2 +- packages/client/src/theme/README.md | 2 +- packages/client/src/theme/defaults.css | 2 + packages/client/src/theme/defaults.spec.ts | 11 +- packages/client/src/theme/registry.spec.ts | 46 ++++++ packages/client/src/theme/registry.ts | 30 ++-- packages/client/src/theme/tailwind.spec.js | 24 +++- .../src/theme/themes/clickhouse.spec.tsx | 15 +- .../client/src/theme/themes/clickhouse.ts | 2 + packages/client/src/theme/themes/clickui.json | 4 + .../client/src/theme/themes/clickui.spec.ts | 33 ++++- packages/client/src/theme/types/index.ts | 4 + packages/client/src/utils/composer.spec.ts | 2 +- packages/client/src/utils/composer.ts | 2 +- packages/client/src/utils/utils.ts | 2 + packages/client/tailwind.preset.cjs | 4 + packages/data-provider/src/theme.ts | 4 + 27 files changed, 314 insertions(+), 37 deletions(-) create mode 100644 e2e/specs/mock/scenarios/control-spacing.spec.ts diff --git a/client/src/components/Chat/Input/CodeApprovalMenu.tsx b/client/src/components/Chat/Input/CodeApprovalMenu.tsx index 7c3867b7c5..cbbf7bde12 100644 --- a/client/src/components/Chat/Input/CodeApprovalMenu.tsx +++ b/client/src/components/Chat/Input/CodeApprovalMenu.tsx @@ -102,7 +102,7 @@ export default function CodeApprovalMenu({ )}`} className={cn( composerControlClasses(), - 'md:px-theme-normal max-w-full min-w-0 px-2.5', + 'md:px-theme-control-x max-w-full min-w-0 px-2.5', isOpen && 'bg-surface-hover', disabled && 'cursor-not-allowed opacity-50', )} diff --git a/client/src/components/Chat/Input/CodeWorkspaceMenu.tsx b/client/src/components/Chat/Input/CodeWorkspaceMenu.tsx index 79bea04a98..9582d2d0ae 100644 --- a/client/src/components/Chat/Input/CodeWorkspaceMenu.tsx +++ b/client/src/components/Chat/Input/CodeWorkspaceMenu.tsx @@ -374,7 +374,7 @@ export default function CodeWorkspaceMenu({ } className={cn( composerControlClasses(), - 'md:px-theme-normal max-w-full min-w-0 px-2.5', + 'md:px-theme-control-x max-w-full min-w-0 px-2.5', isOpen && 'bg-surface-hover', buttonDisabled && 'cursor-not-allowed opacity-50', )} diff --git a/client/src/components/Chat/Input/__tests__/CodeApprovalMenu.spec.tsx b/client/src/components/Chat/Input/__tests__/CodeApprovalMenu.spec.tsx index 8a584b561d..0e4f248122 100644 --- a/client/src/components/Chat/Input/__tests__/CodeApprovalMenu.spec.tsx +++ b/client/src/components/Chat/Input/__tests__/CodeApprovalMenu.spec.tsx @@ -119,7 +119,7 @@ describe('CodeApprovalMenu', () => { expect(screen.getByTestId('code-approval-mode')).toHaveClass( 'h-theme-control', 'rounded-theme-control-round', - 'gap-theme-compact', + 'gap-theme-control-gap', 'border-border-medium', ); }); diff --git a/client/src/components/Chat/Input/__tests__/appearanceTokens.spec.ts b/client/src/components/Chat/Input/__tests__/appearanceTokens.spec.ts index 2d7e7768b1..adfbe92efe 100644 --- a/client/src/components/Chat/Input/__tests__/appearanceTokens.spec.ts +++ b/client/src/components/Chat/Input/__tests__/appearanceTokens.spec.ts @@ -15,7 +15,7 @@ const themedControls = [ ['InterruptSteerButton.tsx', ['size-theme-control', 'rounded-theme-control-round']], ['TokenUsage/index.tsx', ['size-theme-control', 'rounded-theme-control-round']], ['Files/AttachFile.tsx', ['size-theme-control', 'rounded-theme-control-round']], - ['CodeApprovalMenu.tsx', ['composerControlClasses()', 'md:px-theme-normal']], + ['CodeApprovalMenu.tsx', ['composerControlClasses()', 'md:px-theme-control-x']], ] as const; describe('Composer appearance tokens', () => { diff --git a/e2e/specs/mock/scenarios/control-spacing.spec.ts b/e2e/specs/mock/scenarios/control-spacing.spec.ts new file mode 100644 index 0000000000..d786c0b600 --- /dev/null +++ b/e2e/specs/mock/scenarios/control-spacing.spec.ts @@ -0,0 +1,131 @@ +import { expect, test } from '@playwright/test'; +import type { Locator, Page } from '@playwright/test'; +import type { ThemeDefinition } from '../../../../packages/client/src/theme/types'; +import { clickHouseTheme } from '../../../../packages/client/src/theme/themes/clickhouse'; +import { NEW_CHAT_PATH, messagesView, sendMessageAndWaitForCompletion } from '../helpers'; +import { probeStyle } from './style.helpers'; + +/** + * Theme-sized controls read their inline padding and icon-to-label gap from control roles, apart + * from the shared spacing that also pads message bubbles and the composer's send button. The + * temporary-chat status chip is a real `size="theme"` control on the chat header. + */ +test.describe.configure({ timeout: 120_000 }); +test.use({ viewport: { width: 1280, height: 800 } }); + +const TOGGLE = 'button[aria-label="Temporary Chat"]'; + +/** A definition from before the control roles, which named only the shared spacing. */ +const legacySpacingTheme: ThemeDefinition = { + version: 1, + name: 'legacy-spacing-reference', + modes: { + light: { appearance: { spaceNormal: '0.5rem', spaceCompact: '0.25rem' } }, + dark: { appearance: { spaceNormal: '0.5rem', spaceCompact: '0.25rem' } }, + }, +}; + +async function storeDefinition(page: Page, definition: ThemeDefinition | null) { + await page.addInitScript((stored) => { + localStorage.removeItem('theme-colors'); + localStorage.removeItem('theme-name'); + if (stored === null) { + localStorage.removeItem('theme-definition'); + localStorage.removeItem('theme-source'); + return; + } + localStorage.setItem('theme-definition', JSON.stringify(stored)); + localStorage.setItem('theme-source', 'definition'); + }, definition); +} + +/** + * Starts a temporary chat and returns its header status chip, which appears once the first + * message is sent; the exchange also renders a message bubble padded by the shared spacing. + */ +async function temporaryChip(page: Page): Promise { + await page.goto(NEW_CHAT_PATH, { timeout: 15000 }); + const toggle = page.locator(TOGGLE); + await expect(toggle).toBeVisible({ timeout: 20000 }); + if ((await toggle.getAttribute('aria-pressed')) !== 'true') { + await toggle.click(); + } + await expect(toggle).toHaveAttribute('aria-pressed', 'true'); + await sendMessageAndWaitForCompletion(page, 'Control spacing probe'); + const chip = page.getByRole('status').filter({ has: page.locator('svg.lucide-hat-glasses') }); + await expect(chip).toBeVisible({ timeout: 20000 }); + return chip; +} + +/** The mode is persisted locally, so the next scenario starts from a normal chat. */ +async function leaveTemporaryChat(page: Page) { + await page.goto(NEW_CHAT_PATH, { timeout: 15000 }); + const toggle = page.locator(TOGGLE); + await expect(toggle).toBeVisible({ timeout: 20000 }); + if ((await toggle.getAttribute('aria-pressed')) === 'true') { + await toggle.click(); + } + await expect(toggle).toHaveAttribute('aria-pressed', 'false'); +} + +/** The sent message's bubble, the one element padded by `px-theme-normal`. */ +const bubblePadding = (page: Page) => + messagesView(page) + .locator('.px-theme-normal') + .first() + .evaluate((node: HTMLElement) => getComputedStyle(node).paddingLeft); + +const spacing = (chip: Locator) => + chip.evaluate((node: HTMLElement) => { + const style = getComputedStyle(node); + return { + paddingLeft: style.paddingLeft, + paddingRight: style.paddingRight, + gap: style.columnGap, + }; + }); + +test.describe('theme control spacing', () => { + test('theme-sized controls keep 12px padding and a 6px gap without a theme @scenario:theme-controls-keep-default-spacing', async ({ + page, + }) => { + await storeDefinition(page, null); + const chip = await temporaryChip(page); + + expect(await spacing(chip)).toEqual({ paddingLeft: '12px', paddingRight: '12px', gap: '6px' }); + expect(await probeStyle(page, 'px-theme-control-x', 'padding-left')).toBe('12px'); + expect(await probeStyle(page, 'gap-theme-control-gap', 'column-gap')).toBe('6px'); + expect(await bubblePadding(page)).toBe('12px'); + + await leaveTemporaryChat(page); + }); + + test('ClickHouse controls take Click UI button padding and gap while message spacing stays @scenario:clickhouse-controls-take-click-ui-spacing', async ({ + page, + }) => { + await storeDefinition(page, clickHouseTheme); + const chip = await temporaryChip(page); + await expect(page.locator('html')).toHaveAttribute('data-theme', 'clickhouse'); + + /** `button.basic.space.x` and `button.basic.space.gap`. */ + expect(await spacing(chip)).toEqual({ paddingLeft: '16px', paddingRight: '16px', gap: '8px' }); + /** Message bubbles and the send button keep the shared spacing roles. */ + expect(await bubblePadding(page)).toBe('12px'); + expect(await probeStyle(page, 'p-theme-compact', 'padding-top')).toBe('6px'); + + await leaveTemporaryChat(page); + }); + + test('a theme naming only the shared spacing keeps its controls on it @scenario:legacy-space-theme-keeps-control-spacing', async ({ + page, + }) => { + await storeDefinition(page, legacySpacingTheme); + const chip = await temporaryChip(page); + await expect(page.locator('html')).toHaveAttribute('data-theme', 'legacy-spacing-reference'); + + expect(await spacing(chip)).toEqual({ paddingLeft: '8px', paddingRight: '8px', gap: '4px' }); + expect(await bubblePadding(page)).toBe('8px'); + + await leaveTemporaryChat(page); + }); +}); diff --git a/packages/client/src/components/Button.spec.tsx b/packages/client/src/components/Button.spec.tsx index 3ba7ca1c22..34e376dcf1 100644 --- a/packages/client/src/components/Button.spec.tsx +++ b/packages/client/src/components/Button.spec.tsx @@ -14,10 +14,20 @@ describe('Button', () => { expect(screen.getByRole('button', { name: 'Continue' })).toHaveClass( 'h-theme-control', 'rounded-theme-control', - 'gap-theme-compact', + 'gap-theme-control-gap', + 'px-theme-control-x', ); }); + /** The base `gap-2` and the default size's `px-4` would otherwise survive beside the roles and + * leave the winner to stylesheet order, and a caller's own padding must still win. */ + it('lets the control spacing roles replace the base gap and a caller replace them', () => { + const themed = cn(buttonVariants({ size: 'theme' })); + expect(themed).not.toMatch(/(^|\s)gap-2(\s|$)/); + expect(cn(themed, 'px-2')).not.toContain('px-theme-control-x'); + expect(cn(themed, 'gap-1')).not.toContain('gap-theme-control-gap'); + }); + it('offers the composer action row geometry as a size and a shape', () => { render(