1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
Whymarrh Whitby 92971d3c87
Migrate codebase to use ESM (#7730)
* Update eslint-plugin-import version

* Convert JS files to use ESM

* Update ESLint rules to check imports

* Fix test:unit:global command env

* Cleanup mock-dev script
2020-01-09 00:04:58 -03:30

64 lines
1.4 KiB
JavaScript

import React, { Component } from 'react'
import PropTypes from 'prop-types'
import copyToClipboard from 'copy-to-clipboard'
import Tooltip from './tooltip'
class CopyButton extends Component {
static contextTypes = {
t: PropTypes.func,
}
static defaultProps = {
title: null,
}
static propTypes = {
value: PropTypes.string.isRequired,
title: PropTypes.string,
}
state = {}
debounceRestore = () => {
this.setState({ copied: true })
clearTimeout(this.timeout)
this.timeout = setTimeout(() => {
this.setState({ copied: false })
}, 850)
}
render () {
const { title, value } = this.props
const { copied } = this.state
const message = copied ? this.context.t('copiedButton') : title || this.context.t('copyButton')
return (
<div
className="copy-button"
style={{
display: 'flex',
alignItems: 'center',
}}
>
<Tooltip title={message}>
<i
className="fa fa-clipboard cursor-pointer color-orange"
style={{
margin: '5px',
}}
onClick={(event) => {
event.preventDefault()
event.stopPropagation()
copyToClipboard(value)
this.debounceRestore()
}}
/>
</Tooltip>
</div>
)
}
}
export default CopyButton