mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 13:00:55 +00:00
🧩 refactor: Ship Icon Sizes, Status Type and the Label Sweep From @librechat/client (#17800)
* refactor: Ship Icon Sizes, Status Type and the Label Sweep From @librechat/client * test: Prove a Consumer Gets the Shared Part Classes From the Published Stylesheet * test: Stop Asserting the Blockified Display of the Elapsed Reading * fix: End the Status Row Type Chain in a Length for Standalone Consumers
This commit is contained in:
parent
061b666f43
commit
1308ee005b
5 changed files with 236 additions and 98 deletions
|
|
@ -140,9 +140,6 @@ html {
|
|||
html.high-contrast {
|
||||
/* A 0.5rem bar is a small target to hit and a thin thing to see. */
|
||||
--scrollbar-size: 0.75rem;
|
||||
/* Keep both animated text stops at the AAA ratios declared by the palette. */
|
||||
--shimmer-base-alpha: 1;
|
||||
--shimmer-dip-alpha: 1;
|
||||
}
|
||||
html.high-contrast ::-webkit-scrollbar-thumb {
|
||||
/* The 10%-alpha thumb is invisible against a pure black or white canvas. */
|
||||
|
|
@ -288,36 +285,6 @@ html.high-contrast.dark .btn-neutral:hover {
|
|||
background-color: rgb(var(--surface-hover));
|
||||
}
|
||||
|
||||
.icon-sm {
|
||||
stroke-width: 2;
|
||||
height: 1rem;
|
||||
width: 1rem;
|
||||
}
|
||||
.icon-md,
|
||||
.icon-md-heavy {
|
||||
stroke-width: 1.5;
|
||||
height: 1.125rem;
|
||||
width: 1.125rem;
|
||||
}
|
||||
.icon-md-heavy {
|
||||
stroke-width: 2.5;
|
||||
}
|
||||
.icon-lg {
|
||||
stroke-width: 1.5;
|
||||
height: 1.5rem;
|
||||
width: 1.5rem;
|
||||
}
|
||||
.icon-xl {
|
||||
stroke-width: 1.5;
|
||||
height: 1.75rem;
|
||||
width: 1.75rem;
|
||||
}
|
||||
.icon-2xl {
|
||||
stroke-width: 1.5;
|
||||
height: 2rem;
|
||||
width: 2rem;
|
||||
}
|
||||
|
||||
/* Forced-colors overrides the `background-color: currentColor` a masked CustomIcon
|
||||
* paints with. */
|
||||
@media (forced-colors: active) {
|
||||
|
|
@ -1898,11 +1865,6 @@ html {
|
|||
font-size: var(--markdown-font-size, var(--font-size-base));
|
||||
}
|
||||
|
||||
.tool-status-text {
|
||||
font-size: calc(0.9 * var(--markdown-font-size, var(--font-size-base)));
|
||||
line-height: calc(1.25 * 0.9 * var(--markdown-font-size, var(--font-size-base)));
|
||||
}
|
||||
|
||||
.tooltip {
|
||||
z-index: 150;
|
||||
cursor: pointer;
|
||||
|
|
@ -2450,66 +2412,6 @@ html[data-input-modality='keyboard']
|
|||
transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
|
||||
}
|
||||
|
||||
@keyframes shimmer {
|
||||
0% {
|
||||
background-position: 200% 0;
|
||||
}
|
||||
100% {
|
||||
background-position: -200% 0;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes shimmer-rtl {
|
||||
0% {
|
||||
background-position: -200% 0;
|
||||
}
|
||||
100% {
|
||||
background-position: 200% 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* The sweep every in-flight label shares: a running tool call, streaming
|
||||
reasoning, the elapsed timer. Painted from theme roles rather than fixed
|
||||
black/white keyed off `.dark`, so a stored or custom theme restates it the
|
||||
way it restates any other color. Unset, the base falls back to whatever
|
||||
`--text-primary` is in scope AT THE LABEL — resolving it in a `:root`
|
||||
declaration instead would freeze the default and ignore theme scopes applied
|
||||
further down. Dark declares a base outright: its established value is dimmer
|
||||
than that theme's text color rather than equal to it. */
|
||||
.shimmer {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
rgb(var(--shimmer-base, var(--text-primary)) / var(--shimmer-base-alpha, 1)) 25%,
|
||||
rgb(var(--shimmer-dip) / var(--shimmer-dip-alpha, 1)) 50%,
|
||||
rgb(var(--shimmer-base, var(--text-primary)) / var(--shimmer-base-alpha, 1)) 75%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
background-clip: text;
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
animation: shimmer 4s linear infinite;
|
||||
}
|
||||
|
||||
[dir='rtl'] .shimmer,
|
||||
.shimmer:dir(rtl) {
|
||||
animation-name: shimmer-rtl;
|
||||
}
|
||||
|
||||
/* Halting the animation alone is not a fallback: the background would settle
|
||||
at position 0 and show only half the sweep, stranding the tail of the label
|
||||
in the near-invisible dip. Drop the gradient and hand the glyphs back to the
|
||||
color they would have had. */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.shimmer,
|
||||
[dir='rtl'] .shimmer {
|
||||
background: none;
|
||||
animation: none;
|
||||
-webkit-text-fill-color: currentcolor;
|
||||
}
|
||||
}
|
||||
|
||||
.sharepoint-picker-bg {
|
||||
background-color: rgb(var(--surface-dialog));
|
||||
}
|
||||
|
|
|
|||
97
e2e/specs/mock/scenarios/shared-part-classes.spec.ts
Normal file
97
e2e/specs/mock/scenarios/shared-part-classes.spec.ts
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
import { expect, test } from '@playwright/test';
|
||||
import type { Page } from '@playwright/test';
|
||||
import {
|
||||
MOCK_ENDPOINTS,
|
||||
NEW_CHAT_PATH,
|
||||
messagesView,
|
||||
selectMockEndpoint,
|
||||
sendMessage,
|
||||
} from '../helpers';
|
||||
|
||||
/**
|
||||
* The icon sizes, the status row type and the label sweep ship in
|
||||
* `@librechat/client/style.css` so a package consumer gets them; the app must
|
||||
* read exactly as it did when they lived in its own stylesheet. A probe element
|
||||
* measures the classes that no route of the mock harness renders on demand.
|
||||
*/
|
||||
|
||||
const probe = (page: Page, className: string) =>
|
||||
page.evaluate((name) => {
|
||||
const element = document.createElement('span');
|
||||
element.className = name;
|
||||
document.body.append(element);
|
||||
const { width, height, strokeWidth, fontSize, lineHeight } = getComputedStyle(element);
|
||||
const root = getComputedStyle(document.documentElement);
|
||||
const base = root.getPropertyValue('--markdown-font-size').trim();
|
||||
element.style.fontSize = base || 'var(--font-size-base)';
|
||||
const baseSize = parseFloat(getComputedStyle(element).fontSize);
|
||||
element.remove();
|
||||
return { width, height, strokeWidth, fontSize, lineHeight, baseSize };
|
||||
}, className);
|
||||
|
||||
const elapsedReading = (page: Page) => messagesView(page).getByTestId('stream-elapsed');
|
||||
|
||||
const readSweep = (page: Page) =>
|
||||
elapsedReading(page).evaluate((element) => {
|
||||
const style = getComputedStyle(element);
|
||||
return {
|
||||
animationName: style.animationName,
|
||||
backgroundClip: style.backgroundClip,
|
||||
dipAlpha: style.getPropertyValue('--shimmer-dip-alpha').trim(),
|
||||
};
|
||||
});
|
||||
|
||||
test.describe('shared part classes', () => {
|
||||
test('icon sizes and status row type read as they did from the app stylesheet @scenario:shared-part-classes-keep-their-sizes', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(NEW_CHAT_PATH, { timeout: 10_000 });
|
||||
await expect(page.locator('html')).toBeVisible();
|
||||
|
||||
const sizes: Array<[string, string, string]> = [
|
||||
['icon-sm', '16px', '2px'],
|
||||
['icon-md', '18px', '1.5px'],
|
||||
['icon-md-heavy', '18px', '2.5px'],
|
||||
['icon-lg', '24px', '1.5px'],
|
||||
['icon-xl', '28px', '1.5px'],
|
||||
['icon-2xl', '32px', '1.5px'],
|
||||
];
|
||||
for (const [name, size, stroke] of sizes) {
|
||||
const measured = await probe(page, name);
|
||||
expect(measured.width, name).toBe(size);
|
||||
expect(measured.height, name).toBe(size);
|
||||
expect(measured.strokeWidth, name).toBe(stroke);
|
||||
}
|
||||
|
||||
const status = await probe(page, 'tool-status-text');
|
||||
expect(parseFloat(status.fontSize)).toBeCloseTo(0.9 * status.baseSize, 1);
|
||||
expect(parseFloat(status.lineHeight)).toBeCloseTo(1.25 * 0.9 * status.baseSize, 1);
|
||||
});
|
||||
|
||||
test('an in-flight label sweeps, and high contrast holds both stops opaque @scenario:in-flight-label-keeps-its-sweep', async ({
|
||||
page,
|
||||
}) => {
|
||||
test.setTimeout(120_000);
|
||||
const label = `shared-part-classes-${Date.now()}`;
|
||||
|
||||
await page.goto(NEW_CHAT_PATH, { timeout: 10_000 });
|
||||
await selectMockEndpoint(page, MOCK_ENDPOINTS[0]);
|
||||
|
||||
const run = await sendMessage(page, `E2E_SLOW_REPLY:${label}`);
|
||||
expect(run.ok()).toBeTruthy();
|
||||
await expect(elapsedReading(page)).toBeVisible({ timeout: 15_000 });
|
||||
|
||||
const sweep = await readSweep(page);
|
||||
expect(sweep.animationName).toBe('shimmer');
|
||||
expect(sweep.backgroundClip).toBe('text');
|
||||
expect(Number(sweep.dipAlpha)).toBeLessThan(1);
|
||||
|
||||
await page.emulateMedia({ contrast: 'more' });
|
||||
await expect(page.locator('html.high-contrast')).toHaveCount(1, { timeout: 5_000 });
|
||||
await expect.poll(async () => (await readSweep(page)).dipAlpha).toBe('1');
|
||||
await page.emulateMedia({ contrast: null });
|
||||
|
||||
await page.emulateMedia({ reducedMotion: 'reduce' });
|
||||
await expect.poll(async () => (await readSweep(page)).animationName).toBe('none');
|
||||
});
|
||||
});
|
||||
|
|
@ -13,6 +13,9 @@ import {
|
|||
MessageRow,
|
||||
MentionPopover,
|
||||
ChatScreen,
|
||||
RemoveFile,
|
||||
ElapsedTimer,
|
||||
SystemEventHeader,
|
||||
HoverButtons,
|
||||
MessagesView,
|
||||
ComposerField,
|
||||
|
|
@ -694,6 +697,9 @@ describe('a consumer rendering subagent activity', () => {
|
|||
});
|
||||
|
||||
describe('a consumer styled by the published stylesheet alone', () => {
|
||||
const i18n = createInstance();
|
||||
void i18n.use(initReactI18next).init({ lng: 'en', resources: { en: { translation: {} } } });
|
||||
|
||||
/** What `@librechat/client/style.css` declares for an element's own classes. jsdom cannot load
|
||||
* the whole file (`@layer`, `:dir()`), so the rendered class list is matched by hand. */
|
||||
const stylesheet = readFileSync(require.resolve('@librechat/client/style.css'), 'utf8');
|
||||
|
|
@ -719,4 +725,31 @@ describe('a consumer styled by the published stylesheet alone', () => {
|
|||
/** Neither custom property is defined by the published theme, so each chain ends in a length. */
|
||||
expect(rule.match(/var\(--font-size-base, 1rem\)/g)).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('sizes icons, sets the status row type and sweeps in-flight labels', () => {
|
||||
render(
|
||||
<I18nextProvider i18n={i18n}>
|
||||
<SystemEventHeader icon={null} label="Woke up" />
|
||||
<ElapsedTimer start={Date.now()} />
|
||||
<RemoveFile onRemove={() => undefined} label="Remove report.pdf" />
|
||||
</I18nextProvider>,
|
||||
);
|
||||
|
||||
expect(declaredFor(screen.getByText('Woke up'))).toMatch(
|
||||
/font-size:[^;]*--markdown-font-size[^;]*;\s*line-height:[^;]*--markdown-font-size/,
|
||||
);
|
||||
/** Neither custom property is defined by the published theme, so each chain ends in a length. */
|
||||
const statusRule = declaredFor(screen.getByText('Woke up'));
|
||||
expect(statusRule.match(/var\(--font-size-base, 1rem\)/g)).toHaveLength(2);
|
||||
|
||||
expect(declaredFor(screen.getByTestId('stream-elapsed'))).toMatch(/animation:[^;]*\bshimmer\b/);
|
||||
expect(stylesheet).toMatch(/@keyframes shimmer\s*\{/);
|
||||
expect(stylesheet).toMatch(/@keyframes shimmer-rtl\s*\{/);
|
||||
expect(stylesheet).toMatch(/html\.high-contrast\s*\{[^}]*--shimmer-dip-alpha: 1/);
|
||||
|
||||
const icon = screen.getByRole('button', { name: 'Remove report.pdf' }).querySelector('svg');
|
||||
const iconRule = declaredFor(icon as SVGElement);
|
||||
expect(iconRule).toContain('width: 1rem');
|
||||
expect(iconRule).toContain('height: 1rem');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -95,3 +95,9 @@ html.high-contrast ::placeholder {
|
|||
color: rgb(var(--text-secondary));
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/** Keep both animated text stops of `.shimmer` at the AAA ratios declared by the palette. */
|
||||
html.high-contrast {
|
||||
--shimmer-base-alpha: 1;
|
||||
--shimmer-dip-alpha: 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,103 @@
|
|||
/**
|
||||
* Icon sizes, status row type and the in-flight label sweep that `@librechat/client` and
|
||||
* `@librechat/chat` components render. They ship here rather than in the SPA's stylesheet so a
|
||||
* consumer that imports only `@librechat/client/style.css` gets the sizes and motion the app shows.
|
||||
*/
|
||||
.icon-sm {
|
||||
stroke-width: 2;
|
||||
height: 1rem;
|
||||
width: 1rem;
|
||||
}
|
||||
.icon-md,
|
||||
.icon-md-heavy {
|
||||
stroke-width: 1.5;
|
||||
height: 1.125rem;
|
||||
width: 1.125rem;
|
||||
}
|
||||
.icon-md-heavy {
|
||||
stroke-width: 2.5;
|
||||
}
|
||||
.icon-lg {
|
||||
stroke-width: 1.5;
|
||||
height: 1.5rem;
|
||||
width: 1.5rem;
|
||||
}
|
||||
.icon-xl {
|
||||
stroke-width: 1.5;
|
||||
height: 1.75rem;
|
||||
width: 1.75rem;
|
||||
}
|
||||
.icon-2xl {
|
||||
stroke-width: 1.5;
|
||||
height: 2rem;
|
||||
width: 2rem;
|
||||
}
|
||||
|
||||
.tool-status-text {
|
||||
font-size: calc(0.9 * var(--markdown-font-size, var(--font-size-base, 1rem)));
|
||||
line-height: calc(1.25 * 0.9 * var(--markdown-font-size, var(--font-size-base, 1rem)));
|
||||
}
|
||||
|
||||
@keyframes shimmer {
|
||||
0% {
|
||||
background-position: 200% 0;
|
||||
}
|
||||
100% {
|
||||
background-position: -200% 0;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes shimmer-rtl {
|
||||
0% {
|
||||
background-position: -200% 0;
|
||||
}
|
||||
100% {
|
||||
background-position: 200% 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* The sweep every in-flight label shares: a running tool call, streaming
|
||||
reasoning, the elapsed timer. Painted from theme roles rather than fixed
|
||||
black/white keyed off `.dark`, so a stored or custom theme restates it the
|
||||
way it restates any other color. Unset, the base falls back to whatever
|
||||
`--text-primary` is in scope AT THE LABEL; resolving it in a `:root`
|
||||
declaration instead would freeze the default and ignore theme scopes applied
|
||||
further down. Dark declares a base outright: its established value is dimmer
|
||||
than that theme's text color rather than equal to it. */
|
||||
.shimmer {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
rgb(var(--shimmer-base, var(--text-primary)) / var(--shimmer-base-alpha, 1)) 25%,
|
||||
rgb(var(--shimmer-dip) / var(--shimmer-dip-alpha, 1)) 50%,
|
||||
rgb(var(--shimmer-base, var(--text-primary)) / var(--shimmer-base-alpha, 1)) 75%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
background-clip: text;
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
animation: shimmer 4s linear infinite;
|
||||
}
|
||||
|
||||
[dir='rtl'] .shimmer,
|
||||
.shimmer:dir(rtl) {
|
||||
animation-name: shimmer-rtl;
|
||||
}
|
||||
|
||||
/* Halting the animation alone is not a fallback: the background would settle
|
||||
at position 0 and show only half the sweep, stranding the tail of the label
|
||||
in the near-invisible dip. Drop the gradient and hand the glyphs back to the
|
||||
color they would have had. */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.shimmer,
|
||||
[dir='rtl'] .shimmer {
|
||||
background: none;
|
||||
animation: none;
|
||||
-webkit-text-fill-color: currentcolor;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Type scale of the tool and status rows `@librechat/chat` renders. The label
|
||||
* follows the chat font setting (`--markdown-font-size`) at nine tenths, the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue