index.js 1.46 KB
Newer Older
zhanghaozhe committed
1 2 3 4 5 6
import React, { Component } from 'react';
import './input.scss'

import classnames from 'classnames'

class Input extends Component {
FE committed
7 8 9 10 11 12 13 14

    constructor(props) {
        super(props);
        this.state = {
            isFocus: false
        }
    }

zhanghaozhe committed
15 16 17 18 19 20
    clearInput = () => {
        this.props.onChange('')
    }

    render() {
        let {type, placeholder} = this.props
FE committed
21
        const { isFocus } = this.state;
zhanghaozhe committed
22 23 24 25
        return (
            <div className='custom-input-wrapper'>
                <input
                    type={type}
FE committed
26
                    className={classnames('custom-input',{'custom-input--active': isFocus})}
zhanghaozhe committed
27
                    placeholder={placeholder}
zhanghaozhe committed
28 29
                    onChange={this.props.onChange}
                    value={this.props.value}
FE committed
30 31 32 33 34 35 36 37 38 39
                    onBlur={() => {
                        this.setState({
                            isFocus: false
                        })
                    }}
                    onFocus={() => {
                        this.setState({
                            isFocus: true
                        })
                    }}
zhanghaozhe committed
40 41 42
                />
                <i
                    className={classnames('iconfont icondanseshixintubiao-3', {
zhanghaozhe committed
43
                        hide: this.props.value.length === 0
zhanghaozhe committed
44 45
                    })}
                    onClick={this.clearInput}
zhanghaozhe committed
46
                />
zhanghaozhe committed
47 48 49 50 51 52 53 54 55
            </div>
        );
    }
}


Input.defaultProps = {type: 'text', placeholder: ''}

export default Input;