Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/components / src / components / controls / Input / InputFieldWithIcon.js
Size: Mime:
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';

import Icon from '../../visuals/Icon/Icon';

class InputWithIcon extends Component {
  static propTypes = {
    icon: PropTypes.any.isRequired,
    semantic: PropTypes.string,
  };
  static defaultProps = {
    semantic: null,
  };

  constructor(props) {
    super(props);
    this.state = {
      isFocused: false,
    };
  }

  onFocus = () => {
    this.setState({ isFocused: true });
  };

  onBlur = () => {
    this.setState({ isFocused: false });
  };

  render() {
    const { isFocused } = this.state;
    const { icon, semantic, ...props } = this.props;

    const containerClassName = classnames('Input-field', {
      'Input--focused': isFocused,
    });

    return (
      <div className="Input-fieldWithIcon">
        <div className={containerClassName}>
          <input {...props} onBlur={this.onBlur} onFocus={this.onFocus} />
          <Icon icon={icon} semantic={semantic} />
        </div>
      </div>
    );
  }
}

export default InputWithIcon;