Files

154 lines
5.1 KiB
TypeScript
Raw Permalink Normal View History

2026-10-23 11:43:49 -05:00
import { cn } from '@/lib/utils';
2026-10-23 19:56:38 -07:00
import React from 'react';
2026-10-23 11:43:49 -05:00
import { Icon } from './Icon';
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
label?: string;
error?: string;
icon?: string;
compact?: boolean;
suffix?: string;
rightElement?: React.ReactNode;
2026-10-23 11:43:49 -05:00
}
export const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ label, error, icon, compact = false, suffix, rightElement, className, id, ...props }, ref) => {
2026-10-23 11:43:49 -05:00
const inputId = id || (label ? label.toLowerCase().replace(/\s+/g, '-') : undefined);
return (
<div className="flex flex-col gap-1 w-full text-left">
{label && (
<label
htmlFor={inputId}
className="text-[10.5px] font-medium text-[var(--text-muted)]"
2026-10-23 11:43:49 -05:00
>
{label}
</label>
)}
<div className="relative flex items-center w-full">
{icon && (
<div className="absolute left-2 flex items-center pointer-events-none text-[var(--text-dim)]">
<Icon name={icon} size={12} />
2026-10-23 11:43:49 -05:00
</div>
)}
<input
id={inputId}
ref={ref}
className={cn(
'w-full bg-[var(--bg-main)] text-[var(--text)] border border-[var(--border-strong)] placeholder:text-[var(--text-dim)] transition-colors focus:outline-none focus:border-[var(--accent)] disabled:opacity-50 disabled:cursor-not-allowed',
compact ? 'h-7.5 px-2.5 text-[11.5px]' : 'h-8.5 px-3 text-[12px]',
icon && 'pl-7',
rightElement && 'pr-8',
2026-10-23 11:43:49 -05:00
error && 'border-[var(--danger)]',
className
)}
{...props}
/>
{rightElement && (
<div className="absolute right-0 top-0 bottom-0 flex items-center">
{rightElement}
</div>
)}
{suffix && (
<span
className={cn(
'flex shrink-0 items-center border border-l-0 border-[var(--border-strong)] bg-[var(--surface-2)] text-[var(--text-muted)] select-none',
compact ? 'h-7.5 px-2 text-[11px]' : 'h-8.5 px-2.5 text-[11.5px]'
)}
>
{suffix}
</span>
)}
2026-10-23 11:43:49 -05:00
</div>
{error && <span className="text-[11px] text-[var(--danger)]">{error}</span>}
2026-10-23 11:43:49 -05:00
</div>
);
}
);
Input.displayName = 'Input';
export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
label?: string;
error?: string;
}
export const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
({ label, error, className, id, ...props }, ref) => {
const textareaId = id || (label ? label.toLowerCase().replace(/\s+/g, '-') : undefined);
return (
<div className="flex flex-col gap-1 w-full text-left">
{label && (
<label
htmlFor={textareaId}
className="text-[10.5px] font-medium text-[var(--text-muted)]"
2026-10-23 11:43:49 -05:00
>
{label}
</label>
)}
<textarea
id={textareaId}
ref={ref}
className={cn(
'w-full bg-[var(--bg-main)] text-[var(--text)] border border-[var(--border-strong)] p-2.5 text-[12px] placeholder:text-[var(--text-dim)] focus:outline-none focus:border-[var(--accent)] min-h-[80px] resize-y font-mono',
2026-10-23 11:43:49 -05:00
error && 'border-[var(--danger)]',
className
)}
{...props}
/>
{error && <span className="text-[11px] text-[var(--danger)]">{error}</span>}
2026-10-23 11:43:49 -05:00
</div>
);
}
);
Textarea.displayName = 'Textarea';
export interface SelectProps extends React.SelectHTMLAttributes<HTMLSelectElement> {
label?: string;
error?: string;
compact?: boolean;
options?: { value: string; label: string }[];
}
export const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
({ label, error, compact = false, options, children, className, id, ...props }, ref) => {
const selectId = id || (label ? label.toLowerCase().replace(/\s+/g, '-') : undefined);
return (
<div className="flex flex-col gap-1 w-full text-left">
{label && (
<label
htmlFor={selectId}
className="text-[10.5px] font-medium text-[var(--text-muted)]"
2026-10-23 11:43:49 -05:00
>
{label}
</label>
)}
<select
id={selectId}
ref={ref}
className={cn(
'w-full bg-[var(--bg-main)] text-[var(--text)] border border-[var(--border-strong)] focus:outline-none focus:border-[var(--accent)] cursor-pointer',
compact ? 'h-7.5 px-2 text-[11.5px]' : 'h-8.5 px-2.5 text-[12px]',
2026-10-23 11:43:49 -05:00
error && 'border-[var(--danger)]',
className
)}
{...props}
>
{options
? options.map((opt) => (
<option key={opt.value} value={opt.value} className="bg-[var(--bg-elevated)] text-[var(--text)]">
{opt.label}
</option>
))
: children}
</select>
{error && <span className="text-[11px] text-[var(--danger)]">{error}</span>}
2026-10-23 11:43:49 -05:00
</div>
);
}
);
Select.displayName = 'Select';