All files / components/input-file index.js

0% Statements 0/61
0% Branches 0/41
0% Functions 0/12
0% Lines 0/18
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                                                                                                                                                   
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import StylesInputFileLabel from './styled-input'
 
import InputContainer from 'utils/input-container'
import { FileCode } from 'icons'
 
class InputFile extends Component {
  constructor (props) {
    super(props)
    this.state = {
      filename: ''
    }
  }
 
  componentWillReceiveProps (nextProps) {
    if (nextProps.filename) {
      this.setState({
        filename: nextProps.filename
      })
    }
  }
 
  render () {
    const { name, ...rest } = this.props
 
    return (
      <InputContainer {...rest}>
        <StylesInputFileLabel className='InputFile'>
          <div className='elementContainer'>
            <div className='filename'>
              {
                this.state.filename
                  ? this.state.filename
                  : 'Buscar arquivo no computador'
              }
            </div>
            <div className='button-upload'>
              <FileCode />
              <span className='label-button'>Selecionar</span>
            </div>
            <input
              name={name}
              id={name}
              type='file'
              onChange={this.props.onChange}
              accept={this.props.accept}
            />
          </div>
        </StylesInputFileLabel>
      </InputContainer>
    )
  }
}
 
InputFile.defaultProps = {
  filename: '',
  message: '',
  accept: '',
  type: 'default'
}
 
InputFile.propTypes = {
  name: PropTypes.string,
  type: PropTypes.string,
  filename: PropTypes.string,
  label: PropTypes.string,
  message: PropTypes.string,
  onChange: PropTypes.func,
  accept: PropTypes.string
}
 
export { InputFile }