
import React from 'react'
import classnames from 'classnames'

const Textfield = ({
  autoFocus,
  defaultValue,
  disabled,
  error,
  icon,
  label,
  name,
  onChange,
  readOnly,
  type,
  value
}) => {
  var empty = value === ''
  return (
    <label className='Textfield'>
      <div className='Textfield-icon-wrapper'>
        {
          icon
          ? <div className='Textfield-icon'>{icon}</div>
          : null
        }
        <div className='Textfield-wrapper'>
          <input
            autoFocus={autoFocus}
            className={classnames('Textfield-input', {
              'Textfield-input--error': error,
              'is-not-empty': !empty
            })}
            defaultValue={defaultValue}
            disabled={disabled}
            name={name}
            onChange={onChange}
            readOnly={readOnly}
            type={type}
            value={value}
          />
          <span
            className={classnames('Textfield-label', {
              'is-not-empty': !empty
            })}
          >
            {label}
          </span>
          {error
            ? <span className='Textfield-error'>{error}</span>
            : null
          }
        </div>
      </div>
    </label>
  )
}

Textfield.propTypes = {
  autoFocus: React.PropTypes.bool,
  disabled: React.PropTypes.bool,
  error: React.PropTypes.oneOfType([
    React.PropTypes.string,
    React.PropTypes.bool
  ]),
  icon: React.PropTypes.element,
  label: React.PropTypes.string,
  name: React.PropTypes.string,
  onChange: React.PropTypes.func,
  readOnly: React.PropTypes.bool,
  type: React.PropTypes.oneOf(['text', 'password', 'email', 'search', 'tel', 'url']),
  value: React.PropTypes.oneOfType([
    React.PropTypes.string,
    React.PropTypes.number
  ]),
  defaultValue: React.PropTypes.oneOfType([
    React.PropTypes.string,
    React.PropTypes.number
  ])
}

Textfield.defaultProps = {
  autoFocus: false,
  disabled: false,
  readOnly: false,
  type: 'text'
}

export default Textfield

@@ -1672,16 +1672,26 @@
 ', 'url'
+, 'number'
 %5D),%0A  va

add number to allowed input types