import React, { DetailedHTMLProps, InputHTMLAttributes, LabelHTMLAttributes, RefObject, TextareaHTMLAttributes, } from "react"; import { twMerge } from "tailwind-merge"; export type InputProps = DetailedHTMLProps< InputHTMLAttributes, HTMLInputElement > & DetailedHTMLProps< TextareaHTMLAttributes, HTMLTextAreaElement > & { label?: string; variant?: "normal" | "warning" | "error" | "inactive"; prefix?: string | React.ReactNode; suffix?: string | React.ReactNode; showLabel?: boolean; istextarea?: boolean; wrapperProps?: DetailedHTMLProps< InputHTMLAttributes, HTMLDivElement >; labelProps?: DetailedHTMLProps< LabelHTMLAttributes, HTMLLabelElement >; componentRef?: RefObject; }; /** * # Input Element * @className twui-input */ export default function Input({ label, variant, prefix, suffix, componentRef, labelProps, wrapperProps, showLabel, istextarea, ...props }: InputProps) { const [focus, setFocus] = React.useState(false); const targetComponent = istextarea ? ( { setFocus(true); props?.onFocus?.(e); }} onBlur={(e) => { setFocus(false); props?.onBlur?.(e); }} /> ) : ( { setFocus(true); props?.onFocus?.(e); }} onBlur={(e) => { setFocus(false); props?.onBlur?.(e); }} /> ); return ( {showLabel && ( {label || props.placeholder || props.name} )} {prefix && ( {prefix} )} {targetComponent} {suffix && ( {suffix} )} ); }