aboutsummaryrefslogtreecommitdiffstats
path: root/old-ui/app/components/editable-label.js
diff options
context:
space:
mode:
authorCsaba S <csaba.solya@gmail.com>2018-02-22 21:55:46 +0800
committerGitHub <noreply@github.com>2018-02-22 21:55:46 +0800
commit2f3463048685759319eb320c916cc7bc23a41649 (patch)
treee53ac24a1a127f1c684327bca00d23f51b56c542 /old-ui/app/components/editable-label.js
parent5ec311ba3e01bd9b0a9ff447fd7639d22a7b3d9c (diff)
parenteed75735b8e90d121537249cf147c1ece60f1e47 (diff)
downloadtangerine-wallet-browser-2f3463048685759319eb320c916cc7bc23a41649.tar
tangerine-wallet-browser-2f3463048685759319eb320c916cc7bc23a41649.tar.gz
tangerine-wallet-browser-2f3463048685759319eb320c916cc7bc23a41649.tar.bz2
tangerine-wallet-browser-2f3463048685759319eb320c916cc7bc23a41649.tar.lz
tangerine-wallet-browser-2f3463048685759319eb320c916cc7bc23a41649.tar.xz
tangerine-wallet-browser-2f3463048685759319eb320c916cc7bc23a41649.tar.zst
tangerine-wallet-browser-2f3463048685759319eb320c916cc7bc23a41649.zip
Merge branch 'master' into edge-support
Diffstat (limited to 'old-ui/app/components/editable-label.js')
-rw-r--r--old-ui/app/components/editable-label.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/old-ui/app/components/editable-label.js b/old-ui/app/components/editable-label.js
new file mode 100644
index 000000000..8a5c8954f
--- /dev/null
+++ b/old-ui/app/components/editable-label.js
@@ -0,0 +1,57 @@
+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
+ const state = this.state
+
+ if (state && state.isEditingLabel) {
+ return h('div.editable-label', [
+ h('input.sizing-input', {
+ defaultValue: props.textValue,
+ maxLength: '20',
+ onKeyPress: (event) => {
+ this.saveIfEnter(event)
+ },
+ }),
+ h('button.editable-button', {
+ onClick: () => this.saveText(),
+ }, 'Save'),
+ ])
+ } else {
+ return h('div.name-label', {
+ onClick: (event) => {
+ const nameAttribute = event.target.getAttribute('name')
+ // checks for class to handle smaller CTA above the account name
+ const classAttribute = event.target.getAttribute('class')
+ if (nameAttribute === 'edit' || classAttribute === 'edit-text') {
+ this.setState({ isEditingLabel: true })
+ }
+ },
+ }, this.props.children)
+ }
+}
+
+EditableLabel.prototype.saveIfEnter = function (event) {
+ if (event.key === 'Enter') {
+ this.saveText()
+ }
+}
+
+EditableLabel.prototype.saveText = function () {
+ // eslint-disable-next-line react/no-find-dom-node
+ var container = findDOMNode(this)
+ var text = container.querySelector('.editable-label input').value
+ var truncatedText = text.substring(0, 20)
+ this.props.saveText(truncatedText)
+ this.setState({ isEditingLabel: false, textLabel: truncatedText })
+}