index.js 915 Bytes
Newer Older
zhanghaozhe committed
1 2 3
import React, { Component } from "react"
import "./clearable-input.scss"
import classnames from "classnames"
zhanghaozhe committed
4 5

class ClearableInput extends Component {
zhanghaozhe committed
6 7 8 9 10 11 12 13 14 15 16 17 18
  render() {
    let {
      value,
      name,
      wrapperClass,
      inputClass,
      type = "text",
      icon,
      setFieldValue,
      ...rest
    } = this.props
    let clearIconStyle = {
      display: value && value.length ? "block" : "none",
zhanghaozhe committed
19
    }
zhanghaozhe committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
    return (
      <div className={classnames("clearable-input-wrapper", wrapperClass)}>
        <input
          type={type}
          value={value}
          className={inputClass}
          {...rest}
          name={name}
        />
        {icon}
        <i
          className={"iconfont icondanseshixintubiao-3 clear"}
          onClick={() => {
            setFieldValue(name, "")
          }}
          style={clearIconStyle}
        />
      </div>
    )
  }
zhanghaozhe committed
40 41
}

zhanghaozhe committed
42
export default ClearableInput