1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 02:58:09 +01:00
metamask-extension/ui/app/components/editable-label.js

30 lines
797 B
JavaScript
Raw Normal View History

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 () {
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-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()
var truncatedText = text.substring(0, 20)
2016-06-28 20:34:30 +02:00
this.props.saveText(truncatedText)
this.setState({ isEditingLabel: false, textLabel: truncatedText })
}