mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-17 21:43:06 +00:00
🎚️ refactor: Give InputNumber an Option Variant for Setting Values (#16831)
Some checks failed
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been cancelled
Some checks failed
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been cancelled
* refactor: Give InputNumber an Option Variant for Setting Values * fix: Ship the Option InputNumber Reset With the Package Stylesheet * refactor: Prune the Setting Value Suppressions After Rebase
This commit is contained in:
parent
1c3c6f7bc5
commit
d397ecc9ff
11 changed files with 128 additions and 94 deletions
|
|
@ -137,13 +137,8 @@ export default function Settings({
|
|||
min={0}
|
||||
step={0.01}
|
||||
controls={false}
|
||||
className={cn(
|
||||
defaultTextProps,
|
||||
cn(
|
||||
optionText,
|
||||
'reset-rc-number-input reset-rc-number-input-text-right group-hover/temp:border-border-light h-auto w-12 border-0',
|
||||
),
|
||||
)}
|
||||
variant="option"
|
||||
className="w-12"
|
||||
/>
|
||||
</div>
|
||||
<Slider
|
||||
|
|
@ -178,13 +173,8 @@ export default function Settings({
|
|||
min={0}
|
||||
step={0.01}
|
||||
controls={false}
|
||||
className={cn(
|
||||
defaultTextProps,
|
||||
cn(
|
||||
optionText,
|
||||
'reset-rc-number-input reset-rc-number-input-text-right group-hover/temp:border-border-light h-auto w-12 border-0',
|
||||
),
|
||||
)}
|
||||
variant="option"
|
||||
className="w-12"
|
||||
/>
|
||||
</div>
|
||||
<Slider
|
||||
|
|
@ -220,13 +210,8 @@ export default function Settings({
|
|||
min={-2}
|
||||
step={0.01}
|
||||
controls={false}
|
||||
className={cn(
|
||||
defaultTextProps,
|
||||
cn(
|
||||
optionText,
|
||||
'reset-rc-number-input reset-rc-number-input-text-right group-hover/temp:border-border-light h-auto w-12 border-0',
|
||||
),
|
||||
)}
|
||||
variant="option"
|
||||
className="w-12"
|
||||
/>
|
||||
</div>
|
||||
<Slider
|
||||
|
|
@ -262,13 +247,8 @@ export default function Settings({
|
|||
min={-2}
|
||||
step={0.01}
|
||||
controls={false}
|
||||
className={cn(
|
||||
defaultTextProps,
|
||||
cn(
|
||||
optionText,
|
||||
'reset-rc-number-input reset-rc-number-input-text-right group-hover/temp:border-border-light h-auto w-12 border-0',
|
||||
),
|
||||
)}
|
||||
variant="option"
|
||||
className="w-12"
|
||||
/>
|
||||
</div>
|
||||
<Slider
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import React, { useState, useEffect } from 'react';
|
||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
import { Slider, InputNumber, Switch } from '@librechat/client';
|
||||
import { cn, defaultTextProps, optionText } from '~/utils/';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import store from '~/store';
|
||||
|
||||
|
|
@ -70,7 +69,7 @@ export default function AutoSendTextSelector() {
|
|||
{isEnabled && (
|
||||
<div className="mt-2 flex items-center justify-between">
|
||||
<div className="flex items-center justify-between">
|
||||
<div id="auto-send-delay-label" className="text-sm text-text-secondary">
|
||||
<div id="auto-send-delay-label" className="text-text-secondary text-sm">
|
||||
{localize('com_nav_setting_delay')}
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -99,13 +98,8 @@ export default function AutoSendTextSelector() {
|
|||
min={0}
|
||||
max={60}
|
||||
aria-labelledby="auto-send-delay-label"
|
||||
className={cn(
|
||||
defaultTextProps,
|
||||
cn(
|
||||
optionText,
|
||||
'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-border-light',
|
||||
),
|
||||
)}
|
||||
variant="option"
|
||||
className="w-12"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import React from 'react';
|
||||
import { Slider, InputNumber } from '@librechat/client';
|
||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
import { cn, defaultTextProps, optionText } from '~/utils';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import store from '~/store';
|
||||
|
||||
|
|
@ -15,7 +14,7 @@ export default function DecibelSelector() {
|
|||
<div className="flex items-center justify-between">
|
||||
<div id="decibel-selector-label">{localize('com_nav_db_sensitivity')}</div>
|
||||
<div className="w-2" />
|
||||
<small className="opacity-40 high-contrast:opacity-100">
|
||||
<small className="high-contrast:opacity-100 opacity-40">
|
||||
({localize('com_endpoint_default_with_num', { 0: '-45' })})
|
||||
</small>
|
||||
</div>
|
||||
|
|
@ -39,13 +38,8 @@ export default function DecibelSelector() {
|
|||
min={-100}
|
||||
max={-30}
|
||||
aria-labelledby="decibel-selector-label"
|
||||
className={cn(
|
||||
defaultTextProps,
|
||||
cn(
|
||||
optionText,
|
||||
'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-border-light',
|
||||
),
|
||||
)}
|
||||
variant="option"
|
||||
className="w-12"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import React from 'react';
|
||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
import { Slider, InputNumber } from '@librechat/client';
|
||||
import { cn, defaultTextProps, optionText } from '~/utils';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import store from '~/store';
|
||||
|
||||
|
|
@ -15,7 +14,7 @@ export default function DecibelSelector() {
|
|||
<div className="flex items-center justify-between">
|
||||
<div id="playback-rate-label">{localize('com_nav_playback_rate')}</div>
|
||||
<div className="w-2" />
|
||||
<small className="opacity-40 high-contrast:opacity-100">
|
||||
<small className="high-contrast:opacity-100 opacity-40">
|
||||
({localize('com_endpoint_default_with_num', { 0: '1' })})
|
||||
</small>
|
||||
</div>
|
||||
|
|
@ -39,13 +38,8 @@ export default function DecibelSelector() {
|
|||
min={0.1}
|
||||
max={2}
|
||||
aria-labelledby="playback-rate-label"
|
||||
className={cn(
|
||||
defaultTextProps,
|
||||
cn(
|
||||
optionText,
|
||||
'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-border-light',
|
||||
),
|
||||
)}
|
||||
variant="option"
|
||||
className="w-12"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -386,16 +386,6 @@ html.high-contrast.dark .btn-neutral:hover {
|
|||
}
|
||||
}
|
||||
|
||||
.reset-rc-number-input input {
|
||||
width: 100%;
|
||||
border: none !important;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.reset-rc-number-input-text-right input {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
p > small {
|
||||
opacity: 0;
|
||||
animation: fadein 3s forwards;
|
||||
|
|
|
|||
62
e2e/specs/mock/scenarios/input-number-reset.spec.ts
Normal file
62
e2e/specs/mock/scenarios/input-number-reset.spec.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import { expect, test } from '@playwright/test';
|
||||
import type { Page } from '@playwright/test';
|
||||
import { NEW_CHAT_PATH } from '../helpers';
|
||||
|
||||
/**
|
||||
* The `option` InputNumber variant resets the input rc-input-number nests in its wrapper. The reset
|
||||
* ships with the component's own stylesheet, so any consumer of `@librechat/client` gets it, and
|
||||
* the app renders the nested input exactly as it did when the rule lived in the app stylesheet.
|
||||
*/
|
||||
|
||||
type Mode = 'light' | 'dark';
|
||||
type Reset = { width: string; borderStyle: string; background: string; textAlign: string };
|
||||
|
||||
async function probeReset(page: Page, mode: Mode): Promise<Reset> {
|
||||
await page.addInitScript((appearance) => {
|
||||
localStorage.setItem('color-theme', appearance);
|
||||
}, mode);
|
||||
await page.goto(NEW_CHAT_PATH, { timeout: 15000 });
|
||||
await expect(page.getByRole('textbox', { name: 'Message input' })).toBeVisible({
|
||||
timeout: 30000,
|
||||
});
|
||||
await expect(page.locator('html')).toHaveClass(mode === 'dark' ? /\bdark\b/ : /\blight\b/);
|
||||
return page.evaluate(() => {
|
||||
const wrapper = document.createElement('div');
|
||||
wrapper.style.width = '120px';
|
||||
wrapper.className = 'reset-rc-number-input reset-rc-number-input-text-right';
|
||||
const input = document.createElement('input');
|
||||
input.style.border = '1px solid red';
|
||||
wrapper.append(input);
|
||||
document.body.append(wrapper);
|
||||
const style = getComputedStyle(input);
|
||||
const result = {
|
||||
width: style.width,
|
||||
borderStyle: style.borderTopStyle,
|
||||
background: style.backgroundColor,
|
||||
textAlign: style.textAlign,
|
||||
};
|
||||
wrapper.remove();
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
const EXPECTED: Reset = {
|
||||
width: '120px',
|
||||
borderStyle: 'none',
|
||||
background: 'rgba(0, 0, 0, 0)',
|
||||
textAlign: 'right',
|
||||
};
|
||||
|
||||
test.describe('InputNumber option reset', () => {
|
||||
test('the nested input is reset in the light theme @scenario:input-number-reset-light', async ({
|
||||
page,
|
||||
}) => {
|
||||
expect(await probeReset(page, 'light')).toEqual(EXPECTED);
|
||||
});
|
||||
|
||||
test('the nested input is reset in the dark theme @scenario:input-number-reset-dark', async ({
|
||||
page,
|
||||
}) => {
|
||||
expect(await probeReset(page, 'dark')).toEqual(EXPECTED);
|
||||
});
|
||||
});
|
||||
|
|
@ -651,10 +651,10 @@
|
|||
},
|
||||
"client/src/components/Endpoints/Settings/Advanced.tsx": {
|
||||
"shadcn/no-restyle": {
|
||||
"count": 34
|
||||
"count": 18
|
||||
},
|
||||
"shadcn/require-static-classes": {
|
||||
"count": 12
|
||||
"count": 4
|
||||
}
|
||||
},
|
||||
"client/src/components/Endpoints/Settings/Assistants.tsx": {
|
||||
|
|
@ -887,30 +887,6 @@
|
|||
"count": 5
|
||||
}
|
||||
},
|
||||
"client/src/components/Nav/SettingsTabs/Speech/STT/AutoSendTextSelector.tsx": {
|
||||
"shadcn/no-restyle": {
|
||||
"count": 4
|
||||
},
|
||||
"shadcn/require-static-classes": {
|
||||
"count": 2
|
||||
}
|
||||
},
|
||||
"client/src/components/Nav/SettingsTabs/Speech/STT/DecibelSelector.tsx": {
|
||||
"shadcn/no-restyle": {
|
||||
"count": 4
|
||||
},
|
||||
"shadcn/require-static-classes": {
|
||||
"count": 2
|
||||
}
|
||||
},
|
||||
"client/src/components/Nav/SettingsTabs/Speech/TTS/PlaybackRate.tsx": {
|
||||
"shadcn/no-restyle": {
|
||||
"count": 4
|
||||
},
|
||||
"shadcn/require-static-classes": {
|
||||
"count": 2
|
||||
}
|
||||
},
|
||||
"client/src/components/Nav/ShortcutRecorder.tsx": {
|
||||
"shadcn/no-arbitrary-values": {
|
||||
"count": 3
|
||||
|
|
|
|||
|
|
@ -286,6 +286,8 @@ export default [
|
|||
'spinner',
|
||||
'popover-ui',
|
||||
'select-item',
|
||||
'reset-rc-number-input',
|
||||
'reset-rc-number-input-text-right',
|
||||
'assistant-item',
|
||||
'animated-tab',
|
||||
'animated-tab-list',
|
||||
|
|
|
|||
11
packages/client/src/components/InputNumber.css
Normal file
11
packages/client/src/components/InputNumber.css
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/* The rc-input-number field renders its input inside a wrapper the `option` variant classes, so
|
||||
the nested input is reset here, where the component ships, rather than in the app stylesheet. */
|
||||
.reset-rc-number-input input {
|
||||
width: 100%;
|
||||
border: none !important;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.reset-rc-number-input-text-right input {
|
||||
text-align: right;
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import React from 'react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { InputNumber } from './InputNumber';
|
||||
|
||||
|
|
@ -17,4 +18,20 @@ describe('InputNumber', () => {
|
|||
|
||||
expect(container.firstElementChild).toHaveClass('theme-disabled-within:opacity-100');
|
||||
});
|
||||
|
||||
it('keeps the bordered field by default', () => {
|
||||
render(<InputNumber aria-label="count" />);
|
||||
const wrapper = screen.getByRole('spinbutton').closest('.rc-input-number');
|
||||
|
||||
expect(wrapper).toHaveClass('w-full', 'border');
|
||||
expect(wrapper).not.toHaveClass('reset-rc-number-input');
|
||||
});
|
||||
|
||||
it('draws the option variant as a borderless value that a caller can size', () => {
|
||||
render(<InputNumber aria-label="count" variant="option" className="w-12" />);
|
||||
const wrapper = screen.getByRole('spinbutton').closest('.rc-input-number');
|
||||
|
||||
expect(wrapper).toHaveClass('border-0', 'reset-rc-number-input', 'text-right', 'w-12');
|
||||
expect(wrapper).not.toHaveClass('w-full');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,20 +6,34 @@ import RCInputNumber from 'rc-input-number';
|
|||
import * as InputNumberPrimitive from 'rc-input-number';
|
||||
import type { ValueType } from '@rc-component/mini-decimal';
|
||||
import { cn, disabledWithinFillClasses } from '~/utils';
|
||||
import './InputNumber.css';
|
||||
|
||||
// TODO help needed
|
||||
// React.ElementRef<typeof LabelPrimitive.Root>,
|
||||
// React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>
|
||||
|
||||
/** `option` is the borderless value that sits beside a setting's label, such as a slider's
|
||||
* number: it reads as text until the row is hovered or the field is focused. */
|
||||
const INPUT_NUMBER_VARIANTS: Record<'default' | 'option', string> = {
|
||||
default: '',
|
||||
option:
|
||||
'h-auto border-0 border-transparent p-0 pr-1 text-right shadow-none outline-hidden transition-colors hover:bg-surface-hover focus:border-border-heavy focus:bg-surface-secondary focus:ring-text-primary/20 focus:ring-offset-2 focus-within:placeholder:text-text-primary focus:placeholder:text-text-primary placeholder:text-text-secondary group-hover/temp:border-border-light reset-rc-number-input reset-rc-number-input-text-right',
|
||||
};
|
||||
|
||||
export type InputNumberProps = InputNumberPrimitive.InputNumberProps<ValueType> & {
|
||||
variant?: keyof typeof INPUT_NUMBER_VARIANTS;
|
||||
};
|
||||
|
||||
const InputNumber: React.ForwardRefExoticComponent<
|
||||
InputNumberPrimitive.InputNumberProps<ValueType> & React.RefAttributes<HTMLInputElement>
|
||||
> = React.forwardRef<React.ElementRef<typeof RCInputNumber>, InputNumberPrimitive.InputNumberProps>(
|
||||
({ className, ...props }, ref) => {
|
||||
InputNumberProps & React.RefAttributes<HTMLInputElement>
|
||||
> = React.forwardRef<React.ElementRef<typeof RCInputNumber>, InputNumberProps>(
|
||||
({ className, variant = 'default', ...props }, ref) => {
|
||||
return (
|
||||
<RCInputNumber
|
||||
className={cn(
|
||||
'border-border-medium text-text-primary placeholder:text-text-tertiary flex max-h-5 w-full rounded-md border bg-transparent px-3 py-2 text-sm focus:outline-hidden has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-50',
|
||||
disabledWithinFillClasses,
|
||||
INPUT_NUMBER_VARIANTS[variant],
|
||||
className ?? '',
|
||||
)}
|
||||
ref={ref}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue