about summary refs log tree commit diff
path: root/app/assets/javascripts/components/features/ui/components/follow_form.jsx
blob: 4ba5dfc2586db74ccec4aeb4f98ece08997faf59 (plain) (blame)
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
import IconButton      from '../../../components/icon_button';
import PureRenderMixin from 'react-addons-pure-render-mixin';

const FollowForm = React.createClass({

  contextTypes: {
    router: React.PropTypes.object
  },

  propTypes: {
    text: React.PropTypes.string.isRequired,
    is_submitting: React.PropTypes.bool,
    onChange: React.PropTypes.func.isRequired,
    onSubmit: React.PropTypes.func.isRequired
  },

  mixins: [PureRenderMixin],

  handleChange (e) {
    this.props.onChange(e.target.value);
  },

  handleKeyUp (e) {
    if (e.keyCode === 13) {
      this.handleSubmit();
    }
  },

  handleSubmit () {
    this.props.onSubmit(this.context.router);
  },

  render () {
    return (
      <div style={{ display: 'flex', lineHeight: '20px', padding: '10px', background: '#373b4a' }}>
        <input autoComplete='off' type='text' disabled={this.props.is_submitting} placeholder='username@domain' value={this.props.text} onKeyUp={this.handleKeyUp} onChange={this.handleChange} className='follow-form__input' style={{ flex: '1 1 auto', boxSizing: 'border-box', display: 'block', border: 'none', padding: '10px', fontFamily: 'Roboto', color: '#282c37', fontSize: '14px', margin: '0' }} />
        <div style={{ padding: '10px', paddingRight: '0' }}><IconButton title='Follow' size={20} icon='user-plus' onClick={this.handleSubmit} disabled={this.props.is_submitting} /></div>
      </div>
    );
  }

});

export default FollowForm;