mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-21 07:23:11 +00:00
📐 feat: Let a Theme Reshape the Sign-In Field and Button (#16939)
* feat: Let a theme reshape the sign-in field and button The sign-in floating-label field, the submit button and their shared corner read the new authFieldHeight, authButtonHeight and authControlRadius appearance roles, whose defaults reproduce the 44px field, 48px button and 16px corner. The corner follows radius2xl when a theme names only that. The ClickHouse theme draws them at Click UI's single field and button size with the button's square corner. * fix: Size the sign-in button by its height role alone A fixed height with vertical padding left a short theme height less room than the label. Specs now expect the role classes on the sign-in field. * fix: Keep the reset label and password controls inside a themed field height The reset request label rests in the middle of the field instead of 12px from its top, and the password field's reveal and copy buttons size from the sign-in field height, 4px off its edges and never under 24px. Both keep their stock positions and sizes. * fix: Hold the password field controls inside the padding it reserves The reveal and copy buttons stop growing at the stock 2.25rem, so a taller sign-in field keeps them clear of the typed value. * feat: Let a theme reshape the second-factor and reset-success actions The 2FA verify and reset-success continue buttons read authActionHeight and authActionRadius, which follow the sign-in button's height and corner when a theme names those and otherwise the Button height and radiusLg they drew, so the stock screens are unchanged and ClickHouse draws them at 32px with its 4px corner. * test: Reach the second-factor screen through a pending sign-in * fix: Rest the reset label inside a minimum-height field and keep the action corner on radiusLg The reset request label rests from an inset that centers it 2px low as before but never past the field's bottom edge, and the other sign-in actions resolve their corner before the sign-in corner is derived from radius2xl, so a theme that names only radius2xl keeps radiusLg on them.
This commit is contained in:
parent
f698385777
commit
e7484a223b
26 changed files with 397 additions and 19 deletions
|
|
@ -182,7 +182,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.3.fgvuqz', digest: '16q8y55' };
|
||||
const PIN = { fingerprint: '1.3.yila83', digest: '1lhfc04' };
|
||||
|
||||
const digestOf = (text: string): string => {
|
||||
let hash = 5381;
|
||||
|
|
|
|||
|
|
@ -182,7 +182,8 @@ const LoginForm: React.FC<TLoginFormProps> = ({ onSubmit, startupConfig, error,
|
|||
disabled={(requireCaptcha && !turnstileToken) || isSubmitting}
|
||||
variant="submit"
|
||||
shape="soft"
|
||||
className="h-12 w-full"
|
||||
size="auth"
|
||||
className="w-full"
|
||||
>
|
||||
{isSubmitting ? <Spinner /> : localize('com_auth_continue')}
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -234,7 +234,8 @@ const Registration: React.FC = () => {
|
|||
aria-label="Submit registration"
|
||||
variant="submit"
|
||||
shape="soft"
|
||||
className="h-12 w-full"
|
||||
size="auth"
|
||||
className="w-full"
|
||||
>
|
||||
{isSubmitting ? <Spinner /> : localize('com_auth_continue')}
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ function RequestPasswordReset() {
|
|||
/>
|
||||
<label
|
||||
htmlFor="email"
|
||||
className="bg-surface-primary text-text-secondary peer-placeholder-shown:text-text-tertiary peer-focus:text-accent-primary absolute -top-2 left-2 z-10 px-2 text-sm transition-all peer-placeholder-shown:top-3 peer-placeholder-shown:text-base peer-focus:-top-2 peer-focus:text-sm"
|
||||
className="bg-surface-primary text-text-secondary peer-placeholder-shown:text-text-tertiary peer-focus:text-accent-primary peer-placeholder-shown:top-theme-auth-label-rest absolute -top-2 left-2 z-10 px-2 text-sm transition-all peer-placeholder-shown:text-base peer-focus:-top-2 peer-focus:text-sm"
|
||||
>
|
||||
{localize('com_auth_email_address')}
|
||||
</label>
|
||||
|
|
@ -129,7 +129,8 @@ function RequestPasswordReset() {
|
|||
disabled={!!errors.email || isLoading}
|
||||
variant="submit"
|
||||
shape="soft"
|
||||
className="h-12 w-full"
|
||||
size="auth"
|
||||
className="w-full"
|
||||
>
|
||||
{isLoading ? <Spinner /> : localize('com_auth_continue')}
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ function ResetPassword() {
|
|||
onClick={() => navigate('/login')}
|
||||
aria-label={localize('com_auth_sign_in')}
|
||||
variant="submit"
|
||||
size="auth-action"
|
||||
shape="auth-action"
|
||||
>
|
||||
{localize('com_auth_continue')}
|
||||
</Button>
|
||||
|
|
@ -139,7 +141,8 @@ function ResetPassword() {
|
|||
disabled={!!errors.password || !!errors.confirm_password || isSubmitting}
|
||||
variant="submit"
|
||||
shape="soft"
|
||||
className="h-12 w-full"
|
||||
size="auth"
|
||||
className="w-full"
|
||||
>
|
||||
{isSubmitting ? <Spinner /> : localize('com_auth_continue')}
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@ const TwoFactorScreen: React.FC = React.memo(() => {
|
|||
data-testid="login-button"
|
||||
disabled={isLoading}
|
||||
shape="soft"
|
||||
size="auth-action"
|
||||
className="w-full disabled:opacity-80"
|
||||
>
|
||||
{isLoading ? localize('com_auth_email_verifying_ellipsis') : localize('com_ui_verify')}
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ test('renders login form', () => {
|
|||
setError={jest.fn()}
|
||||
/>,
|
||||
);
|
||||
expect(getByLabelText(/email/i)).toHaveClass('h-auto');
|
||||
expect(getByLabelText(/email/i)).toHaveClass('h-theme-auth-field');
|
||||
expect(getByLabelText(/password/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ jest.mock('react-router-dom', () => ({
|
|||
test('renders registration form', () => {
|
||||
const { getByText, getByTestId, getByRole } = setup();
|
||||
expect(getByText(/Create your account/i)).toBeInTheDocument();
|
||||
expect(getByRole('textbox', { name: /Full name/i })).toHaveClass('h-auto');
|
||||
expect(getByRole('textbox', { name: /Full name/i })).toHaveClass('h-theme-auth-field');
|
||||
expect(getByRole('form', { name: /Registration form/i })).toBeVisible();
|
||||
expect(getByRole('textbox', { name: /Username/i })).toBeInTheDocument();
|
||||
expect(getByRole('textbox', { name: /Email/i })).toBeInTheDocument();
|
||||
|
|
|
|||
211
e2e/specs/mock/scenarios/auth-control-shape.spec.ts
Normal file
211
e2e/specs/mock/scenarios/auth-control-shape.spec.ts
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
import { expect, test } from '@playwright/test';
|
||||
import type { Locator, Page } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* The sign-in form's floating-label field and submit button take their height and corner from
|
||||
* the `authFieldHeight`, `authButtonHeight` and `authControlRadius` appearance roles. The stock
|
||||
* theme keeps the 44px field, the 48px button and the 16px corner they always drew; a theme
|
||||
* served through `interface.theme` reshapes all three without touching the form.
|
||||
*/
|
||||
|
||||
test.use({ storageState: { cookies: [], origins: [] } });
|
||||
|
||||
const REFERENCE_THEME = {
|
||||
version: 1,
|
||||
name: 'auth-shape-reference',
|
||||
modes: {
|
||||
light: {
|
||||
appearance: { authFieldHeight: '3.5rem', authButtonHeight: '2.5rem', authControlRadius: '0' },
|
||||
},
|
||||
dark: {
|
||||
appearance: { authFieldHeight: '3.5rem', authButtonHeight: '2.5rem', authControlRadius: '0' },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/** The smallest sign-in field a theme may draw. */
|
||||
const MINIMUM_FIELD_THEME = {
|
||||
version: 1,
|
||||
name: 'auth-shape-minimum',
|
||||
modes: {
|
||||
light: { appearance: { authFieldHeight: '24px' } },
|
||||
dark: { appearance: { authFieldHeight: '24px' } },
|
||||
},
|
||||
};
|
||||
|
||||
async function serveTheme(page: Page, theme: string | Record<string, unknown>) {
|
||||
await page.route(
|
||||
(url) => url.pathname === '/api/config',
|
||||
async (route) => {
|
||||
const response = await route.fetch();
|
||||
const body = await response.json();
|
||||
await route.fulfill({ response, json: { ...body, interface: { ...body.interface, theme } } });
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
async function openLogin(page: Page) {
|
||||
await page.goto('/login');
|
||||
await expect(page.getByTestId('login-button')).toBeVisible({ timeout: 20000 });
|
||||
}
|
||||
|
||||
async function shapeOf(locator: Locator) {
|
||||
return locator.evaluate((element) => {
|
||||
const style = getComputedStyle(element);
|
||||
return {
|
||||
height: element.getBoundingClientRect().height,
|
||||
radius: style.borderTopLeftRadius,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/** The typed value has to fit inside the field at any height, so nothing clips it. */
|
||||
async function expectValueFits(field: Locator) {
|
||||
await field.fill('someone@example.com');
|
||||
const fits = await field.evaluate((element) => {
|
||||
const input = element as HTMLInputElement;
|
||||
return input.scrollHeight <= input.clientHeight;
|
||||
});
|
||||
expect(fits).toBe(true);
|
||||
}
|
||||
|
||||
async function expectShape(
|
||||
page: Page,
|
||||
expected: { field: number; button: number; radius: string },
|
||||
) {
|
||||
const field = page.getByLabel('Email');
|
||||
const password = page.getByLabel('Password');
|
||||
const button = page.getByTestId('login-button');
|
||||
expect(await shapeOf(field)).toEqual({ height: expected.field, radius: expected.radius });
|
||||
expect(await shapeOf(password)).toEqual({ height: expected.field, radius: expected.radius });
|
||||
expect(await shapeOf(button)).toEqual({ height: expected.button, radius: expected.radius });
|
||||
const reveal = page.getByRole('button', { name: /show/i });
|
||||
await expectWithin(reveal, password);
|
||||
await expectClearOfValue(reveal, password);
|
||||
await expectValueFits(field);
|
||||
}
|
||||
|
||||
/** A control drawn inside a field, or a label resting in it, stays inside the field's box. */
|
||||
async function expectWithin(inner: Locator, outer: Locator) {
|
||||
const [box, frame] = await Promise.all([inner.boundingBox(), outer.boundingBox()]);
|
||||
expect(box).not.toBeNull();
|
||||
expect(frame).not.toBeNull();
|
||||
if (!box || !frame) {
|
||||
return;
|
||||
}
|
||||
expect(box.y).toBeGreaterThanOrEqual(frame.y);
|
||||
expect(box.y + box.height).toBeLessThanOrEqual(frame.y + frame.height);
|
||||
expect(box.height).toBeGreaterThanOrEqual(24);
|
||||
}
|
||||
|
||||
/** The reveal button stays clear of the typed value, inside the end padding the field reserves. */
|
||||
async function expectClearOfValue(control: Locator, field: Locator) {
|
||||
const [box, frame, padding] = await Promise.all([
|
||||
control.boundingBox(),
|
||||
field.boundingBox(),
|
||||
field.evaluate((element) => parseFloat(getComputedStyle(element).paddingRight)),
|
||||
]);
|
||||
if (!box || !frame) {
|
||||
throw new Error('The password field or its reveal button has no box');
|
||||
}
|
||||
expect(box.x).toBeGreaterThanOrEqual(frame.x + frame.width - padding);
|
||||
}
|
||||
|
||||
/** The reset request form's resting label sits in the middle of the field at any height. */
|
||||
async function expectResetLabelCentered(page: Page) {
|
||||
await page.goto('/forgot-password');
|
||||
const field = page.getByRole('textbox', { name: /email/i });
|
||||
await expect(field).toBeVisible({ timeout: 20000 });
|
||||
const label = page.locator('label[for="email"]');
|
||||
await expectWithin(label, field);
|
||||
const [box, frame] = await Promise.all([label.boundingBox(), field.boundingBox()]);
|
||||
if (!box || !frame) {
|
||||
throw new Error('The reset request field or its label has no box');
|
||||
}
|
||||
const offset = box.y + box.height / 2 - (frame.y + frame.height / 2);
|
||||
expect(Math.abs(offset)).toBeLessThanOrEqual(2);
|
||||
}
|
||||
|
||||
/** The second-factor verify button, on the screen a sign-in that needs one lands on; the sign-in
|
||||
* itself is answered here with a pending second factor. */
|
||||
async function twoFactorShape(page: Page) {
|
||||
await page.route(
|
||||
(url) => url.pathname === '/api/auth/login',
|
||||
(route) => route.fulfill({ status: 200, json: { twoFAPending: true, tempToken: 'e2e-shape' } }),
|
||||
);
|
||||
await openLogin(page);
|
||||
await page.getByLabel('Email').fill('someone@example.com');
|
||||
await page.getByLabel('Password').fill('a-password-1');
|
||||
await page.getByTestId('login-button').click();
|
||||
await page.waitForURL(/\/login\/2fa/, { timeout: 20000 });
|
||||
const verify = page.getByRole('button', { name: 'Verify' });
|
||||
await expect(verify).toBeVisible({ timeout: 20000 });
|
||||
return shapeOf(verify);
|
||||
}
|
||||
|
||||
/** The continue button a successful reset shows; the reset request itself is answered here. */
|
||||
async function resetSuccessShape(page: Page) {
|
||||
await page.route(
|
||||
(url) => url.pathname === '/api/auth/resetPassword',
|
||||
(route) => route.fulfill({ status: 200, json: { message: 'Password reset' } }),
|
||||
);
|
||||
await page.goto('/reset-password?token=e2e-shape&userId=e2e-shape');
|
||||
await page.locator('#password').fill('a-new-password-1');
|
||||
await page.locator('#confirm_password').fill('a-new-password-1');
|
||||
await page.locator('#confirm_password').press('Enter');
|
||||
const proceed = page.getByRole('button', { name: 'Sign in' });
|
||||
await expect(proceed).toBeVisible({ timeout: 20000 });
|
||||
return shapeOf(proceed);
|
||||
}
|
||||
|
||||
test.describe('sign-in control shape roles', () => {
|
||||
test('the stock theme keeps the sign-in field, button and corner it always drew @scenario:sign-in-controls-keep-default-shape', async ({
|
||||
page,
|
||||
}) => {
|
||||
await openLogin(page);
|
||||
await expectShape(page, { field: 44, button: 48, radius: '16px' });
|
||||
await expectResetLabelCentered(page);
|
||||
});
|
||||
|
||||
test('the ClickHouse theme draws the sign-in controls at its own height and corner @scenario:clickhouse-reshapes-sign-in-controls', async ({
|
||||
page,
|
||||
}) => {
|
||||
await serveTheme(page, 'clickhouse');
|
||||
await openLogin(page);
|
||||
await expect(page.locator('html')).toHaveAttribute('data-theme', 'clickhouse');
|
||||
await expectShape(page, { field: 32, button: 32, radius: '4px' });
|
||||
await expectResetLabelCentered(page);
|
||||
});
|
||||
|
||||
test('a theme that names the sign-in roles reshapes the controls without touching the form @scenario:theme-reshapes-sign-in-controls', async ({
|
||||
page,
|
||||
}) => {
|
||||
await serveTheme(page, REFERENCE_THEME);
|
||||
await openLogin(page);
|
||||
await expect(page.locator('html')).toHaveAttribute('data-theme', REFERENCE_THEME.name);
|
||||
await expectShape(page, { field: 56, button: 40, radius: '0px' });
|
||||
await expectResetLabelCentered(page);
|
||||
|
||||
await serveTheme(page, MINIMUM_FIELD_THEME);
|
||||
await expectResetLabelCentered(page);
|
||||
});
|
||||
|
||||
test('the stock theme keeps the second-factor and reset-success actions at the size they drew @scenario:auth-actions-keep-default-shape', async ({
|
||||
page,
|
||||
}) => {
|
||||
expect(await twoFactorShape(page)).toEqual({ height: 40, radius: '16px' });
|
||||
expect(await resetSuccessShape(page)).toEqual({ height: 40, radius: '8px' });
|
||||
});
|
||||
|
||||
test('a theme that reshapes the sign-in button reshapes the second-factor and reset-success actions @scenario:theme-reshapes-auth-actions', async ({
|
||||
page,
|
||||
}) => {
|
||||
await serveTheme(page, 'clickhouse');
|
||||
expect(await twoFactorShape(page)).toEqual({ height: 32, radius: '4px' });
|
||||
expect(await resetSuccessShape(page)).toEqual({ height: 32, radius: '4px' });
|
||||
|
||||
await serveTheme(page, REFERENCE_THEME);
|
||||
expect(await twoFactorShape(page)).toEqual({ height: 40, radius: '0px' });
|
||||
expect(await resetSuccessShape(page)).toEqual({ height: 40, radius: '0px' });
|
||||
});
|
||||
});
|
||||
|
|
@ -425,7 +425,12 @@ describe('Button', () => {
|
|||
});
|
||||
|
||||
it('offers the sign-in sizes, shape and link variants as roles rather than caller classes', () => {
|
||||
expect(cn(buttonVariants({ shape: 'soft' }))).toContain('rounded-2xl');
|
||||
expect(cn(buttonVariants({ shape: 'soft' }))).toContain('rounded-theme-auth-control');
|
||||
expect(cn(buttonVariants({ shape: 'soft' }))).not.toContain('rounded-lg');
|
||||
expect(cn(buttonVariants({ size: 'auth' }))).toContain('h-theme-auth-button');
|
||||
expect(cn(buttonVariants({ size: 'auth-action' }))).toContain('h-theme-auth-action');
|
||||
expect(cn(buttonVariants({ shape: 'auth-action' }))).toContain('rounded-theme-auth-action');
|
||||
expect(cn(buttonVariants({ shape: 'auth-action' }))).not.toContain('rounded-lg');
|
||||
expect(cn(buttonVariants({ size: 'snug' }))).toContain('p-1');
|
||||
expect(cn(buttonVariants({ size: 'wide' }))).toContain('px-8');
|
||||
expect(cn(buttonVariants({ size: 'bare' }))).toContain('p-0');
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ type ButtonVariantOptions =
|
|||
| 'xs'
|
||||
| 'sm'
|
||||
| 'lg'
|
||||
| 'auth'
|
||||
| 'auth-action'
|
||||
| 'wide'
|
||||
| 'snug'
|
||||
| 'bare'
|
||||
|
|
@ -59,7 +61,7 @@ type ButtonVariantOptions =
|
|||
| 'tile'
|
||||
| null
|
||||
| undefined;
|
||||
shape?: 'default' | 'soft' | 'theme' | 'round' | null | undefined;
|
||||
shape?: 'default' | 'soft' | 'auth-action' | 'theme' | 'round' | null | undefined;
|
||||
} & ClassProp)
|
||||
| undefined;
|
||||
|
||||
|
|
@ -239,6 +241,10 @@ const buttonVariantRecipe = cva(
|
|||
xs: 'h-theme-button-xs rounded-md px-2.5 text-xs',
|
||||
sm: 'h-theme-button-sm rounded-lg px-3',
|
||||
lg: 'h-theme-button-lg rounded-lg px-8',
|
||||
/** The height of a sign-in form's submit button, the `authButtonHeight` role. */
|
||||
auth: 'h-theme-auth-button px-theme-button-x',
|
||||
/** The other actions of the sign-in flow, the `authActionHeight` role. */
|
||||
'auth-action': 'h-theme-auth-action px-theme-button-x',
|
||||
/** Default height with the generous pad of a dialog's confirming action. */
|
||||
wide: 'h-theme-button px-8',
|
||||
/** Default height with a snug pad, for a text action that sits close to its neighbors. */
|
||||
|
|
@ -262,8 +268,10 @@ const buttonVariantRecipe = cva(
|
|||
},
|
||||
shape: {
|
||||
default: 'rounded-lg',
|
||||
/** The generous corner of a sign-in form's controls. */
|
||||
soft: 'rounded-2xl',
|
||||
/** The corner of a sign-in form's controls, the `authControlRadius` role. */
|
||||
soft: 'rounded-theme-auth-control',
|
||||
/** The corner of the sign-in flow's other actions, the `authActionRadius` role. */
|
||||
'auth-action': 'rounded-theme-auth-action',
|
||||
theme: 'rounded-theme-control',
|
||||
round: 'rounded-theme-control-round',
|
||||
unset: '',
|
||||
|
|
|
|||
|
|
@ -71,9 +71,13 @@ describe('SecretInput', () => {
|
|||
render(<SecretInput id="pw" variant="floating" label="Password" />);
|
||||
const field = document.getElementById('pw');
|
||||
|
||||
expect(field).toHaveClass('peer', 'rounded-2xl', 'pr-11');
|
||||
expect(field).toHaveClass('peer', 'rounded-theme-auth-control', 'pr-11');
|
||||
expect(field).toHaveAttribute('placeholder', ' ');
|
||||
expect(screen.getByText('Password')).toHaveClass('peer-placeholder-shown:top-1/2');
|
||||
expect(screen.getByRole('button', { name: 'Show secret' })).toHaveClass('size-9', 'rounded-xl');
|
||||
expect(screen.getByRole('button', { name: 'Show secret' })).toHaveClass(
|
||||
'size-theme-auth-field-action',
|
||||
'rounded-xl',
|
||||
);
|
||||
expect(screen.getByRole('button', { name: 'Show secret' })).not.toHaveClass('size-7');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,13 +2,15 @@
|
|||
* The floating-label field of a sign-in form: a generous corner and edge, with the label resting
|
||||
* inside the field until the field is focused or filled, then lifting onto its top edge. The
|
||||
* label is the field's `peer`, so it follows the field's placeholder and focus state in CSS.
|
||||
* Its height and corner are the `authFieldHeight` and `authControlRadius` roles; the value
|
||||
* sits 1px below the middle of that height, where the content-sized field always set it.
|
||||
* `webkit-dark-styles` keeps a browser's autofill from repainting the field.
|
||||
*/
|
||||
export const floatingField: string =
|
||||
'webkit-dark-styles peer h-auto w-full rounded-2xl border px-3.5 pb-2.5 pt-3 text-text-primary duration-200 motion-reduce:transition-none focus:border-accent-primary focus-visible:border-accent-primary';
|
||||
'webkit-dark-styles peer h-theme-auth-field w-full rounded-theme-auth-control border px-3.5 pb-0 pt-0.5 text-text-primary duration-200 motion-reduce:transition-none focus:border-accent-primary focus-visible:border-accent-primary';
|
||||
|
||||
export const floatingLabel: string =
|
||||
'absolute start-3 top-1.5 z-10 origin-[0] -translate-y-4 scale-75 transform bg-surface-primary px-2 theme-field-fill:bg-field-fill text-sm text-text-secondary-alt duration-200 peer-placeholder-shown:top-1/2 peer-placeholder-shown:-translate-y-1/2 peer-placeholder-shown:scale-100 peer-focus:top-1.5 peer-focus:-translate-y-4 peer-focus:scale-75 peer-focus:px-2 peer-focus:text-accent-primary motion-reduce:transition-none rtl:peer-focus:left-auto rtl:peer-focus:translate-x-1/4';
|
||||
|
||||
export const floatingSecretButton: string =
|
||||
'size-9 rounded-xl text-text-secondary-alt hover:bg-transparent hover:text-text-primary';
|
||||
'size-theme-auth-field-action rounded-xl text-text-secondary-alt hover:bg-transparent hover:text-text-primary';
|
||||
|
|
|
|||
|
|
@ -70,6 +70,15 @@ panel `menuPanelRadius` (0.75rem, `rounded-theme-menu-panel`) and the send and s
|
|||
onto `menuRadius` or a square corner without moving the control or surface radii. An inline code
|
||||
chip in Markdown takes its weight from `inlineCodeWeight` (600).
|
||||
|
||||
The sign-in forms' floating-label field reads `authFieldHeight` (2.75rem, `h-theme-auth-field`), their
|
||||
submit button `authButtonHeight` (3rem, the Button's `auth` size) and both the corner
|
||||
`authControlRadius` (1rem, the Button's `soft` shape), which follows `radius2xl` when a theme names
|
||||
that and not this. The flow's other actions, the second-factor verify and the reset-success continue
|
||||
buttons, read `authActionHeight` (the Button's `auth-action` size) and `authActionRadius` (its
|
||||
`auth-action` shape; the 2FA button keeps `soft`). They follow `authButtonHeight` and
|
||||
`authControlRadius` when a theme names those, and otherwise the `buttonHeight` and `radiusLg` they
|
||||
drew before (2.5rem and 0.5rem). Every height here rejects a value under 24px.
|
||||
|
||||
Most appearance defaults hold in both modes. `darkAppearanceDefaults` lists the ones that differ in
|
||||
dark mode, and `defaultAppearanceFor(mode)` returns the full set for a mode: the menu panel's
|
||||
`menuShadow` and the tooltip's `tooltipShadow` are heavier on a dark page, as they always were. A
|
||||
|
|
|
|||
|
|
@ -291,6 +291,11 @@ html {
|
|||
--theme-icon-button-size-sm: 2rem;
|
||||
--theme-field-height: 2.5rem;
|
||||
--theme-field-height-lg: 3rem;
|
||||
--theme-auth-field-height: 2.75rem;
|
||||
--theme-auth-button-height: 3rem;
|
||||
--theme-auth-control-radius: var(--theme-radius-2xl, 1rem);
|
||||
--theme-auth-action-height: var(--theme-button-height, 2.5rem);
|
||||
--theme-auth-action-radius: var(--theme-radius-lg, 0.5rem);
|
||||
--theme-field-padding-y: 0.5rem;
|
||||
--theme-field-focus-style: ring;
|
||||
--theme-field-fill-style: transparent;
|
||||
|
|
|
|||
|
|
@ -96,6 +96,9 @@ const stockAliases: Partial<
|
|||
popoverRadius: 'radius2xl',
|
||||
menuPanelRadius: 'radiusXl',
|
||||
composerActionRadius: 'roundControlRadius',
|
||||
authControlRadius: 'radius2xl',
|
||||
authActionHeight: 'buttonHeight',
|
||||
authActionRadius: 'radiusLg',
|
||||
};
|
||||
|
||||
/** Color roles split out of a broader one read it in the stylesheet, in both modes, so a
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { join } from 'node:path';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import type { IThemeRGB, ThemeDefinition } from './types';
|
||||
import type { IThemeAppearance, IThemeRGB, ThemeDefinition } from './types';
|
||||
import {
|
||||
collectThemeWarnings,
|
||||
darkAppearanceDefaults,
|
||||
|
|
@ -1437,12 +1437,44 @@ describe('theme registry', () => {
|
|||
buttonHeightLg: '2.75rem',
|
||||
iconButtonSizeSm: '2rem',
|
||||
fieldHeightLg: '3rem',
|
||||
authFieldHeight: '2.75rem',
|
||||
authButtonHeight: '3rem',
|
||||
authControlRadius: '1rem',
|
||||
authActionHeight: '2.5rem',
|
||||
authActionRadius: '0.5rem',
|
||||
checkboxSize: '1rem',
|
||||
listMinWidth: '8rem',
|
||||
listMaxHeight: '24rem',
|
||||
});
|
||||
});
|
||||
|
||||
it('sizes the other sign-in actions from the sign-in pair, then the Button roles they drew', () => {
|
||||
const resolve = (appearance: Partial<IThemeAppearance>) =>
|
||||
resolveTheme({ version: 1, name: 'auth-actions', modes: { light: { appearance } } }, 'light')
|
||||
.appearance;
|
||||
|
||||
expect(resolve({})).toMatchObject({ authActionHeight: '2.5rem', authActionRadius: '0.5rem' });
|
||||
expect(resolve({ buttonHeight: '2.25rem', radiusLg: '3px' })).toMatchObject({
|
||||
authActionHeight: '2.25rem',
|
||||
authActionRadius: '3px',
|
||||
});
|
||||
expect(
|
||||
resolve({
|
||||
buttonHeight: '2.25rem',
|
||||
radiusLg: '3px',
|
||||
authButtonHeight: '2rem',
|
||||
authControlRadius: '0',
|
||||
}),
|
||||
).toMatchObject({ authActionHeight: '2rem', authActionRadius: '0' });
|
||||
expect(resolve({ radius2xl: '2px', radiusLg: '5px' })).toMatchObject({
|
||||
authControlRadius: '2px',
|
||||
authActionRadius: '5px',
|
||||
});
|
||||
expect(
|
||||
resolve({ authButtonHeight: '2rem', authActionHeight: '3.5rem', authActionRadius: '1px' }),
|
||||
).toMatchObject({ authActionHeight: '3.5rem', authActionRadius: '1px' });
|
||||
});
|
||||
|
||||
it("bounds a Select list's width and scroll height", () => {
|
||||
const issues = (appearance: Record<string, string>) =>
|
||||
validateThemeDefinition({
|
||||
|
|
@ -1483,6 +1515,8 @@ describe('theme registry', () => {
|
|||
{ fieldHeightLg: '20px' },
|
||||
{ fieldHeightLg: '1rem' },
|
||||
{ fieldHeightLg: '1.5em' },
|
||||
{ authFieldHeight: '20px' },
|
||||
{ authButtonHeight: 'auto' },
|
||||
{ iconSize: '0' },
|
||||
{ iconSize: '1.5rem' },
|
||||
{ iconSize: '10px' },
|
||||
|
|
|
|||
|
|
@ -258,6 +258,11 @@ export const themeAppearanceProperties: Readonly<
|
|||
iconButtonSizeSm: '--theme-icon-button-size-sm',
|
||||
fieldHeight: '--theme-field-height',
|
||||
fieldHeightLg: '--theme-field-height-lg',
|
||||
authFieldHeight: '--theme-auth-field-height',
|
||||
authButtonHeight: '--theme-auth-button-height',
|
||||
authControlRadius: '--theme-auth-control-radius',
|
||||
authActionHeight: '--theme-auth-action-height',
|
||||
authActionRadius: '--theme-auth-action-radius',
|
||||
fieldPaddingY: '--theme-field-padding-y',
|
||||
fieldFocusStyle: '--theme-field-focus-style',
|
||||
fieldFillStyle: '--theme-field-fill-style',
|
||||
|
|
@ -364,6 +369,11 @@ export const defaultAppearance: IThemeAppearance = Object.freeze({
|
|||
iconButtonSizeSm: '2rem',
|
||||
fieldHeight: '2.5rem',
|
||||
fieldHeightLg: '3rem',
|
||||
authFieldHeight: '2.75rem',
|
||||
authButtonHeight: '3rem',
|
||||
authControlRadius: '1rem',
|
||||
authActionHeight: '2.5rem',
|
||||
authActionRadius: '0.5rem',
|
||||
fieldPaddingY: '0.5rem',
|
||||
fieldFocusStyle: 'ring',
|
||||
fieldFillStyle: 'transparent',
|
||||
|
|
@ -596,9 +606,10 @@ function withComposableShadows(appearance: IThemeAppearance): IThemeAppearance {
|
|||
/**
|
||||
* 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, theme-sized controls were padded by the shared spacing,
|
||||
* and dialog titles were set in the `text-lg` step and the display family, the composer's popovers, the model selector and the send button drew `rounded-2xl`, `rounded-xl` and the round control corner, so a theme that names
|
||||
* and dialog titles were set in the `text-lg` step and the display family, the composer's popovers, the model selector and the send button drew `rounded-2xl`, `rounded-xl` and the round control corner, and the sign-in controls drew `rounded-2xl` and the other sign-in actions the default Button's height and corner, so a theme that names
|
||||
* the broader role and not the split one keeps what it drew. Pairs resolve in order, so a role can
|
||||
* follow one that is itself inherited.
|
||||
* follow one that is itself inherited; the other sign-in actions resolve before the sign-in corner
|
||||
* is derived, so they follow only a corner the theme names and otherwise keep `radiusLg`.
|
||||
*/
|
||||
const inheritedAppearance: ReadonlyArray<[keyof IThemeAppearance, keyof IThemeAppearance]> = [
|
||||
['displayFontFamily', 'fontFamily'],
|
||||
|
|
@ -610,6 +621,11 @@ const inheritedAppearance: ReadonlyArray<[keyof IThemeAppearance, keyof IThemeAp
|
|||
['popoverRadius', 'radius2xl'],
|
||||
['menuPanelRadius', 'radiusXl'],
|
||||
['composerActionRadius', 'roundControlRadius'],
|
||||
['authActionRadius', 'authControlRadius'],
|
||||
['authActionRadius', 'radiusLg'],
|
||||
['authControlRadius', 'radius2xl'],
|
||||
['authActionHeight', 'authButtonHeight'],
|
||||
['authActionHeight', 'buttonHeight'],
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -177,6 +177,19 @@ describe('LibreChat Tailwind preset', () => {
|
|||
defaultAppearance.buttonHeightCompact,
|
||||
],
|
||||
['h-theme-field-lg', '--theme-field-height-lg', defaultAppearance.fieldHeightLg],
|
||||
['h-theme-auth-field', '--theme-auth-field-height', defaultAppearance.authFieldHeight],
|
||||
['h-theme-auth-button', '--theme-auth-button-height', defaultAppearance.authButtonHeight],
|
||||
['h-theme-auth-action', '--theme-auth-action-height', defaultAppearance.authActionHeight],
|
||||
[
|
||||
'rounded-theme-auth-action',
|
||||
'--theme-auth-action-radius',
|
||||
defaultAppearance.authActionRadius,
|
||||
],
|
||||
[
|
||||
'rounded-theme-auth-control',
|
||||
'--theme-auth-control-radius',
|
||||
defaultAppearance.authControlRadius,
|
||||
],
|
||||
['size-theme-button', '--theme-button-height', defaultAppearance.buttonHeight],
|
||||
[
|
||||
'size-theme-icon-button-sm',
|
||||
|
|
@ -296,6 +309,9 @@ describe('LibreChat Tailwind preset', () => {
|
|||
popoverRadius: 'radius2xl',
|
||||
menuPanelRadius: 'radiusXl',
|
||||
composerActionRadius: 'roundControlRadius',
|
||||
authControlRadius: 'radius2xl',
|
||||
authActionHeight: 'buttonHeight',
|
||||
authActionRadius: 'radiusLg',
|
||||
};
|
||||
Object.entries(themeAppearanceProperties).forEach(([key, property]) => {
|
||||
const value = aliases[key]
|
||||
|
|
|
|||
|
|
@ -525,6 +525,11 @@ const clickHouseShape = {
|
|||
fieldHeight: '2rem',
|
||||
fieldHeightLg: '3.6876rem', // content-sized like fieldHeight: the 3rem title line (2rem at 1.5), field.space.y twice, a 1px stroke each side
|
||||
fieldPaddingY: '0.2813rem', // field.space.y
|
||||
/** Click UI draws one field and one button size, so the sign-in form's controls take them and
|
||||
* the button's square corner instead of LibreChat's taller, rounder sign-in pair. */
|
||||
authFieldHeight: '2rem',
|
||||
authButtonHeight: '2rem',
|
||||
authControlRadius: '0.25rem', // button.radii.all
|
||||
fieldFocusStyle: 'border' as const,
|
||||
/** Click UI fills its fields in `field.color.background.default`. */
|
||||
fieldFillStyle: 'fill' as const,
|
||||
|
|
|
|||
|
|
@ -526,6 +526,16 @@ const appearanceDecisions: Partial<Record<keyof IThemeAppearance, AppearanceDeci
|
|||
reason:
|
||||
'3.6876rem: the title field is content-sized like fieldHeight, a 3rem line (typography.font.sizes.6 at line-height 1.5), field.space.y (0.2813rem) twice and a 1px stroke each side',
|
||||
},
|
||||
authFieldHeight: {
|
||||
value: '2rem',
|
||||
status: 'match',
|
||||
reason: '2rem: Click UI draws one field size, so the sign-in field matches fieldHeight',
|
||||
},
|
||||
authButtonHeight: {
|
||||
value: '2rem',
|
||||
status: 'match',
|
||||
reason: '2rem: Click UI draws one button size, so the sign-in button matches buttonHeight',
|
||||
},
|
||||
fieldFocusStyle: {
|
||||
value: 'border',
|
||||
status: 'match',
|
||||
|
|
@ -593,6 +603,7 @@ const appearanceSources: Partial<Record<keyof IThemeAppearance, string>> = {
|
|||
popoverRadius: 'click.genericMenu.panel.radii.all',
|
||||
menuPanelRadius: 'click.genericMenu.panel.radii.all',
|
||||
composerActionRadius: 'click.button.radii.all',
|
||||
authControlRadius: 'click.button.radii.all',
|
||||
inlineCodeWeight: 'typography.font.weights.2',
|
||||
tooltipRadius: 'click.tooltip.radii.all',
|
||||
tooltipPaddingX: 'click.tooltip.space.x',
|
||||
|
|
|
|||
|
|
@ -704,6 +704,16 @@ export interface IThemeAppearance {
|
|||
fieldHeight: string;
|
||||
/** The height of the large `title` field. */
|
||||
fieldHeightLg: string;
|
||||
/** The sign-in form's floating-label field and submit button heights, and the corner both
|
||||
* share; the corner follows `radius2xl` when a theme names that and not this. */
|
||||
authFieldHeight: string;
|
||||
authButtonHeight: string;
|
||||
authControlRadius: string;
|
||||
/** The height and corner of the other actions in the sign-in flow, the second-factor verify and
|
||||
* the reset-success continue buttons. They follow `authButtonHeight` and `authControlRadius`
|
||||
* when a theme names those, then `buttonHeight` and `radiusLg`, which they drew before. */
|
||||
authActionHeight: string;
|
||||
authActionRadius: string;
|
||||
/** The field's vertical padding, which has to leave its line room inside `fieldHeight`. */
|
||||
fieldPaddingY: string;
|
||||
fieldFocusStyle: 'ring' | 'border';
|
||||
|
|
|
|||
|
|
@ -12,6 +12,9 @@ describe('cn', () => {
|
|||
['min-h-theme-target', 'min-h-0'],
|
||||
['min-w-theme-list', 'min-w-48'],
|
||||
['max-h-theme-list', 'max-h-60'],
|
||||
['h-theme-field', 'h-theme-auth-field'],
|
||||
['h-theme-button', 'h-theme-auth-button'],
|
||||
['rounded-lg', 'rounded-theme-auth-control'],
|
||||
])('lets a caller size replace %s', (role, caller) => {
|
||||
expect(cn(role, caller)).toBe(caller);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -36,6 +36,9 @@ const twMerge = extendTailwindMerge({
|
|||
'theme-button-compact',
|
||||
'theme-field',
|
||||
'theme-field-lg',
|
||||
'theme-auth-field',
|
||||
'theme-auth-button',
|
||||
'theme-auth-action',
|
||||
'theme-target',
|
||||
],
|
||||
},
|
||||
|
|
@ -54,11 +57,13 @@ const twMerge = extendTailwindMerge({
|
|||
'theme-icon',
|
||||
'theme-icon-md',
|
||||
'theme-icon-lg',
|
||||
'theme-auth-field-action',
|
||||
],
|
||||
},
|
||||
],
|
||||
px: [{ px: ['theme-button-x', 'theme-control-x', 'theme-dialog-x'] }],
|
||||
gap: [{ gap: ['theme-control-gap'] }],
|
||||
rounded: [{ rounded: ['theme-auth-control', 'theme-auth-action'] }],
|
||||
'space-y': [{ 'space-y': ['theme-dialog-header'] }],
|
||||
'font-weight': [{ font: ['theme-control', 'theme-dialog-title-weight', 'theme-label'] }],
|
||||
'font-family': [{ font: ['theme-dialog-title'] }],
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ module.exports = {
|
|||
/** A form field's height, and the large `title` field's. */
|
||||
'theme-field': 'var(--theme-field-height, 2.5rem)',
|
||||
'theme-field-lg': 'var(--theme-field-height-lg, 3rem)',
|
||||
/** The sign-in form's floating-label field and submit button. */
|
||||
'theme-auth-field': 'var(--theme-auth-field-height, 2.75rem)',
|
||||
'theme-auth-button': 'var(--theme-auth-button-height, 3rem)',
|
||||
'theme-auth-action': 'var(--theme-auth-action-height, 2.5rem)',
|
||||
/** WCAG 2.5.8's 24px target minimum, fixed so a theme can draw controls larger, never
|
||||
* smaller. */
|
||||
'theme-target': '24px',
|
||||
|
|
@ -55,6 +59,12 @@ module.exports = {
|
|||
/** The tallest a Select's list draws before it scrolls. */
|
||||
'theme-list': 'var(--theme-list-max-height, 24rem)',
|
||||
},
|
||||
inset: {
|
||||
/** Where a sign-in label rests in its field: centered 2px low, as on the stock 44px field,
|
||||
* and never past the field's bottom edge at the 24px minimum height. Read on the label, so
|
||||
* `lh` is the label's own line. */
|
||||
'theme-auth-label-rest': 'min(calc(50% - 0.5lh + 2px), calc(100% - 1lh))',
|
||||
},
|
||||
width: {
|
||||
/** Never narrower than the track is tall, so the knob always has somewhere to travel. */
|
||||
'theme-switch':
|
||||
|
|
@ -72,6 +82,11 @@ module.exports = {
|
|||
'theme-icon': 'var(--theme-icon-size, 1rem)',
|
||||
'theme-icon-md': 'var(--theme-icon-size-md, 1.25rem)',
|
||||
'theme-icon-lg': 'var(--theme-icon-size-lg, 1.5rem)',
|
||||
/** A square control inside the sign-in field, 4px off its edges, never under the 24px
|
||||
* target and never over the stock 2.25rem the field's end padding reserves: the password
|
||||
* field's reveal and copy buttons. */
|
||||
'theme-auth-field-action':
|
||||
'clamp(24px, calc(var(--theme-auth-field-height, 2.75rem) - 0.5rem), 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-button-x': 'var(--theme-button-padding-x, 1rem)',
|
||||
|
|
@ -139,6 +154,8 @@ module.exports = {
|
|||
'theme-popover': 'var(--theme-popover-radius, 1rem)',
|
||||
'theme-menu-panel': 'var(--theme-menu-panel-radius, 0.75rem)',
|
||||
'theme-composer-action': 'var(--theme-composer-action-radius, 9999px)',
|
||||
'theme-auth-control': 'var(--theme-auth-control-radius, 1rem)',
|
||||
'theme-auth-action': 'var(--theme-auth-action-radius, 0.5rem)',
|
||||
'theme-surface-lg': 'var(--theme-large-surface-radius, 1.5rem)',
|
||||
'theme-tab': 'var(--theme-tab-radius, 0.185rem)',
|
||||
},
|
||||
|
|
|
|||
|
|
@ -466,6 +466,13 @@ const appearanceValidators = {
|
|||
* field's edge color. */
|
||||
fieldHeight: isLength,
|
||||
fieldHeightLg: isTargetSize,
|
||||
/** The sign-in field and submit button heights, each a pointer target, and their corner. */
|
||||
authFieldHeight: isTargetSize,
|
||||
authButtonHeight: isTargetSize,
|
||||
authControlRadius: isLength,
|
||||
/** The second-factor and reset-success actions' height and corner. */
|
||||
authActionHeight: isTargetSize,
|
||||
authActionRadius: isLength,
|
||||
fieldPaddingY: isLength,
|
||||
fieldFocusStyle: (value: unknown) => value === 'ring' || value === 'border',
|
||||
/** Whether a field stays transparent or paints `field-fill`. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue