You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.9 KiB

  1. import CharacterCounter from './character_counter';
  2. import Button from './button';
  3. import PureRenderMixin from 'react-addons-pure-render-mixin';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import ReplyIndicator from './reply_indicator';
  6. const ComposeForm = React.createClass({
  7. propTypes: {
  8. text: React.PropTypes.string.isRequired,
  9. is_submitting: React.PropTypes.bool,
  10. in_reply_to: ImmutablePropTypes.map,
  11. onChange: React.PropTypes.func.isRequired,
  12. onSubmit: React.PropTypes.func.isRequired,
  13. onCancelReply: React.PropTypes.func.isRequired
  14. },
  15. mixins: [PureRenderMixin],
  16. handleChange (e) {
  17. this.props.onChange(e.target.value);
  18. },
  19. handleKeyUp (e) {
  20. if (e.keyCode === 13 && e.ctrlKey) {
  21. this.props.onSubmit();
  22. }
  23. },
  24. handleSubmit () {
  25. this.props.onSubmit();
  26. },
  27. render () {
  28. let replyArea = '';
  29. if (this.props.in_reply_to) {
  30. replyArea = <ReplyIndicator status={this.props.in_reply_to} onCancel={this.props.onCancelReply} />;
  31. }
  32. return (
  33. <div style={{ marginBottom: '30px', padding: '10px' }}>
  34. {replyArea}
  35. <textarea disabled={this.props.is_submitting} placeholder='What is on your mind?' value={this.props.text} onKeyUp={this.handleKeyUp} onChange={this.handleChange} className='compose-form__textarea' style={{ display: 'block', boxSizing: 'border-box', width: '100%', height: '100px', resize: 'none', border: 'none', color: '#282c37', padding: '10px', fontFamily: 'Roboto', fontSize: '14px', margin: '0' }} />
  36. <div style={{ marginTop: '10px', overflow: 'hidden' }}>
  37. <div style={{ float: 'right' }}><Button text='Publish' onClick={this.handleSubmit} disabled={this.props.is_submitting} /></div>
  38. <div style={{ float: 'right', marginRight: '16px', lineHeight: '36px' }}><CharacterCounter text={this.props.text} /></div>
  39. </div>
  40. </div>
  41. );
  42. }
  43. });
  44. export default ComposeForm;