source: node_modules/react-copy-to-clipboard/README.md

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 4.2 KB
Line 
1# react-copy-to-clipboard [![npm](https://img.shields.io/npm/v/react-copy-to-clipboard.svg?style=flat-square)](https://www.npmjs.com/package/react-copy-to-clipboard)
2
3[![Gitter](https://img.shields.io/gitter/room/nkbt/help.svg?style=flat-square)](https://gitter.im/nkbt/help)
4
5[![CircleCI](https://img.shields.io/circleci/project/nkbt/react-copy-to-clipboard.svg?style=flat-square&label=nix-build)](https://circleci.com/gh/nkbt/react-copy-to-clipboard)
6[![Dependencies](https://img.shields.io/david/nkbt/react-copy-to-clipboard.svg?style=flat-square)](https://david-dm.org/nkbt/react-copy-to-clipboard)
7[![Dev Dependencies](https://img.shields.io/david/dev/nkbt/react-copy-to-clipboard.svg?style=flat-square)](https://david-dm.org/nkbt/react-copy-to-clipboard#info=devDependencies)
8
9Copy to clipboard React component
10
11Based on [copy-to-clipboard](https://npm.im/copy-to-clipboard)
12
13> 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'
14
15
16![Copy to clipboard](example/copy-to-clipboard.gif)
17
18
19## Installation
20
21### NPM
22
23```sh
24npm install --save react-copy-to-clipboard
25```
26
27Don't forget to manually install peer dependencies (`react`) if you use npm@3.
28
29
30### 1998 Script Tag:
31```html
32<script src="https://unpkg.com/react@16.0.0/umd/react.production.min.js"></script>
33<script src="https://unpkg.com/react-copy-to-clipboard/build/react-copy-to-clipboard.js"></script>
34(Module exposed as `CopyToClipboard`)
35```
36
37## Live design system demo
38
39[https://www.jinno.io/app/18/](https://www.jinno.io/app/18/?source=react-copy-to-clipboard)
40
41## Simple web demo
42
43[http://nkbt.github.io/react-copy-to-clipboard](http://nkbt.github.io/react-copy-to-clipboard)
44
45## Codepen demo
46
47[http://codepen.io/nkbt/pen/eNPoQv](http://codepen.io/nkbt/pen/eNPoQv?editors=0010)
48
49## Usage
50```js
51import React from 'react';
52import ReactDOM from 'react-dom';
53import {CopyToClipboard} from 'react-copy-to-clipboard';
54
55class App extends React.Component {
56 state = {
57 value: '',
58 copied: false,
59 };
60
61 render() {
62 return (
63 <div>
64 <input value={this.state.value}
65 onChange={({target: {value}}) => this.setState({value, copied: false})} />
66
67 <CopyToClipboard text={this.state.value}
68 onCopy={() => this.setState({copied: true})}>
69 <span>Copy to clipboard with span</span>
70 </CopyToClipboard>
71
72 <CopyToClipboard text={this.state.value}
73 onCopy={() => this.setState({copied: true})}>
74 <button>Copy to clipboard with button</button>
75 </CopyToClipboard>
76
77 {this.state.copied ? <span style={{color: 'red'}}>Copied.</span> : null}
78 </div>
79 );
80 }
81}
82
83const appRoot = document.createElement('div');
84document.body.appendChild(appRoot);
85ReactDOM.render(<App />, appRoot);
86```
87
88## Options
89
90
91#### `text`: PropTypes.string.isRequired
92
93Text to be copied to clipboard
94
95
96#### `onCopy`: PropTypes.func
97
98Optional callback, will be called when text is copied
99
100```
101onCopy(text, result)
102```
103`result (bool)`: Returns `true` if copied successfully, else `false`.
104
105
106#### `options`: PropTypes.shape({debug: bool, message: string})
107
108Optional [copy-to-clipboard](https://npm.im/copy-to-clipboard) options.
109
110See [API docs](https://npm.im/copy-to-clipboard#api) for details
111
112#### `children`: PropTypes.node.isRequired
113
114CopyToClipboard 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.
115
116```js
117<CopyToClipboard text="Hello!">
118 <button>Copy to clipboard</button>
119</CopyToClipboard>
120```
121
122## Development and testing
123
124Currently is being developed and tested with the latest stable `Node 8` on `OSX`.
125
126To run example covering all `CopyToClipboard` features, use `yarn start`, which will compile `example/Example.js`
127
128```bash
129git clone git@github.com:nkbt/react-copy-to-clipboard.git
130cd react-copy-to-clipboard
131yarn install
132yarn start
133
134# then
135open http://localhost:8080
136```
137
138## Tests
139
140```bash
141# to run ESLint check
142yarn lint
143
144# to run tests
145yarn test
146
147# to run end-to-end tests
148# first, run `selenium/standalone-firefox:3.4.0` docker image
149docker run -p 4444:4444 selenium/standalone-firefox:3.4.0
150# then run test
151yarn e2e
152```
153
154## License
155
156MIT
Note: See TracBrowser for help on using the repository browser.