🔤 feat: Give Display Type and the Type Scale Their Own Theme Roles (#16491)

* feat: Give Display Type and the Type Scale Their Own Theme Roles

Add a displayFontFamily appearance role, which the dialog titles compose
through font-display, and textXs..text2xl and leadingXs..leading2xl,
which the app's text-* utilities now read like the radius and shadow
scales. The defaults are Tailwind's own sizes and line heights and the
UI family, so the default theme is unchanged, and a theme that names
only its fontFamily keeps its headings in it.

ClickHouse takes Click UI's display family, font sizes 1 to 6 and its
1.5 product line height, cited in the drift guard. Basier Square is
named but not self-hosted: it is a commercial face, so browsers without
it fall through to the Inter stack.

* fix: Publish the Display Family Utility With the Theme Tokens

* fix: Keep the ClickHouse 2xl Step Below the Unthemed 3xl

Click UI has no size between 1.25rem and 2rem, and 2rem would overtake
Tailwind's unthemed text-3xl (1.875rem), so a responsive text-2xl to
sm:text-3xl heading shrank as the viewport grew. ClickHouse keeps
LibreChat's 1.5rem for 2xl at Click UI's line height, recorded as a
decision in the drift guard, and a registry test holds every bundled
2xl below 3xl.
This commit is contained in:
Marco Beretta 2026-09-29 16:12:47 +02:00 • committed by GitHub
parent 83d7afb0d1
commit 400e4549ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 417 additions and 13 deletions

View file

@ -12,7 +12,7 @@
}
/* The plain radius, font and shadow utilities read theme-owned properties, so a theme definition
* reshapes the existing `rounded-*`, `font-sans`, `font-mono` and `shadow-*` call sites without a
* reshapes the existing `rounded-*`, `font-sans`, `font-mono`, `text-*` and `shadow-*` call sites without a
* migration. The defaults in the `html` block reproduce the scale these utilities resolved to
* before. Bare `rounded` stays Tailwind's fixed 0.25rem: `sm` keeps its px offset, so the two part
* at a non-16px root. Bare `shadow` reads `--shadow`, which has always equalled `sm`, and follows
@ -28,6 +28,18 @@
--radius-3xl: var(--theme-radius-3xl);
--font-sans: var(--theme-font-family);
--font-mono: var(--theme-mono-font-family);
--text-xs: var(--theme-text-xs);
--text-xs--line-height: var(--theme-text-xs-leading);
--text-sm: var(--theme-text-sm);
--text-sm--line-height: var(--theme-text-sm-leading);
--text-base: var(--theme-text-base);
--text-base--line-height: var(--theme-text-base-leading);
--text-lg: var(--theme-text-lg);
--text-lg--line-height: var(--theme-text-lg-leading);
--text-xl: var(--theme-text-xl);
--text-xl--line-height: var(--theme-text-xl-leading);
--text-2xl: var(--theme-text-2xl);
--text-2xl--line-height: var(--theme-text-2xl-leading);
--shadow: var(--theme-shadow-sm);
--shadow-2xs: var(--theme-shadow-2xs);
--shadow-xs: var(--theme-shadow-xs);
@ -323,6 +335,19 @@ html {
--theme-space-normal: 0.75rem;
--theme-disabled-style: dim;
--theme-font-family: Inter, sans-serif;
--theme-display-font-family: Inter, sans-serif;
--theme-text-xs: 0.75rem;
--theme-text-xs-leading: calc(1 / 0.75);
--theme-text-sm: 0.875rem;
--theme-text-sm-leading: calc(1.25 / 0.875);
--theme-text-base: 1rem;
--theme-text-base-leading: calc(1.5 / 1);
--theme-text-lg: 1.125rem;
--theme-text-lg-leading: calc(1.75 / 1.125);
--theme-text-xl: 1.25rem;
--theme-text-xl-leading: calc(1.75 / 1.25);
--theme-text-2xl: 1.5rem;
--theme-text-2xl-leading: calc(2 / 1.5);
/* Roboto Mono is self-hosted (the `@font-face` block below), so code renders the same on every
* platform with real bold and italic faces. The tail is reached while the font loads, if it
* fails, and per glyph for what the bundled latin subset omits (box drawing in terminal output

View file

@ -0,0 +1,151 @@
import { expect, test } from '@playwright/test';
import type { Page } from '@playwright/test';
import { clickHouseTheme } from '../../../../packages/client/src/theme/themes/clickhouse';
import { NEW_CHAT_PATH } from '../helpers';
/**
* The display family and the `text-*` type scale. The default theme keeps Tailwind's own sizes and
* line heights and sets headings in the UI family; ClickHouse takes Click UI's sizes at its 1.5
* product line height and leads its headings with Basier Square; a reference theme proves both
* follow the roles. The probes carry `font-display` (what the dialog titles compose) and the
* `text-*` steps, so only the theme's roles style them.
*/
type Mode = 'light' | 'dark';
type Metrics = { size: string; leading: string };
const REFERENCE_THEME = {
version: 1,
name: 'e2e-type-roles',
modes: {
light: {
appearance: {
displayFontFamily: '"Reference Display", serif',
textSm: '0.9375rem',
leadingSm: '1.6',
text2xl: '1.75rem',
leading2xl: '1.2',
},
},
dark: {
appearance: {
displayFontFamily: '"Reference Display", serif',
textSm: '0.9375rem',
leadingSm: '1.6',
text2xl: '1.75rem',
leading2xl: '1.2',
},
},
},
} as const;
async function openChat(page: Page, mode: Mode, definition?: { name: string }) {
await page.addInitScript(
([appearance, stored]) => {
localStorage.setItem('color-theme', appearance as string);
localStorage.removeItem('theme-colors');
localStorage.removeItem('theme-name');
if (stored) {
localStorage.setItem('theme-definition', JSON.stringify(stored));
localStorage.setItem('theme-source', 'definition');
} else {
localStorage.removeItem('theme-definition');
localStorage.removeItem('theme-source');
}
},
[mode, definition ?? null] as [string, unknown],
);
await page.goto(NEW_CHAT_PATH, { timeout: 15000 });
await expect(page.getByRole('textbox', { name: 'Message input' })).toBeVisible({
timeout: 30000,
});
const root = page.locator('html');
if (definition) {
await expect(root).toHaveAttribute('data-theme', definition.name);
} else {
await expect(root).not.toHaveAttribute('data-theme');
}
}
/** Renders one probe per class list and reads what the browser computed for each. */
async function measure(page: Page) {
return page.evaluate(() => {
const probe = (className: string) => {
const node = document.createElement('p');
node.className = className;
node.textContent = 'Type probe';
document.body.append(node);
const style = getComputedStyle(node);
const result = { size: style.fontSize, leading: style.lineHeight, family: style.fontFamily };
node.remove();
return result;
};
const sm = probe('text-sm');
const xl2 = probe('text-2xl');
const display = probe('font-display');
return {
sm: { size: sm.size, leading: sm.leading },
xl2: { size: xl2.size, leading: xl2.leading },
display: display.family,
};
});
}
/** Each tag is written out whole: the runner finds a scenario by its literal tag. */
const CASES: Array<{
title: string;
mode: Mode;
definition?: { name: string };
sm: Metrics;
xl2: Metrics;
displayLeads: string;
}> = [
{
title:
'the default theme keeps Tailwind’s type scale and sets headings in the UI family @scenario:type-roles-default-unchanged',
mode: 'light',
sm: { size: '14px', leading: '20px' },
xl2: { size: '24px', leading: '32px' },
displayLeads: 'Inter',
},
{
title:
'the ClickHouse light theme takes Click UI’s type scale and display family @scenario:type-roles-clickhouse-light',
mode: 'light',
definition: clickHouseTheme,
sm: { size: '14px', leading: '21px' },
xl2: { size: '24px', leading: '36px' },
displayLeads: '"Basier Square"',
},
{
title:
'the ClickHouse dark theme takes Click UI’s type scale and display family @scenario:type-roles-clickhouse-dark',
mode: 'dark',
definition: clickHouseTheme,
sm: { size: '14px', leading: '21px' },
xl2: { size: '24px', leading: '36px' },
displayLeads: '"Basier Square"',
},
{
title:
'a theme that names the type roles sizes text and sets headings in them @scenario:type-roles-follow-reference-theme',
mode: 'light',
definition: REFERENCE_THEME,
sm: { size: '15px', leading: '24px' },
xl2: { size: '28px', leading: '33.6px' },
displayLeads: '"Reference Display"',
},
];
test.describe('display family and type scale roles', () => {
for (const { title, mode, definition, sm, xl2, displayLeads } of CASES) {
test(title, async ({ page }) => {
await openChat(page, mode, definition);
const metrics = await measure(page);
expect(metrics.sm).toEqual(sm);
expect(metrics.xl2).toEqual(xl2);
expect(metrics.display.split(',')[0].trim()).toBe(displayLeads);
});
}
});

View file

@ -110,7 +110,7 @@ const AlertDialogTitle: React.ForwardRefExoticComponent<
>(({ className = '', ...props }, ref) => (
<AlertDialogPrimitive.Title
ref={ref}
className={cn('text-text-primary text-lg font-semibold', className)}
className={cn('text-text-primary font-display text-lg font-semibold', className)}
{...props}
/>
));

View file

@ -113,7 +113,7 @@ const DialogTitle: React.ForwardRefExoticComponent<
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title
ref={ref}
className={cn('text-text-primary text-lg font-semibold', className ?? '')}
className={cn('text-text-primary font-display text-lg font-semibold', className ?? '')}
{...props}
/>
));

View file

@ -412,7 +412,7 @@ const DialogTitle: React.ForwardRefExoticComponent<
<DialogPrimitive.Title
ref={ref}
className={cn(
'text-lg leading-none font-semibold tracking-tight',
'font-display text-lg leading-none font-semibold tracking-tight',
focusOutlineVariants({ focusOutline }),
className,
)}

View file

@ -317,6 +317,11 @@ Each status family has a foreground, a `-subtle` background, a `-border`, and a
disabled fill, ink and edge, painted through the `theme-disabled:` variant only
when the theme's `disabledStyle` appearance role is `fill`. The default `dim`
keeps the half-opacity treatment every primitive carries.
- `font-display` - Headings and dialog titles (`displayFontFamily`). Follows the
theme's `fontFamily` when it names no display family.
- `text-xs` to `text-2xl` - Sizes and line heights read `textXs`..`text2xl` and
`leadingXs`..`leading2xl` (app only, like the radius scale); the defaults are
Tailwind's own values.
- `ring-focus-control` - The keyboard focus ring of the shared primitives
(`Checkbox`, `Switch`, `Field`, `IconButton` and their siblings). Defaults to
the primary text ink; a theme that names only `rgb-text-primary` rings its

View file

@ -1,3 +1,5 @@
import { join } from 'node:path';
import { readFileSync } from 'node:fs';
import type { ThemeDefinition } from './types';
import {
collectThemeWarnings,
@ -9,6 +11,7 @@ import {
themeColorTokens,
validateThemeDefinition,
} from './registry';
import { clickHouseTheme } from './themes/clickhouse';
import { defaultTheme } from './themes/default';
import { darkTheme } from './themes/dark';
@ -366,6 +369,89 @@ describe('theme registry', () => {
).toEqual(['Invalid appearance value for disabledStyle: fade']);
});
it('sets headings in the UI family of a theme that names no display family', () => {
const family = '"Reference Sans", sans-serif';
const resolved = resolveTheme(
{
version: 1,
name: 'family-only-reference',
modes: { light: { appearance: { fontFamily: family } } },
},
'light',
);
expect(resolved.appearance.displayFontFamily).toBe(family);
});
it('keeps an explicit display family and the bundled one for a theme that names neither', () => {
const explicit = resolveTheme(
{
version: 1,
name: 'display-reference',
modes: {
light: {
appearance: { fontFamily: 'Body, sans-serif', displayFontFamily: 'Head, serif' },
},
},
},
'light',
);
const bundled = resolveTheme({ version: 1, name: 'fontless-reference', modes: {} }, 'dark');
expect(explicit.appearance.displayFontFamily).toBe('Head, serif');
expect(bundled.appearance.displayFontFamily).toBe(defaultAppearance.fontFamily);
});
it('reproduces Tailwind’s own type scale by default', () => {
const tailwind = readFileSync(
join(__dirname, '..', '..', '..', '..', 'node_modules', 'tailwindcss', 'theme.css'),
'utf8',
);
const steps = [
['xs', 'textXs', 'leadingXs'],
['sm', 'textSm', 'leadingSm'],
['base', 'textBase', 'leadingBase'],
['lg', 'textLg', 'leadingLg'],
['xl', 'textXl', 'leadingXl'],
['2xl', 'text2xl', 'leading2xl'],
] as const;
const declared = (name: string) =>
new RegExp(`--${name}:\\s*([^;]+);`).exec(tailwind)?.[1].trim();
steps.forEach(([step, size, leading]) => {
expect(defaultAppearance[size]).toBe(declared(`text-${step}`));
expect(defaultAppearance[leading]).toBe(declared(`text-${step}--line-height`));
});
});
it('keeps every bundled theme’s largest themed step below the unthemed text-3xl', () => {
const rem = (value: string) => parseFloat(value);
[
defaultAppearance,
{ ...defaultAppearance, ...clickHouseTheme.modes.light?.appearance },
].forEach((appearance) => {
expect(rem(appearance.text2xl)).toBeLessThan(1.875);
});
});
it('accepts ratio and length line heights and rejects anything else', () => {
const withLeading = (leadingSm: string): ThemeDefinition => ({
version: 1,
name: 'leading-reference',
modes: { light: { appearance: { leadingSm } } },
});
expect(validateThemeDefinition(withLeading('1.5'))).toEqual([]);
expect(validateThemeDefinition(withLeading('calc(1.25 / 0.875)'))).toEqual([]);
expect(validateThemeDefinition(withLeading('1.25rem'))).toEqual([]);
expect(validateThemeDefinition(withLeading('calc(1 / 0)'))).toEqual([
'Invalid appearance value for leadingSm: calc(1 / 0)',
]);
expect(validateThemeDefinition(withLeading('normal; color: red'))).toEqual([
'Invalid appearance value for leadingSm: normal; color: red',
]);
});
it('draws the focus outline in the ring of a theme that predates the role', () => {
const resolved = resolveTheme(
{

View file

@ -139,6 +139,19 @@ export const themeAppearanceProperties: Readonly<
disabledStyle: '--theme-disabled-style',
fontFamily: '--theme-font-family',
monoFontFamily: '--theme-mono-font-family',
displayFontFamily: '--theme-display-font-family',
textXs: '--theme-text-xs',
textSm: '--theme-text-sm',
textBase: '--theme-text-base',
textLg: '--theme-text-lg',
textXl: '--theme-text-xl',
text2xl: '--theme-text-2xl',
leadingXs: '--theme-text-xs-leading',
leadingSm: '--theme-text-sm-leading',
leadingBase: '--theme-text-base-leading',
leadingLg: '--theme-text-lg-leading',
leadingXl: '--theme-text-xl-leading',
leading2xl: '--theme-text-2xl-leading',
elevationSurface: '--theme-elevation-surface',
shadow2xs: '--theme-shadow-2xs',
shadowXs: '--theme-shadow-xs',
@ -169,6 +182,19 @@ export const defaultAppearance: IThemeAppearance = Object.freeze({
fontFamily: 'Inter, sans-serif',
monoFontFamily:
"'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, 'Cascadia Mono', 'Liberation Mono', Consolas, monospace",
displayFontFamily: 'Inter, sans-serif',
textXs: '0.75rem',
textSm: '0.875rem',
textBase: '1rem',
textLg: '1.125rem',
textXl: '1.25rem',
text2xl: '1.5rem',
leadingXs: 'calc(1 / 0.75)',
leadingSm: 'calc(1.25 / 0.875)',
leadingBase: 'calc(1.5 / 1)',
leadingLg: 'calc(1.75 / 1.125)',
leadingXl: 'calc(1.75 / 1.25)',
leading2xl: 'calc(2 / 1.5)',
elevationSurface: '0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)',
shadow2xs: '0 1px rgb(0 0 0 / 0.05)',
shadowXs: '0 1px 2px 0 rgb(0 0 0 / 0.05)',
@ -314,6 +340,19 @@ function withComposableShadows(appearance: IThemeAppearance): IThemeAppearance {
);
}
/**
* Headings drew the UI family before the display role existed, so a theme that
* names its own `fontFamily` and no display family keeps its headings in it.
*/
function withDisplayFamily(appearance?: Partial<IThemeAppearance>): IThemeAppearance {
const known = knownAppearance(appearance);
const display =
known.displayFontFamily === undefined && known.fontFamily !== undefined
? { displayFontFamily: known.fontFamily }
: {};
return { ...defaultAppearance, ...known, ...display };
}
export function resolveTheme(theme: ThemeDefinition, mode: ThemeMode): ResolvedThemeDefinition {
const errors = validateThemeDefinition(theme);
if (errors.length > 0) {
@ -454,10 +493,7 @@ export function resolveTheme(theme: ThemeDefinition, mode: ThemeMode): ResolvedT
...seriesEightFallback,
...verifiedFallback,
} as Required<IThemeRGB>,
appearance: withComposableShadows({
...defaultAppearance,
...knownAppearance(definition?.appearance),
}),
appearance: withComposableShadows(withDisplayFamily(definition?.appearance)),
/** Mode last: a mode override is more specific than the theme-wide set. */
brands: {
...defaultBrands,

View file

@ -298,6 +298,13 @@ export const clickHouseDarkTheme: IThemeRGB = {
* (latin 400 and 700). The tail is the same metric-matched stack the default theme uses (Click
* UI's own tail names `"SFMono Regular"`, which no platform installs).
*
* Click UI's display family leads with Basier Square, a commercial face ClickHouse licenses for
* its own sites. It is named here but not self-hosted: a browser that has it installed renders
* headings in it, and every other one falls through to the same Inter stack as the body. The
* `text-*` scale takes Click UI's `font.sizes` 1 to 5 at its product line height of 1.5. Click UI
* has no step between 1.25rem and 2rem, and 2rem would overtake Tailwind's unthemed `text-3xl`
* (1.875rem), so `2xl` keeps LibreChat's 1.5rem at Click UI's line height.
*
* Click UI raises every elevated surface (card, dialog, menu, panel, popover, toast) with
* `shadow.1`, and its only lighter step is the hairline `shadow.5`. Steps 2 to 4 are the flyout's
* inset and directional edges, which do not belong on a general scale. `shadow.1` darkens from
@ -319,6 +326,20 @@ const clickHouseShape = {
'"Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif',
monoFontFamily:
'"Inconsolata", ui-monospace, SFMono-Regular, Menlo, "Cascadia Mono", "Liberation Mono", Consolas, monospace',
displayFontFamily:
'\'Basier Square\', "Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif', // typography.font.families.display
textXs: '0.75rem', // typography.font.sizes.1
textSm: '0.875rem', // typography.font.sizes.2
textBase: '1rem', // typography.font.sizes.3
textLg: '1.125rem', // typography.font.sizes.4
textXl: '1.25rem', // typography.font.sizes.5
text2xl: '1.5rem', // LibreChat's: Click UI's next step (sizes.6, 2rem) passes the unthemed text-3xl
leadingXs: '1.5', // typography.font.line-height.1
leadingSm: '1.5', // typography.font.line-height.1
leadingBase: '1.5', // typography.font.line-height.1
leadingLg: '1.5', // typography.font.line-height.1
leadingXl: '1.5', // typography.font.line-height.1
leading2xl: '1.5', // typography.font.line-height.1
shadow2xs: '0 2px 2px 0 rgb(0 0 0 / 0.03)', // shadow.5
shadowXs: '0 2px 2px 0 rgb(0 0 0 / 0.03)', // shadow.5
shadowSm: '0 2px 2px 0 rgb(0 0 0 / 0.03)', // shadow.5

View file

@ -75,8 +75,15 @@
"shadow.5": "0 2px 2px 0 rgba(0, 0, 0, 0.03)",
"transition.duration.medium": "100ms",
"transition.duration.smooth": "150ms",
"typography.font.families.display": "'Basier Square', \"Inter\", \"SF Pro Display\", -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Oxygen, Ubuntu, Cantarell, \"Open Sans\", \"Helvetica Neue\", sans-serif;",
"typography.font.families.mono": "\"Inconsolata\", Consolas, \"SFMono Regular\", monospace",
"typography.font.families.regular": "\"Inter\", \"SF Pro Display\", -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Oxygen, Ubuntu, Cantarell, \"Open Sans\", \"Helvetica Neue\", sans-serif;"
"typography.font.families.regular": "\"Inter\", \"SF Pro Display\", -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Oxygen, Ubuntu, Cantarell, \"Open Sans\", \"Helvetica Neue\", sans-serif;",
"typography.font.line-height.1": 1.5,
"typography.font.sizes.1": "0.75rem",
"typography.font.sizes.2": "0.875rem",
"typography.font.sizes.3": "1rem",
"typography.font.sizes.4": "1.125rem",
"typography.font.sizes.5": "1.25rem"
},
"dark": {
"border.radii.1": "0.25rem",
@ -150,7 +157,14 @@
"shadow.5": "0 2px 2px 0 rgba(0, 0, 0, 0.03)",
"transition.duration.medium": "100ms",
"transition.duration.smooth": "150ms",
"typography.font.families.display": "'Basier Square', \"Inter\", \"SF Pro Display\", -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Oxygen, Ubuntu, Cantarell, \"Open Sans\", \"Helvetica Neue\", sans-serif;",
"typography.font.families.mono": "\"Inconsolata\", Consolas, \"SFMono Regular\", monospace",
"typography.font.families.regular": "\"Inter\", \"SF Pro Display\", -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Oxygen, Ubuntu, Cantarell, \"Open Sans\", \"Helvetica Neue\", sans-serif;"
"typography.font.families.regular": "\"Inter\", \"SF Pro Display\", -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Oxygen, Ubuntu, Cantarell, \"Open Sans\", \"Helvetica Neue\", sans-serif;",
"typography.font.line-height.1": 1.5,
"typography.font.sizes.1": "0.75rem",
"typography.font.sizes.2": "0.875rem",
"typography.font.sizes.3": "1rem",
"typography.font.sizes.4": "1.125rem",
"typography.font.sizes.5": "1.25rem"
}
}

View file

@ -13,7 +13,8 @@ import snapshot from './clickui.json';
*/
type Rgba = [number, number, number, number];
type Snapshot = Record<ThemeMode, Record<string, string>>;
/** Click UI writes its line heights as bare numbers; every other token is a string. */
type Snapshot = Record<ThemeMode, Record<string, string | number>>;
const tokens: Snapshot = { light: snapshot.light, dark: snapshot.dark };
const modes: ThemeMode[] = ['light', 'dark'];
@ -243,6 +244,8 @@ const unsourcedColors: Record<ThemeMode, Partial<Record<keyof IThemeRGB, string>
*/
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)",
};
const appearanceSources: Partial<Record<keyof IThemeAppearance, string>> = {
@ -258,6 +261,18 @@ const appearanceSources: Partial<Record<keyof IThemeAppearance, string>> = {
roundControlRadius: 'border.radii.full',
fontFamily: 'typography.font.families.regular',
monoFontFamily: 'typography.font.families.mono',
displayFontFamily: 'typography.font.families.display',
textXs: 'typography.font.sizes.1',
textSm: 'typography.font.sizes.2',
textBase: 'typography.font.sizes.3',
textLg: 'typography.font.sizes.4',
textXl: 'typography.font.sizes.5',
leadingXs: 'typography.font.line-height.1',
leadingSm: 'typography.font.line-height.1',
leadingBase: 'typography.font.line-height.1',
leadingLg: 'typography.font.line-height.1',
leadingXl: 'typography.font.line-height.1',
leading2xl: 'typography.font.line-height.1',
shadow2xs: 'shadow.5',
shadowXs: 'shadow.5',
shadowSm: 'shadow.5',
@ -329,7 +344,8 @@ const normalizeShadow = (value: string) =>
const firstFamily = (value: string) => value.split(',')[0].trim();
/** How a Click UI appearance token compares with the theme value that cites it. */
function comparable(key: keyof IThemeAppearance, value: string): string {
function comparable(key: keyof IThemeAppearance, raw: string | number): string {
const value = String(raw);
if (key.startsWith('shadow') || key === 'elevationSurface') {
return normalizeShadow(value);
}
@ -371,7 +387,7 @@ describe('ClickHouse theme drift against Click UI', () => {
return [`${key}: Click UI token ${token} is not in clickui.json`];
}
const theme = colors[key as keyof IThemeRGB] ?? '';
return sameRgb(theme, parseColor(source))
return sameRgb(theme, parseColor(String(source)))
? []
: [`${key}: theme ${theme}, Click UI ${token} is ${source}`];
});

View file

@ -122,6 +122,14 @@
--color-switch-unchecked: rgb(var(--switch-unchecked));
}
/* The display family the shared dialog titles compose as `font-display`. A
* theme definition paints `--theme-display-font-family`; without one a title
* keeps the family it inherits, so a consumer that never sets the role sees no
* change. */
@theme inline {
--font-display: var(--theme-display-font-family, inherit);
}
/* A theme whose `disabledStyle` is `fill` paints a disabled control in the
* disabled roles instead of fading it; `ThemeProvider` mirrors that choice as
* `data-theme-disabled` on the root. The default `dim` style keeps the

View file

@ -407,6 +407,21 @@ export interface IThemeAppearance {
disabledStyle: 'dim' | 'fill';
fontFamily: string;
monoFontFamily: string;
/** Headings and dialog titles; follows `fontFamily` when a theme omits it. */
displayFontFamily: string;
/** The `text-*` scale: size and line height per step, Tailwind's own values by default. */
textXs: string;
textSm: string;
textBase: string;
textLg: string;
textXl: string;
text2xl: string;
leadingXs: string;
leadingSm: string;
leadingBase: string;
leadingLg: string;
leadingXl: string;
leading2xl: string;
elevationSurface: string;
shadow2xs: string;
shadowXs: string;

View file

@ -142,6 +142,8 @@ const cssLengthPattern = /^(0|\d*\.?\d+(px|rem|em))$/;
const cssLengthDifferencePattern =
/^calc\(\s*\d*\.?\d+(px|rem|em)\s+[-+]\s+\d*\.?\d+(px|rem|em)\s*\)$/;
const cssDurationPattern = /^\d*\.?\d+(ms|s)$/;
/** A unitless ratio, written bare or as one `calc()` quotient the way Tailwind's scale is. */
const cssLineHeightPattern = /^(\d*\.?\d+|calc\(\s*\d*\.?\d+\s*\/\s*\d*\.?\d+\s*\))$/;
const hexColorPattern = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
const shadowLengthPattern = /^(-?(0|\d*\.?\d+[a-z]+)|(calc|min|max|clamp)\(.*\))$/i;
const shadowColorPattern = /^(#[0-9a-f]{3,8}|[a-z]+|[a-z-]+\(.*\))$/i;
@ -244,6 +246,18 @@ const isShadow = (value: unknown): value is string => {
}
return globalThis.CSS?.supports?.('box-shadow', value) ?? true;
};
/** A ratio whose `calc()` divides by zero is dropped by the browser, so it is rejected here. */
const isLineHeight = (value: unknown): value is string => {
if (typeof value !== 'string') {
return false;
}
const match = cssLineHeightPattern.exec(value.trim());
if (!match) {
return isLength(value);
}
const divisor = /\/\s*(\d*\.?\d+)\s*\)$/.exec(match[0]);
return divisor === null || Number(divisor[1]) > 0;
};
const isDuration = (value: unknown): value is string =>
typeof value === 'string' && cssDurationPattern.test(value);
@ -277,6 +291,19 @@ const appearanceValidators = {
disabledStyle: (value: unknown) => value === 'dim' || value === 'fill',
fontFamily: isFontFamily,
monoFontFamily: isFontFamily,
displayFontFamily: isFontFamily,
textXs: isLength,
textSm: isLength,
textBase: isLength,
textLg: isLength,
textXl: isLength,
text2xl: isLength,
leadingXs: isLineHeight,
leadingSm: isLineHeight,
leadingBase: isLineHeight,
leadingLg: isLineHeight,
leadingXl: isLineHeight,
leading2xl: isLineHeight,
/** Released themes may hold `var()` here, so this role keeps its original, looser check. */
elevationSurface: (value: unknown) =>
typeof value === 'string' && value.trim().length > 0 && !/[;{}]|url\s*\(/i.test(value),