/* eslint-disable jsx-a11y/no-autofocus */ import React, { FC, forwardRef, memo, useState } from 'react'; import { cn } from '../../util/bem'; import { FormSizesType, SizeType } from '../../util/global-props'; import { Icon, IconPropsType } from '../icon/icon.component'; import { iconMap } from '../icon/icon.library'; import './input.component.scss'; export type InputPropsType = { className?: string; value?: string | typeof undefined; name?: string; placeholder?: string; icon?: keyof typeof iconMap; iconColor?: IconPropsType['color']; after?: React.ReactNode; before?: React.ReactNode; type?: 'text' | 'number' | 'password' | 'email'; size?: FormSizesType; flex?: number; margin?: SizeType; autocompleteAttr?: string; clearable?: boolean; autoFocus?: boolean; autoComplete?: boolean; disabled?: boolean; fullWidth?: boolean; transparent?: boolean; readOnly?: boolean; required?: boolean; nativeProps?: React.InputHTMLAttributes; textCentered?: boolean; ref?: React.Ref; onChange?: React.ChangeEventHandler; onClick?: React.MouseEventHandler; onClear?: React.MouseEventHandler; onFocus?: React.FocusEventHandler; onBlur?: React.FocusEventHandler; onKeyDown?: React.KeyboardEventHandler; onKeyPress?: React.KeyboardEventHandler; onKeyUp?: React.KeyboardEventHandler; } const className = cn('input'); export const Input: FC = memo(forwardRef((props, ref: React.Ref) => { const [ focus, setFocus ] = useState(false); const handleFocus = (event: React.FocusEvent) => { setFocus(true); if (props.onFocus) { props.onFocus(event); } }; const handleBlur = (event: React.FocusEvent) => { setFocus(false); if (props.onBlur) { props.onBlur(event); } }; return (
{ props.icon && ( ) } { props.before && ( { props.before } ) } { /* @ts-ignore */ } { props.clearable && ( ) } { props.after && ( { props.after } ) }
); })); Input.defaultProps = { size: 'lg', type: 'text', iconColor: 'grey' };