'use client'; import { ChangeEventHandler, FocusEventHandler, HTMLInputTypeAttribute, ReactNode, } from 'react'; import { cn } from '@/lib/helper'; export interface TextInputProps { type?: HTMLInputTypeAttribute; label?: string; bottomLabel?: string; name: string; value?: string | number; placeholder?: string; className?: { wrapper?: string; label?: string; inputWrapper?: string; input?: string; inputPrefix?: string; inputSuffix?: string; inputPrefixSuffixWrapper?: string; }; isError?: boolean; isValid?: boolean; disabled?: boolean; readOnly?: boolean; required?: boolean; isLoading?: boolean; errorMessage?: string; startAdornment?: ReactNode; endAdornment?: ReactNode; inputPrefix?: ReactNode; inputSuffix?: ReactNode; onChange?: ChangeEventHandler; onBlur?: FocusEventHandler; } const TextInput = ({ type = 'text', label, bottomLabel, name, value, placeholder, className, isError, isValid, errorMessage, startAdornment, endAdornment, inputPrefix, inputSuffix, disabled = false, required = false, onChange, onBlur, readOnly = false, isLoading = false, }: TextInputProps) => { return (
{label && ( )} {inputPrefix || inputSuffix ? (
{inputPrefix && (
{inputPrefix}
)}
{startAdornment && startAdornment} {(isLoading || endAdornment) && (
{isLoading && } {endAdornment && endAdornment}
)}
{inputSuffix && (
{inputSuffix}
)}
) : (
{startAdornment && startAdornment} {(isLoading || endAdornment) && (
{isLoading && } {endAdornment && endAdornment}
)}
)} {!isError && bottomLabel && (

{bottomLabel}

)} {isError && errorMessage && (

{errorMessage}

)}
); }; export default TextInput;