blob: 14c0294a28832944275ae395671b00bd4d51b7f9 (
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
|
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)
function EditableLabel () {
Component.call(this)
}
EditableLabel.prototype.render = function () {
return h('div.name-label', {
contentEditable: true,
style: {
outline: 'none',
marginTop: '0.5rem',
},
onInput: (event) => this.saveText(),
}, this.props.children)
}
EditableLabel.prototype.saveText = function () {
var text = findDOMNode(this).textContent.trim()
var truncatedText = text.substring(0, 20)
this.props.saveText(truncatedText)
this.setState({ isEditingLabel: false, textLabel: truncatedText })
}
|