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;
|
2026-11-16 21:58:18 +06:00
|
|
|
suffix?: string;
|
|
|
|
|
rightElement?: React.ReactNode;
|
2026-10-23 11:43:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
2026-11-16 21:58:18 +06:00
|
|
|
({ 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}
|
2026-11-16 21:58:18 +06:00
|
|
|
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 && (
|
2026-11-16 21:58:18 +06:00
|
|
|
<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',
|
2026-11-16 21:58:18 +06:00
|
|
|
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}
|
|
|
|
|
/>
|
2026-11-16 21:58:18 +06:00
|
|
|
{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>
|
2026-11-16 21:58:18 +06:00
|
|
|
{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}
|
2026-11-16 21:58:18 +06:00
|
|
|
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(
|
2026-11-16 21:58:18 +06:00
|
|
|
'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}
|
|
|
|
|
/>
|
2026-11-16 21:58:18 +06:00
|
|
|
{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}
|
2026-11-16 21:58:18 +06:00
|
|
|
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',
|
2026-11-16 21:58:18 +06:00
|
|
|
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>
|
2026-11-16 21:58:18 +06:00
|
|
|
{error && <span className="text-[11px] text-[var(--danger)]">{error}</span>}
|
2026-10-23 11:43:49 -05:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Select.displayName = 'Select';
|