diff --git a/client/src/Providers/__tests__/DeploymentTheme.spec.tsx b/client/src/Providers/__tests__/DeploymentTheme.spec.tsx index a38f928782..2972563466 100644 --- a/client/src/Providers/__tests__/DeploymentTheme.spec.tsx +++ b/client/src/Providers/__tests__/DeploymentTheme.spec.tsx @@ -172,10 +172,31 @@ describe('DeploymentTheme', () => { expect(snapshotStorage()).toEqual(before); }); + it('applies an inline definition carrying a color role this build predates', async () => { + serveTheme({ + ...inlineTheme, + modes: { + ...inlineTheme.modes, + light: { + ...inlineTheme.modes.light, + colors: { ...inlineTheme.modes.light.colors, 'rgb-future-role': '1 2 3' }, + }, + }, + }); + renderTheme(queryClient); + + await waitFor(() => expect(root().dataset.theme).toBe('acme')); + expect(root().style.getPropertyValue('--surface-primary')).toBe('10 20 30'); + expect(root().getAttribute('style')).not.toContain('--future-role'); + expect(warn).toHaveBeenCalledWith( + '[ThemeProvider] Unknown light color token ignored: rgb-future-role', + ); + }); + it('ignores an invalid inline definition with a warning and keeps the stored theme', async () => { serveTheme({ ...inlineTheme, - modes: { light: { colors: { 'rgb-not-a-token': '1 2 3' } } }, + modes: { light: { colors: { 'rgb-not-a-token': 'red' } } }, }); renderTheme(queryClient); diff --git a/client/src/style.css b/client/src/style.css index b02463a00e..4a5145a212 100644 --- a/client/src/style.css +++ b/client/src/style.css @@ -321,6 +321,7 @@ html { --theme-control-height: 2.25rem; --theme-space-compact: 0.375rem; --theme-space-normal: 0.75rem; + --theme-disabled-style: dim; --theme-font-family: Inter, sans-serif; /* Roboto Mono is self-hosted (the `@font-face` block below), so code renders the same on every * platform with real bold and italic faces. The tail is reached while the font loads, if it diff --git a/e2e/specs/mock/scenarios/deployment-theme.spec.ts b/e2e/specs/mock/scenarios/deployment-theme.spec.ts index 5915f03bad..3a032588b1 100644 --- a/e2e/specs/mock/scenarios/deployment-theme.spec.ts +++ b/e2e/specs/mock/scenarios/deployment-theme.spec.ts @@ -150,7 +150,7 @@ test.describe('deployment theme from librechat.yaml', () => { }); await serveTheme(page, { ...INLINE_THEME, - modes: { light: { colors: { 'rgb-not-a-token': '1 2 3' } } }, + modes: { light: { colors: { 'rgb-not-a-token': 'red' } } }, }); await openLogin(page); diff --git a/e2e/specs/mock/scenarios/state-roles.spec.ts b/e2e/specs/mock/scenarios/state-roles.spec.ts new file mode 100644 index 0000000000..72ec896309 --- /dev/null +++ b/e2e/specs/mock/scenarios/state-roles.spec.ts @@ -0,0 +1,315 @@ +import { expect, test } from '@playwright/test'; +import type { Page } from '@playwright/test'; +import { clickHouseTheme } from '../../../../packages/client/src/theme/themes/clickhouse'; +import { NEW_CHAT_PATH } from '../helpers'; + +/** + * The pressed and disabled state roles. A held control takes `surface-pressed` (or the inverted + * pressed fill), which defaults to the hover fill a pointer press has always shown. A disabled + * control dims to half opacity unless the theme's `disabledStyle` is `fill`, which paints it in + * `surface-disabled` and `text-disabled` at full opacity. The probes carry the class lists the + * shared `IconButton` and `Field` primitives compose, so only those rules style them. + */ + +type Mode = 'light' | 'dark'; + +const PRESS_CLASSES = 'bg-surface-secondary hover:bg-surface-hover hover:active:bg-surface-pressed'; +const DISABLED_CLASSES = + 'bg-transparent text-text-primary disabled:opacity-50 theme-disabled:bg-surface-disabled theme-disabled:text-text-disabled theme-disabled:opacity-100'; + +/** Names every state role apart from the hover and ink it would otherwise follow. */ +const STATE_ROLE_THEME = { + version: 1, + name: 'e2e-state-roles', + modes: { + light: { + colors: { + 'rgb-surface-hover': '200 200 200', + 'rgb-surface-pressed': '150 60 20', + 'rgb-surface-disabled': '20 150 60', + 'rgb-text-disabled': '60 20 150', + }, + appearance: { disabledStyle: 'fill' }, + }, + dark: { + colors: { + 'rgb-surface-hover': '60 60 60', + 'rgb-surface-pressed': '240 160 120', + 'rgb-surface-disabled': '120 240 160', + 'rgb-text-disabled': '160 120 240', + }, + appearance: { disabledStyle: 'fill' }, + }, + }, +} as const; + +async function openChat(page: Page, mode: Mode, definition?: { name: string }) { + await page.addInitScript( + ([appearance, stored]) => { + localStorage.setItem('color-theme', appearance as string); + localStorage.removeItem('theme-colors'); + localStorage.removeItem('theme-name'); + if (stored) { + localStorage.setItem('theme-definition', JSON.stringify(stored)); + localStorage.setItem('theme-source', 'definition'); + } else { + localStorage.removeItem('theme-definition'); + localStorage.removeItem('theme-source'); + } + }, + [mode, definition ?? null] as [string, unknown], + ); + await page.goto(NEW_CHAT_PATH, { timeout: 15000 }); + await expect(page.getByRole('textbox', { name: 'Message input' })).toBeVisible({ + timeout: 30000, + }); + const root = page.locator('html'); + if (definition) { + await expect(root).toHaveAttribute('data-theme', definition.name); + } else { + await expect(root).not.toHaveAttribute('data-theme'); + } + await expect(root).toHaveClass(mode === 'dark' ? /\bdark\b/ : /\blight\b/); +} + +async function addProbe(page: Page, id: string, className: string, disabled = false) { + await page.evaluate( + ([probeId, classes, isDisabled]) => { + const probe = document.createElement('button'); + probe.id = probeId as string; + probe.className = classes as string; + probe.disabled = isDisabled as boolean; + probe.textContent = 'State probe'; + probe.style.position = 'fixed'; + probe.style.top = '8px'; + probe.style.left = '8px'; + probe.style.zIndex = '2147483647'; + document.body.append(probe); + }, + [id, className, disabled] as [string, string, boolean], + ); + return page.locator(`#${id}`); +} + +/** + * Holds the pointer down on a hovered probe and reads its fill. Tailwind gates `hover:` behind + * `(hover: hover)`, so on a touch device neither the hover nor the pressed fill applies and the + * probe keeps its resting fill, as it always has; `null` marks that case. + */ +async function pressedFill(page: Page): Promise { + if (!(await page.evaluate(() => matchMedia('(hover: hover)').matches))) { + return null; + } + const probe = await addProbe(page, 'state-press-probe', PRESS_CLASSES); + const box = await probe.boundingBox(); + if (!box) { + throw new Error('press probe has no box'); + } + await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2); + await page.mouse.down(); + const fill = await probe.evaluate((node) => getComputedStyle(node).backgroundColor); + await page.mouse.up(); + return fill; +} + +/** The ink an empty disabled field shows is its placeholder, which `Field` colors on its own. */ +const PLACEHOLDER_CLASSES = + 'placeholder:text-text-secondary disabled:opacity-50 theme-disabled:placeholder:text-text-disabled'; + +async function disabledLook(page: Page) { + const probe = await addProbe(page, 'state-disabled-probe', DISABLED_CLASSES, true); + const look = await probe.evaluate((node) => { + const style = getComputedStyle(node); + return { fill: style.backgroundColor, ink: style.color, opacity: style.opacity }; + }); + const placeholder = await page.evaluate((classes) => { + const field = document.createElement('input'); + field.className = classes; + field.placeholder = 'Disabled field'; + field.disabled = true; + document.body.append(field); + const color = getComputedStyle(field, '::placeholder').color; + field.remove(); + return color; + }, PLACEHOLDER_CLASSES); + /** Radix marks a disabled part that is not a form control, a slider thumb, with `data-disabled`. */ + const part = await page.evaluate(() => { + const thumb = document.createElement('span'); + thumb.className = 'bg-surface-primary theme-disabled:bg-surface-disabled'; + thumb.setAttribute('data-disabled', ''); + document.body.append(thumb); + const fill = getComputedStyle(thumb).backgroundColor; + thumb.remove(); + return fill; + }); + /** `InputNumber` styles a wrapper whose disabled input sits inside it. */ + const wrapper = await page.evaluate(() => { + const box = document.createElement('div'); + box.className = + 'bg-transparent text-text-primary theme-disabled-within:bg-surface-disabled theme-disabled-within:text-text-disabled theme-disabled-within:[&_*]:border-border-disabled'; + const field = document.createElement('input'); + field.disabled = true; + const slot = document.createElement('div'); + slot.className = 'border border-border-control'; + box.append(field, slot); + document.body.append(box); + const style = getComputedStyle(box); + const result = `${style.backgroundColor} ${getComputedStyle(field).color} ${getComputedStyle(slot).borderTopColor}`; + box.remove(); + return result; + }); + /** A menu item keeps its surface and grays its text; a label follows its control through `peer`. */ + const items = await page.evaluate(() => { + const item = document.createElement('div'); + item.className = + 'text-text-primary theme-disabled:text-text-disabled theme-disabled:[&_*]:text-text-disabled'; + item.setAttribute('data-disabled', ''); + const icon = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); + icon.setAttribute('class', 'text-status-warning'); + item.append(icon); + const field = document.createElement('input'); + field.className = 'peer'; + field.disabled = true; + const label = document.createElement('label'); + label.className = 'text-text-secondary peer-theme-disabled:text-text-disabled'; + document.body.append(item, field, label); + const result = `${getComputedStyle(icon).color} ${getComputedStyle(label).color}`; + item.remove(); + field.remove(); + label.remove(); + return result; + }); + return { ...look, placeholder, part, wrapper, items }; +} + +/** Each tag is written out whole: the runner finds a scenario by its literal tag. */ +const CASES: Array<{ + title: string; + mode: Mode; + definition?: { name: string }; + pressed: string; + disabled: { + fill: string; + ink: string; + opacity: string; + placeholder: string; + part: string; + wrapper: string; + items: string; + }; +}> = [ + { + title: + 'the default light theme presses in its hover fill and dims disabled controls @scenario:state-roles-default-light-unchanged', + mode: 'light', + pressed: 'rgb(227, 227, 227)', + disabled: { + fill: 'rgba(0, 0, 0, 0)', + ink: 'rgb(33, 33, 33)', + opacity: '0.5', + placeholder: 'rgb(66, 66, 66)', + part: 'rgb(255, 255, 255)', + wrapper: 'rgba(0, 0, 0, 0) rgb(33, 33, 33) rgb(227, 227, 227)', + items: 'rgb(180, 83, 9) rgb(66, 66, 66)', + }, + }, + { + title: + 'the default dark theme presses in its hover fill and dims disabled controls @scenario:state-roles-default-dark-unchanged', + mode: 'dark', + pressed: 'rgb(57, 57, 57)', + disabled: { + fill: 'rgba(0, 0, 0, 0)', + ink: 'rgb(236, 236, 236)', + opacity: '0.5', + placeholder: 'rgb(205, 205, 205)', + part: 'rgb(13, 13, 13)', + wrapper: 'rgba(0, 0, 0, 0) rgb(236, 236, 236) rgb(33, 33, 33)', + items: 'rgb(252, 211, 77) rgb(205, 205, 205)', + }, + }, + { + title: + 'the ClickHouse light theme presses and disables in Click UI fills @scenario:state-roles-clickhouse-light', + mode: 'light', + definition: clickHouseTheme, + pressed: 'rgb(221, 222, 225)', + disabled: { + fill: 'rgb(223, 223, 223)', + ink: 'rgb(160, 160, 160)', + opacity: '1', + placeholder: 'rgb(160, 160, 160)', + part: 'rgb(223, 223, 223)', + wrapper: 'rgb(223, 223, 223) rgb(160, 160, 160) rgb(223, 223, 223)', + items: 'rgb(160, 160, 160) rgb(160, 160, 160)', + }, + }, + { + title: + 'the ClickHouse dark theme presses and disables in Click UI fills @scenario:state-roles-clickhouse-dark', + mode: 'dark', + definition: clickHouseTheme, + pressed: 'rgb(36, 36, 36)', + disabled: { + fill: 'rgb(65, 65, 65)', + ink: 'rgb(128, 128, 128)', + opacity: '1', + placeholder: 'rgb(128, 128, 128)', + part: 'rgb(65, 65, 65)', + wrapper: 'rgb(65, 65, 65) rgb(128, 128, 128) rgb(65, 65, 65)', + items: 'rgb(128, 128, 128) rgb(128, 128, 128)', + }, + }, +]; + +test.describe('pressed and disabled state roles', () => { + for (const { title, mode, definition, pressed, disabled } of CASES) { + test(title, async ({ page }) => { + await openChat(page, mode, definition); + + const fill = await pressedFill(page); + if (fill !== null) { + expect(fill).toBe(pressed); + } + expect(await disabledLook(page)).toEqual(disabled); + }); + } + + test('a theme that names the state roles presses and disables in them, in both modes @scenario:state-roles-follow-reference-theme', async ({ + page, + }) => { + const expected: Record = { + light: { + pressed: 'rgb(150, 60, 20)', + fill: 'rgb(20, 150, 60)', + ink: 'rgb(60, 20, 150)', + edge: 'rgb(227, 227, 227)', + }, + dark: { + pressed: 'rgb(240, 160, 120)', + fill: 'rgb(120, 240, 160)', + ink: 'rgb(160, 120, 240)', + edge: 'rgb(57, 57, 57)', + }, + }; + /** One page per mode: a page's init scripts accumulate, and their order is not guaranteed. */ + for (const mode of ['light', 'dark'] as const) { + const modePage = mode === 'light' ? page : await page.context().newPage(); + await openChat(modePage, mode, STATE_ROLE_THEME); + + const fill = await pressedFill(modePage); + if (fill !== null) { + expect(fill).toBe(expected[mode].pressed); + } + expect(await disabledLook(modePage)).toEqual({ + fill: expected[mode].fill, + ink: expected[mode].ink, + opacity: '1', + placeholder: expected[mode].ink, + part: expected[mode].fill, + wrapper: `${expected[mode].fill} ${expected[mode].ink} ${expected[mode].edge}`, + items: `${expected[mode].ink} ${expected[mode].ink}`, + }); + } + }); +}); diff --git a/packages/client/src/components/AlertDialog.tsx b/packages/client/src/components/AlertDialog.tsx index 6e6bbee22c..2607dc8ee9 100644 --- a/packages/client/src/components/AlertDialog.tsx +++ b/packages/client/src/components/AlertDialog.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { JSX } from 'react/jsx-runtime'; import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog'; import { useDialogDepth } from './OriginalDialog'; -import { cn } from '~/utils'; +import { cn, disabledFillClasses } from '~/utils'; const AlertDialog: React.FC = AlertDialogPrimitive.Root; @@ -148,6 +148,7 @@ const AlertDialogAction: React.ForwardRefExoticComponent< ref={ref} className={cn( 'bg-surface-inverted text-text-inverted hover:bg-surface-inverted-hover focus:ring-focus-control inline-flex h-10 items-center justify-center rounded-md px-4 py-2 text-sm font-semibold transition-colors focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:cursor-not-allowed disabled:opacity-50', + disabledFillClasses, className, )} {...props} @@ -169,6 +170,7 @@ const AlertDialogCancel: React.ForwardRefExoticComponent< ref={ref} className={cn( 'border-border-light text-text-primary hover:bg-surface-hover focus:ring-focus-control mt-2 inline-flex h-10 items-center justify-center rounded-md border bg-transparent px-4 py-2 text-sm font-semibold transition-colors focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:cursor-not-allowed disabled:opacity-50 sm:mt-0', + disabledFillClasses, className, )} {...props} diff --git a/packages/client/src/components/AnimatedTabs.tsx b/packages/client/src/components/AnimatedTabs.tsx index b58a31f686..2c13fff3ae 100644 --- a/packages/client/src/components/AnimatedTabs.tsx +++ b/packages/client/src/components/AnimatedTabs.tsx @@ -1,7 +1,7 @@ import { forwardRef, useEffect, useRef } from 'react'; import * as Ariakit from '@ariakit/react'; import type { ElementRef } from 'react'; -import { cn } from '~/utils'; +import { cn, disabledInkClasses } from '~/utils'; import './AnimatedTabs.css'; import { JSX } from 'react/jsx-runtime'; @@ -60,7 +60,11 @@ const Tab = forwardRef, Ariakit.TabProps>(functio else if (ref) ref.current = node; }} {...props} - className={`animated-tab aria-selected:text-text-primary flex items-center justify-center gap-2 border-none text-sm font-medium whitespace-nowrap outline-hidden transition-colors select-none aria-disabled:opacity-50 ${props.className || ''}`} + className={cn( + 'animated-tab aria-selected:text-text-primary flex items-center justify-center gap-2 border-none text-sm font-medium whitespace-nowrap outline-hidden transition-colors select-none aria-disabled:opacity-50', + disabledInkClasses, + props.className, + )} /> ); }); diff --git a/packages/client/src/components/Checkbox.tsx b/packages/client/src/components/Checkbox.tsx index ff0dcfc225..f26f44d7d3 100644 --- a/packages/client/src/components/Checkbox.tsx +++ b/packages/client/src/components/Checkbox.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; import { Check } from 'lucide-react'; import * as CheckboxPrimitive from '@radix-ui/react-checkbox'; -import { cn } from '~/utils'; +import { cn, disabledFillClasses } from '~/utils'; type BaseCheckboxProps = Omit< React.ComponentPropsWithoutRef, @@ -28,6 +28,7 @@ const Checkbox: React.ForwardRefExoticComponent< ref={ref} className={cn( 'peer border-border-xheavy ring-offset-surface-primary focus-visible:ring-focus-control data-[state=checked]:bg-surface-inverted data-[state=checked]:text-text-inverted h-4 w-4 shrink-0 rounded-sm border focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-50', + disabledFillClasses, className, )} {...props} diff --git a/packages/client/src/components/Combobox.tsx b/packages/client/src/components/Combobox.tsx index 47c68fc6b1..aa1b1b9c35 100644 --- a/packages/client/src/components/Combobox.tsx +++ b/packages/client/src/components/Combobox.tsx @@ -13,8 +13,8 @@ import { import type { OptionWithIcon } from '~/common'; import { SelectTrigger, SelectValue, SelectScrollDownButton } from './Select'; import { useNestedPopoverStyle } from './OriginalDialog'; +import { cn, disabledInkClasses } from '~/utils'; import { useCombobox } from '~/hooks'; -import { cn } from '~/utils'; export default function ComboboxComponent({ selectedValue, @@ -145,6 +145,7 @@ export default function ComboboxComponent({ = DialogPrimitive.Root; @@ -145,6 +145,7 @@ const DialogClose: React.ForwardRefExoticComponent< ref={ref} className={cn( 'border-border-light text-text-primary hover:bg-surface-hover mt-2 inline-flex h-10 items-center justify-center rounded-lg border bg-transparent px-4 py-2 text-sm font-semibold transition-colors focus:outline-hidden disabled:cursor-not-allowed disabled:opacity-50 sm:mt-0', + disabledFillClasses, className ?? '', /* Important: for accessibility */ 'focus:ring-focus-control focus:ring-2 focus:ring-offset-2', @@ -166,6 +167,7 @@ const DialogButton: React.ForwardRefExoticComponent< variant="outline" className={cn( 'border-border-light text-text-primary hover:bg-surface-hover focus:ring-focus-control mt-2 inline-flex h-10 items-center justify-center rounded-lg border bg-transparent px-4 py-2 text-sm font-semibold transition-colors focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:cursor-not-allowed disabled:opacity-50 sm:mt-0', + disabledFillClasses, className ?? '', /* Important: for accessibility */ 'focus:ring-focus-control focus:ring-2 focus:ring-offset-2', diff --git a/packages/client/src/components/DialogTemplate.tsx b/packages/client/src/components/DialogTemplate.tsx index ab3f02930e..5623067745 100644 --- a/packages/client/src/components/DialogTemplate.tsx +++ b/packages/client/src/components/DialogTemplate.tsx @@ -7,7 +7,7 @@ import { DialogHeader, DialogTitle, } from './Dialog'; -import { cn } from '~/utils/'; +import { cn, disabledFillClasses } from '~/utils'; type SelectionProps = { selectHandler?: () => void; @@ -48,20 +48,22 @@ const DialogTemplate: ForwardRefExoticComponent< const { selectHandler, selectClasses, selectText } = selection || {}; const Cancel = 'cancel'; - const defaultSelect = - 'bg-surface-inverted text-text-inverted transition-colors hover:bg-surface-inverted-hover disabled:cursor-not-allowed disabled:opacity-50'; + const defaultSelect = cn( + 'bg-surface-inverted text-text-inverted transition-colors hover:bg-surface-inverted-hover disabled:cursor-not-allowed disabled:opacity-50', + disabledFillClasses, + ); return ( e.stopPropagation()} > - + {title} {description && ( diff --git a/packages/client/src/components/Dropdown.tsx b/packages/client/src/components/Dropdown.tsx index 79e4495efe..ca9d909c7d 100644 --- a/packages/client/src/components/Dropdown.tsx +++ b/packages/client/src/components/Dropdown.tsx @@ -4,8 +4,8 @@ import { matchSorter } from 'match-sorter'; import * as Select from '@ariakit/react/select'; import * as Combobox from '@ariakit/react/combobox'; import type { Option } from '~/common'; +import { cn, disabledFillClasses } from '~/utils'; import { fieldControl } from './Field'; -import { cn } from '~/utils/'; import './Dropdown.css'; interface DropdownProps { @@ -152,6 +152,7 @@ const Dropdown: React.FC = ({ className={cn( 'border-border-control text-text-primary hover:bg-surface-hover hover:text-text-primary relative inline-flex items-center justify-between rounded-xl border bg-transparent py-2 text-sm transition-all duration-200 ease-in-out', 'disabled:hover:text-text-primary disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-transparent', + disabledFillClasses, /** Horizontal padding would squeeze the icon, which flex-shrinks to fit */ iconOnly ? 'size-10 justify-center px-0' : 'w-fit gap-2 px-3', variant === 'field' && fieldControl, diff --git a/packages/client/src/components/DropdownMenu.tsx b/packages/client/src/components/DropdownMenu.tsx index cdb31b3d25..4bcf059e1b 100644 --- a/packages/client/src/components/DropdownMenu.tsx +++ b/packages/client/src/components/DropdownMenu.tsx @@ -3,7 +3,7 @@ import { JSX } from 'react/jsx-runtime'; import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu'; import { CheckIcon, ChevronRightIcon, CircleIcon } from 'lucide-react'; import { usePopoverZIndex } from './OriginalDialog'; -import { cn } from '~/utils'; +import { cn, disabledInkClasses } from '~/utils'; function DropdownMenu({ ...props @@ -68,6 +68,7 @@ function DropdownMenuItem({ data-variant={variant} className={cn( "focus:bg-surface-hover focus:text-text-primary data-[variant=destructive]:text-text-destructive data-[variant=destructive]:focus:bg-status-error-subtle data-[variant=destructive]:focus:text-text-destructive [&_svg:not([class*='text-'])]:text-text-secondary relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", + disabledInkClasses, className, )} {...props} @@ -86,6 +87,7 @@ function DropdownMenuCheckboxItem({ data-slot="dropdown-menu-checkbox-item" className={cn( "focus:bg-surface-hover focus:text-text-primary relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", + disabledInkClasses, className, )} checked={checked} @@ -117,6 +119,7 @@ function DropdownMenuRadioItem({ data-slot="dropdown-menu-radio-item" className={cn( "focus:bg-surface-hover focus:text-text-primary relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", + disabledInkClasses, className, )} {...props} diff --git a/packages/client/src/components/DropdownPopup.tsx b/packages/client/src/components/DropdownPopup.tsx index 038186a2a3..ab6dfd4ad5 100644 --- a/packages/client/src/components/DropdownPopup.tsx +++ b/packages/client/src/components/DropdownPopup.tsx @@ -2,7 +2,7 @@ import React from 'react'; import * as Ariakit from '@ariakit/react'; import type * as t from '~/common'; import { usePopoverZIndex } from './OriginalDialog'; -import { cn } from '~/utils'; +import { cn, disabledInkClasses } from '~/utils'; import './Dropdown.css'; interface DropdownProps { @@ -113,6 +113,7 @@ const Menu: React.FC = ({ = ({ id={item.id} className={cn( 'group text-text-primary hover:bg-surface-hover focus:bg-surface-hover flex w-full cursor-pointer items-center gap-2 rounded-lg px-3 py-3.5 text-sm outline-hidden md:px-2.5 md:py-2', + disabledInkClasses, itemClassName, item.className, )} diff --git a/packages/client/src/components/Field.ts b/packages/client/src/components/Field.ts index c2177e8ffd..377a9a24b3 100644 --- a/packages/client/src/components/Field.ts +++ b/packages/client/src/components/Field.ts @@ -1,3 +1,5 @@ +import { disabledFillClasses } from '~/utils/theme'; + /** * The shared appearance of a form control: border, radius, type scale and focus * treatment. Owned here so `Input`, `Textarea`, and the select/combobox triggers @@ -6,8 +8,7 @@ * border is `border-control` because it is the only edge the control has, so a * palette can raise it to the 3:1 non-text floor without touching separators. */ -export const fieldBase: string = - 'lc-field flex w-full rounded-lg border border-border-control px-3 py-2 text-sm text-text-primary placeholder:text-text-secondary focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-focus-control disabled:cursor-not-allowed disabled:opacity-50'; +export const fieldBase: string = `lc-field flex w-full rounded-lg border border-border-control px-3 py-2 text-sm text-text-primary placeholder:text-text-secondary focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-focus-control disabled:cursor-not-allowed disabled:opacity-50 ${disabledFillClasses}`; /** A single-line control sized to sit in a form row, matching `Input`. */ export const fieldControl: string = `${fieldBase} h-10 bg-transparent`; diff --git a/packages/client/src/components/FilterInput.tsx b/packages/client/src/components/FilterInput.tsx index 0fc66c2173..43b0620dda 100644 --- a/packages/client/src/components/FilterInput.tsx +++ b/packages/client/src/components/FilterInput.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { cn } from '~/utils'; +import { cn, disabledFillClasses, peerDisabledInkClasses } from '~/utils'; export interface FilterInputProps extends Omit, 'placeholder'> { @@ -48,13 +48,17 @@ const FilterInput: React.ForwardRefExoticComponent< aria-label={label} className={cn( 'peer border-border-light text-text-primary ring-offset-surface-primary placeholder:text-text-secondary flex h-9 w-full rounded-lg border bg-transparent px-3 py-2 text-sm focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-50', + disabledFillClasses, className, )} {...props} /> diff --git a/packages/client/src/components/IconButton.tsx b/packages/client/src/components/IconButton.tsx index b3c2fc8af0..9100bb132a 100644 --- a/packages/client/src/components/IconButton.tsx +++ b/packages/client/src/components/IconButton.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import { cva } from 'class-variance-authority'; import type { ClassProp } from 'class-variance-authority/types'; import { composerSubmitClasses } from '~/utils/composer'; +import { disabledFillClasses } from '~/utils/theme'; import { cn } from '~/utils'; type IconButtonVariantProps = { @@ -19,21 +20,29 @@ type IconButtonVariantProps = { }; const iconButtonVariants: (props?: IconButtonVariantProps & ClassProp) => string = cva( - 'inline-flex shrink-0 items-center justify-center text-text-primary transition-colors duration-theme-fast focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-focus-control focus-visible:ring-offset-2 focus-visible:ring-offset-surface-primary disabled:pointer-events-none disabled:opacity-50', + [ + 'inline-flex shrink-0 items-center justify-center text-text-primary transition-colors duration-theme-fast focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-focus-control focus-visible:ring-offset-2 focus-visible:ring-offset-surface-primary disabled:pointer-events-none disabled:opacity-50', + disabledFillClasses, + ], { variants: { variant: { - default: 'bg-surface-secondary hover:bg-surface-hover', - primary: 'bg-surface-inverted text-text-inverted hover:bg-surface-inverted-hover', - secondary: 'border border-border-light bg-surface-secondary hover:bg-surface-hover', - ghost: 'bg-transparent hover:bg-surface-hover', + default: 'bg-surface-secondary hover:bg-surface-hover hover:active:bg-surface-pressed', + primary: + 'bg-surface-inverted text-text-inverted hover:bg-surface-inverted-hover hover:active:bg-surface-inverted-pressed', + secondary: + 'border border-border-light bg-surface-secondary hover:bg-surface-hover hover:active:bg-surface-pressed', + ghost: 'bg-transparent hover:bg-surface-hover hover:active:bg-surface-pressed', /** An action inside a list row whose highlight is already `surface-hover`, * so its own hover takes the active fill to stay visible on top of it. */ 'row-action': 'bg-transparent hover:bg-surface-active', destructive: 'bg-surface-destructive text-text-on-status hover:bg-surface-destructive-hover', /** The composer's submit slot: send, stop and the during-run send share it. */ - submit: cn('hover:bg-surface-inverted-hover', composerSubmitClasses()), + submit: cn( + 'hover:bg-surface-inverted-hover hover:active:bg-surface-inverted-pressed', + composerSubmitClasses(), + ), }, size: { xs: 'size-6', diff --git a/packages/client/src/components/InputNumber.tsx b/packages/client/src/components/InputNumber.tsx index d18f17f563..6d149940ca 100644 --- a/packages/client/src/components/InputNumber.tsx +++ b/packages/client/src/components/InputNumber.tsx @@ -5,7 +5,7 @@ import * as React from 'react'; import RCInputNumber from 'rc-input-number'; import * as InputNumberPrimitive from 'rc-input-number'; import type { ValueType } from '@rc-component/mini-decimal'; -import { cn } from '~/utils'; +import { cn, disabledWithinFillClasses } from '~/utils'; // TODO help needed // React.ElementRef, @@ -19,6 +19,7 @@ const InputNumber: React.ForwardRefExoticComponent< = T | { label: string; value: T }; @@ -147,6 +147,7 @@ export default function MultiSelect({ 'flex items-center justify-between gap-2 rounded-xl px-3 py-2 text-sm', 'bg-surface-tertiary text-text-primary hover:bg-surface-hover shadow-xs hover:cursor-pointer', 'disabled:hover:bg-surface-tertiary disabled:cursor-not-allowed disabled:opacity-60', + disabledFillClasses, 'focus-visible:ring-focus-control outline-hidden focus-visible:ring-2 focus-visible:outline-hidden', selectClassName, selectedValues.length > 0 && selectItemsClassName != null && selectItemsClassName, diff --git a/packages/client/src/components/Radio.tsx b/packages/client/src/components/Radio.tsx index 86070ff093..7f59490ccf 100644 --- a/packages/client/src/components/Radio.tsx +++ b/packages/client/src/components/Radio.tsx @@ -1,4 +1,5 @@ import React, { useState, useRef, useLayoutEffect, useCallback, memo } from 'react'; +import { disabledInkClasses } from '~/utils'; import { useLocalize } from '~/hooks'; /** Matches the `inset-y-1` the single-row indicator uses. */ @@ -190,7 +191,7 @@ const Radio: React.NamedExoticComponent = memo(function Radio({ disabled={disabled} className={`focus-visible:ring-focus-control relative z-10 flex h-[34px] items-center justify-center gap-2 rounded-md px-4 text-sm font-medium transition-colors duration-150 focus-visible:ring-2 focus-visible:outline-hidden ${ currentValue === option.value ? 'text-text-primary' : 'text-text-secondary' - } ${disabled ? 'cursor-not-allowed opacity-50' : ''} ${fullWidth ? 'flex-1' : ''} ${buttonClassName}`} + } ${disabled ? 'cursor-not-allowed opacity-50' : ''} ${disabledInkClasses} ${fullWidth ? 'flex-1' : ''} ${buttonClassName}`} > {option.icon && (