aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/copyable.js
diff options
context:
space:
mode:
authorKevin Serrano <kevgagser@gmail.com>2017-06-06 03:17:26 +0800
committerGitHub <noreply@github.com>2017-06-06 03:17:26 +0800
commitf5faeed2c96f25333a83631833ccb8805fea3c47 (patch)
tree084a2ea7b674f28301a6eea4cbe6692ab4cd36b2 /ui/app/components/copyable.js
parent9eea990425f1f68eabca8b283bdfc662befcd226 (diff)
parent8dc6aa9c4c4f11e08eee0688c210324b313b710b (diff)
downloadtangerine-wallet-browser-f5faeed2c96f25333a83631833ccb8805fea3c47.tar
tangerine-wallet-browser-f5faeed2c96f25333a83631833ccb8805fea3c47.tar.gz
tangerine-wallet-browser-f5faeed2c96f25333a83631833ccb8805fea3c47.tar.bz2
tangerine-wallet-browser-f5faeed2c96f25333a83631833ccb8805fea3c47.tar.lz
tangerine-wallet-browser-f5faeed2c96f25333a83631833ccb8805fea3c47.tar.xz
tangerine-wallet-browser-f5faeed2c96f25333a83631833ccb8805fea3c47.tar.zst
tangerine-wallet-browser-f5faeed2c96f25333a83631833ccb8805fea3c47.zip
Merge pull request #1542 from MetaMask/i1539-CopyAddresses
Add ability to copy addresses from tx confirmation view
Diffstat (limited to 'ui/app/components/copyable.js')
-rw-r--r--ui/app/components/copyable.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/ui/app/components/copyable.js b/ui/app/components/copyable.js
new file mode 100644
index 000000000..a4f6f4bc6
--- /dev/null
+++ b/ui/app/components/copyable.js
@@ -0,0 +1,46 @@
+const Component = require('react').Component
+const h = require('react-hyperscript')
+const inherits = require('util').inherits
+
+const Tooltip = require('./tooltip')
+const copyToClipboard = require('copy-to-clipboard')
+
+module.exports = Copyable
+
+inherits(Copyable, Component)
+function Copyable () {
+ Component.call(this)
+ this.state = {
+ copied: false,
+ }
+}
+
+Copyable.prototype.render = function () {
+ const props = this.props
+ const state = this.state
+ const { value, children } = props
+ const { copied } = state
+
+ return h(Tooltip, {
+ title: copied ? 'Copied!' : 'Copy',
+ position: 'bottom',
+ }, h('span', {
+ style: {
+ cursor: 'pointer',
+ },
+ onClick: (event) => {
+ event.preventDefault()
+ event.stopPropagation()
+ copyToClipboard(value)
+ this.debounceRestore()
+ },
+ }, children))
+}
+
+Copyable.prototype.debounceRestore = function () {
+ this.setState({ copied: true })
+ clearTimeout(this.timeout)
+ this.timeout = setTimeout(() => {
+ this.setState({ copied: false })
+ }, 850)
+}