🏷️ refactor: Paint the Provider Badge Over Media Through a Theme Role (#17681)

* test: Verify the Provider Badge Keeps Its Translucent Page Tone

* feat: Paint the Provider Badge Over Media With a Surface Media Chip Role
This commit is contained in:
Marco Beretta 2026-10-31 22:48:10 +01:00 • committed by GitHub
parent 919bf99143
commit fec19ca3f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 109 additions and 3 deletions

View file

@ -224,7 +224,7 @@ describe('theme cache storage', () => {
* - definitions with one or both mode blocks absent.
* A new role, or a new fallback, joins by construction.
*/
const PIN = { fingerprint: '1.5.1ln9dy9', digest: '1ohs8yp' };
const PIN = { fingerprint: '1.5.11s6b78', digest: '1xfmtot' };
const digestOf = (text: string): string => {
let hash = 5381;

View file

@ -0,0 +1,85 @@
import { expect, test } from '@playwright/test';
import { FileSources } from 'librechat-data-provider';
import type { TFile } from 'librechat-data-provider';
import type { Page } from '@playwright/test';
/**
* The provider badge pinned over an uploaded image in My Files: the page's own tone, translucent,
* so the provider mark reads on any image. White at 75% in light and black at 65% in dark, the
* look it has always had. The account menu sits behind the mobile drawer on a phone-width
* viewport, so this scenario uses a desktop viewport.
*/
test.use({ viewport: { width: 1280, height: 800 }, deviceScaleFactor: 3 });
const IMAGE_PATH = '/images/e2e-source-chip.svg';
/** Bright, saturated stripes, so the badge's translucency shows in the screenshot. */
const STRIPES = `<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40">
<rect width="40" height="40" fill="#e4572e"/>
<path d="M0 40 40 0M-10 30 30-10M10 50 50 10" stroke="#29335c" stroke-width="6"/>
</svg>`;
const file: TFile = {
file_id: 'e2e-source-chip',
filename: 'Provider upload.svg',
filepath: IMAGE_PATH,
user: 'source-chip-user',
bytes: STRIPES.length,
object: 'file',
source: FileSources.openai,
type: 'image/svg+xml',
usage: 0,
embedded: false,
createdAt: '2026-10-31T00:00:00.000Z',
updatedAt: '2026-10-31T00:00:00.000Z',
};
/** The RGBA a colour paints, whatever syntax the browser serialises it in. */
const painted = (page: Page, color: string): Promise<number[]> =>
page.evaluate((value) => {
const canvas = document.createElement('canvas');
canvas.width = 1;
canvas.height = 1;
const context = canvas.getContext('2d');
if (!context) {
return [];
}
context.fillStyle = value;
context.fillRect(0, 0, 1, 1);
return Array.from(context.getImageData(0, 0, 1, 1).data);
}, color);
test('the provider badge over an uploaded image keeps its translucent page tone @scenario:source-badge-keeps-its-tone', async ({
page,
}, testInfo) => {
await page.route('**/api/files', (route) => route.fulfill({ json: [file] }));
await page.route(`**${IMAGE_PATH}`, (route) =>
route.fulfill({ contentType: 'image/svg+xml', body: STRIPES }),
);
const imageServed = page.waitForResponse((response) => response.url().endsWith(IMAGE_PATH));
await page.goto('/c/new', { timeout: 15_000 });
await page.getByTestId('nav-user').click();
await page.getByRole('menu').getByRole('menuitem', { name: 'My Files', exact: true }).click();
const dialog = page.getByRole('dialog', { name: 'My Files', exact: true });
const row = dialog.getByRole('row').filter({ hasText: file.filename });
await expect(row).toBeVisible({ timeout: 15_000 });
await imageServed;
const badge = row.locator('button div.rounded-full');
await expect(badge).toBeVisible();
const dark = await page.evaluate(() => document.documentElement.classList.contains('dark'));
const background = await badge.evaluate((element) => getComputedStyle(element).backgroundColor);
const [red, green, blue, alpha] = await painted(page, background);
const expected = dark
? [0, 0, 0, Math.round(0.65 * 255)]
: [255, 255, 255, Math.round(0.75 * 255)];
expect([red, green, blue]).toEqual(expected.slice(0, 3));
expect(Math.abs(alpha - expected[3])).toBeLessThanOrEqual(1);
const cell = row.getByRole('cell').filter({ hasText: file.filename });
await testInfo.attach(`source-badge-${dark ? 'dark' : 'light'}`, {
body: await cell.screenshot(),
contentType: 'image/png',
});
});

View file

@ -11,7 +11,7 @@ const sourceToEndpoint = (): Partial<Record<string, EModelEndpoint>> => ({
});
const sourceToClassname = (): Partial<Record<string, string>> => ({
[FileSources.openai]: 'bg-white/75 dark:bg-black/65',
[FileSources.openai]: 'bg-surface-media-chip',
[FileSources.azure]: 'azure-bg-color',
[FileSources.azure_blob]: 'azure-bg-color',
[FileSources.execute_code]: 'bg-surface-media-overlay text-text-on-media opacity-85',

View file

@ -316,6 +316,7 @@ function MyComponent() {
- `bg-surface-dialog` - Dialog/modal background
- `bg-surface-overlay` - Dialog/modal scrim, adapted per theme
- `bg-surface-media-overlay` - Scrim, chip or progress drawn over the user's own media (lightbox, image preview, upload); `text-text-on-media` is its ink. Black and white in every bundled theme, since they frame the image rather than the page
- `bg-surface-media-chip` - A source badge pinned over the user's media: the page tone, translucent (white at 75% in light, black at 65% in dark by default; the opacity is the `--surface-media-chip-alpha` property)
- `bg-surface-chat` - Chat interface background
- `bg-surface-code` - Code block chrome: toolbar, output and result switcher
- `bg-surface-code-body` - Code block pane behind the highlighted code

View file

@ -147,6 +147,8 @@ html {
--surface-overlay: var(--gray-500);
--surface-media-overlay: 0 0 0;
--text-on-media: var(--white);
--surface-media-chip: var(--white);
--surface-media-chip-alpha: 0.75;
--surface-submit: var(--green-700);
--surface-submit-hover: var(--green-800);
--surface-destructive: var(--red-700);
@ -458,6 +460,8 @@ html {
--surface-overlay: 0 0 0;
--surface-media-overlay: 0 0 0;
--text-on-media: var(--white);
--surface-media-chip: 0 0 0;
--surface-media-chip-alpha: 0.65;
--surface-submit: var(--green-700);
--surface-submit-hover: var(--green-800);
--surface-destructive: var(--red-800);

View file

@ -68,7 +68,7 @@ describe.each([
const tokens = Object.keys(theme) as Array<keyof IThemeRGB>;
it('covers every registry color', () => {
expect(tokens).toHaveLength(169);
expect(tokens).toHaveLength(170);
});
it('resolves every registry color to the runtime theme value', () => {

View file

@ -81,6 +81,7 @@ export const clickHouseLightTheme: IThemeRGB = {
'rgb-surface-overlay': '21 21 21', // #151515 (dialog.color.opaqueBackground, lch(6.7738 0 none))
'rgb-surface-media-overlay': '0 0 0', // #000000 (Click UI has no media scrim; the image frame stays black)
'rgb-text-on-media': '255 255 255', // #ffffff (palette.neutral.0)
'rgb-surface-media-chip': '255 255 255', // #ffffff (Click UI has no media chip; the stock white, at 0.75 alpha)
'rgb-surface-submit': '21 21 21', // #151515 (accent.default)
'rgb-surface-submit-hover': '50 50 50', // #323232 (palette.neutral.712)
'rgb-surface-destructive': '193 0 0', // #c10000 (palette.danger.600)
@ -280,6 +281,7 @@ export const clickHouseDarkTheme: IThemeRGB = {
'rgb-surface-overlay': '96 96 96', // #606060 (dialog.color.opaqueBackground, lch(40.731 0 none), drawn at the 0.75 scrimOpacity)
'rgb-surface-media-overlay': '0 0 0', // #000000 (Click UI has no media scrim; the image frame stays black)
'rgb-text-on-media': '255 255 255', // #ffffff (palette.neutral.0)
'rgb-surface-media-chip': '0 0 0', // #000000 (Click UI has no media chip; the stock black, at 0.65 alpha)
'rgb-surface-submit': '250 255 105', // #faff69 (accent.default)
'rgb-surface-submit-hover': '253 255 163', // #fdffa3 (palette.brand.200)
'rgb-surface-destructive': '255 117 117', // #ff7575 (palette.danger.300)

View file

@ -392,6 +392,8 @@ const colorSources: Record<ThemeMode, Partial<Record<keyof IThemeRGB, string>>>
/** Values the theme sets on purpose without a Click UI source, and why. */
const MEDIA_OVERLAY_REASON =
'Click UI has no media scrim; the image frame stays black in both modes';
const MEDIA_CHIP_REASON =
'Click UI has no source badge over media; the theme keeps the stock white and black chip';
const STYLESHEET_ROLE_REASON =
'Click UI has no scrollbar, secondary button fill or toast edge; the theme keeps the stock role';
const STROKE_INK_REASON =
@ -399,6 +401,7 @@ const STROKE_INK_REASON =
const STYLESHEET_ROLES: Partial<Record<keyof IThemeRGB, string>> = {
'rgb-surface-media-overlay': MEDIA_OVERLAY_REASON,
'rgb-surface-media-chip': MEDIA_CHIP_REASON,
'rgb-scrollbar-thumb': STYLESHEET_ROLE_REASON,
'rgb-button-neutral-hover': STYLESHEET_ROLE_REASON,
'rgb-toast-edge': STYLESHEET_ROLE_REASON,

View file

@ -77,6 +77,7 @@
--color-surface-overlay: rgb(var(--surface-overlay));
--color-surface-media-overlay: rgb(var(--surface-media-overlay));
--color-text-on-media: rgb(var(--text-on-media));
--color-surface-media-chip: rgb(var(--surface-media-chip) / var(--surface-media-chip-alpha, 1));
/* The dialog scrims: the overlay at the opacity each dialog family's appearance
* role sets (OGDialog, AlertDialog, Dialog), defaulting to the 80%, 90% and 65%
* the families have always drawn. */

View file

@ -56,6 +56,7 @@ export const themeColorTokens = Object.freeze([
'rgb-surface-overlay',
'rgb-surface-media-overlay',
'rgb-text-on-media',
'rgb-surface-media-chip',
'rgb-surface-submit',
'rgb-surface-submit-hover',
'rgb-surface-destructive',

View file

@ -56,6 +56,7 @@ export const darkTheme: IThemeRGB = {
'rgb-surface-overlay': '0 0 0', // #000 (black)
'rgb-surface-media-overlay': '0 0 0', // #000 (black, over the user's media in both modes)
'rgb-text-on-media': '255 255 255', // #fff (white)
'rgb-surface-media-chip': '0 0 0', // #000 (black), carried at 0.65 alpha
'rgb-surface-submit': '4 120 87', // #047857 (green-700)
'rgb-surface-submit-hover': '6 95 70', // #065f46 (green-800)
'rgb-surface-destructive': '153 27 27', // #991b1b (red-800)

View file

@ -56,6 +56,7 @@ export const defaultTheme: IThemeRGB = {
'rgb-surface-overlay': '89 89 89', // #595959 (gray-500)
'rgb-surface-media-overlay': '0 0 0', // #000 (black, over the user's media in both modes)
'rgb-text-on-media': '255 255 255', // #fff (white)
'rgb-surface-media-chip': '255 255 255', // #fff (white), carried at 0.75 alpha
'rgb-surface-submit': '4 120 87', // #047857 (green-700)
'rgb-surface-submit-hover': '6 95 70', // #065f46 (green-800)
'rgb-surface-destructive': '185 28 28', // #b91c1c (red-700)

View file

@ -92,6 +92,7 @@ export const highContrastLightTheme: IThemeRGB = {
'rgb-surface-overlay': '0 0 0', // #000000
'rgb-surface-media-overlay': '0 0 0', // #000000
'rgb-text-on-media': '255 255 255', // #ffffff
'rgb-surface-media-chip': '255 255 255', // #ffffff, carried at 0.75 alpha
'rgb-surface-submit': '0 92 46', // #005c2e
'rgb-surface-submit-hover': '0 61 30', // #003d1e
'rgb-surface-destructive': '161 0 0', // #a10000
@ -310,6 +311,7 @@ export const highContrastDarkTheme: IThemeRGB = {
'rgb-surface-overlay': '0 0 0', // #000000
'rgb-surface-media-overlay': '0 0 0', // #000000
'rgb-text-on-media': '255 255 255', // #ffffff
'rgb-surface-media-chip': '0 0 0', // #000000, carried at 0.65 alpha
'rgb-surface-submit': '127 240 179', // #7ff0b3
'rgb-surface-submit-hover': '163 245 204', // #a3f5cc
'rgb-surface-destructive': '255 143 143', // #ff8f8f

View file

@ -68,6 +68,9 @@ export interface IThemeRGB {
* than the page, so every bundled theme keeps them black and white in both modes. */
'rgb-surface-media-overlay'?: string;
'rgb-text-on-media'?: string;
/** A source badge pinned over the user's media: the page's own tone, translucent, so the
* provider mark reads on any image. Its opacity stays in CSS as `--surface-media-chip-alpha`. */
'rgb-surface-media-chip'?: string;
'rgb-surface-submit'?: string;
'rgb-surface-submit-hover'?: string;
'rgb-surface-destructive'?: string;
@ -326,6 +329,7 @@ export interface IThemeVariables {
'--surface-overlay': string;
'--surface-media-overlay': string;
'--text-on-media': string;
'--surface-media-chip': string;
'--surface-submit': string;
'--surface-submit-hover': string;
'--surface-destructive': string;
@ -507,6 +511,7 @@ export interface IThemeColors {
'surface-overlay'?: string;
'surface-media-overlay'?: string;
'text-on-media'?: string;
'surface-media-chip'?: string;
'surface-submit'?: string;
'surface-submit-hover'?: string;
'surface-destructive'?: string;