CopyToClipboard ReactJS component


              class CopyToClipboard extends React.Component {
	copy() {
		const textarea = this.textarea;
		let { text, onCopy, silent } = this.props;
		silent =
			typeof silent === "boolean" ||
			silent.toLowerCase() == "true" ||
			silent == "1";
		textarea.value = onCopy.call(this, text);
		textarea.select();

		try {
			const successful = document.execCommand("copy");
			const msg = successful ? "successful" : "unsuccessful";
			if (!silent) {
				prompt("Copying text command was " + msg, textarea.value);
			}
		} catch (err) {
			alert(`Oops, unable to copy (${err.message})`);
		}
	}
	render() {
		const { label } = this.props;
		const attr = {
			style: this.props.style,
			className: this.props.className,
		}
		return (
			

Let’s block ads! (Why?)

 

Propellerads
 

7 days ago

Leave a Reply