import React from 'react'; import {ThemeProps, themeable} from '../theme'; import Input from './Input'; import {autobind} from '../utils/helper'; import {Icon} from './icons'; export interface InputBoxProps extends ThemeProps, Omit, 'prefix' | 'onChange'> { value?: string; readOnly?: boolean; onChange?: (value: string) => void; onClear?: (e: React.MouseEvent) => void; clearable?: boolean; disabled?: boolean; hasError?: boolean; placeholder?: string; prefix?: JSX.Element; children?: JSX.Element; } export interface InputBoxState { isFocused: boolean; } export class InputBox extends React.Component { static defaultProps = { clearable: true, placeholder: '' }; state = { isFocused: false }; @autobind clearValue(e: any) { e.preventDefault(); const onClear = this.props.onChange; const onChange = this.props.onChange; onClear?.(e); onChange?.(''); } @autobind handleChange(e: React.ChangeEvent) { const onChange = this.props.onChange; onChange && onChange(e.currentTarget.value); } @autobind handleFocus(e: any) { const onFocus = this.props.onFocus; onFocus && onFocus(e); this.setState({ isFocused: true }); } @autobind handleBlur(e: any) { const onBlur = this.props.onBlur; onBlur && onBlur(e); this.setState({ isFocused: false }); } render() { const { className, classnames: cx, classPrefix, clearable, disabled, hasError, value, placeholder, prefix: result, children, ...rest } = this.props; const isFocused = this.state.isFocused; return (
{result} {children} {clearable && !disabled && value ? ( ) : null}
); } } export default themeable(InputBox);