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(