aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/editable-label.js
diff options
context:
space:
mode:
authorDan Finlay <somniac@me.com>2016-05-24 05:43:17 +0800
committerDan Finlay <somniac@me.com>2016-05-24 05:43:17 +0800
commit0c73e583727e8cd67df7ad119e8d453306fa5c5d (patch)
tree350ed72bc2cc609bc6fd2e638cda3ad03b7d3e61 /ui/app/components/editable-label.js
parent7f77fe1a790fbd466b91f5a8f6bf25fbd0982ae4 (diff)
parenta439e04ed4fae2bbf4da6cfca2a516991aa89178 (diff)
downloadtangerine-wallet-browser-0c73e583727e8cd67df7ad119e8d453306fa5c5d.tar
tangerine-wallet-browser-0c73e583727e8cd67df7ad119e8d453306fa5c5d.tar.gz
tangerine-wallet-browser-0c73e583727e8cd67df7ad119e8d453306fa5c5d.tar.bz2
tangerine-wallet-browser-0c73e583727e8cd67df7ad119e8d453306fa5c5d.tar.lz
tangerine-wallet-browser-0c73e583727e8cd67df7ad119e8d453306fa5c5d.tar.xz
tangerine-wallet-browser-0c73e583727e8cd67df7ad119e8d453306fa5c5d.tar.zst
tangerine-wallet-browser-0c73e583727e8cd67df7ad119e8d453306fa5c5d.zip
Merge pull request #204 from MetaMask/dev
Merge UI redesign into master
Diffstat (limited to 'ui/app/components/editable-label.js')
-rw-r--r--ui/app/components/editable-label.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/ui/app/components/editable-label.js b/ui/app/components/editable-label.js
new file mode 100644
index 000000000..20e24a9c7
--- /dev/null
+++ b/ui/app/components/editable-label.js
@@ -0,0 +1,52 @@
+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() {
+ const props = this.props
+ let state = this.state
+
+ if (state && state.isEditingLabel) {
+
+ return h('div.editable-label', [
+ h('input', {
+ defaultValue: props.textValue,
+ onKeyPress:(event) => {
+ this.saveIfEnter(event)
+ },
+ }),
+ h('button', {
+ onClick:() => this.saveText(),
+ }, 'Save')
+ ])
+
+ } else {
+ return h('div', {
+ onClick:(event) => {
+ this.setState({ isEditingLabel: true })
+ },
+ }, this.props.children)
+ }
+}
+
+EditableLabel.prototype.saveIfEnter = function(event) {
+ if (event.key === 'Enter') {
+ this.saveText()
+ }
+}
+
+EditableLabel.prototype.saveText = function() {
+ var container = findDOMNode(this)
+ var text = container.querySelector('.editable-label input').value
+ this.props.saveText(text)
+ this.setState({ isEditingLabel: false, textLabel: text })
+}