summaryrefslogtreecommitdiff
path: root/animism-align/frontend/common/copyToClipboardButton.component.js
blob: cfe7103b4fd8d292b5eddce18d89a69b7e87ba34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import React, { Component } from 'react';
import { writeToClipboard } from '../util'

export default class CopyToClipboardButton extends Component {
  state = {
    copied: false,
  }

  handleClick() {
    writeToClipboard(this.props.data)
    this.setState({ copied: true })
  }

  render() {
    return (
      <button
        className={this.state.copied ? 'copyButton copied' : 'copyButton'}
        onClick={this.handleClick.bind(this)}
      >
        {this.state.copied ? 'Copied!' : 'Copy'}
      </button>
    )
  }
}