react-copy-to-clipboard
Would try to use execCommand with fallback to IE specific clipboardData interface and finally, fallback to simple prompt with proper text content & 'Copy to clipboard: Ctrl+C, Enter'
Installation
NPM
Don't forget to manually install peer dependencies (react
) if you use npm@3.
1998 Script Tag:
Usage
Options
text
: PropTypes.string.isRequired
Text to be copied to clipboard
onCopy
: PropTypes.func
Optional callback, will be called when text is copied
onCopy(text, result)
result (bool)
: Returns true
if copied successfully, else false
.
options
: PropTypes.shape({debug: bool, message: string})
Optional copy-to-clipboard options.
See API docs for details
children
: PropTypes.node.isRequired
CopyToClipboard is a simple wrapping component, it does not render any tags, so it requires the only child element to be present, which will be used to capture clicks.
Development and testing
Currently is being developed and tested with the latest stable Node 8
on OSX
.
To run example covering all CopyToClipboard
features, use yarn start
, which will compile example/Example.js