import React, { ReactNode, useMemo } from 'react'; import { ComponentPropsWithoutRef } from 'react'; import { InputTheme, inputTheme } from './Input.theme'; import { WarningIcon } from 'components/shared/CustomIcon'; import { cloneIcon } from 'utils/cloneIcon'; import { cn } from 'utils/classnames'; export interface InputProps extends InputTheme, Omit, 'size'> { label?: string; description?: string; leftIcon?: ReactNode; rightIcon?: ReactNode; helperText?: string; } export const Input = ({ className, label, description, leftIcon, rightIcon, helperText, size, state, appearance, ...props }: InputProps) => { 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( () => (

{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( () => (
{state && cloneIcon(, { 'aria-hidden': true, })}

{helperText}

), [cloneIcon, state, helperIconCls, helperText, helperTextCls], ); return (
{renderLabels}
{leftIcon && renderLeftIcon} {rightIcon && renderRightIcon}
{renderHelperText}
); };