client/src/components/NoteInput.js
author Alexandre Segura <mex.zktk@gmail.com>
Tue, 23 May 2017 16:18:34 +0200
changeset 5 5c91bfa8fcde
parent 2 b52921a63e77
child 8 6f572b6b6be3
permissions -rw-r--r--
Introduce SlateJS.

import React, {Component} from 'react';

import ReactDOM from 'react-dom'
import { Form, FormControl, FormGroup, Button } from 'react-bootstrap';

import PropTypes from 'prop-types';
import SlateEditor from './SlateEditor';

class NoteInput extends Component {
  constructor(props) {
    super(props);

    this.state = {value: ''};

    this.onAddNoteClick = this.onAddNoteClick.bind(this);
    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(event) {
    this.setState({value : event.target.value});
  }

  onAddNoteClick(event) {
    const text = this.refs.editor.asPlain();
    this.props.addNote(text);
    this.refs.editor.clear();
  }

  componentDidMount() {
    // this.noteInput.focus();
  }

  render() {
    return (
      <Form>
        <FormGroup>
          <SlateEditor ref="editor" />
        </FormGroup>
        <Button type="button" onClick={this.onAddNoteClick}>Add Note</Button>
      </Form>
    );
  }
}

NoteInput.propTypes = {
  addNote: PropTypes.func.isRequired
};

export default NoteInput;