Download wp-calypso/client/components/forms/clipboard-button/index.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 944 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/components/forms/clipboard-button/index.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/components/forms/clipboard-button/index.tsx
-
curl -L -o index.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/components/forms/clipboard-button/index.tsx
944 Bytes
| import { Button } from '@automattic/components'; | |
| import clsx from 'clsx'; | |
| import { forwardRef } from 'react'; | |
| interface ClipboardButtonProps { | |
| className?: string; | |
| compact?: boolean; | |
| disabled?: boolean; | |
| primary?: boolean; | |
| scary?: boolean; | |
| busy?: boolean; | |
| borderless?: boolean; | |
| plain?: boolean; | |
| transparent?: boolean; | |
| text: string | null; | |
| onCopy?: () => void; | |
| onMouseLeave?: () => void; | |
| } | |
| // eslint-disable-next-line @typescript-eslint/no-empty-function | |
| const noop = () => {}; | |
| const ClipboardButton = forwardRef< | |
| HTMLButtonElement, | |
| React.PropsWithChildren< ClipboardButtonProps > | |
| >( ( { className, text, onCopy = noop, ...rest }, ref ) => { | |
| function onCopyHandler() { | |
| if ( text ) { | |
| navigator.clipboard.writeText( text ); | |
| onCopy(); | |
| } | |
| } | |
| return ( | |
| <Button | |
| { ...rest } | |
| onClick={ onCopyHandler } | |
| ref={ ref } | |
| className={ clsx( 'clipboard-button', className ) } | |
| /> | |
| ); | |
| } ); | |
| export default ClipboardButton; | |