import React, {PropTypes} from 'react'; import I18n from 'coral-framework/modules/i18n/i18n'; import translations from './translations'; import onClickOutside from 'react-onclickoutside'; const name = 'coral-plugin-permalinks'; const lang = new I18n(translations); class PermalinkButton extends React.Component { static propTypes = { articleURL: PropTypes.string.isRequired, commentId: PropTypes.string.isRequired } constructor (props) { super(props); this.state = {popoverOpen: false, copySuccessful: null, copyFailure: null}; this.toggle = this.toggle.bind(this); this.copyPermalink = this.copyPermalink.bind(this); } toggle () { this.setState({popoverOpen: !this.state.popoverOpen}); } handleClickOutside () { this.setState({popoverOpen: false}); } copyPermalink () { this.permalinkInput.select(); try { document.execCommand('copy'); this.setState({copySuccessful: true}); } catch (err) { this.setState({copyFailure: true}); } setTimeout(() => { this.setState({copyFailure: null, copySuccessful: null}); }, 4500); } render () { return (
this.permalinkInput = input} value={`${this.props.articleURL}#${this.props.commentId}`} onChange={() => {}} /> { this.state.copySuccessful ?

copied to clipboard

: null } { this.state.copyFailure ?

copying to clipboard not supported in this browser. Use Cmd + C.

: null }
); } } export default onClickOutside(PermalinkButton);