{"size": 865, "ext": "js", "max_stars_repo_path": "scripts/copytoclipboard.js", "max_stars_repo_name": "gustavoguichard/react-copy-to-clipboard", "max_stars_repo_stars_event_min_datetime": "2015-06-08T21:42:04.000Z", "max_stars_repo_stars_event_max_datetime": "2015-06-08T21:42:04.000Z", "max_issues_repo_path": "scripts/copytoclipboard.js", "max_issues_repo_name": "gustavoguichard/react-copy-to-clipboard", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "scripts/copytoclipboard.js", "max_forks_repo_name": "gustavoguichard/react-copy-to-clipboard", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.8333333333, "max_line_length": 104, "alphanum_fraction": 0.6589595376}
import React from 'react'

const CopyToClipboard = React.createClass({
  propTypes: {
    value: React.PropTypes.string.isRequired
  },
  handleClick(event) {
    const node = React.findDOMNode(this.refs.toCopy)
    const range = document.createRange()
    range.selectNode(node)
    window.getSelection().addRange(range)
    try {
      const copied = document.execCommand('copy')
      if(copied) alert("Successfully copied to your clipboard")
    } catch(err) {
      console.log(`Your browser doesn't support copying to clipboard, you'll need to do it manually =/`)
    }
    window.getSelection().removeAllRanges()
  },
  render() {
    return (
      <div>
        <span ref="toCopy">{this.props.children}</span>
        <button {...this.props} onClick={this.handleClick}>{this.props.value}</button>
      </div>
    )
  }
})

module.exports = CopyToClipboard