aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/editable-label.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-05-21 07:18:54 +0800
committerDan Finlay <dan@danfinlay.com>2016-05-21 07:18:54 +0800
commit95a3cfe3fcffee2ffabd4cf71e568ae94693b10f (patch)
tree9c19992a823fb76a790cfdcbabb11ac1dc9b8fc1 /ui/app/components/editable-label.js
parent24fc5f9ea3a8cddfbf3993bdf0b18187a0787a64 (diff)
downloadtangerine-wallet-browser-95a3cfe3fcffee2ffabd4cf71e568ae94693b10f.tar.gz
tangerine-wallet-browser-95a3cfe3fcffee2ffabd4cf71e568ae94693b10f.tar.zst
tangerine-wallet-browser-95a3cfe3fcffee2ffabd4cf71e568ae94693b10f.zip
Added ability to nickname wallets locally
The changes are persisted to localstorage, so they cannot be restored on a new computer, but for right now it's a nice organizational feature.
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 })
+}