index.js 963 Bytes
Newer Older
zhanghaozhe committed
1
import React, { PureComponent } from 'react';
zhanghaozhe committed
2
import './password-input.scss'
3
import classnames from 'classnames'
zhanghaozhe committed
4 5 6

import Input from '../Input'

zhanghaozhe committed
7
class PasswordInput extends PureComponent {
zhanghaozhe committed
8 9 10 11 12 13 14 15 16 17 18 19
    constructor(props) {
        super(props);
        this.state = {
            showPassword: false
        }
    }

    togglePasswordVisibility = () => {
        this.setState({showPassword: !this.state.showPassword})
    }

    render() {
zhanghaozhe committed
20
        let {placeholder, ...rest} = this.props
zhanghaozhe committed
21 22 23 24 25
        return (
            <Input
                type={this.state.showPassword ? 'text' : 'password'}
                wrapperClass={'password-input'}
                placeholder={placeholder}
zhanghaozhe committed
26
                {...rest}
zhanghaozhe committed
27
            >
xuzhenghua committed
28
                <i className={classnames('iconfont', [this.state.showPassword ? 'iconyanjing' : 'iconpwd-hidden'])}
zhanghaozhe committed
29
                   onClick={this.togglePasswordVisibility}/>
zhanghaozhe committed
30 31 32 33 34
            </Input>
        );
    }
}

zhanghaozhe committed
35
export default PasswordInput;