LibreChat/packages/data-provider/specs/theme.spec.ts
Marco Beretta 687f69e187
🫗 feat: Field Fill and Ink Theme Roles (#16607)
* feat: Field fill and ink theme roles

Fields ink their value in a new field-text role, which follows text-primary, and a theme whose fieldFillStyle appearance role is fill paints them in a new field-fill role, which follows surface-primary. The default transparent style keeps every field clear, read from the nearest themed root through a style-query variant. The ClickHouse theme fills and inks fields with Click UI's field tokens, which empties the not-expressible list.

* fix: Ink the TimePicker value in the field role and type the field colors

* fix: Keep field ink and state fills over the field fill

Field-variant Dropdown triggers no longer swap to the primary ink on hover, and the field fill variant carries a single class's weight so hover, open and disabled fills paint over it.

* test: Count the field roles beside the media overlay roles

* fix: Type the color fallbacks as one object and keep a disabled field's fill under the pointer

resolveTheme spread about twenty fallbacks typed as role-or-empty unions; each union spread doubled the type checker's work, and the field roles pushed the client typecheck past the CI heap. Typing them as IThemeRGB drops its memory from 3.3GB to 0.65GB. A fill theme with the default dim disabled style also keeps a disabled field's fill under the pointer.
2026-10-01 23:14:37 +02:00

88 lines
3.1 KiB
TypeScript

import { collectThemeIssues } from '../src/theme';
import { deploymentThemeSchema } from '../src/config';
/** A deployment theme as `librechat.yaml` delivers it, with appearance only in the given modes. */
const definition = (modes: Record<string, Record<string, string>>) => ({
version: 1,
name: 'mode-shadow-reference',
modes: Object.fromEntries(
Object.entries(modes).map(([mode, appearance]) => [mode, { appearance }]),
),
});
const messages = (theme: unknown) => collectThemeIssues(theme).map(({ message }) => message);
describe('menu and tooltip shadow roles in a theme definition', () => {
it('accepts a different shadow per mode, `none` included', () => {
const theme = definition({
light: { menuShadow: '0 4px 6px -1px rgb(21 21 21 / 0.15)', tooltipShadow: 'none' },
dark: {
menuShadow: '0 4px 6px -1px rgb(21 21 21 / 0.6), 0 2px 4px -1px rgb(21 21 21 / 0.6)',
tooltipShadow: '0 1px 2px 0 rgb(0 0 0 / 0.35)',
},
});
expect(deploymentThemeSchema.safeParse(theme).success).toBe(true);
expect(messages(theme)).toEqual([]);
});
it('accepts a shadow named in one mode only, leaving the other to its default', () => {
const theme = definition({ dark: { tooltipShadow: 'none' } });
expect(deploymentThemeSchema.safeParse(theme).success).toBe(true);
expect(messages(theme)).toEqual([]);
});
it.each([
['menuShadow', 'var(--theme-shadow-lg)'],
['menuShadow', '0 4px; color: red'],
['menuShadow', 'big'],
['tooltipShadow', '0 1px 2px 0 rgb(0 0 0 / 0.35),'],
['tooltipShadow', 'url(x.png)'],
])('rejects %s %s in either mode', (role, value) => {
for (const mode of ['light', 'dark']) {
expect(messages(definition({ [mode]: { [role]: value } }))).toEqual([
`Invalid appearance value for ${role}: ${value}`,
]);
}
});
});
describe('field fill roles in a theme definition', () => {
const theme = {
version: 1,
name: 'field-fill-reference',
modes: {
light: {
colors: { 'rgb-field-fill': '251 252 255', 'rgb-field-text': '48 46 50' },
appearance: { fieldFillStyle: 'fill' },
},
dark: { appearance: { fieldFillStyle: 'transparent' } },
},
};
it('accepts the fill style and opaque field colors', () => {
expect(deploymentThemeSchema.safeParse(theme).success).toBe(true);
expect(messages(theme)).toEqual([]);
});
it('rejects an unknown fill style and a translucent field color', () => {
const glass = { ...theme, modes: { light: { appearance: { fieldFillStyle: 'glass' } } } };
expect(messages(glass)).toEqual(['Invalid appearance value for fieldFillStyle: glass']);
const translucent = {
...theme,
modes: { light: { colors: { 'rgb-field-fill': '1 2 3 / 0.5' } } },
};
expect(deploymentThemeSchema.safeParse(translucent).success).toBe(false);
expect(messages(translucent)).toHaveLength(1);
});
it('keeps a definition that names a color token this reader does not know', () => {
const newer = {
...theme,
modes: { light: { colors: { 'rgb-field-fill': '251 252 255', 'rgb-field-hover': '1 2 3' } } },
};
expect(messages(newer)).toEqual([]);
});
});