2016-05-21 01:18:54 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
|
|
|
const findDOMNode = require('react-dom').findDOMNode
|
|
|
|
|
|
|
|
module.exports = EditableLabel
|
|
|
|
|
|
|
|
inherits(EditableLabel, Component)
|
2016-06-21 22:18:32 +02:00
|
|
|
function EditableLabel () {
|
2016-05-21 01:18:54 +02:00
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
EditableLabel.prototype.render = function () {
|
2016-12-14 18:38:20 +01:00
|
|
|
return h('div.name-label', {
|
|
|
|
contentEditable: true,
|
2016-12-14 19:03:56 +01:00
|
|
|
style: {
|
|
|
|
outline: 'none',
|
|
|
|
marginTop: '0.5rem',
|
|
|
|
},
|
2016-12-14 18:38:20 +01:00
|
|
|
onInput: (event) => this.saveText(),
|
|
|
|
}, this.props.children)
|
2016-05-21 01:18:54 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
EditableLabel.prototype.saveText = function () {
|
2016-12-14 18:38:20 +01:00
|
|
|
var text = findDOMNode(this).textContent.trim()
|
2016-06-28 22:10:57 +02:00
|
|
|
var truncatedText = text.substring(0, 20)
|
2016-06-28 20:34:30 +02:00
|
|
|
this.props.saveText(truncatedText)
|
|
|
|
this.setState({ isEditingLabel: false, textLabel: truncatedText })
|
2016-05-21 01:18:54 +02:00
|
|
|
}
|