mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-21 07:23:11 +00:00
🎨 feat: Add Secondary Label Variant and Spinner Tone (#16837)
This commit is contained in:
parent
1a86069e25
commit
38a3eb097c
4 changed files with 44 additions and 2 deletions
|
|
@ -19,6 +19,22 @@ describe('Label', () => {
|
|||
expect(label).toHaveClass('text-text-primary', 'peer-disabled:opacity-70');
|
||||
});
|
||||
|
||||
it('renders the secondary ink at the default label metrics', () => {
|
||||
render(
|
||||
<Label htmlFor="field" variant="secondary">
|
||||
Hint
|
||||
</Label>,
|
||||
);
|
||||
|
||||
expect(screen.getByText('Hint')).toHaveClass(
|
||||
'text-(length:--theme-label-size)',
|
||||
'leading-(--theme-label-leading)',
|
||||
'font-theme-label',
|
||||
'text-text-secondary',
|
||||
);
|
||||
expect(screen.getByText('Hint')).not.toHaveClass('text-text-primary');
|
||||
});
|
||||
|
||||
it('renders the section eyebrow from the shared variant', () => {
|
||||
render(
|
||||
<Label htmlFor="field" variant="section">
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { cva, type VariantProps } from 'class-variance-authority';
|
|||
import { cn, peerDisabledInkClasses } from '~/utils';
|
||||
|
||||
type LabelVariantOptions =
|
||||
| ({ variant?: 'default' | 'section' | null | undefined } & ClassProp)
|
||||
| ({ variant?: 'default' | 'secondary' | 'section' | null | undefined } & ClassProp)
|
||||
| undefined;
|
||||
|
||||
/**
|
||||
|
|
@ -22,6 +22,9 @@ const labelVariants: (props?: LabelVariantOptions) => string = cva('', {
|
|||
* surrounding weight by default. */
|
||||
default:
|
||||
'text-(length:--theme-label-size) leading-(--theme-label-leading) font-theme-label text-text-primary',
|
||||
/** The default metrics in the secondary ink, for a label that annotates rather than names. */
|
||||
secondary:
|
||||
'text-(length:--theme-label-size) leading-(--theme-label-leading) font-theme-label text-text-secondary',
|
||||
/** Eyebrow above a field or settings group. */
|
||||
section: 'text-[11px] font-medium uppercase tracking-wide text-text-secondary',
|
||||
},
|
||||
|
|
|
|||
|
|
@ -53,8 +53,16 @@ function schedulePin(svg: SVGSVGElement) {
|
|||
}
|
||||
}
|
||||
|
||||
/** `current` follows the surrounding ink; the others pin it to a text role. */
|
||||
const SPINNER_TONES = {
|
||||
current: '',
|
||||
primary: 'text-text-primary',
|
||||
secondary: 'text-text-secondary',
|
||||
} as const;
|
||||
|
||||
interface SpinnerProps {
|
||||
className?: string;
|
||||
tone?: keyof typeof SPINNER_TONES;
|
||||
size?: string | number;
|
||||
color?: string;
|
||||
bgOpacity?: number;
|
||||
|
|
@ -73,6 +81,7 @@ interface SpinnerProps {
|
|||
*/
|
||||
export default function Spinner({
|
||||
className = 'm-auto',
|
||||
tone = 'current',
|
||||
size = 20,
|
||||
color = 'currentColor',
|
||||
bgOpacity = 0.1,
|
||||
|
|
@ -115,7 +124,7 @@ export default function Spinner({
|
|||
<svg
|
||||
ref={svgRef}
|
||||
onAnimationStart={handleAnimationStart}
|
||||
className={cn(className, 'spinner')}
|
||||
className={cn(className, SPINNER_TONES[tone], 'spinner')}
|
||||
width={size}
|
||||
height={size}
|
||||
viewBox="0 0 40 40"
|
||||
|
|
|
|||
|
|
@ -229,4 +229,18 @@ describe('Spinner', () => {
|
|||
|
||||
expect(container.querySelector('svg')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('follows the surrounding ink by default and pins a text role on request', () => {
|
||||
const { container, rerender } = render(<Spinner />);
|
||||
const svg = () => container.querySelector('svg');
|
||||
|
||||
expect(svg()).not.toHaveClass('text-text-primary');
|
||||
expect(svg()).not.toHaveClass('text-text-secondary');
|
||||
|
||||
rerender(<Spinner tone="primary" />);
|
||||
expect(svg()).toHaveClass('text-text-primary');
|
||||
|
||||
rerender(<Spinner tone="secondary" />);
|
||||
expect(svg()).toHaveClass('text-text-secondary');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue