All files / components/input index.js

0% Statements 0/77
0% Branches 0/48
0% Functions 0/13
0% Lines 0/2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91                                                                                                                                                                                     
import React, { Component } from 'react'
import css from 'classnames'
import PropTypes from 'prop-types'
import InputMask from 'react-input-mask';
 
import {
  SmallSuccess,
  SmallAlert,
  SmallBlocked,
  SmallError
} from 'icons'
 
import InputContainer from 'utils/input-container'
import StyledInput from './styled-input'
 
class Input extends Component {
 
  renderStatusIcon () {
    switch (this.props.type) {
      case 'success':
        return <SmallSuccess />
      case 'alert':
        return <SmallAlert />
      case 'blocked':
        return <SmallBlocked />
      case 'error':
        return <SmallError />
      default:
        return null
    }
  }
 
  render () {
    const { htmlType, name, onChange, placeholder = '', inputStyle = {}, mask, ...rest } = this.props
    return (
      <InputContainer {...rest}>
        <StyledInput>
          {
            <div>
              {
                mask !== null ?
                  <InputMask
                    mask={mask}
                    name={name}
                    placeholder={placeholder}
                    style={inputStyle}
                    type={htmlType}
                    autoComplete="off"
                    onChange={onChange}
                  /> :
                  <input
                    name={name}
                    placeholder={placeholder}
                    style={inputStyle}
                    type={htmlType}
                    autoComplete="off"
                    onChange={onChange}
                  />
              }
            </div>
          }
          {this.renderStatusIcon()}
        </StyledInput>
      </InputContainer>
    )
  }
}
 
Input.defaultProps = {
  message: ''
}
 
Input.propTypes = {
  name: PropTypes.string,
  label: PropTypes.string,
  message: PropTypes.string,
  mask: PropTypes.string,
  value: PropTypes.string,
  htmlType: PropTypes.string,
  onChange: PropTypes.func,
  onKeyUp: PropTypes.func,
  type: PropTypes.oneOf([
    'success',
    'error',
    'alert'
  ])
}
 
export { Input }
export { InputGroup } from './input-group'