Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/core/components/copy-to-clipboard-btn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,35 @@ import PropTypes from "prop-types"
* @constructor
*/
export default class CopyToClipboardBtn extends React.Component {
constructor(props) {
super(props)
this.state = { copied: false }
this.handleCopy = this.handleCopy.bind(this)
}

handleCopy() {
this.setState({ copied: true })
this._timer = setTimeout(() => {
this.setState({ copied: false })
}, 2000)
}

componentWillUnmount() {
if (this._timer) {
clearTimeout(this._timer)
}
}

render() {
let { getComponent } = this.props
const { copied } = this.state

const CopyIcon = getComponent("CopyIcon")

return (
<div className="view-line-link copy-to-clipboard" title="Copy to clipboard">
<CopyToClipboard text={this.props.textToCopy}>
<CopyIcon />
<div className="view-line-link copy-to-clipboard" title={copied ? "Copied!" : "Copy to clipboard"}>
<CopyToClipboard text={this.props.textToCopy} onCopy={this.handleCopy}>
{copied ? <span className="copy-to-clipboard__copied">Copied!</span> : <CopyIcon />}
</CopyToClipboard>
</div>
)
Expand Down
7 changes: 7 additions & 0 deletions src/style/_buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,10 @@ button {
height: 26px;
position: unset;
}

.copy-to-clipboard__copied {
color: #fff;
font-size: 11px;
font-weight: 600;
user-select: none;
}