mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-19 22:43:38 +00:00
📏 feat: Size Roles for the Select List (#16714)
* feat: Size Roles for the Select List The Select list drew a fixed max-h-96 and min-w-[8rem], the last hard-coded sizes among the ten shared primitives. They are now the listMaxHeight and listMinWidth appearance roles, defaulting to 24rem and 8rem. The ClickHouse theme sizes the list by its trigger and keeps the 24rem cap, since Click UI caps it only at the viewport's available height. * test: Resize the Select List From a Reference Theme
This commit is contained in:
parent
7957d0b587
commit
f156160c99
17 changed files with 146 additions and 34 deletions
|
|
@ -1,5 +1,6 @@
|
|||
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';
|
||||
import { openSidebar } from './sidebar';
|
||||
|
||||
|
|
@ -138,3 +139,50 @@ test.describe('popovers inside a modal dialog', () => {
|
|||
await expectIndicator(page, '20px');
|
||||
});
|
||||
});
|
||||
|
||||
/** Sets both list roles apart from their defaults, so a list still drawing a fixed size shows. */
|
||||
const REFERENCE_LIST_THEME = {
|
||||
version: 1,
|
||||
name: 'e2e-list-reference',
|
||||
modes: {
|
||||
light: { appearance: { listMinWidth: '12rem', listMaxHeight: '20rem' } },
|
||||
dark: { appearance: { listMinWidth: '12rem', listMaxHeight: '20rem' } },
|
||||
},
|
||||
} as const;
|
||||
|
||||
/** The open list's width floor and scroll cap, as the browser computed them. */
|
||||
async function listBounds(page: Page) {
|
||||
return page.getByRole('listbox').evaluate((element) => {
|
||||
const style = getComputedStyle(element);
|
||||
return { minWidth: style.minWidth, maxHeight: style.maxHeight };
|
||||
});
|
||||
}
|
||||
|
||||
test.describe('Select list size roles', () => {
|
||||
test('the default theme keeps the list at 8rem wide and 24rem tall at most @scenario:select-list-size-default', async ({
|
||||
page,
|
||||
}) => {
|
||||
await offerStatefulSessions(page);
|
||||
await useTheme(page);
|
||||
await openWorkspaceSelect(page);
|
||||
expect(await listBounds(page)).toEqual({ minWidth: '128px', maxHeight: '384px' });
|
||||
});
|
||||
|
||||
test('the ClickHouse theme sizes the list by its trigger @scenario:select-list-size-clickhouse', async ({
|
||||
page,
|
||||
}) => {
|
||||
await offerStatefulSessions(page);
|
||||
await useTheme(page, clickHouseTheme);
|
||||
await openWorkspaceSelect(page);
|
||||
expect(await listBounds(page)).toEqual({ minWidth: '0px', maxHeight: '384px' });
|
||||
});
|
||||
|
||||
test('a theme that sets both list roles resizes the list @scenario:select-list-size-reference', async ({
|
||||
page,
|
||||
}) => {
|
||||
await offerStatefulSessions(page);
|
||||
await useTheme(page, REFERENCE_LIST_THEME);
|
||||
await openWorkspaceSelect(page);
|
||||
expect(await listBounds(page)).toEqual({ minWidth: '192px', maxHeight: '320px' });
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ async function sizes(page: Page): Promise<Record<string, string>> {
|
|||
['h-theme-target', 'height'],
|
||||
['min-w-theme-target', 'min-width'],
|
||||
['min-w-theme-tab', 'min-width'],
|
||||
['min-w-theme-list', 'min-width'],
|
||||
['max-h-theme-list', 'max-height'],
|
||||
['select-item', 'border-top-left-radius'],
|
||||
];
|
||||
const result: Record<string, string> = {};
|
||||
|
|
@ -87,6 +89,8 @@ const DEFAULT_SIZES = {
|
|||
'h-theme-target': '24px',
|
||||
'min-w-theme-target': '24px',
|
||||
'min-w-theme-tab': '100px',
|
||||
'min-w-theme-list': '128px',
|
||||
'max-h-theme-list': '384px',
|
||||
'select-item': '8px',
|
||||
};
|
||||
|
||||
|
|
@ -121,6 +125,7 @@ test.describe('primitive size roles', () => {
|
|||
'size-theme-icon-button-sm': '24px',
|
||||
'select-item': '4px',
|
||||
'min-w-theme-tab': '0px',
|
||||
'min-w-theme-list': '0px',
|
||||
'h-theme-field': '32px',
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import '@testing-library/jest-dom';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { Select, SelectTrigger, SelectValue } from './Select';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './Select';
|
||||
|
||||
describe('SelectTrigger', () => {
|
||||
/** The trigger hid the outline on every focus and drew nothing in its place, so a keyboard
|
||||
|
|
@ -23,3 +23,21 @@ describe('SelectTrigger', () => {
|
|||
expect(trigger).not.toHaveClass('focus:outline-hidden');
|
||||
});
|
||||
});
|
||||
|
||||
describe('SelectContent', () => {
|
||||
/** The list's width floor and scroll cap are theme roles, so a theme can retune both. */
|
||||
it('bounds the list with the list size roles', () => {
|
||||
render(
|
||||
<Select open value="one">
|
||||
<SelectTrigger aria-label="Model">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="one">One</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>,
|
||||
);
|
||||
|
||||
expect(screen.getByRole('listbox')).toHaveClass('min-w-theme-list', 'max-h-theme-list');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ const SelectContent: React.ForwardRefExoticComponent<
|
|||
(see `useNestedPopoverStyle`); elsewhere `z-40` applies. */
|
||||
style={{ zIndex: nested ? zIndex : undefined, ...style }}
|
||||
className={cn(
|
||||
'border-border-light bg-surface-secondary text-text-primary data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-40 max-h-96 min-w-[8rem] overflow-hidden rounded-md border shadow-md',
|
||||
'border-border-light bg-surface-secondary text-text-primary data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 max-h-theme-list min-w-theme-list relative z-40 overflow-hidden rounded-md border shadow-md',
|
||||
position === 'popper'
|
||||
? 'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1'
|
||||
: '',
|
||||
|
|
|
|||
|
|
@ -367,7 +367,8 @@ Each status family has a foreground, a `-subtle` background, a `-border`, and a
|
|||
`size-theme-icon-lg` (`iconSize`, `iconSizeLg`) the icons in menus and selects and
|
||||
the dialog's close icon, `h-theme-field-lg` (`fieldHeightLg`) the large `title`
|
||||
input, and `h-theme-target` the switch's hit area, and `min-w-theme-tab` (`tabMinWidth`, `0` to size a tab by its label) the tab
|
||||
trigger. Every default is the size the primitive drew before. The icon and checkbox roles
|
||||
trigger. `min-w-theme-list` and `max-h-theme-list` (`listMinWidth`, `0` to size the list by
|
||||
its trigger, and `listMaxHeight`, 8 to 40rem) bound the Select's list. Every default is the size the primitive drew before. The icon and checkbox roles
|
||||
are bounded to the room their layouts leave: `iconSize` 0.75 to 1.25rem, `iconSizeMd` (the
|
||||
exported Dialog's close glyph) 1.25 to 1.5rem, `iconSizeLg` 1 to 2rem, `checkboxSize` 1 to
|
||||
1.5rem. The target floor (`h-theme-target`, `min-h-theme-target`, `min-w-theme-target`) is
|
||||
|
|
|
|||
|
|
@ -221,6 +221,8 @@ html {
|
|||
--theme-tooltip-radius: 0.275rem;
|
||||
--theme-tab-radius: 0.185rem;
|
||||
--theme-tab-min-width: 100px;
|
||||
--theme-list-min-width: 8rem;
|
||||
--theme-list-max-height: 24rem;
|
||||
--theme-radius-sm: calc(0.5rem - 4px);
|
||||
--theme-radius-md: calc(0.5rem - 2px);
|
||||
--theme-radius-lg: 0.5rem;
|
||||
|
|
|
|||
|
|
@ -7,9 +7,8 @@ import { readFileSync } from 'fs';
|
|||
* raw palette utilities, hex/rgb/hsl literals, arbitrary corners and shadows, fixed size
|
||||
* utilities (`h-4`, `size-10`, `min-w-[8rem]`; a fraction such as `w-11/12`, a viewport unit or a
|
||||
* value read from the component library is relative, and a `0` is a reset, not a size), literal
|
||||
* corners and shadows in its stylesheet, and design-rule suppressions. Move a primitive into
|
||||
* `themeDriven` when a change clears it; the remaining values of the others are pinned so a new
|
||||
* literal fails by name.
|
||||
* corners and shadows in its stylesheet, and design-rule suppressions. All ten are theme-driven,
|
||||
* so a new literal in any of them fails by name.
|
||||
*/
|
||||
|
||||
const components = join(__dirname, '../components');
|
||||
|
|
@ -28,24 +27,6 @@ const primitives: Record<string, string[]> = {
|
|||
Tooltip: ['Tooltip.tsx', 'Tooltip.css'],
|
||||
};
|
||||
|
||||
const themeDriven = [
|
||||
'Button',
|
||||
'Input',
|
||||
'Dialog',
|
||||
'Menu',
|
||||
'Tabs',
|
||||
'Switch',
|
||||
'Checkbox',
|
||||
'Table',
|
||||
'Tooltip',
|
||||
];
|
||||
|
||||
/** What the other still hard-codes, and why it stays. */
|
||||
const remaining: Record<string, string[]> = {
|
||||
/** The list's scroll cap and its minimum width have no role. */
|
||||
Select: ['Select.tsx: arbitrary size min-w-[8rem]', 'Select.tsx: fixed size h-96'],
|
||||
};
|
||||
|
||||
const suppressions: Record<string, Record<string, { count: number }>> = JSON.parse(
|
||||
readFileSync(join(repoRoot, 'eslint-suppressions.json'), 'utf8'),
|
||||
);
|
||||
|
|
@ -158,11 +139,8 @@ const values = Object.fromEntries(
|
|||
);
|
||||
|
||||
describe('the ten named primitives', () => {
|
||||
it('draws at least eight of them from theme roles alone', () => {
|
||||
const driven = Object.keys(primitives).filter((name) => values[name].length === 0);
|
||||
|
||||
expect(driven).toEqual(themeDriven);
|
||||
expect(driven.length).toBeGreaterThanOrEqual(8);
|
||||
it.each(Object.keys(primitives))('draws %s from theme roles alone', (name) => {
|
||||
expect(values[name]).toEqual([]);
|
||||
});
|
||||
|
||||
it('reads any raw palette hue under any color utility', () => {
|
||||
|
|
@ -184,8 +162,4 @@ describe('the ten named primitives', () => {
|
|||
'.a { box-shadow: var(--local-shadow, 0 1px #000); }',
|
||||
);
|
||||
});
|
||||
|
||||
it.each(Object.keys(remaining))('pins what %s still hard-codes', (name) => {
|
||||
expect(values[name]).toEqual(remaining[name]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1141,9 +1141,31 @@ describe('theme registry', () => {
|
|||
iconButtonSizeSm: '2rem',
|
||||
fieldHeightLg: '3rem',
|
||||
checkboxSize: '1rem',
|
||||
listMinWidth: '8rem',
|
||||
listMaxHeight: '24rem',
|
||||
});
|
||||
});
|
||||
|
||||
it("bounds a Select list's width and scroll height", () => {
|
||||
const issues = (appearance: Record<string, string>) =>
|
||||
validateThemeDefinition({
|
||||
version: 1,
|
||||
name: 'list-values',
|
||||
modes: { light: { appearance } },
|
||||
});
|
||||
|
||||
expect(issues({ listMinWidth: '0', listMaxHeight: '8rem' })).toEqual([]);
|
||||
expect(issues({ listMinWidth: '12rem', listMaxHeight: '640px' })).toEqual([]);
|
||||
[
|
||||
{ listMinWidth: 'auto' },
|
||||
{ listMinWidth: '-1rem' },
|
||||
{ listMaxHeight: '0' },
|
||||
{ listMaxHeight: '7rem' },
|
||||
{ listMaxHeight: '41rem' },
|
||||
{ listMaxHeight: '50vh' },
|
||||
].forEach((appearance) => expect(issues(appearance)).toHaveLength(1));
|
||||
});
|
||||
|
||||
it('rejects a pointer target under 24px and a size that is not a positive length', () => {
|
||||
const issues = (appearance: Record<string, string>) =>
|
||||
validateThemeDefinition({
|
||||
|
|
|
|||
|
|
@ -167,6 +167,8 @@ export const themeAppearanceProperties: Readonly<
|
|||
tooltipRadius: '--theme-tooltip-radius',
|
||||
tabRadius: '--theme-tab-radius',
|
||||
tabMinWidth: '--theme-tab-min-width',
|
||||
listMinWidth: '--theme-list-min-width',
|
||||
listMaxHeight: '--theme-list-max-height',
|
||||
radiusSm: '--theme-radius-sm',
|
||||
radiusMd: '--theme-radius-md',
|
||||
radiusLg: '--theme-radius-lg',
|
||||
|
|
@ -253,6 +255,8 @@ export const defaultAppearance: IThemeAppearance = Object.freeze({
|
|||
tooltipRadius: '0.275rem',
|
||||
tabRadius: '0.185rem',
|
||||
tabMinWidth: '100px',
|
||||
listMinWidth: '8rem',
|
||||
listMaxHeight: '24rem',
|
||||
radiusSm: 'calc(0.5rem - 4px)',
|
||||
radiusMd: 'calc(0.5rem - 2px)',
|
||||
radiusLg: '0.5rem',
|
||||
|
|
|
|||
|
|
@ -159,6 +159,8 @@ describe('LibreChat Tailwind preset', () => {
|
|||
],
|
||||
['rounded-theme-tab', '--theme-tab-radius', defaultAppearance.tabRadius],
|
||||
['min-w-theme-tab', '--theme-tab-min-width', defaultAppearance.tabMinWidth],
|
||||
['min-w-theme-list', '--theme-list-min-width', defaultAppearance.listMinWidth],
|
||||
['max-h-theme-list', '--theme-list-max-height', defaultAppearance.listMaxHeight],
|
||||
['h-theme-button-xs', '--theme-button-height-xs', defaultAppearance.buttonHeightXs],
|
||||
['h-theme-button-lg', '--theme-button-height-lg', defaultAppearance.buttonHeightLg],
|
||||
[
|
||||
|
|
|
|||
|
|
@ -386,6 +386,12 @@ const clickHouseShape = {
|
|||
tabRadius: '0.25rem', // tabs.radii.all
|
||||
/** Click UI sizes a tab trigger by its label, in `tabs.space.x` on each side. */
|
||||
tabMinWidth: '0',
|
||||
/** Click UI's select list is as wide as its trigger (`select-popover-content` in
|
||||
* SelectComponents.module.css), which the list's viewport already enforces, so it takes no
|
||||
* floor of its own. Its height is capped only by the viewport's available height, which a
|
||||
* length role cannot express, so the cap keeps LibreChat's. */
|
||||
listMinWidth: '0',
|
||||
listMaxHeight: '24rem',
|
||||
radiusSm: '0.25rem', // border.radii.1
|
||||
radiusMd: '0.25rem', // border.radii.1
|
||||
radiusLg: '0.25rem', // border.radii.1
|
||||
|
|
|
|||
|
|
@ -529,6 +529,18 @@ const appearanceDecisions: Partial<Record<keyof IThemeAppearance, AppearanceDeci
|
|||
status: 'match',
|
||||
reason: '0: Click UI sizes tab triggers by their label in tabs.space.x, with no minimum width',
|
||||
},
|
||||
listMinWidth: {
|
||||
value: '0',
|
||||
status: 'match',
|
||||
reason:
|
||||
'0: Click UI draws its select list at var(--radix-popover-trigger-width) (select-popover-content), with no minimum of its own',
|
||||
},
|
||||
listMaxHeight: {
|
||||
value: '24rem',
|
||||
status: 'mismatch',
|
||||
reason:
|
||||
"24rem: Click UI caps its select list only at var(--radix-popover-content-available-height), which a length role cannot express, so the cap keeps LibreChat's",
|
||||
},
|
||||
iconButtonSizeSm: {
|
||||
value: '1.5rem',
|
||||
status: 'match',
|
||||
|
|
@ -1859,6 +1871,7 @@ describe('ClickHouse primitive parity against Click UI components', () => {
|
|||
|
||||
expect(moved).toEqual([]);
|
||||
expect(statuses.filter(([, status]) => status === 'mismatch').map(([key]) => key)).toEqual([
|
||||
'listMaxHeight',
|
||||
'text2xl',
|
||||
]);
|
||||
expect(statuses.filter(([, status]) => status === 'near').map(([key]) => key)).toEqual([]);
|
||||
|
|
|
|||
|
|
@ -520,6 +520,10 @@ export interface IThemeAppearance {
|
|||
tabRadius: string;
|
||||
/** The narrowest a tab trigger draws; `0` sizes it by its label. */
|
||||
tabMinWidth: string;
|
||||
/** The narrowest a Select's list draws; `0` sizes it by its trigger and options. */
|
||||
listMinWidth: string;
|
||||
/** The tallest a Select's list draws before it scrolls, 8 to 40rem. */
|
||||
listMaxHeight: string;
|
||||
radiusSm: string;
|
||||
radiusMd: string;
|
||||
radiusLg: string;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ describe('cn', () => {
|
|||
['h-theme-control', 'size-theme-control'],
|
||||
['min-w-theme-target', 'min-w-0'],
|
||||
['min-h-theme-target', 'min-h-0'],
|
||||
['min-w-theme-list', 'min-w-48'],
|
||||
['max-h-theme-list', 'max-h-60'],
|
||||
])('lets a caller size replace %s', (role, caller) => {
|
||||
expect(cn(role, caller)).toBe(caller);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -37,7 +37,8 @@ const twMerge = extendTailwindMerge({
|
|||
],
|
||||
},
|
||||
],
|
||||
'min-w': [{ 'min-w': ['theme-tab', 'theme-target'] }],
|
||||
'min-w': [{ 'min-w': ['theme-tab', 'theme-list', 'theme-target'] }],
|
||||
'max-h': [{ 'max-h': ['theme-list'] }],
|
||||
'min-h': [{ 'min-h': ['theme-target'] }],
|
||||
size: [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -48,6 +48,12 @@ module.exports = {
|
|||
'theme-target': '24px',
|
||||
/** The narrowest a tab trigger draws. */
|
||||
'theme-tab': 'var(--theme-tab-min-width, 100px)',
|
||||
/** The narrowest a Select's list draws. */
|
||||
'theme-list': 'var(--theme-list-min-width, 8rem)',
|
||||
},
|
||||
maxHeight: {
|
||||
/** The tallest a Select's list draws before it scrolls. */
|
||||
'theme-list': 'var(--theme-list-max-height, 24rem)',
|
||||
},
|
||||
width: {
|
||||
/** Never narrower than the track is tall, so the knob always has somewhere to travel. */
|
||||
|
|
|
|||
|
|
@ -361,6 +361,10 @@ const appearanceValidators = {
|
|||
tooltipRadius: isLength,
|
||||
tabRadius: isLength,
|
||||
tabMinWidth: isTableLength,
|
||||
/** A Select list's narrowest width (`0` to size it by its trigger), and the height it scrolls
|
||||
* past: never under 8rem, so a few options always show, nor over 40rem. */
|
||||
listMinWidth: isTableLength,
|
||||
listMaxHeight: lengthWithin(128, 640),
|
||||
radiusSm: isLength,
|
||||
radiusMd: isLength,
|
||||
radiusLg: isLength,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue