import React, { DetailedHTMLProps, ForwardedRef, InputHTMLAttributes, ReactElement, forwardRef, JSX, useId, } from 'react'; import cn from 'classnames'; import { RemoveSvg } from '../../icons'; import Loader from '../Loader/Loader'; import './TextField.scss'; type HTMLInputProps = DetailedHTMLProps< InputHTMLAttributes, HTMLInputElement >; interface TextFieldProps extends Omit { label?: string; icon?: ReactElement; loading?: boolean; id?: string; value: string; onChange: (value: string) => void; } const TextField = forwardRef( function TextField( { label, icon, loading = false, disabled = false, className, id, value, onChange, ...inputProps }: TextFieldProps, ref: ForwardedRef, ): JSX.Element { const defaultId = useId(); return ( {label && ( {label} )} {icon && {icon}} onChange(e.currentTarget.value)} /> {!loading && value && ( onChange('')} /> )} {loading && !disabled && ( )} ); }, ); export default TextField;