import { InputHTMLAttributes, forwardRef, ForwardedRef, useId } from 'react'; import clsx from 'clsx'; import { InputProps, SVGComponent } from '../../types'; import { useClearButton } from '../../hooks'; import { Button } from '../Button/Button'; import { InputWrapper } from '../utils'; import { ReactComponent as SearchSVG } from './images/search.svg'; import styles from './Input.module.scss'; type Props = Omit, 'size'> & InputProps & { icon?: SVGComponent; }; const Input = forwardRef((props: Props, forwardedRef: ForwardedRef) => { const { label, icon: Icon, className, error, gap, tooltip, type, block, size = 'normal', color = 'dark', direction = 'x', onBlur, onFocus, ...attrs } = props; const { readOnly, disabled } = attrs; const isSearch = type === 'search'; const wrapperClassName = clsx( styles.wrapper, readOnly && styles.readOnly, styles[size], styles[color], error && styles.error, block && styles.block, ); const inputClassName = clsx(styles.input, styles[color]); const { clearButton, inputRef } = useClearButton(forwardedRef, color); const id = useId(); return (
{Icon && } { if (!readOnly) clearButton.show(); if (onFocus) onFocus(e); }} onBlur={(e) => { clearButton.hide(); if (onBlur) onBlur(e); }} /> {clearButton.isVisible && (
); }); export { Input, styles as inputStyles }; export type { Props as InputProps };