mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 13:00:55 +00:00
📏 feat: Give Theme-Sized Controls Their Own Padding and Gap Roles (#16528)
* 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
This commit is contained in:
parent
4062bc3c00
commit
bdfd3012ea
27 changed files with 314 additions and 37 deletions
|
|
@ -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',
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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', () => {
|
||||
|
|
|
|||
131
e2e/specs/mock/scenarios/control-spacing.spec.ts
Normal file
131
e2e/specs/mock/scenarios/control-spacing.spec.ts
Normal file
|
|
@ -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<Locator> {
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
|
@ -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(
|
||||
<Button size="icon-theme" shape="round" aria-label="Scroll to bottom">
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ const buttonVariantRecipe = cva(
|
|||
* line up with them.
|
||||
*/
|
||||
'icon-theme': 'size-theme-control p-0',
|
||||
theme: 'h-theme-control gap-theme-compact px-theme-normal',
|
||||
theme: 'h-theme-control gap-theme-control-gap px-theme-control-x',
|
||||
/** The padding of a list row that is itself the click target. */
|
||||
row: 'h-auto gap-3 px-3.5 py-3',
|
||||
/** The padding of a tile that reserves a corner for an overflow menu. */
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ describe('CheckboxButton', () => {
|
|||
'h-theme-control',
|
||||
'w-theme-control',
|
||||
'rounded-theme-control-round',
|
||||
'gap-theme-compact',
|
||||
'gap-theme-control-gap',
|
||||
'p-theme-compact',
|
||||
'md:px-theme-normal',
|
||||
'md:px-theme-control-x',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ const CheckboxButton: React.ForwardRefExoticComponent<
|
|||
onChange={onChange}
|
||||
className={cn(
|
||||
composerControlClasses(),
|
||||
'w-theme-control max-w-fit p-theme-compact md:w-full md:px-theme-normal',
|
||||
'w-theme-control p-theme-compact md:px-theme-control-x max-w-fit md:w-full',
|
||||
|
||||
// Checked state styling
|
||||
isChecked && isCheckedClassName && isCheckedClassName,
|
||||
|
|
|
|||
|
|
@ -50,7 +50,8 @@ describe('Chip', () => {
|
|||
expect(screen.getByText('Themeable').parentElement).toHaveClass(
|
||||
'h-theme-control',
|
||||
'rounded-theme-control',
|
||||
'gap-theme-compact',
|
||||
'gap-theme-control-gap',
|
||||
'px-theme-control-x',
|
||||
);
|
||||
expect(screen.getByRole('button', { name: 'Remove theme' })).toHaveClass(
|
||||
'rounded-theme-control-round',
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ const chipVariants: (props?: ChipVariantProps & ClassProp) => string = cva(
|
|||
size: {
|
||||
sm: 'min-h-6 px-2 py-0.5',
|
||||
md: 'min-h-8 px-2.5 py-1',
|
||||
theme: 'h-theme-control gap-theme-compact px-theme-normal',
|
||||
theme: 'h-theme-control gap-theme-control-gap px-theme-control-x',
|
||||
},
|
||||
shape: {
|
||||
round: 'rounded-full',
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ v4 loads no config file on its own, so without the directive the preset, the `co
|
|||
and class-based dark mode are all silently absent.
|
||||
|
||||
The published preset supplies the semantic appearance utilities used by theme-aware component
|
||||
variants, including `h-theme-control`, `rounded-theme-control`, `gap-theme-compact`, and
|
||||
variants, including `h-theme-control`, `rounded-theme-control`, `px-theme-control-x`, `gap-theme-control-gap`, and
|
||||
`duration-theme-fast`. Keep the preset enabled even when defining additional project utilities.
|
||||
|
||||
The published stylesheet and preset preserve the host's standard Tailwind color palettes.
|
||||
|
|
|
|||
|
|
@ -197,6 +197,8 @@ html {
|
|||
--theme-radius-2xl: 1rem;
|
||||
--theme-radius-3xl: 1.5rem;
|
||||
--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-switch-width: 2.75rem;
|
||||
--theme-switch-height: 1.5rem;
|
||||
--theme-table-cell-space-y: 1rem;
|
||||
|
|
|
|||
|
|
@ -77,12 +77,21 @@ describe.each([
|
|||
});
|
||||
});
|
||||
|
||||
/** Control roles split out of the shared spacing alias it, so a stylesheet that sets only the
|
||||
* shared role still spaces its controls. */
|
||||
const stockAliases: Partial<
|
||||
Record<keyof typeof defaultAppearance, keyof typeof defaultAppearance>
|
||||
> = { controlPaddingX: 'spaceNormal', controlGap: 'spaceCompact' };
|
||||
|
||||
describe('the stock appearance and brands', () => {
|
||||
it('declares every appearance property with the registry default', () => {
|
||||
Object.entries(themeAppearanceProperties).forEach(([key, property]) => {
|
||||
const role = key as keyof typeof defaultAppearance;
|
||||
const value = defaultAppearance[role].replace(/\s+/g, ' ');
|
||||
const source = stockAliases[role];
|
||||
expect([property, light.get(property)]).toEqual([
|
||||
property,
|
||||
defaultAppearance[key as keyof typeof defaultAppearance].replace(/\s+/g, ' '),
|
||||
source ? `var(${themeAppearanceProperties[source]}, ${value})` : value,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -591,6 +591,52 @@ describe('theme registry', () => {
|
|||
expect(bundled.appearance.displayFontFamily).toBe(defaultAppearance.fontFamily);
|
||||
});
|
||||
|
||||
it('pads theme-sized controls with the shared spacing by default', () => {
|
||||
expect(defaultAppearance.controlPaddingX).toBe(defaultAppearance.spaceNormal);
|
||||
expect(defaultAppearance.controlGap).toBe(defaultAppearance.spaceCompact);
|
||||
});
|
||||
|
||||
it('keeps the controls of a theme that names only the shared spacing on it', () => {
|
||||
const { appearance } = resolveTheme(compactTheme, 'light');
|
||||
|
||||
expect(appearance).toMatchObject({ controlPaddingX: '0.5rem', controlGap: '0.25rem' });
|
||||
});
|
||||
|
||||
it('spaces controls apart from message rows when a theme names the control roles', () => {
|
||||
const { appearance } = resolveTheme(
|
||||
{
|
||||
version: 1,
|
||||
name: 'roomy-controls-reference',
|
||||
modes: {
|
||||
light: {
|
||||
appearance: { spaceNormal: '0.5rem', controlPaddingX: '2rem', controlGap: '1rem' },
|
||||
},
|
||||
},
|
||||
},
|
||||
'light',
|
||||
);
|
||||
|
||||
expect(appearance).toMatchObject({
|
||||
spaceNormal: '0.5rem',
|
||||
spaceCompact: defaultAppearance.spaceCompact,
|
||||
controlPaddingX: '2rem',
|
||||
controlGap: '1rem',
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects a control spacing role that is not a length', () => {
|
||||
const issues = (appearance: Record<string, string>) =>
|
||||
validateThemeDefinition({
|
||||
version: 1,
|
||||
name: 'bad-controls',
|
||||
modes: { light: { appearance } },
|
||||
});
|
||||
|
||||
expect(issues({ controlPaddingX: '1rem', controlGap: 'calc(1rem - 2px)' })).toEqual([]);
|
||||
expect(issues({ controlPaddingX: '12' })).toHaveLength(1);
|
||||
expect(issues({ controlGap: '1rem; color: red' })).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('reproduces Tailwind’s own type scale by default', () => {
|
||||
const tailwind = readFileSync(
|
||||
join(__dirname, '..', '..', '..', '..', 'node_modules', 'tailwindcss', 'theme.css'),
|
||||
|
|
|
|||
|
|
@ -135,6 +135,8 @@ export const themeAppearanceProperties: Readonly<
|
|||
radius2xl: '--theme-radius-2xl',
|
||||
radius3xl: '--theme-radius-3xl',
|
||||
controlHeight: '--theme-control-height',
|
||||
controlPaddingX: '--theme-control-padding-x',
|
||||
controlGap: '--theme-control-gap',
|
||||
switchWidth: '--theme-switch-width',
|
||||
switchHeight: '--theme-switch-height',
|
||||
tableCellSpaceY: '--theme-table-cell-space-y',
|
||||
|
|
@ -184,6 +186,8 @@ export const defaultAppearance: IThemeAppearance = Object.freeze({
|
|||
radius2xl: '1rem',
|
||||
radius3xl: '1.5rem',
|
||||
controlHeight: '2.25rem',
|
||||
controlPaddingX: '0.75rem',
|
||||
controlGap: '0.375rem',
|
||||
...defaultSwitchSize,
|
||||
tableCellSpaceY: '1rem',
|
||||
tableRowStroke: '0px',
|
||||
|
|
@ -355,16 +359,24 @@ 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.
|
||||
* Roles split out of a broader one, each paired with the role it read before. Headings drew the UI
|
||||
* family before the display role existed, and theme-sized controls were padded by the shared
|
||||
* spacing, so a theme that names the broader role and not the split one keeps what it drew.
|
||||
*/
|
||||
function withDisplayFamily(appearance?: Partial<IThemeAppearance>): IThemeAppearance {
|
||||
const inheritedAppearance: ReadonlyArray<[keyof IThemeAppearance, keyof IThemeAppearance]> = [
|
||||
['displayFontFamily', 'fontFamily'],
|
||||
['controlPaddingX', 'spaceNormal'],
|
||||
['controlGap', 'spaceCompact'],
|
||||
];
|
||||
|
||||
function withInheritedRoles(appearance?: Partial<IThemeAppearance>): IThemeAppearance {
|
||||
const known = knownAppearance(appearance);
|
||||
const display =
|
||||
known.displayFontFamily === undefined && known.fontFamily !== undefined
|
||||
? { displayFontFamily: known.fontFamily }
|
||||
: {};
|
||||
return { ...defaultAppearance, ...known, ...display };
|
||||
const inherited = Object.fromEntries(
|
||||
inheritedAppearance
|
||||
.filter(([role, source]) => known[role] === undefined && known[source] !== undefined)
|
||||
.map(([role, source]) => [role, known[source]]),
|
||||
);
|
||||
return { ...defaultAppearance, ...known, ...inherited };
|
||||
}
|
||||
|
||||
export function resolveTheme(theme: ThemeDefinition, mode: ThemeMode): ResolvedThemeDefinition {
|
||||
|
|
@ -544,7 +556,7 @@ export function resolveTheme(theme: ThemeDefinition, mode: ThemeMode): ResolvedT
|
|||
...seriesEightFallback,
|
||||
...verifiedFallback,
|
||||
} as Required<IThemeRGB>,
|
||||
appearance: withComposableShadows(withDisplayFamily(definition?.appearance)),
|
||||
appearance: withComposableShadows(withInheritedRoles(definition?.appearance)),
|
||||
/** Mode last: a mode override is more specific than the theme-wide set. */
|
||||
brands: {
|
||||
...defaultBrands,
|
||||
|
|
|
|||
|
|
@ -144,7 +144,13 @@ describe('LibreChat Tailwind preset', () => {
|
|||
['duration-theme-normal', '--theme-motion-normal', defaultAppearance.motionNormal],
|
||||
];
|
||||
|
||||
const css = await generate([...roles.map(([candidate]) => candidate), 'font-sans', 'p-4']);
|
||||
const css = await generate([
|
||||
...roles.map(([candidate]) => candidate),
|
||||
'px-theme-control-x',
|
||||
'gap-theme-control-gap',
|
||||
'font-sans',
|
||||
'p-4',
|
||||
]);
|
||||
|
||||
roles.forEach(([candidate, property, fallback]) => {
|
||||
expect(css).toContain(`.${candidate}`);
|
||||
|
|
@ -157,6 +163,15 @@ describe('LibreChat Tailwind preset', () => {
|
|||
`max(var(--theme-control-height, ${defaultAppearance.controlHeight}), 2.75rem)`,
|
||||
);
|
||||
|
||||
/** A stylesheet that predates the control spacing roles pads controls with the shared
|
||||
* spacing they read before. */
|
||||
expect(rule(css, 'px-theme-control-x')).toContain(
|
||||
`padding-inline: var(--theme-control-padding-x, var(--theme-space-normal, ${defaultAppearance.spaceNormal}))`,
|
||||
);
|
||||
expect(rule(css, 'gap-theme-control-gap')).toContain(
|
||||
`gap: var(--theme-control-gap, var(--theme-space-compact, ${defaultAppearance.spaceCompact}))`,
|
||||
);
|
||||
|
||||
/** The preset extends the default theme rather than replacing it. */
|
||||
expect(css).toContain('.font-sans');
|
||||
expect(css).toContain('.p-4');
|
||||
|
|
@ -204,8 +219,13 @@ describe('LibreChat Tailwind preset', () => {
|
|||
|
||||
/** Prettier wraps a long font stack, so declarations compare with whitespace collapsed. */
|
||||
const collapsed = stockStyles.replace(/\s+/g, ' ');
|
||||
/** The control spacing roles alias the shared spacing they were split from. */
|
||||
const aliases = { controlPaddingX: 'spaceNormal', controlGap: 'spaceCompact' };
|
||||
Object.entries(themeAppearanceProperties).forEach(([key, property]) => {
|
||||
expect(collapsed).toContain(`${property}: ${defaultAppearance[key]};`);
|
||||
const value = aliases[key]
|
||||
? `var(${themeAppearanceProperties[aliases[key]]}, ${defaultAppearance[key]})`
|
||||
: defaultAppearance[key];
|
||||
expect(collapsed).toContain(`${property}: ${value};`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -359,6 +359,8 @@ describe('clickhouse theme definition', () => {
|
|||
'shadow2xl',
|
||||
'elevationSurface',
|
||||
'controlHeight',
|
||||
'controlPaddingX',
|
||||
'controlGap',
|
||||
'motionFast',
|
||||
] as const;
|
||||
expect(
|
||||
|
|
@ -366,12 +368,17 @@ describe('clickhouse theme definition', () => {
|
|||
).toEqual([]);
|
||||
});
|
||||
|
||||
/** Click UI's control height and `transition.default`. The spacing roles keep LibreChat's
|
||||
* values: they also pad message bubbles and the composer's send button, and 0.75rem is
|
||||
* already Click UI's field padding. */
|
||||
/** Click UI's control height, button padding and gap, and `transition.default`. The shared
|
||||
* spacing roles keep LibreChat's values: they also pad message bubbles and the composer's send
|
||||
* button, and 0.75rem is already Click UI's field padding. */
|
||||
it('sizes theme controls from Click UI and leaves the shared spacing alone', () => {
|
||||
const { appearance } = resolveTheme(clickHouseTheme, 'light');
|
||||
expect(appearance).toMatchObject({ controlHeight: '2rem', motionFast: '100ms' });
|
||||
expect(appearance).toMatchObject({
|
||||
controlHeight: '2rem',
|
||||
controlPaddingX: '1rem',
|
||||
controlGap: '0.5rem',
|
||||
motionFast: '100ms',
|
||||
});
|
||||
expect(appearance.spaceCompact).toBe(defaultAppearance.spaceCompact);
|
||||
expect(appearance.spaceNormal).toBe(defaultAppearance.spaceNormal);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -358,6 +358,8 @@ const clickHouseShape = {
|
|||
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
|
||||
controlHeight: '2rem', // genericMenu.panel.size.height
|
||||
controlPaddingX: '1rem', // button.basic.space.x
|
||||
controlGap: '0.5rem', // button.basic.space.gap
|
||||
scrimOpacity: '0.75', // dialog.color.opaqueBackground alpha
|
||||
alertScrimOpacity: '0.75', // dialog.color.opaqueBackground alpha
|
||||
modalScrimOpacity: '0.75', // dialog.color.opaqueBackground alpha
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
"click.button.basic.color.primary.background.disabled": "#dfdfdf",
|
||||
"click.button.basic.color.primary.text.default": "#ffffff",
|
||||
"click.button.basic.color.secondary.stroke.default": "#e6e7e9",
|
||||
"click.button.basic.space.gap": "0.5rem",
|
||||
"click.button.basic.space.x": "1rem",
|
||||
"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",
|
||||
|
|
@ -127,6 +129,8 @@
|
|||
"click.button.basic.color.primary.background.hover": "rgb(98.627% 100% 58.824%)",
|
||||
"click.button.basic.color.primary.text.default": "#1f1f1c",
|
||||
"click.button.basic.color.secondary.stroke.default": "#414141",
|
||||
"click.button.basic.space.gap": "0.5rem",
|
||||
"click.button.basic.space.x": "1rem",
|
||||
"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",
|
||||
|
|
|
|||
|
|
@ -314,6 +314,8 @@ const appearanceSources: Partial<Record<keyof IThemeAppearance, string>> = {
|
|||
shadow2xl: 'shadow.1',
|
||||
elevationSurface: 'shadow.1',
|
||||
controlHeight: 'click.genericMenu.panel.size.height',
|
||||
controlPaddingX: 'click.button.basic.space.x',
|
||||
controlGap: 'click.button.basic.space.gap',
|
||||
scrimOpacity: 'click.dialog.color.opaqueBackground.default',
|
||||
alertScrimOpacity: 'click.dialog.color.opaqueBackground.default',
|
||||
modalScrimOpacity: 'click.dialog.color.opaqueBackground.default',
|
||||
|
|
@ -448,7 +450,7 @@ function comparable(key: keyof IThemeAppearance, raw: string | number): string {
|
|||
* every decision; the floors below only move up.
|
||||
*/
|
||||
type ParityKind = 'color' | 'shape';
|
||||
type Utility = 'bg' | 'text' | 'border' | 'rounded' | 'w' | 'h' | 'py';
|
||||
type Utility = 'bg' | 'text' | 'border' | 'rounded' | 'w' | 'h' | 'py' | 'px' | 'gap';
|
||||
|
||||
interface ParityProbe {
|
||||
/** The Click UI component token the primitive should reproduce. */
|
||||
|
|
@ -523,6 +525,10 @@ const dropdownProbe = () =>
|
|||
const buttonProbe = (variant: 'default' | 'outline') => () =>
|
||||
mount(createElement(Button, { variant }, 'Save'), 'button');
|
||||
|
||||
/** A button on the theme's control metrics, the size that reads the control spacing roles. */
|
||||
const themeButtonProbe = () =>
|
||||
mount(createElement(Button, { size: 'theme', shape: 'theme' }, 'Save'), 'button');
|
||||
|
||||
const parityProbes: Record<string, ParityProbe> = {
|
||||
'Button primary fill': {
|
||||
token: 'click.button.basic.color.primary.background.default',
|
||||
|
|
@ -548,6 +554,18 @@ const parityProbes: Record<string, ParityProbe> = {
|
|||
utility: 'rounded',
|
||||
element: buttonProbe('default'),
|
||||
},
|
||||
'Button inline padding': {
|
||||
token: 'click.button.basic.space.x',
|
||||
kind: 'shape',
|
||||
utility: 'px',
|
||||
element: themeButtonProbe,
|
||||
},
|
||||
'Button gap': {
|
||||
token: 'click.button.basic.space.gap',
|
||||
kind: 'shape',
|
||||
utility: 'gap',
|
||||
element: themeButtonProbe,
|
||||
},
|
||||
'Field fill': {
|
||||
token: 'click.field.color.background.default',
|
||||
kind: 'color',
|
||||
|
|
@ -733,8 +751,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: 10 },
|
||||
dark: { color: 10, shape: 10 },
|
||||
light: { color: 9, shape: 12 },
|
||||
dark: { color: 10, shape: 12 },
|
||||
};
|
||||
|
||||
const radiusRoles: Record<string, keyof IThemeAppearance> = {
|
||||
|
|
@ -752,12 +770,14 @@ const radiusRoles: Record<string, keyof IThemeAppearance> = {
|
|||
|
||||
const fixedRadii: Record<string, string> = { full: '9999px', none: '0px' };
|
||||
|
||||
type SizeUtility = 'w' | 'h' | 'py';
|
||||
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' },
|
||||
py: { 'theme-table-cell': 'tableCellSpaceY' },
|
||||
px: { 'theme-control-x': 'controlPaddingX' },
|
||||
gap: { 'theme-control-gap': 'controlGap' },
|
||||
};
|
||||
|
||||
/** The compact and dense table sizes divide the cell space, as the preset does. */
|
||||
|
|
@ -766,8 +786,7 @@ const derivedSizes: Record<string, [keyof IThemeAppearance, number]> = {
|
|||
'theme-table-cell-dense': ['tableCellSpaceY', 4],
|
||||
};
|
||||
|
||||
const isSizeUtility = (utility: Utility): utility is SizeUtility =>
|
||||
utility === 'w' || utility === 'h' || utility === 'py';
|
||||
const isSizeUtility = (utility: Utility): utility is SizeUtility => utility in sizeRoles;
|
||||
|
||||
/** A `border`, `border-2` or one-sided `border-b` class, or a theme stroke role that is not
|
||||
* zero: the width a border color needs to show. */
|
||||
|
|
@ -781,7 +800,7 @@ const drawsBorder = (classes: string[], resolved: Resolved) =>
|
|||
|
||||
type Resolved = ReturnType<typeof resolveTheme>;
|
||||
|
||||
/** A `w-*`, `h-*` or `py-*` step: a theme role, or Tailwind's 0.25rem spacing scale. */
|
||||
/** A `w-*`, `h-*`, `py-*`, `px-*` or `gap-*` step: a theme role, or Tailwind's 0.25rem scale. */
|
||||
function sizeValue(utility: SizeUtility, name: string, resolved: Resolved): string | undefined {
|
||||
const role = sizeRoles[utility][name];
|
||||
if (role !== undefined) {
|
||||
|
|
|
|||
|
|
@ -422,6 +422,10 @@ export interface IThemeAppearance {
|
|||
radius2xl: string;
|
||||
radius3xl: string;
|
||||
controlHeight: string;
|
||||
/** A theme-sized control's inline padding and icon-to-label gap; they follow `spaceNormal` and
|
||||
* `spaceCompact` when a theme names those and not these. */
|
||||
controlPaddingX: string;
|
||||
controlGap: string;
|
||||
switchWidth: string;
|
||||
switchHeight: string;
|
||||
tableCellSpaceY: string;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ describe('composerControlClasses', () => {
|
|||
|
||||
expect(classes).toContain('h-theme-control');
|
||||
expect(classes).toContain('rounded-theme-control-round');
|
||||
expect(classes).toContain('gap-theme-compact');
|
||||
expect(classes).toContain('gap-theme-control-gap');
|
||||
});
|
||||
|
||||
it('draws its border and fills from semantic roles', () => {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ export const composerSubmitClasses = (): string =>
|
|||
*/
|
||||
export const composerControlClasses = (): string =>
|
||||
cn(
|
||||
'group relative inline-flex items-center justify-center gap-theme-compact',
|
||||
'group relative inline-flex items-center justify-center gap-theme-control-gap',
|
||||
'h-theme-control rounded-theme-control-round border border-border-medium',
|
||||
'bg-transparent text-sm font-medium text-text-primary transition-all',
|
||||
/** No elevation: a row of raised pills inside the composer competes with the
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ const twMerge = extendTailwindMerge({
|
|||
classGroups: {
|
||||
py: [{ py: ['theme-table-cell', 'theme-table-cell-compact', 'theme-table-cell-dense'] }],
|
||||
h: [{ h: ['theme-table-head', 'theme-table-head-compact'] }],
|
||||
px: [{ px: ['theme-control-x'] }],
|
||||
gap: [{ gap: ['theme-control-gap'] }],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -22,6 +22,10 @@ module.exports = {
|
|||
'theme-compact': 'var(--theme-space-compact, 0.375rem)',
|
||||
'theme-normal': 'var(--theme-space-normal, 0.75rem)',
|
||||
'theme-control': 'var(--theme-control-height, 2.25rem)',
|
||||
/** A theme-sized control's inline padding and gap, falling back to the shared spacing it
|
||||
* read before, for a stylesheet that predates the roles. */
|
||||
'theme-control-x': 'var(--theme-control-padding-x, var(--theme-space-normal, 0.75rem))',
|
||||
'theme-control-gap': 'var(--theme-control-gap, var(--theme-space-compact, 0.375rem))',
|
||||
/**
|
||||
* The comfortable tap target (2.75rem / 44px), held against the theme's
|
||||
* own control height with `max()` so a theme that already draws larger
|
||||
|
|
|
|||
|
|
@ -308,6 +308,10 @@ const appearanceValidators = {
|
|||
radius2xl: isLength,
|
||||
radius3xl: isLength,
|
||||
controlHeight: isLength,
|
||||
/** The inline padding and icon-to-label gap of a theme-sized control, apart from the shared
|
||||
* spacing that also pads message rows. */
|
||||
controlPaddingX: isLength,
|
||||
controlGap: isLength,
|
||||
switchWidth: isSwitchLength,
|
||||
switchHeight: isSwitchLength,
|
||||
tableCellSpaceY: isTableLength,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue