golden hour
/home/godaofbq/oxyrevive.com/wp-content/plugins/code-snippets/js/common
⬆️ Go Up
Upload
File/Folder
Size
Actions
Button.tsx
786 B
Del
OK
ConfirmDialog.tsx
1.07 KB
Del
OK
CopyToClipboardButton.tsx
961 B
Del
OK
TagEditor
-
Del
OK
Edit: CopyToClipboardButton.tsx
import React, { HTMLAttributes, MouseEventHandler, useState } from 'react' const TIMEOUT = 3000 export interface CopyToClipboardButtonProps extends HTMLAttributes<HTMLAnchorElement> { text: string copyIcon?: string successIcon?: string timeout?: number } export const CopyToClipboardButton: React.FC<CopyToClipboardButtonProps> = ({ text, copyIcon = 'clipboard', successIcon = 'yes', ...props }) => { const [isSuccess, setIsSuccess] = useState(false) const clickHandler: MouseEventHandler<HTMLAnchorElement> = event => { event.preventDefault() window.navigator.clipboard?.writeText(text) .then(() => { setIsSuccess(true) setTimeout(() => setIsSuccess(false), TIMEOUT) }) .catch(error => console.error(error)) } return window.navigator.clipboard ? <a href="#" className={`code-snippets-copy-text dashicons dashicons-${isSuccess ? successIcon : copyIcon}`} onClick={clickHandler} {...props} ></a> : null }
Save