import { forwardRef, ReactNode, useMemo, ComponentPropsWithoutRef, } from 'react'; import { FieldValues, UseFormRegister } from 'react-hook-form'; import { WarningIcon } from 'components/shared/CustomIcon'; import { cloneIcon } from 'utils/cloneIcon'; import { cn } from 'utils/classnames'; import { InputTheme, inputTheme } from './Input.theme'; export interface InputProps extends InputTheme, Omit, 'size'> { label?: string; description?: string; leftIcon?: ReactNode; rightIcon?: ReactNode; helperText?: string; // react-hook-form optional register register?: ReturnType>; } const Input = forwardRef( ( { className, label, description, leftIcon, rightIcon, helperText, register, size, state, appearance, ...props }, ref, ) => { const styleProps = useMemo( () => ({ size: size || 'md', state: state || 'default', appearance, // Pass appearance to inputTheme }), [size, state, appearance], ); const { container: containerCls, label: labelCls, description: descriptionCls, input: inputCls, icon: iconCls, iconContainer: iconContainerCls, helperText: helperTextCls, helperIcon: helperIconCls, } = inputTheme({ ...styleProps }); const renderLabels = useMemo(() => { if (!label && !description) return null; return (

{label}

{description}

); }, [labelCls, descriptionCls, label, description]); const renderLeftIcon = useMemo(() => { return (
{cloneIcon(leftIcon, { className: iconCls(), 'aria-hidden': true })}
); }, [cloneIcon, iconCls, iconContainerCls, leftIcon]); const renderRightIcon = useMemo(() => { return (
{cloneIcon(rightIcon, { className: iconCls(), 'aria-hidden': true })}
); }, [cloneIcon, iconCls, iconContainerCls, rightIcon]); const renderHelperText = useMemo(() => { if (!helperText) return null; return (
{state && cloneIcon(, { 'aria-hidden': true, })}

{helperText}

); }, [cloneIcon, state, helperIconCls, helperText, helperTextCls]); return (
{renderLabels}
{leftIcon && renderLeftIcon} {rightIcon && renderRightIcon}
{renderHelperText}
); }, ); Input.displayName = 'Input'; export { Input };