All files / components/select-box index.js

0% Statements 0/80
0% Branches 0/41
0% Functions 0/15
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                                                                                                                                                                 
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import Select from 'react-select'
import { Arrow as ArrowIcon } from 'icons'
 
import InputContainer from 'utils/input-container'
import SelectStyled from './select-box.styled'
 
const arrowRenderer = () => (
  <div>
    <ArrowIcon />
  </div>
)
 
class SelectBox extends Component {
  renderOption = (option) => {
    const { labelKey } = this.props
 
    return (
      <div className='option-item'>
        {option[labelKey]}
      </div>
    )
  }
 
  render () {
    const {
      placeholder,
      onChange,
      value,
      labelKey,
      valueKey,
      options,
      simpleValue,
      ...rest
    } = this.props
 
    return (
      <InputContainer {...rest} >
        <SelectStyled>
          <Select
            placeholder={placeholder}
            onChange={onChange}
            value={value}
            clearable={false}
            autosize={false}
            autoload
            searchable={false}
            backspaceRemoves={false}
            arrowRenderer={arrowRenderer}
            optionRenderer={this.renderOption}
            valueKey={valueKey}
            labelKey={labelKey}
            options={options}
            simpleValue={simpleValue}
            {...rest}
          />
        </SelectStyled>
      </InputContainer>
    )
  }
}
 
SelectBox.propTypes = {
  width: PropTypes.string,
  placeholder: PropTypes.string,
  label: PropTypes.string,
  type: PropTypes.oneOf(['primary', 'error', 'alert', 'success']),
  message: PropTypes.string,
  name: PropTypes.string,
  onChange: PropTypes.func,
  value: PropTypes.object,
  labelKey: PropTypes.string,
  valueKey: PropTypes.string,
  options: PropTypes.array,
  simpleValue: PropTypes.bool
}
 
export { AutoComplete } from './auto-complete'
export { SelectBox }