all files / packages/input/ Input.js

0% Statements 0/17
0% Branches 0/6
0% Functions 0/3
0% Lines 0/17
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 45 46                                                                                           
import { Component } from '../../ui'
 
class Input extends Component {
 
  _onChange() {
    let editorSession = this.context.editorSession
    let path = this.props.path
    let newVal = this.el.val()
 
    editorSession.transaction(function(tx) {
      tx.set(path, newVal)
    })
  }
 
  render($$) {
    let val
 
    if (this.props.path) {
      let editorSession = this.context.editorSession
      let doc = editorSession.getDocument()
      val = doc.get(this.props.path)
    } else {
      val = this.props.value
    }
 
    let el = $$('input').attr({
      value: val,
      type: this.props.type,
      placeholder: this.props.placeholder
    })
    .addClass('sc-input')
 
    if (this.props.path) {
      el.on('change', this._onChange)
    }
 
    if (this.props.centered) {
      el.addClass('sm-centered')
    }
 
    return el
  }
}
 
export default Input