import React, { forwardRef, InputHTMLAttributes } from 'react';
import { Box } from './Box';
import { Icon } from './Icon';
import { Text } from './Text';
import { LucideIcon } from 'lucide-react';
export interface InputProps extends Omit, 'size'> {
icon?: LucideIcon | React.ReactNode;
rightElement?: React.ReactNode;
variant?: 'default' | 'ghost' | 'search' | 'error';
fullWidth?: boolean;
label?: string;
error?: string;
errorMessage?: string; // Alias for error
hint?: string;
size?: string | number; // Allow size prop
}
export const Input = forwardRef(({
icon,
rightElement,
variant = 'default',
fullWidth = false,
className,
label,
error,
errorMessage,
hint,
id,
size,
...props
}, ref) => {
const variantClasses = {
default: 'bg-surface-charcoal border border-outline-steel focus:border-primary-accent',
ghost: 'bg-transparent border-none',
search: 'bg-surface-charcoal/50 border border-outline-steel focus:border-primary-accent hover:border-text-low/50',
error: 'bg-surface-charcoal border border-critical-red focus:border-critical-red',
};
const inputId = id || (label ? `input-${label.toLowerCase().replace(/\s+/g, '-')}` : undefined);
const displayError = error || errorMessage;
return (
{label && (
{label}
)}
{icon && (
React.isValidElement(icon) ? icon : (
)
)}
{rightElement}
{displayError && (
{displayError}
)}
{hint && !displayError && (
{hint}
)}
);
});
Input.displayName = 'Input';