50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import React from 'react';
|
|
|
|
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
label?: string;
|
|
unit?: string;
|
|
error?: string;
|
|
helperText?: string;
|
|
}
|
|
|
|
export const Input: React.FC<InputProps> = ({
|
|
label,
|
|
unit,
|
|
error,
|
|
helperText,
|
|
id,
|
|
className = '',
|
|
...props
|
|
}) => {
|
|
const inputId = id || (label ? label.toLowerCase().replace(/\s+/g, '-') : undefined);
|
|
|
|
return (
|
|
<div className="w-full">
|
|
{label && (
|
|
<label htmlFor={inputId} className="block text-xs font-semibold uppercase tracking-wider text-text-muted mb-1.5">
|
|
{label}
|
|
</label>
|
|
)}
|
|
<div className="relative rounded">
|
|
<input
|
|
id={inputId}
|
|
className={`w-full bg-white text-text-primary border ${
|
|
error ? 'border-error' : 'border-card-border'
|
|
} rounded px-3 py-2 text-sm focus:outline-none focus:border-sidebar-surface focus:ring-2 focus:ring-secondary-amber/20 transition ${
|
|
unit ? 'pr-14 font-mono' : ''
|
|
} ${className}`}
|
|
{...props}
|
|
/>
|
|
{unit && (
|
|
<div className="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
|
|
<span className="font-mono text-xs text-text-muted">{unit}</span>
|
|
</div>
|
|
)}
|
|
</div>
|
|
{error && <p className="mt-1 text-xs text-error font-medium">{error}</p>}
|
|
{helperText && !error && <p className="mt-1 text-xs text-text-muted">{helperText}</p>}
|
|
</div>
|
|
);
|
|
};
|
|
|