File size: 608 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { ClipboardButton } from '@wordpress/components';
import { useState } from 'react';

const ClipboardButtonExample = () => {
	const [ isCopied, setCopied ] = useState( false );

	const text = 'Code is Poetry';
	return (
		<ClipboardButton
			// @ts-expect-error The button props are passed into a Button component internally, but the types don't account that.
			variant="primary"
			text={ text }
			onCopy={ () => setCopied( true ) }
			onFinishCopy={ () => setCopied( false ) }
		>
			{ isCopied ? 'Copied!' : `Copy "${ text }"` }
		</ClipboardButton>
	);
};

export default ClipboardButtonExample;