diff options
author | kumavis <kumavis@users.noreply.github.com> | 2016-06-30 08:06:31 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-30 08:06:31 +0800 |
commit | f7bb3cdcfebacc3f3970b469503db202e0bdda28 (patch) | |
tree | 29833bc540d8f30378e82deaae842a21aecb2ab6 /ui/app/components/copyButton.js | |
parent | 3ae479f5ac3a569eb3840f119148bc4db626a295 (diff) | |
parent | 2880f8631c4de09860b2be01c90b4b30d08c8415 (diff) | |
download | tangerine-wallet-browser-f7bb3cdcfebacc3f3970b469503db202e0bdda28.tar tangerine-wallet-browser-f7bb3cdcfebacc3f3970b469503db202e0bdda28.tar.gz tangerine-wallet-browser-f7bb3cdcfebacc3f3970b469503db202e0bdda28.tar.bz2 tangerine-wallet-browser-f7bb3cdcfebacc3f3970b469503db202e0bdda28.tar.lz tangerine-wallet-browser-f7bb3cdcfebacc3f3970b469503db202e0bdda28.tar.xz tangerine-wallet-browser-f7bb3cdcfebacc3f3970b469503db202e0bdda28.tar.zst tangerine-wallet-browser-f7bb3cdcfebacc3f3970b469503db202e0bdda28.zip |
Merge pull request #368 from MetaMask/CopyTxHash
Copy tx hash
Diffstat (limited to 'ui/app/components/copyButton.js')
-rw-r--r-- | ui/app/components/copyButton.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/ui/app/components/copyButton.js b/ui/app/components/copyButton.js new file mode 100644 index 000000000..a01603585 --- /dev/null +++ b/ui/app/components/copyButton.js @@ -0,0 +1,61 @@ +const Component = require('react').Component +const h = require('react-hyperscript') +const inherits = require('util').inherits +const copyToClipboard = require('copy-to-clipboard') + +const Tooltip = require('./tooltip') + +module.exports = CopyButton + +inherits(CopyButton, Component) +function CopyButton () { + Component.call(this) +} + +// As parameters, accepts: +// "value", which is the value to copy (mandatory) +// "title", which is the text to show on hover (optional, defaults to 'Copy') +CopyButton.prototype.render = function () { + const props = this.props + const state = this.state || {} + + const value = props.value + const copied = state.copied + + const message = copied ? 'Copied' : props.title || ' Copy ' + + return h('.copy-button', { + style: { + display: 'flex', + alignItems: 'center', + }, + }, [ + + h(Tooltip, { + title: message, + }, [ + h('i.fa.fa-clipboard.cursor-pointer.color-orange', { + style: { + margin: '5px', + }, + onClick: (event) => { + event.preventDefault() + event.stopPropagation() + copyToClipboard(value) + this.debounceRestore() + }, + }), + ]), + + ]) +} + +CopyButton.prototype.debounceRestore = function() { + + this.setState({ copied: true }) + clearTimeout(this.timeout) + this.timeout = setTimeout(() => { + this.setState({ copied: false }) + }, 850) + +} |