Skip to content

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

🎛️ feat: Give the Button Theme Roles for Its Label, Height, Fill and States (#16530)

Marco Beretta0eccfbfa5844
diff --git a/client/src/components/UnifiedSidebar/mobile/__tests__/Scrim.spec.tsx b/client/src/components/UnifiedSidebar/mobile/__tests__/Scrim.spec.tsx
index 9deacf035e..6e97567d8f 100644
--- a/client/src/components/UnifiedSidebar/mobile/__tests__/Scrim.spec.tsx
+++ b/client/src/components/UnifiedSidebar/mobile/__tests__/Scrim.spec.tsx
@@ -58,7 +58,7 @@ describe('mobile drawer Scrim', () => {
'focus-visible:outline-hidden',
'focus-visible:ring-2',
'focus-visible:ring-inset',
- 'focus-visible:ring-text-primary',
+ 'focus-visible:ring-focus-control',
);
});
diff --git a/e2e/specs/mock/scenarios/button-roles.spec.ts b/e2e/specs/mock/scenarios/button-roles.spec.ts
new file mode 100644
index 0000000000..f9252463e4
--- /dev/null
+++ b/e2e/specs/mock/scenarios/button-roles.spec.ts
@@ -0,0 +1,112 @@
+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 } from '../helpers';
+import { probeStyle } from './style.helpers';
+
+/**
+ * The shared Button reads its label weight, its default and small heights and its primary fill
+ * from theme roles. The Data & Privacy tab's "Archive all chats" button is a plain default-size Button with
+ * no weight or height of its own, so it shows what the primitive draws.
+ */
+test.describe.configure({ timeout: 120_000 });
+test.use({ viewport: { width: 1280, height: 800 } });
+
+type Mode = 'light' | 'dark';
+
+/** A definition from before the button roles, which repainted only the inverted surface. */
+const legacyInvertedTheme: ThemeDefinition = {
+ version: 1,
+ name: 'legacy-inverted-reference',
+ modes: {
+ light: { colors: { 'rgb-surface-inverted': '10 20 30' } },
+ dark: { colors: { 'rgb-surface-inverted': '10 20 30' } },
+ },
+};
+
+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);
+}
+
+async function archiveButton(page: Page): Promise<Locator> {
+ await page.goto(NEW_CHAT_PATH, { 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: 'Data & Privacy' }).click();
+ const button = dialog.getByRole('button', { name: 'Archive all chats' });
+ await expect(button).toBeVisible();
+ return button;
+}
+
+/** Layout height, not the client rect: the dialog may still be zooming in when this reads. */
+const drawn = (button: Locator) =>
+ button.evaluate((node: HTMLElement) => ({
+ weight: getComputedStyle(node).fontWeight,
+ height: node.offsetHeight,
+ }));
+
+const resolvedMode = (page: Page) =>
+ page.evaluate(() =>
+ document.documentElement.classList.contains('dark') ? 'dark' : 'light',
+ ) as Promise<Mode>;
+
+test.describe('theme button roles', () => {
+ test('buttons keep a 500 label, 40px height and the inverted fill without a theme @scenario:buttons-keep-default-weight-height-and-fill', async ({
+ page,
+ }) => {
+ await storeDefinition(page, null);
+ const button = await archiveButton(page);
+
+ expect(await drawn(button)).toEqual({ weight: '500', height: 40 });
+ expect(await probeStyle(page, 'h-theme-button-sm', 'height')).toBe('36px');
+ expect(await probeStyle(page, 'bg-button-primary', 'background-color')).toBe(
+ await probeStyle(page, 'bg-surface-inverted', 'background-color'),
+ );
+ expect(await probeStyle(page, 'bg-button-primary-hover', 'background-color')).toBe(
+ await probeStyle(page, 'bg-surface-inverted-hover', 'background-color'),
+ );
+ });
+
+ test('ClickHouse buttons take Click UI weight, height and primary fill @scenario:clickhouse-buttons-follow-click-ui', async ({
+ page,
+ }) => {
+ await storeDefinition(page, clickHouseTheme);
+ const button = await archiveButton(page);
+ await expect(page.locator('html')).toHaveAttribute('data-theme', 'clickhouse');
+ const mode = await resolvedMode(page);
+
+ /** `button.basic.typography.label.default` is 400; Click UI's content-sized button is 32px. */
+ expect(await drawn(button)).toEqual({ weight: '400', height: 32 });
+ expect(await probeStyle(page, 'h-theme-button-sm', 'height')).toBe('32px');
+ /** The button's own primary fill; the checkbox and switch keep `#151515` in light. */
+ const fill = mode === 'light' ? 'rgb(48, 46, 50)' : 'rgb(250, 255, 105)';
+ const inverted = mode === 'light' ? 'rgb(21, 21, 21)' : 'rgb(250, 255, 105)';
+ expect(await probeStyle(page, 'bg-button-primary', 'background-color')).toBe(fill);
+ expect(await probeStyle(page, 'bg-surface-inverted', 'background-color')).toBe(inverted);
+ });
+
+ test('a theme that repaints only the inverted surface keeps its buttons on it @scenario:legacy-inverted-theme-keeps-button-fill', async ({
+ page,
+ }) => {
+ await storeDefinition(page, legacyInvertedTheme);
+ await archiveButton(page);
+ await expect(page.locator('html')).toHaveAttribute('data-theme', 'legacy-inverted-reference');
+
+ expect(await probeStyle(page, 'bg-button-primary', 'background-color')).toBe('rgb(10, 20, 30)');
+ });
+});
diff --git a/packages/client/src/components/Button.spec.tsx b/packages/client/src/components/Button.spec.tsx
index 34e376dcf1..c841b9130f 100644
--- a/packages/client/src/components/Button.spec.tsx
+++ b/packages/client/src/components/Button.spec.tsx
@@ -19,6 +19,30 @@ describe('Button', () => {
);
});
+ it('draws its label, height, fills, focus and states from theme roles', () => {
+ render(<Button>Save</Button>);
+
+ expect(screen.getByRole('button', { name: 'Save' })).toHaveClass(
+ 'font-theme-control',
+ 'h-theme-button',
+ 'bg-button-primary',
+ 'hover:bg-button-primary-hover',
+ 'hover:active:bg-surface-inverted-pressed',
+ 'focus-visible:ring-focus-control',
+ 'disabled:opacity-50',
+ 'theme-disabled:bg-surface-disabled',
+ );
+ expect(cn(buttonVariants({ size: 'sm' }))).toContain('h-theme-button-sm');
+ expect(cn(buttonVariants({ variant: 'outline' }))).toContain('hover:active:bg-surface-pressed');
+ });
+
+ it('lets a caller replace the themed label weight and height', () => {
+ const classes = cn(buttonVariants({ size: 'sm' }), 'h-9 font-semibold');
+
+ expect(classes).not.toContain('h-theme-button-sm');
+ expect(classes).not.toContain('font-theme-control');
+ });
+
/** 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', () => {
@@ -69,7 +93,7 @@ describe('Button', () => {
);
const button = screen.getByRole('button', { name: 'Back' });
- expect(button).toHaveClass('rounded-xl', 'h-9', 'bg-presentation');
+ expect(button).toHaveClass('rounded-xl', 'h-theme-button-sm', 'bg-presentation');
expect(button).not.toHaveClass('rounded-lg');
rerender(
@@ -78,7 +102,7 @@ describe('Button', () => {
</Button>,
);
- expect(button).toHaveClass('rounded-theme-control', 'h-9');
+ expect(button).toHaveClass('rounded-theme-control', 'h-theme-button-sm');
expect(button).not.toHaveClass('rounded-xl');
});
@@ -162,13 +186,16 @@ describe('Button', () => {
expect(header).toContain('px-1');
expect(header).toContain('h-auto');
- expect(header).not.toContain('h-10');
+ expect(header).not.toContain('h-theme-button');
expect(header).not.toContain('px-4');
/** A heading is not a control: nothing fills under the pointer. */
- expect(header).not.toContain('hover:bg-');
+ /** Only the disabled recipe's `theme-disabled:hover:` pin may name a hover fill. */
+ expect(header).not.toMatch(/(^|\s)hover:bg-/);
});
it('still takes a size when a caller asks for one', () => {
- expect(cn(buttonVariants({ variant: 'section-header', size: 'sm' }))).toContain('h-9');
+ expect(cn(buttonVariants({ variant: 'section-header', size: 'sm' }))).toContain(
+ 'h-theme-button-sm',
+ );
});
});
diff --git a/packages/client/src/components/Button.tsx b/packages/client/src/components/Button.tsx
index d7da863f23..86758bfff0 100644
--- a/packages/client/src/components/Button.tsx
+++ b/packages/client/src/components/Button.tsx
@@ -2,6 +2,7 @@ import * as React from 'react';
import { Slot } from '@radix-ui/react-slot';
import { ClassProp } from 'class-variance-authority/types';
import { cva, type VariantProps } from 'class-variance-authority';
+import { disabledFillClasses } from '~/utils/theme';
import { cn } from '~/utils';
type ButtonVariantOptions =
@@ -44,15 +45,19 @@ type ButtonVariantOptions =
| undefined;
const buttonVariantRecipe = cva(
- 'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg text-sm font-medium ring-offset-surface-primary transition-colors duration-theme-fast focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-text-primary focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
+ [
+ 'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg text-sm font-theme-control ring-offset-surface-primary transition-colors duration-theme-fast focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-focus-control focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
+ disabledFillClasses,
+ ],
{
variants: {
variant: {
- default: 'bg-surface-inverted text-text-inverted hover:bg-surface-inverted-hover',
+ default:
+ 'bg-button-primary text-text-inverted hover:bg-button-primary-hover hover:active:bg-surface-inverted-pressed',
destructive:
'bg-surface-destructive text-text-on-status hover:bg-surface-destructive-hover',
outline:
- 'text-text-primary border border-border-light bg-transparent hover:bg-surface-hover hover:text-text-primary',
+ 'text-text-primary border border-border-light bg-transparent hover:bg-surface-hover hover:active:bg-surface-pressed hover:text-text-primary',
/**
* A selectable answer inside a question card. `outline` is wrong here:
* its `border-light` edge measures ~1.2:1 against the panel these sit
@@ -62,11 +67,12 @@ const buttonVariantRecipe = cva(
* and drops to `font-normal` so the question above stays the heading.
*/
choice:
- 'border border-border-xheavy bg-surface-tertiary font-normal text-text-primary hover:bg-surface-hover hover:text-text-primary',
+ 'border border-border-xheavy bg-surface-tertiary font-normal text-text-primary hover:bg-surface-hover hover:active:bg-surface-pressed hover:text-text-primary',
subtle:
- 'border border-border-light bg-transparent text-text-primary hover:bg-surface-secondary focus-visible:ring-text-primary focus-visible:ring-offset-0',
- secondary: 'bg-surface-secondary text-text-primary hover:bg-surface-hover',
- ghost: 'hover:bg-surface-hover hover:text-text-primary',
+ 'border border-border-light bg-transparent text-text-primary hover:bg-surface-secondary focus-visible:ring-focus-control focus-visible:ring-offset-0',
+ secondary:
+ 'bg-surface-secondary text-text-primary hover:bg-surface-hover hover:active:bg-surface-pressed',
+ ghost: 'hover:bg-surface-hover hover:active:bg-surface-pressed hover:text-text-primary',
/**
* A compact action living inside a list row — a pinned row's unpin
* badge, a conversation's overflow trigger, a table row's controls. The
@@ -132,14 +138,14 @@ const buttonVariantRecipe = cva(
card: 'justify-start whitespace-normal rounded-2xl text-left font-normal hover:bg-surface-hover focus-visible:ring-inset focus-visible:ring-offset-0',
},
size: {
- default: 'h-10 px-4 py-2',
+ default: 'h-theme-button px-4 py-2',
/**
* A chip, the text counterpart of `icon-xs`: the reset beside a list that
* matched nothing, and anything else that offers a way out without asking
* to be the thing the eye lands on.
*/
xs: 'h-7 rounded-md px-2.5 text-xs',
- sm: 'h-9 rounded-lg px-3',
+ sm: 'h-theme-button-sm rounded-lg px-3',
lg: 'h-11 rounded-lg px-8',
icon: 'size-10',
'icon-sm': 'size-8 p-0',
diff --git a/packages/client/src/components/InputCombobox.tsx b/packages/client/src/components/InputCombobox.tsx
index e4ddcc8038..7aba7a8a7a 100644
--- a/packages/client/src/components/InputCombobox.tsx
+++ b/packages/client/src/components/InputCombobox.tsx
@@ -50,7 +50,9 @@ export const InputCombobox: React.FC<ComboboxProps> = ({
{label}
</Ariakit.ComboboxLabel>
)}
- <div className={cn('relative', isKeyboardFocus ? 'ring-ring-primary rounded-md ring-2' : '')}>
+ <div
+ className={cn('relative', isKeyboardFocus ? 'ring-focus-control rounded-md ring-2' : '')}
+ >
<Ariakit.Combobox
placeholder={placeholder}
className={cn(
diff --git a/packages/client/src/components/InputWithDropDown.tsx b/packages/client/src/components/InputWithDropDown.tsx
index 10ba6b4007..d2d437c221 100644
--- a/packages/client/src/components/InputWithDropDown.tsx
+++ b/packages/client/src/components/InputWithDropDown.tsx
@@ -97,7 +97,7 @@ const InputWithDropdown: React.ForwardRefExoticComponent<
/>
<button
type="button"
- className="text-text-tertiary hover:text-text-secondary focus-visible:ring-ring-primary absolute inset-y-0 right-0 flex items-center rounded-md px-2 focus-visible:ring-1 focus-visible:outline-hidden"
+ className="text-text-tertiary hover:text-text-secondary focus-visible:ring-focus-control absolute inset-y-0 right-0 flex items-center rounded-md px-2 focus-visible:ring-1 focus-visible:outline-hidden"
onClick={() => setIsOpen(!isOpen)}
aria-label={isOpen ? 'Close dropdown' : 'Open dropdown'}
>
@@ -121,7 +121,7 @@ const InputWithDropdown: React.ForwardRefExoticComponent<
<ul
id="dropdown-list"
role="listbox"
- className="border-border-medium bg-surface-secondary focus:ring-ring-primary absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-md border shadow-lg focus:ring-1 focus:ring-inset"
+ className="border-border-medium bg-surface-secondary focus:ring-focus-control absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-md border shadow-lg focus:ring-1 focus:ring-inset"
>
{options.map((option, index) => (
<li
@@ -130,7 +130,7 @@ const InputWithDropdown: React.ForwardRefExoticComponent<
aria-selected={index === highlightedIndex}
className={cn(
'cursor-pointer rounded-md px-3 py-2',
- 'focus:bg-surface-tertiary focus:ring-ring-primary focus:ring-1 focus:outline-hidden focus:ring-inset',
+ 'focus:bg-surface-tertiary focus:ring-focus-control focus:ring-1 focus:outline-hidden focus:ring-inset',
index === highlightedIndex
? 'bg-surface-active text-text-primary'
: 'text-text-secondary hover:bg-surface-tertiary',
diff --git a/packages/client/src/components/MultiSearch.tsx b/packages/client/src/components/MultiSearch.tsx
index f7641d7c34..d3519cb1c1 100644
--- a/packages/client/src/components/MultiSearch.tsx
+++ b/packages/client/src/components/MultiSearch.tsx
@@ -47,7 +47,7 @@ export default function MultiSearch({
onChange={onChangeHandler}
placeholder={String(placeholder ?? 'Search...')}
aria-label="Search Model"
- className="placeholder-text-secondary focus:ring-ring-primary flex-1 rounded-md border-none bg-transparent px-2.5 py-2 text-sm focus:ring-1 focus:outline-hidden"
+ className="placeholder-text-secondary focus:ring-focus-control flex-1 rounded-md border-none bg-transparent px-2.5 py-2 text-sm focus:ring-1 focus:outline-hidden"
/>
<button
className={cn(
diff --git a/packages/client/src/components/SecretInput.tsx b/packages/client/src/components/SecretInput.tsx
index 8190e0c0c8..6d653bd1f4 100644
--- a/packages/client/src/components/SecretInput.tsx
+++ b/packages/client/src/components/SecretInput.tsx
@@ -116,7 +116,7 @@ const SecretInput: React.ForwardRefExoticComponent<
onClick={handleCopy}
disabled={disabled || !value}
className={cn(
- 'text-text-secondary focus-visible:ring-ring-primary inline-flex size-7 shrink-0 items-center justify-center rounded-md transition-colors duration-150 focus-visible:ring-2 focus-visible:outline-hidden [&>svg]:block',
+ 'text-text-secondary focus-visible:ring-focus-control inline-flex size-7 shrink-0 items-center justify-center rounded-md transition-colors duration-150 focus-visible:ring-2 focus-visible:outline-hidden [&>svg]:block',
disabled || !value
? 'cursor-not-allowed opacity-50'
: 'hover:bg-surface-hover hover:text-text-primary',
@@ -133,7 +133,7 @@ const SecretInput: React.ForwardRefExoticComponent<
onClick={toggleVisibility}
disabled={disabled}
className={cn(
- 'text-text-secondary focus-visible:ring-ring-primary inline-flex size-7 shrink-0 items-center justify-center rounded-md transition-colors duration-150 focus-visible:ring-2 focus-visible:outline-hidden [&>svg]:block',
+ 'text-text-secondary focus-visible:ring-focus-control inline-flex size-7 shrink-0 items-center justify-center rounded-md transition-colors duration-150 focus-visible:ring-2 focus-visible:outline-hidden [&>svg]:block',
disabled
? 'cursor-not-allowed opacity-50'
: 'hover:bg-surface-hover hover:text-text-primary',
diff --git a/packages/client/src/components/Select.spec.tsx b/packages/client/src/components/Select.spec.tsx
new file mode 100644
index 0000000000..734b546041
--- /dev/null
+++ b/packages/client/src/components/Select.spec.tsx
@@ -0,0 +1,25 @@
+import '@testing-library/jest-dom';
+import { render, screen } from '@testing-library/react';
+import { Select, SelectTrigger, SelectValue } from './Select';
+
+describe('SelectTrigger', () => {
+ /** The trigger hid the outline on every focus and drew nothing in its place, so a keyboard
+ * user could not see which control held focus. */
+ it('draws keyboard focus in the control focus role', () => {
+ render(
+ <Select>
+ <SelectTrigger aria-label="Model">
+ <SelectValue placeholder="Pick one" />
+ </SelectTrigger>
+ </Select>,
+ );
+
+ const trigger = screen.getByRole('combobox', { name: 'Model' });
+ expect(trigger).toHaveClass(
+ 'focus-visible:outline-hidden',
+ 'focus-visible:ring-2',
+ 'focus-visible:ring-focus-control',
+ );
+ expect(trigger).not.toHaveClass('focus:outline-hidden');
+ });
+});
diff --git a/packages/client/src/components/Select.tsx b/packages/client/src/components/Select.tsx
index 1760bd45de..3d2a5edd5b 100644
--- a/packages/client/src/components/Select.tsx
+++ b/packages/client/src/components/Select.tsx
@@ -27,7 +27,7 @@ const SelectTrigger: React.ForwardRefExoticComponent<
<SelectPrimitive.Trigger
ref={ref}
className={cn(
- 'border-border-control ring-offset-surface-primary placeholder:text-text-secondary flex h-9 w-full items-center justify-between rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs focus:outline-hidden disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1',
+ 'border-border-control ring-offset-surface-primary placeholder:text-text-secondary focus-visible:ring-focus-control flex h-9 w-full items-center justify-between rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs focus-visible:ring-2 focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1',
disabledFillClasses,
'hover:bg-surface-hover rounded-lg',
className,
diff --git a/packages/client/src/components/focus.spec.tsx b/packages/client/src/components/focus.spec.tsx
new file mode 100644
index 0000000000..9ce256b95e
--- /dev/null
+++ b/packages/client/src/components/focus.spec.tsx
@@ -0,0 +1,107 @@
+import React from 'react';
+import '@testing-library/jest-dom';
+import userEvent from '@testing-library/user-event';
+import { render, screen } from '@testing-library/react';
+import InputWithDropdown from './InputWithDropDown';
+import { InputCombobox } from './InputCombobox';
+import { SecretInput } from './SecretInput';
+import MultiSearch from './MultiSearch';
+
+jest.mock('./MorphIcon', () => {
+ const { createMorphIconMock } = jest.requireActual('../test/mockMorphIcon');
+ const { Eye, EyeOff, Copy, Check } = jest.requireActual('lucide');
+ return {
+ MorphIcon: createMorphIconMock([
+ [Eye, 'eye'],
+ [EyeOff, 'eye-off'],
+ [Copy, 'copy'],
+ [Check, 'check'],
+ ]),
+ };
+});
+
+/**
+ * These controls drew keyboard focus in the decorative `ring-primary`, about 2.3:1 on the dark
+ * default canvas. Each is reached by Tab, as a keyboard user reaches it, and must paint its ring in
+ * the `focus-control` role that `semanticTokens.spec.ts` holds at 3:1 on every control canvas.
+ */
+describe('shared control keyboard focus', () => {
+ it('rings the secret reveal and copy buttons in the focus role', async () => {
+ const user = userEvent.setup();
+ render(<SecretInput value="secret" showCopy readOnly aria-label="token" />);
+
+ const reached: Element[] = [];
+ for (let stop = 0; stop < 3; stop++) {
+ await user.tab();
+ if (document.activeElement) {
+ reached.push(document.activeElement);
+ }
+ }
+
+ const buttons = [
+ screen.getByRole('button', { name: 'Show secret' }),
+ screen.getByRole('button', { name: 'Copy to clipboard' }),
+ ];
+ buttons.forEach((button) => {
+ expect(reached).toContain(button);
+ expect(button).toHaveClass('focus-visible:ring-2', 'focus-visible:ring-focus-control');
+ });
+ });
+
+ it('rings the model search field in the focus role', async () => {
+ const user = userEvent.setup();
+ render(<MultiSearch value="" onChange={jest.fn()} />);
+
+ await user.tab();
+ const search = screen.getByRole('textbox', { name: 'Search Model' });
+ expect(search).toHaveFocus();
+ expect(search).toHaveClass('focus:ring-1', 'focus:ring-focus-control');
+ });
+
+ it('rings the dropdown toggle and its options in the focus role', async () => {
+ const user = userEvent.setup();
+ render(<InputWithDropdown aria-label="Stop word" options={['alpha', 'beta']} />);
+
+ await user.tab();
+ await user.tab();
+ const toggle = screen.getByRole('button', { name: 'Open dropdown' });
+ expect(toggle).toHaveFocus();
+ expect(toggle).toHaveClass('focus-visible:ring-1', 'focus-visible:ring-focus-control');
+
+ await user.keyboard('{Enter}');
+ expect(screen.getByRole('listbox')).toHaveClass('focus:ring-focus-control');
+
+ await user.tab();
+ const [first] = screen.getAllByRole('option');
+ expect(first).toHaveFocus();
+ expect(first).toHaveClass('focus:ring-1', 'focus:ring-focus-control');
+ });
+
+ it('rings the combobox only while it holds keyboard focus', async () => {
+ const user = userEvent.setup();
+ render(
+ <>
+ <InputCombobox
+ label="Region"
+ options={['eu', 'us']}
+ value=""
+ onChange={jest.fn()}
+ onBlur={jest.fn()}
+ />
+ <button type="button">after</button>
+ </>,
+ );
+
+ const combobox = screen.getByRole('combobox', { name: 'Region' });
+ const ringHost = combobox.parentElement as HTMLElement;
+ expect(ringHost).not.toHaveClass('ring-focus-control');
+
+ await user.tab();
+ expect(combobox).toHaveFocus();
+ expect(ringHost).toHaveClass('ring-2', 'ring-focus-control');
+ expect(ringHost).not.toHaveClass('ring-ring-primary');
+
+ await user.tab();
+ expect(ringHost).not.toHaveClass('ring-focus-control');
+ });
+});
diff --git a/packages/client/src/theme/README.md b/packages/client/src/theme/README.md
index 5a5cd33762..1d9dd333e0 100644
--- a/packages/client/src/theme/README.md
+++ b/packages/client/src/theme/README.md
@@ -325,6 +325,9 @@ Each status family has a foreground, a `-subtle` background, a `-border`, and a
inverted control takes while held (`hover:active:`). Defaults to the hover fill,
which a pointer press has always shown; a theme that names only its hover fills
presses in them.
+- `bg-button-primary` / `bg-button-primary-hover` - The `Button`'s primary fill
+ and its hover, apart from the inverted surface the checkbox and switch keep.
+ They follow `surface-inverted` and its hover when a theme names only those.
- `bg-surface-disabled` / `text-text-disabled` / `border-border-disabled` - The
disabled fill, ink and edge, painted through the `theme-disabled:` variant only
when the theme's `disabledStyle` appearance role is `fill`. The default `dim`
diff --git a/packages/client/src/theme/defaults.css b/packages/client/src/theme/defaults.css
index 99e49698e6..c501b4b562 100644
--- a/packages/client/src/theme/defaults.css
+++ b/packages/client/src/theme/defaults.css
@@ -181,6 +181,8 @@ html {
--surface-inverted: var(--gray-850);
--surface-inverted-hover: var(--gray-700);
--surface-inverted-pressed: var(--gray-700);
+ --button-primary: var(--gray-850);
+ --button-primary-hover: var(--gray-700);
--surface-disabled: var(--gray-100);
--text-inverted: var(--white);
--surface-fixed: var(--white);
@@ -199,6 +201,9 @@ html {
--theme-control-height: 2.25rem;
--theme-control-padding-x: var(--theme-space-normal, 0.75rem);
--theme-control-gap: var(--theme-space-compact, 0.375rem);
+ --theme-control-font-weight: 500;
+ --theme-button-height: 2.5rem;
+ --theme-button-height-sm: 2.25rem;
--theme-switch-width: 2.75rem;
--theme-switch-height: 1.5rem;
--theme-table-cell-space-y: 1rem;
@@ -361,6 +366,8 @@ html {
--surface-inverted: var(--white);
--surface-inverted-hover: var(--gray-100);
--surface-inverted-pressed: var(--gray-100);
+ --button-primary: var(--white);
+ --button-primary-hover: var(--gray-100);
--surface-disabled: var(--gray-700);
--text-inverted: var(--gray-850);
--surface-fixed: var(--white);
diff --git a/packages/client/src/theme/defaults.spec.ts b/packages/client/src/theme/defaults.spec.ts
index b9f6f89ea1..12324e96ff 100644
--- a/packages/client/src/theme/defaults.spec.ts
+++ b/packages/client/src/theme/defaults.spec.ts
@@ -63,7 +63,7 @@ describe.each([
const tokens = Object.keys(theme) as Array<keyof IThemeRGB>;
it('covers every registry color', () => {
- expect(tokens).toHaveLength(106);
+ expect(tokens).toHaveLength(108);
});
it('resolves every registry color to the runtime theme value', () => {
diff --git a/packages/client/src/theme/registry.spec.ts b/packages/client/src/theme/registry.spec.ts
index 644b406d32..583829b7cd 100644
--- a/packages/client/src/theme/registry.spec.ts
+++ b/packages/client/src/theme/registry.spec.ts
@@ -637,6 +637,73 @@ describe('theme registry', () => {
expect(issues({ controlGap: '1rem; color: red' })).toHaveLength(1);
});
+ it('keeps the primary buttons of a theme that predates the role on its inverted surface', () => {
+ const resolved = resolveTheme(
+ {
+ version: 1,
+ name: 'inverted-reference',
+ modes: { light: { colors: { 'rgb-surface-inverted': '10 20 30' } } },
+ },
+ 'light',
+ );
+
+ expect(resolved.colors['rgb-button-primary']).toBe('10 20 30');
+ expect(resolved.colors['rgb-button-primary-hover']).toBe(
+ defaultTheme['rgb-button-primary-hover'],
+ );
+ });
+
+ it('draws buttons from their own roles apart from the checkbox fill', () => {
+ const { colors, appearance } = resolveTheme(
+ {
+ version: 1,
+ name: 'bold-buttons-reference',
+ modes: {
+ dark: {
+ colors: { 'rgb-button-primary': '200 30 90', 'rgb-button-primary-hover': '220 60 110' },
+ appearance: {
+ controlFontWeight: '700',
+ buttonHeight: '3rem',
+ buttonHeightSm: '2.75rem',
+ },
+ },
+ },
+ },
+ 'dark',
+ );
+
+ expect(colors['rgb-surface-inverted']).toBe(darkTheme['rgb-surface-inverted']);
+ expect(colors['rgb-button-primary']).toBe('200 30 90');
+ expect(appearance).toMatchObject({
+ controlFontWeight: '700',
+ buttonHeight: '3rem',
+ buttonHeightSm: '2.75rem',
+ });
+ });
+
+ it('keeps LibreChat’s button weight and heights by default', () => {
+ expect(defaultAppearance).toMatchObject({
+ controlFontWeight: '500',
+ buttonHeight: '2.5rem',
+ buttonHeightSm: '2.25rem',
+ });
+ });
+
+ it('accepts a numeric label weight from 1 to 1000 and rejects anything else', () => {
+ const issues = (controlFontWeight: string) =>
+ validateThemeDefinition({
+ version: 1,
+ name: 'weights',
+ modes: { light: { appearance: { controlFontWeight } } },
+ });
+
+ expect(issues('400')).toEqual([]);
+ expect(issues('1000')).toEqual([]);
+ ['0', '1001', 'bold', '400;', '4.5e2'].forEach((value) =>
+ expect(issues(value)).toHaveLength(1),
+ );
+ });
+
it('reproduces Tailwind’s own type scale by default', () => {
const tailwind = readFileSync(
join(__dirname, '..', '..', '..', '..', 'node_modules', 'tailwindcss', 'theme.css'),
diff --git a/packages/client/src/theme/registry.ts b/packages/client/src/theme/registry.ts
index cb68882fed..fc2d00428c 100644
--- a/packages/client/src/theme/registry.ts
+++ b/packages/client/src/theme/registry.ts
@@ -105,6 +105,19 @@ export function pressedFallbacks(colors: IThemeRGB): IThemeRGB {
};
}
+/**
+ * The Button's primary fills for a theme that predates them. The Button was painted in the
+ * inverted surface, so a theme that repaints that surface or its hover keeps its buttons on it.
+ */
+export function primaryButtonFallbacks(colors: IThemeRGB): IThemeRGB {
+ const fill = colors['rgb-button-primary'] ?? colors['rgb-surface-inverted'];
+ const hover = colors['rgb-button-primary-hover'] ?? colors['rgb-surface-inverted-hover'];
+ return {
+ ...(fill !== undefined ? { 'rgb-button-primary': fill } : {}),
+ ...(hover !== undefined ? { 'rgb-button-primary-hover': hover } : {}),
+ };
+}
+
/**
* The focus roles for a stored or environment theme that predates them. The
* global outline followed a theme's `rgb-ring-primary` whenever it named one,
@@ -137,6 +150,9 @@ export const themeAppearanceProperties: Readonly<
controlHeight: '--theme-control-height',
controlPaddingX: '--theme-control-padding-x',
controlGap: '--theme-control-gap',
+ controlFontWeight: '--theme-control-font-weight',
+ buttonHeight: '--theme-button-height',
+ buttonHeightSm: '--theme-button-height-sm',
switchWidth: '--theme-switch-width',
switchHeight: '--theme-switch-height',
tableCellSpaceY: '--theme-table-cell-space-y',
@@ -188,6 +204,9 @@ export const defaultAppearance: IThemeAppearance = Object.freeze({
controlHeight: '2.25rem',
controlPaddingX: '0.75rem',
controlGap: '0.375rem',
+ controlFontWeight: '500',
+ buttonHeight: '2.5rem',
+ buttonHeightSm: '2.25rem',
...defaultSwitchSize,
tableCellSpaceY: '1rem',
tableRowStroke: '0px',
@@ -487,6 +506,7 @@ export function resolveTheme(theme: ThemeDefinition, mode: ThemeMode): ResolvedT
borderControlSource !== undefined ? { 'rgb-border-control': borderControlSource } : {};
const focusFallback = customColors != null ? focusFallbacks(customColors) : {};
const pressedFallback = customColors != null ? pressedFallbacks(customColors) : {};
+ const primaryButtonFallback = customColors != null ? primaryButtonFallbacks(customColors) : {};
/**
* Slot 8 arrived after the seven-slot scale shipped, so a stored or
* environment theme that paints its own scale cannot name it. Filling the
@@ -553,6 +573,7 @@ export function resolveTheme(theme: ThemeDefinition, mode: ThemeMode): ResolvedT
...borderControlFallback,
...focusFallback,
...pressedFallback,
+ ...primaryButtonFallback,
...seriesEightFallback,
...verifiedFallback,
} as Required<IThemeRGB>,
diff --git a/packages/client/src/theme/semanticTokens.spec.ts b/packages/client/src/theme/semanticTokens.spec.ts
index 4bd0e6b687..574cc84468 100644
--- a/packages/client/src/theme/semanticTokens.spec.ts
+++ b/packages/client/src/theme/semanticTokens.spec.ts
@@ -373,6 +373,32 @@ describe.each([
});
});
+describe.each([
+ ['default', defaultTheme],
+ ['dark', darkTheme],
+ ['high contrast light', highContrastLightTheme],
+ ['high contrast dark', highContrastDarkTheme],
+ ['clickhouse light', clickHouseLightTheme],
+ ['clickhouse dark', clickHouseDarkTheme],
+])('%s control focus', (_name, theme: IThemeRGB) => {
+ it('keeps the keyboard focus ring at the 3:1 floor on every control canvas', () => {
+ const ring = toRgb(theme, 'rgb-focus-control');
+ const surfaces: Array<keyof IThemeRGB> = [
+ 'rgb-surface-primary',
+ 'rgb-presentation',
+ 'rgb-surface-secondary',
+ 'rgb-surface-dialog',
+ ];
+
+ const failures = surfaces.flatMap((surface) => {
+ const ratio = contrast(ring, toRgb(theme, surface));
+ return ratio < WCAG_MARK_MIN ? [`${surface}: ${ratio.toFixed(2)}:1`] : [];
+ });
+
+ expect(failures).toEqual([]);
+ });
+});
+
describe.each([
['default', defaultTheme],
['dark', darkTheme],
@@ -721,6 +747,16 @@ describe('state role defaults', () => {
expect(theme['rgb-surface-pressed']).toBe(theme['rgb-surface-hover']);
expect(theme['rgb-surface-inverted-pressed']).toBe(theme['rgb-surface-inverted-hover']);
});
+
+ it.each([
+ ['default light', defaultTheme],
+ ['default dark', darkTheme],
+ ['high contrast light', highContrastLightTheme],
+ ['high contrast dark', highContrastDarkTheme],
+ ])('fills %s primary buttons with the inverted surface', (_name, theme: IThemeRGB) => {
+ expect(theme['rgb-button-primary']).toBe(theme['rgb-surface-inverted']);
+ expect(theme['rgb-button-primary-hover']).toBe(theme['rgb-surface-inverted-hover']);
+ });
});
/**
diff --git a/packages/client/src/theme/tailwind.spec.js b/packages/client/src/theme/tailwind.spec.js
index b8012ce72a..b4f3ec979d 100644
--- a/packages/client/src/theme/tailwind.spec.js
+++ b/packages/client/src/theme/tailwind.spec.js
@@ -104,6 +104,9 @@ describe('LibreChat Tailwind preset', () => {
['font-theme-ui', '--theme-font-family', defaultAppearance.fontFamily],
['h-theme-control', '--theme-control-height', defaultAppearance.controlHeight],
['h-theme-switch', '--theme-switch-height', defaultAppearance.switchHeight],
+ ['h-theme-button', '--theme-button-height', defaultAppearance.buttonHeight],
+ ['h-theme-button-sm', '--theme-button-height-sm', defaultAppearance.buttonHeightSm],
+ ['font-theme-control', '--theme-control-font-weight', defaultAppearance.controlFontWeight],
['w-theme-switch', '--theme-switch-width', defaultAppearance.switchWidth],
['size-theme-switch-thumb', '--theme-switch-height', defaultAppearance.switchHeight],
['translate-x-theme-switch-travel', '--theme-switch-width', defaultAppearance.switchWidth],
diff --git a/packages/client/src/theme/themes/clickhouse.spec.tsx b/packages/client/src/theme/themes/clickhouse.spec.tsx
index 142d32a60d..992958bb55 100644
--- a/packages/client/src/theme/themes/clickhouse.spec.tsx
+++ b/packages/client/src/theme/themes/clickhouse.spec.tsx
@@ -193,6 +193,17 @@ describe.each(modes)('clickhouse %s palette', (_mode, theme) => {
expect(below(theme, WCAG_AA_NORMAL, onStatusFills, fills)).toEqual([]);
});
+ it('keeps the primary button label at WCAG AA on its fill, hovered and pressed', () => {
+ expect(
+ below(
+ theme,
+ WCAG_AA_NORMAL,
+ ['rgb-text-inverted'],
+ ['rgb-button-primary', 'rgb-button-primary-hover', 'rgb-surface-inverted-pressed'],
+ ),
+ ).toEqual([]);
+ });
+
it('keeps warning and destructive text at WCAG AA on canvas surfaces', () => {
expect(
below(theme, WCAG_AA_NORMAL, ['rgb-text-warning', 'rgb-text-destructive'], canvasSurfaces),
@@ -377,6 +388,9 @@ describe('clickhouse theme definition', () => {
controlHeight: '2rem',
controlPaddingX: '1rem',
controlGap: '0.5rem',
+ controlFontWeight: '400',
+ buttonHeight: '2rem',
+ buttonHeightSm: '2rem',
motionFast: '100ms',
});
expect(appearance.spaceCompact).toBe(defaultAppearance.spaceCompact);
diff --git a/packages/client/src/theme/themes/clickhouse.ts b/packages/client/src/theme/themes/clickhouse.ts
index 232c19d94c..d5cb836345 100644
--- a/packages/client/src/theme/themes/clickhouse.ts
+++ b/packages/client/src/theme/themes/clickhouse.ts
@@ -88,6 +88,9 @@ export const clickHouseLightTheme: IThemeRGB = {
'rgb-surface-inverted': '21 21 21', // #151515 (palette.neutral.900)
'rgb-surface-inverted-hover': '50 50 50', // #323232 (palette.neutral.712)
'rgb-surface-inverted-pressed': '22 21 23', // #161517 (button.basic.color.primary.background.active)
+ /** The button's own primary fill, apart from the `#151515` its checkbox and switch share. */
+ 'rgb-button-primary': '48 46 50', // #302e32 (button.basic.color.primary.background.default)
+ 'rgb-button-primary-hover': '67 70 76', // #43464c (button.basic.color.primary.background.hover)
'rgb-text-inverted': '255 255 255', // #ffffff (palette.neutral.0)
'rgb-surface-fixed': '255 255 255', // #ffffff (palette.neutral.0, same in light and dark)
'rgb-surface-fixed-hover': '230 231 233', // #e6e7e9 (palette.slate.100, same in light and dark)
@@ -225,6 +228,8 @@ export const clickHouseDarkTheme: IThemeRGB = {
'rgb-surface-inverted': '250 255 105', // #faff69 (button.basic.color.primary.background.default)
'rgb-surface-inverted-hover': '252 255 150', // #fcff96 (button.basic.color.primary.background.hover)
'rgb-surface-inverted-pressed': '231 236 97', // #e7ec61 (button.basic.color.primary.background.active)
+ 'rgb-button-primary': '250 255 105', // #faff69 (button.basic.color.primary.background.default)
+ 'rgb-button-primary-hover': '252 255 150', // #fcff96 (button.basic.color.primary.background.hover)
'rgb-text-inverted': '31 31 28', // #1f1f1c (button.basic.color.primary.text.default)
'rgb-surface-fixed': '255 255 255', // #ffffff (palette.neutral.0, same in light and dark)
'rgb-surface-fixed-hover': '230 231 233', // #e6e7e9 (palette.slate.100, same in light and dark)
@@ -360,6 +365,11 @@ const clickHouseShape = {
controlHeight: '2rem', // genericMenu.panel.size.height
controlPaddingX: '1rem', // button.basic.space.x
controlGap: '0.5rem', // button.basic.space.gap
+ controlFontWeight: '400', // button.basic.typography.label.default
+ /** Click UI's button is sized by its content: 0.2813rem of space.y on both sides of a
+ * 0.875rem/1.5 label and a 1px stroke, 32px in all. */
+ buttonHeight: '2rem',
+ buttonHeightSm: '2rem',
scrimOpacity: '0.75', // dialog.color.opaqueBackground alpha
alertScrimOpacity: '0.75', // dialog.color.opaqueBackground alpha
modalScrimOpacity: '0.75', // dialog.color.opaqueBackground alpha
diff --git a/packages/client/src/theme/themes/clickui.json b/packages/client/src/theme/themes/clickui.json
index 36c7715070..ee6f854572 100644
--- a/packages/client/src/theme/themes/clickui.json
+++ b/packages/client/src/theme/themes/clickui.json
@@ -18,10 +18,12 @@
"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.background.hover": "lch(29.47 4.1845 266.96)",
"click.button.basic.color.primary.text.default": "#ffffff",
"click.button.basic.color.secondary.stroke.default": "#e6e7e9",
"click.button.basic.space.gap": "0.5rem",
"click.button.basic.space.x": "1rem",
+ "click.button.basic.typography.label.default": "400 0.875rem/1.5 \"Inter\", \"SF Pro Display\", -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Oxygen, Ubuntu, Cantarell, \"Open Sans\", \"Helvetica Neue\", sans-serif;",
"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",
@@ -131,6 +133,7 @@
"click.button.basic.color.secondary.stroke.default": "#414141",
"click.button.basic.space.gap": "0.5rem",
"click.button.basic.space.x": "1rem",
+ "click.button.basic.typography.label.default": "400 0.875rem/1.5 \"Inter\", \"SF Pro Display\", -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Oxygen, Ubuntu, Cantarell, \"Open Sans\", \"Helvetica Neue\", sans-serif;",
"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",
diff --git a/packages/client/src/theme/themes/clickui.spec.ts b/packages/client/src/theme/themes/clickui.spec.ts
index ca67fe6343..d5bd6806ee 100644
--- a/packages/client/src/theme/themes/clickui.spec.ts
+++ b/packages/client/src/theme/themes/clickui.spec.ts
@@ -92,6 +92,8 @@ const colorSources: Record<ThemeMode, Partial<Record<keyof IThemeRGB, string>>>
'rgb-surface-inverted': 'palette.neutral.900',
'rgb-surface-inverted-hover': 'palette.neutral.712',
'rgb-surface-inverted-pressed': 'click.button.basic.color.primary.background.active',
+ 'rgb-button-primary': 'click.button.basic.color.primary.background.default',
+ 'rgb-button-primary-hover': 'click.button.basic.color.primary.background.hover',
'rgb-text-inverted': 'palette.neutral.0',
'rgb-surface-fixed': 'palette.neutral.0',
'rgb-surface-fixed-hover': 'palette.slate.100',
@@ -199,6 +201,8 @@ const colorSources: Record<ThemeMode, Partial<Record<keyof IThemeRGB, string>>>
'rgb-surface-inverted': 'click.button.basic.color.primary.background.default',
'rgb-surface-inverted-hover': 'click.button.basic.color.primary.background.hover',
'rgb-surface-inverted-pressed': 'click.button.basic.color.primary.background.active',
+ 'rgb-button-primary': 'click.button.basic.color.primary.background.default',
+ 'rgb-button-primary-hover': 'click.button.basic.color.primary.background.hover',
'rgb-text-inverted': 'click.button.basic.color.primary.text.default',
'rgb-surface-fixed': 'palette.neutral.0',
'rgb-surface-fixed-hover': 'palette.slate.100',
@@ -278,6 +282,9 @@ const appearanceDecisions: Partial<Record<keyof IThemeAppearance, string>> = {
disabledStyle: 'fill: Click UI paints disabled controls in fixed disabled tokens, never opacity',
text2xl:
"1.5rem: Click UI's next size, font.sizes.6 (2rem), would pass Tailwind's unthemed text-3xl (1.875rem)",
+ buttonHeight:
+ '2rem: Click UI sizes its button by content, button.basic.space.y (0.2813rem) twice, a 0.875rem/1.5 label and a 1px stroke each side',
+ buttonHeightSm: '2rem: Click UI draws one button size, so the small step matches the default',
};
const appearanceSources: Partial<Record<keyof IThemeAppearance, string>> = {
@@ -316,6 +323,7 @@ const appearanceSources: Partial<Record<keyof IThemeAppearance, string>> = {
controlHeight: 'click.genericMenu.panel.size.height',
controlPaddingX: 'click.button.basic.space.x',
controlGap: 'click.button.basic.space.gap',
+ controlFontWeight: 'click.button.basic.typography.label.default',
scrimOpacity: 'click.dialog.color.opaqueBackground.default',
alertScrimOpacity: 'click.dialog.color.opaqueBackground.default',
modalScrimOpacity: 'click.dialog.color.opaqueBackground.default',
@@ -435,6 +443,10 @@ function comparable(key: keyof IThemeAppearance, raw: string | number): string {
if (key === 'monoFontFamily') {
return firstFamily(value);
}
+ /** Click UI writes the label as a `font` shorthand; the role is its leading weight. */
+ if (key === 'controlFontWeight') {
+ return value.trim().split(/\s+/)[0];
+ }
return value.replace(/;$/, '').trim();
}
@@ -554,6 +566,13 @@ const parityProbes: Record<string, ParityProbe> = {
utility: 'rounded',
element: buttonProbe('default'),
},
+ 'Button height': {
+ token: 'click.genericMenu.panel.size.height',
+ kind: 'shape',
+ utility: 'h',
+ element: buttonProbe('default'),
+ deviation: 'Click UI sizes its button by content; the 32px it draws is the menu row height',
+ },
'Button inline padding': {
token: 'click.button.basic.space.x',
kind: 'shape',
@@ -751,8 +770,8 @@ const parityProbes: Record<string, ParityProbe> = {
/** 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: 9, shape: 12 },
- dark: { color: 10, shape: 12 },
+ light: { color: 10, shape: 13 },
+ dark: { color: 10, shape: 13 },
};
const radiusRoles: Record<string, keyof IThemeAppearance> = {
@@ -774,7 +793,12 @@ type SizeUtility = 'w' | 'h' | 'py' | 'px' | 'gap';
const sizeRoles: Record<SizeUtility, Record<string, keyof IThemeAppearance>> = {
w: { 'theme-switch': 'switchWidth' },
- h: { 'theme-switch': 'switchHeight', 'theme-control': 'controlHeight' },
+ h: {
+ 'theme-switch': 'switchHeight',
+ 'theme-control': 'controlHeight',
+ 'theme-button': 'buttonHeight',
+ 'theme-button-sm': 'buttonHeightSm',
+ },
py: { 'theme-table-cell': 'tableCellSpaceY' },
px: { 'theme-control-x': 'controlPaddingX' },
gap: { 'theme-control-gap': 'controlGap' },
diff --git a/packages/client/src/theme/themes/dark.ts b/packages/client/src/theme/themes/dark.ts
index ab46f28fb7..5ff2d2d006 100644
--- a/packages/client/src/theme/themes/dark.ts
+++ b/packages/client/src/theme/themes/dark.ts
@@ -63,6 +63,8 @@ export const darkTheme: IThemeRGB = {
'rgb-surface-inverted': '255 255 255', // #fff (white)
'rgb-surface-inverted-hover': '236 236 236', // #ececec (gray-100)
'rgb-surface-inverted-pressed': '236 236 236', // #ececec (gray-100), the hover fill
+ 'rgb-button-primary': '255 255 255', // #fff (white, matching surface-inverted)
+ 'rgb-button-primary-hover': '236 236 236', // #ececec (gray-100, matching surface-inverted-hover)
'rgb-text-inverted': '23 23 23', // #171717 (gray-850)
'rgb-surface-fixed': '255 255 255', // #fff (white) — same in light + dark
'rgb-surface-fixed-hover': '236 236 236', // #ececec (gray-100) — same in light + dark
diff --git a/packages/client/src/theme/themes/default.ts b/packages/client/src/theme/themes/default.ts
index 057d8616e0..f562fdbeb1 100644
--- a/packages/client/src/theme/themes/default.ts
+++ b/packages/client/src/theme/themes/default.ts
@@ -63,6 +63,8 @@ export const defaultTheme: IThemeRGB = {
'rgb-surface-inverted': '23 23 23', // #171717 (gray-850)
'rgb-surface-inverted-hover': '47 47 47', // #2f2f2f (gray-700)
'rgb-surface-inverted-pressed': '47 47 47', // #2f2f2f (gray-700), the hover fill
+ 'rgb-button-primary': '23 23 23', // #171717 (gray-850, matching surface-inverted)
+ 'rgb-button-primary-hover': '47 47 47', // #2f2f2f (gray-700, matching surface-inverted-hover)
'rgb-text-inverted': '255 255 255', // #fff (white)
'rgb-surface-fixed': '255 255 255', // #fff (white) — same in light + dark
'rgb-surface-fixed-hover': '236 236 236', // #ececec (gray-100) — same in light + dark
diff --git a/packages/client/src/theme/themes/highContrast.ts b/packages/client/src/theme/themes/highContrast.ts
index 6ea583b80b..0e27fb7ee5 100644
--- a/packages/client/src/theme/themes/highContrast.ts
+++ b/packages/client/src/theme/themes/highContrast.ts
@@ -99,6 +99,8 @@ export const highContrastLightTheme: IThemeRGB = {
'rgb-surface-inverted': '0 0 0', // #000000
'rgb-surface-inverted-hover': '51 51 51', // #333333
'rgb-surface-inverted-pressed': '51 51 51', // #333333, the hover fill
+ 'rgb-button-primary': '0 0 0', // #000000 (matching surface-inverted)
+ 'rgb-button-primary-hover': '51 51 51', // #333333 (matching surface-inverted-hover)
'rgb-text-inverted': '255 255 255', // #ffffff
'rgb-surface-fixed': '255 255 255', // #ffffff
'rgb-surface-fixed-hover': '212 212 212', // #d4d4d4
@@ -253,6 +255,8 @@ export const highContrastDarkTheme: IThemeRGB = {
'rgb-surface-inverted': '255 255 255', // #ffffff
'rgb-surface-inverted-hover': '212 212 212', // #d4d4d4
'rgb-surface-inverted-pressed': '212 212 212', // #d4d4d4, the hover fill
+ 'rgb-button-primary': '255 255 255', // #ffffff (matching surface-inverted)
+ 'rgb-button-primary-hover': '212 212 212', // #d4d4d4 (matching surface-inverted-hover)
'rgb-text-inverted': '0 0 0', // #000000
'rgb-surface-fixed': '255 255 255', // #ffffff
'rgb-surface-fixed-hover': '212 212 212', // #d4d4d4
diff --git a/packages/client/src/theme/tokens.css b/packages/client/src/theme/tokens.css
index 452ca7b8cc..14d17e4e14 100644
--- a/packages/client/src/theme/tokens.css
+++ b/packages/client/src/theme/tokens.css
@@ -63,6 +63,9 @@
--color-surface-inverted: rgb(var(--surface-inverted));
--color-surface-inverted-hover: rgb(var(--surface-inverted-hover));
--color-surface-inverted-pressed: rgb(var(--surface-inverted-pressed));
+ /* Fall back to the inverted fill they were painted with, for a stylesheet that predates them. */
+ --color-button-primary: rgb(var(--button-primary, var(--surface-inverted)));
+ --color-button-primary-hover: rgb(var(--button-primary-hover, var(--surface-inverted-hover)));
--color-surface-fixed: rgb(var(--surface-fixed));
--color-surface-fixed-hover: rgb(var(--surface-fixed-hover));
--color-surface-disabled: rgb(var(--surface-disabled));
diff --git a/packages/client/src/theme/types/index.ts b/packages/client/src/theme/types/index.ts
index 1340e0e1f7..e5eebb28d4 100644
--- a/packages/client/src/theme/types/index.ts
+++ b/packages/client/src/theme/types/index.ts
@@ -69,6 +69,10 @@ export interface IThemeRGB {
'rgb-surface-inverted-hover'?: string;
/** Fill of an inverted control while pressed; follows `rgb-surface-inverted-hover` when omitted. */
'rgb-surface-inverted-pressed'?: string;
+ /** The Button's primary fill and its hover; they follow `rgb-surface-inverted` and its hover
+ * when omitted, which the checkbox and switch keep painting. */
+ 'rgb-button-primary'?: string;
+ 'rgb-button-primary-hover'?: string;
'rgb-text-inverted'?: string;
'rgb-surface-fixed'?: string;
'rgb-surface-fixed-hover'?: string;
@@ -227,6 +231,8 @@ export interface IThemeVariables {
'--surface-inverted': string;
'--surface-inverted-hover': string;
'--surface-inverted-pressed': string;
+ '--button-primary': string;
+ '--button-primary-hover': string;
'--text-inverted': string;
'--surface-fixed': string;
'--surface-fixed-hover': string;
@@ -345,6 +351,8 @@ export interface IThemeColors {
'surface-inverted'?: string;
'surface-inverted-hover'?: string;
'surface-inverted-pressed'?: string;
+ 'button-primary'?: string;
+ 'button-primary-hover'?: string;
'text-inverted'?: string;
'surface-fixed'?: string;
'surface-fixed-hover'?: string;
@@ -426,6 +434,10 @@ export interface IThemeAppearance {
* `spaceCompact` when a theme names those and not these. */
controlPaddingX: string;
controlGap: string;
+ /** A theme-sized control's label weight, and the Button's default and `sm` heights. */
+ controlFontWeight: string;
+ buttonHeight: string;
+ buttonHeightSm: string;
switchWidth: string;
switchHeight: string;
tableCellSpaceY: string;
diff --git a/packages/client/src/theme/utils/applyTheme.spec.ts b/packages/client/src/theme/utils/applyTheme.spec.ts
index 42b1d7bf12..7be3974b49 100644
--- a/packages/client/src/theme/utils/applyTheme.spec.ts
+++ b/packages/client/src/theme/utils/applyTheme.spec.ts
@@ -349,6 +349,19 @@ describe('applyTheme', () => {
expect(root.style.getPropertyValue('--surface-inverted-pressed')).toBe('20 21 22');
});
+ it('fills the primary button with the inverted surface of a theme that predates the role', () => {
+ const root = document.documentElement;
+
+ applyTheme(
+ { 'rgb-surface-inverted': '30 31 32', 'rgb-surface-inverted-hover': '40 41 42' },
+ root,
+ defaultTheme,
+ );
+
+ expect(root.style.getPropertyValue('--button-primary')).toBe('30 31 32');
+ expect(root.style.getPropertyValue('--button-primary-hover')).toBe('40 41 42');
+ });
+
it('marks the root only for a theme that fills its disabled controls, and clears it', () => {
const root = document.documentElement;
const fill: ThemeDefinition = {
diff --git a/packages/client/src/theme/utils/applyTheme.ts b/packages/client/src/theme/utils/applyTheme.ts
index c7f497b011..3f8aa871fa 100644
--- a/packages/client/src/theme/utils/applyTheme.ts
+++ b/packages/client/src/theme/utils/applyTheme.ts
@@ -3,6 +3,7 @@ import {
controlBorderFallback,
focusFallbacks,
pressedFallbacks,
+ primaryButtonFallbacks,
MARK_NEIGHBOURHOOD,
themeAppearanceProperties,
themeBrandTokens,
@@ -110,6 +111,17 @@ function mapColors(colors: IThemeRGB, base?: IThemeRGB): Array<[string, string]>
variables.push(['--surface-inverted-pressed', pressed['rgb-surface-inverted-pressed']]);
}
+ const primary = primaryButtonFallbacks(colors);
+ if (colors['rgb-button-primary'] === undefined && primary['rgb-button-primary'] !== undefined) {
+ variables.push(['--button-primary', primary['rgb-button-primary']]);
+ }
+ if (
+ colors['rgb-button-primary-hover'] === undefined &&
+ primary['rgb-button-primary-hover'] !== undefined
+ ) {
+ variables.push(['--button-primary-hover', primary['rgb-button-primary-hover']]);
+ }
+
/**
* Same rule as `resolveTheme`: a theme that paints what the mark is measured
* against coordinated the `status-success-strong` the mark wore before it had
diff --git a/packages/client/src/utils/utils.ts b/packages/client/src/utils/utils.ts
index a2d1016049..5f58a126bb 100644
--- a/packages/client/src/utils/utils.ts
+++ b/packages/client/src/utils/utils.ts
@@ -11,9 +11,12 @@ const twMerge = extendTailwindMerge({
extend: {
classGroups: {
py: [{ py: ['theme-table-cell', 'theme-table-cell-compact', 'theme-table-cell-dense'] }],
- h: [{ h: ['theme-table-head', 'theme-table-head-compact'] }],
+ h: [
+ { h: ['theme-table-head', 'theme-table-head-compact', 'theme-button', 'theme-button-sm'] },
+ ],
px: [{ px: ['theme-control-x'] }],
gap: [{ gap: ['theme-control-gap'] }],
+ 'font-weight': [{ font: ['theme-control'] }],
},
},
});
diff --git a/packages/client/tailwind.preset.cjs b/packages/client/tailwind.preset.cjs
index 3ed22f99b0..305177aa8f 100644
--- a/packages/client/tailwind.preset.cjs
+++ b/packages/client/tailwind.preset.cjs
@@ -5,9 +5,16 @@ module.exports = {
fontFamily: {
'theme-ui': ['var(--theme-font-family, Inter, sans-serif)'],
},
+ fontWeight: {
+ /** A theme-sized control's label weight. */
+ 'theme-control': 'var(--theme-control-font-weight, 500)',
+ },
height: {
'theme-control': 'var(--theme-control-height, 2.25rem)',
'theme-switch': 'var(--theme-switch-height, 1.5rem)',
+ /** The Button's default and `sm` heights. */
+ 'theme-button': 'var(--theme-button-height, 2.5rem)',
+ 'theme-button-sm': 'var(--theme-button-height-sm, 2.25rem)',
/** A header cell: the table's vertical cell space on both sides of one text line. */
'theme-table-head': 'calc(var(--theme-table-cell-space-y, 1rem) * 2 + 1rem)',
/** A compact header: half the cell space on both sides of a text-sm line. */
diff --git a/packages/data-provider/src/theme.ts b/packages/data-provider/src/theme.ts
index 7c03b478c0..89ca2c9531 100644
--- a/packages/data-provider/src/theme.ts
+++ b/packages/data-provider/src/theme.ts
@@ -63,6 +63,8 @@ export const themeColorTokens = Object.freeze([
'rgb-surface-inverted',
'rgb-surface-inverted-hover',
'rgb-surface-inverted-pressed',
+ 'rgb-button-primary',
+ 'rgb-button-primary-hover',
'rgb-text-inverted',
'rgb-surface-fixed',
'rgb-surface-fixed-hover',
@@ -200,6 +202,12 @@ const isTableLength = (value: unknown): value is string =>
typeof value === 'string' && /^(0|\d*\.?\d+(px|rem))$/.test(value);
const isSwitchLength = (value: unknown): value is string =>
typeof value === 'string' && /^\d*\.?\d+(px|rem)$/.test(value) && parseFloat(value) > 0;
+/** A numeric CSS font weight, 1 to 1000, which is all a label weight needs. */
+const isFontWeight = (value: unknown): value is string =>
+ typeof value === 'string' &&
+ /^\d{1,4}$/.test(value) &&
+ Number(value) >= 1 &&
+ Number(value) <= 1000;
const isFontFamily = (value: unknown): value is string =>
typeof value === 'string' && value.trim().length > 0 && !/[;{}]/.test(value);
@@ -312,6 +320,10 @@ const appearanceValidators = {
* spacing that also pads message rows. */
controlPaddingX: isLength,
controlGap: isLength,
+ /** A theme-sized control's label weight, and the Button's default and `sm` heights. */
+ controlFontWeight: isFontWeight,
+ buttonHeight: isLength,
+ buttonHeightSm: isLength,
switchWidth: isSwitchLength,
switchHeight: isSwitchLength,
tableCellSpaceY: isTableLength,