diff --git a/ui/app/components/ui/copyButton.js b/ui/app/components/ui/copyButton.js index a60d33523..d235fea04 100644 --- a/ui/app/components/ui/copyButton.js +++ b/ui/app/components/ui/copyButton.js @@ -1,66 +1,66 @@ -const Component = require('react').Component -const PropTypes = require('prop-types') -const h = require('react-hyperscript') -const inherits = require('util').inherits -const copyToClipboard = require('copy-to-clipboard') -const connect = require('react-redux').connect +import React, { Component } from 'react' +import PropTypes from 'prop-types' +import { connect } from 'react-redux' +const copyToClipboard = require('copy-to-clipboard') const Tooltip = require('./tooltip') -CopyButton.contextTypes = { - t: PropTypes.func, +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 state = this.state + const props = this.props + const value = props.value + const copied = state.copied + const message = copied ? this.context.t('copiedButton') : props.title || this.context.t('copyButton') + + return ( +