diff --git a/src/components/ui/Input.tsx b/src/components/ui/Input.tsx index 8fd5908..225df87 100644 --- a/src/components/ui/Input.tsx +++ b/src/components/ui/Input.tsx @@ -1,8 +1,9 @@ -"use client"; -import React, { useState } from 'react'; -import { FiEye, FiEyeOff, FiX, FiAlertCircle } from 'react-icons/fi'; +import React, { useState } from "react"; -export interface InputProps extends Omit, 'size'> { +import { Input as HeroInput, TextField, Label, Description, FieldError, InputGroup } from "@heroui/react"; +import { FiEye, FiEyeOff, FiX, FiAlertCircle } from "react-icons/fi"; + +export interface InputProps extends Omit, "size"> { label?: string; helperText?: string; errorMessage?: string; @@ -10,28 +11,28 @@ export interface InputProps extends Omit void; - sizeVariant?: 'sm' | 'md' | 'lg'; + sizeVariant?: "sm" | "md" | "lg"; fullWidth?: boolean; } const sizeStyles = { sm: { - input: 'py-2 text-xs rounded-lg', - icon: 'text-sm', - leftPad: 'pl-8', - rightPad: 'pr-8', + input: "py-2 text-xs rounded-lg", + icon: "text-sm", + leftPad: "pl-8", + rightPad: "pr-8", }, md: { - input: 'py-2.5 text-sm rounded-xl', - icon: 'text-base', - leftPad: 'pl-10', - rightPad: 'pr-10', + input: "py-2.5 text-sm rounded-xl", + icon: "text-base", + leftPad: "pl-10", + rightPad: "pr-10", }, lg: { - input: 'py-3.5 text-base rounded-2xl', - icon: 'text-lg', - leftPad: 'pl-12', - rightPad: 'pr-12', + input: "py-3.5 text-base rounded-2xl", + icon: "text-lg", + leftPad: "pl-12", + rightPad: "pr-12", }, }; @@ -45,145 +46,139 @@ export const Input = React.forwardRef( rightIcon, isClearable = false, onClear, - sizeVariant = 'md', + sizeVariant = "md", fullWidth = true, - type = 'text', + type = "text", id, name, disabled, required, - className = '', + className = "", value, ...props }, - ref + ref, ) => { const [showPassword, setShowPassword] = useState(false); - const inputId = id || name || (label ? label.toLowerCase().replace(/\s+/g, '-') : undefined); - - const isPasswordType = type === 'password'; - const computedType = isPasswordType ? (showPassword ? 'text' : 'password') : type; + const inputId = id || name || (label ? label.toLowerCase().replace(/\s+/g, "-") : undefined); + const isPasswordType = type === "password"; + const computedType = isPasswordType ? (showPassword ? "text" : "password") : type; const hasError = Boolean(errorMessage); - const hasValue = value !== undefined && value !== '' && value !== null; - + const hasValue = value !== undefined && value !== "" && value !== null; const currentSize = sizeStyles[sizeVariant]; return ( -
+ + {/* Label */} {label && ( -
- -
+ )} {/* Input Wrapper */} -
- {/* Left Icon */} - {leftIcon && ( -
- {leftIcon} -
- )} - - {/* Core Input Element */} - + + flex items-center w-full overflow-hidden transition-all duration-200 outline-none + bg-white border border-slate-300 hover:border-slate-400 + focus-within:border-cyan-500 focus-within:ring-4 focus-within:ring-cyan-500/15 + dark:bg-slate-900/90 dark:border-slate-800 dark:hover:border-slate-700 + dark:focus-within:border-cyan-500 dark:focus-within:ring-cyan-500/25 + ${disabled ? "opacity-60 bg-slate-100 dark:bg-slate-950 cursor-not-allowed" : ""} + ${hasError ? "border-rose-500! ring-rose-500/20! focus-within:border-rose-500! focus-within:ring-rose-500/20!" : ""} + ${currentSize.input} `}> - {/* Right Action Icons (Clear, Password Toggle, Custom RightIcon) */} -
- {isClearable && hasValue && !disabled && ( - + {/* Left Icon */} + {leftIcon && ( + + {leftIcon} + )} - {isPasswordType && !disabled && ( - - )} + {/* Core Input Element */} + - {!isPasswordType && rightIcon && ( -
- {rightIcon} -
- )} -
+ {/* Right Action Icons */} + + + {/* Clear */} + {isClearable && hasValue && !disabled && ( + + )} + + {/* Password Toggle */} + {isPasswordType && !disabled && ( + + )} + + {/* Custom Right Icon */} + {!isPasswordType && rightIcon && ( +
+ {rightIcon} +
+ )} +
+
{/* Error or Helper Message */} {hasError ? ( -

+ + {errorMessage} -

+ ) : helperText ? ( -

{helperText}

+ {helperText} ) : null} -
+ ); - } + }, ); -Input.displayName = 'Input'; +Input.displayName = "Input";