From e7484a223b7ad36a9d136a01d33d0fdb00c64a0e Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Fri, 9 Oct 2026 23:35:13 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=90=20feat:=20Let=20a=20Theme=20Reshap?= =?UTF-8?q?e=20the=20Sign-In=20Field=20and=20Button=20(#16939)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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. --- .../Providers/__tests__/themeCache.spec.ts | 2 +- client/src/components/Auth/LoginForm.tsx | 3 +- client/src/components/Auth/Registration.tsx | 3 +- .../components/Auth/RequestPasswordReset.tsx | 5 +- client/src/components/Auth/ResetPassword.tsx | 5 +- .../src/components/Auth/TwoFactorScreen.tsx | 1 + .../Auth/__tests__/LoginForm.spec.tsx | 2 +- .../Auth/__tests__/Registration.spec.tsx | 2 +- .../mock/scenarios/auth-control-shape.spec.ts | 211 ++++++++++++++++++ .../client/src/components/Button.spec.tsx | 7 +- packages/client/src/components/Button.tsx | 14 +- .../src/components/SecretInput.spec.tsx | 8 +- packages/client/src/components/floating.ts | 6 +- packages/client/src/theme/README.md | 9 + packages/client/src/theme/defaults.css | 5 + packages/client/src/theme/defaults.spec.ts | 3 + packages/client/src/theme/registry.spec.ts | 36 ++- packages/client/src/theme/registry.ts | 20 +- packages/client/src/theme/tailwind.spec.js | 16 ++ .../client/src/theme/themes/clickhouse.ts | 5 + .../client/src/theme/themes/clickui.spec.ts | 11 + packages/client/src/theme/types/index.ts | 10 + packages/client/src/utils/utils.spec.ts | 3 + packages/client/src/utils/utils.ts | 5 + packages/client/tailwind.preset.cjs | 17 ++ packages/data-provider/src/theme.ts | 7 + 26 files changed, 397 insertions(+), 19 deletions(-) create mode 100644 e2e/specs/mock/scenarios/auth-control-shape.spec.ts diff --git a/client/src/Providers/__tests__/themeCache.spec.ts b/client/src/Providers/__tests__/themeCache.spec.ts index d63673fcd7..6d3ce1c28b 100644 --- a/client/src/Providers/__tests__/themeCache.spec.ts +++ b/client/src/Providers/__tests__/themeCache.spec.ts @@ -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; diff --git a/client/src/components/Auth/LoginForm.tsx b/client/src/components/Auth/LoginForm.tsx index a3d3e7a9ba..b46867699d 100644 --- a/client/src/components/Auth/LoginForm.tsx +++ b/client/src/components/Auth/LoginForm.tsx @@ -182,7 +182,8 @@ const LoginForm: React.FC = ({ onSubmit, startupConfig, error, disabled={(requireCaptcha && !turnstileToken) || isSubmitting} variant="submit" shape="soft" - className="h-12 w-full" + size="auth" + className="w-full" > {isSubmitting ? : localize('com_auth_continue')} diff --git a/client/src/components/Auth/Registration.tsx b/client/src/components/Auth/Registration.tsx index c8d81d8f81..9541ec9a1c 100644 --- a/client/src/components/Auth/Registration.tsx +++ b/client/src/components/Auth/Registration.tsx @@ -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 ? : localize('com_auth_continue')} diff --git a/client/src/components/Auth/RequestPasswordReset.tsx b/client/src/components/Auth/RequestPasswordReset.tsx index 1fadf27aef..24492052db 100644 --- a/client/src/components/Auth/RequestPasswordReset.tsx +++ b/client/src/components/Auth/RequestPasswordReset.tsx @@ -111,7 +111,7 @@ function RequestPasswordReset() { /> @@ -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 ? : localize('com_auth_continue')} diff --git a/client/src/components/Auth/ResetPassword.tsx b/client/src/components/Auth/ResetPassword.tsx index 2a111b2a31..8f047e115b 100644 --- a/client/src/components/Auth/ResetPassword.tsx +++ b/client/src/components/Auth/ResetPassword.tsx @@ -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')} @@ -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 ? : localize('com_auth_continue')} diff --git a/client/src/components/Auth/TwoFactorScreen.tsx b/client/src/components/Auth/TwoFactorScreen.tsx index 034394ad83..4fd57fa601 100644 --- a/client/src/components/Auth/TwoFactorScreen.tsx +++ b/client/src/components/Auth/TwoFactorScreen.tsx @@ -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')} diff --git a/client/src/components/Auth/__tests__/LoginForm.spec.tsx b/client/src/components/Auth/__tests__/LoginForm.spec.tsx index 93e4b014df..dc35a8f132 100644 --- a/client/src/components/Auth/__tests__/LoginForm.spec.tsx +++ b/client/src/components/Auth/__tests__/LoginForm.spec.tsx @@ -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(); }); diff --git a/client/src/components/Auth/__tests__/Registration.spec.tsx b/client/src/components/Auth/__tests__/Registration.spec.tsx index 69cc6540ea..5fc0f87654 100644 --- a/client/src/components/Auth/__tests__/Registration.spec.tsx +++ b/client/src/components/Auth/__tests__/Registration.spec.tsx @@ -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(); diff --git a/e2e/specs/mock/scenarios/auth-control-shape.spec.ts b/e2e/specs/mock/scenarios/auth-control-shape.spec.ts new file mode 100644 index 0000000000..f92e15c0fb --- /dev/null +++ b/e2e/specs/mock/scenarios/auth-control-shape.spec.ts @@ -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) { + 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' }); + }); +}); diff --git a/packages/client/src/components/Button.spec.tsx b/packages/client/src/components/Button.spec.tsx index 74fb2f2555..809a7e31d1 100644 --- a/packages/client/src/components/Button.spec.tsx +++ b/packages/client/src/components/Button.spec.tsx @@ -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'); diff --git a/packages/client/src/components/Button.tsx b/packages/client/src/components/Button.tsx index 76c797da57..a2e830c1e9 100644 --- a/packages/client/src/components/Button.tsx +++ b/packages/client/src/components/Button.tsx @@ -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: '', diff --git a/packages/client/src/components/SecretInput.spec.tsx b/packages/client/src/components/SecretInput.spec.tsx index 05c132945d..cc267c841a 100644 --- a/packages/client/src/components/SecretInput.spec.tsx +++ b/packages/client/src/components/SecretInput.spec.tsx @@ -71,9 +71,13 @@ describe('SecretInput', () => { render(); 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'); }); }); diff --git a/packages/client/src/components/floating.ts b/packages/client/src/components/floating.ts index 6510067592..2b0d7e62bd 100644 --- a/packages/client/src/components/floating.ts +++ b/packages/client/src/components/floating.ts @@ -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'; diff --git a/packages/client/src/theme/README.md b/packages/client/src/theme/README.md index 08c96ca217..f46cd99305 100644 --- a/packages/client/src/theme/README.md +++ b/packages/client/src/theme/README.md @@ -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 diff --git a/packages/client/src/theme/defaults.css b/packages/client/src/theme/defaults.css index 0507b2e76f..8f9ccb18fa 100644 --- a/packages/client/src/theme/defaults.css +++ b/packages/client/src/theme/defaults.css @@ -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; diff --git a/packages/client/src/theme/defaults.spec.ts b/packages/client/src/theme/defaults.spec.ts index 7e8fd1449e..8fcdcac255 100644 --- a/packages/client/src/theme/defaults.spec.ts +++ b/packages/client/src/theme/defaults.spec.ts @@ -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 diff --git a/packages/client/src/theme/registry.spec.ts b/packages/client/src/theme/registry.spec.ts index 3754e52caa..58dbeec372 100644 --- a/packages/client/src/theme/registry.spec.ts +++ b/packages/client/src/theme/registry.spec.ts @@ -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) => + 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) => 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' }, diff --git a/packages/client/src/theme/registry.ts b/packages/client/src/theme/registry.ts index 7340651439..08d4fb3135 100644 --- a/packages/client/src/theme/registry.ts +++ b/packages/client/src/theme/registry.ts @@ -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'], ]; /** diff --git a/packages/client/src/theme/tailwind.spec.js b/packages/client/src/theme/tailwind.spec.js index 2df18a400e..0091c4443d 100644 --- a/packages/client/src/theme/tailwind.spec.js +++ b/packages/client/src/theme/tailwind.spec.js @@ -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] diff --git a/packages/client/src/theme/themes/clickhouse.ts b/packages/client/src/theme/themes/clickhouse.ts index 9343b02973..503518c2e5 100644 --- a/packages/client/src/theme/themes/clickhouse.ts +++ b/packages/client/src/theme/themes/clickhouse.ts @@ -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, diff --git a/packages/client/src/theme/themes/clickui.spec.ts b/packages/client/src/theme/themes/clickui.spec.ts index b9c2b31c11..76499138b0 100644 --- a/packages/client/src/theme/themes/clickui.spec.ts +++ b/packages/client/src/theme/themes/clickui.spec.ts @@ -526,6 +526,16 @@ const appearanceDecisions: Partial> = { 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', diff --git a/packages/client/src/theme/types/index.ts b/packages/client/src/theme/types/index.ts index ff44e22f19..685ab7d75d 100644 --- a/packages/client/src/theme/types/index.ts +++ b/packages/client/src/theme/types/index.ts @@ -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'; diff --git a/packages/client/src/utils/utils.spec.ts b/packages/client/src/utils/utils.spec.ts index 31ee08c5b9..5bd91f488c 100644 --- a/packages/client/src/utils/utils.spec.ts +++ b/packages/client/src/utils/utils.spec.ts @@ -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); }); diff --git a/packages/client/src/utils/utils.ts b/packages/client/src/utils/utils.ts index 3b1472aa79..00c571ab53 100644 --- a/packages/client/src/utils/utils.ts +++ b/packages/client/src/utils/utils.ts @@ -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'] }], diff --git a/packages/client/tailwind.preset.cjs b/packages/client/tailwind.preset.cjs index c762f9562d..a9673aaaf1 100644 --- a/packages/client/tailwind.preset.cjs +++ b/packages/client/tailwind.preset.cjs @@ -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)', }, diff --git a/packages/data-provider/src/theme.ts b/packages/data-provider/src/theme.ts index 6d5dd4bcba..ae1f3b545f 100644 --- a/packages/data-provider/src/theme.ts +++ b/packages/data-provider/src/theme.ts @@ -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`. */