-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
45 lines (37 loc) · 922 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import copy from 'copy-to-clipboard';
const CopyToClipboardProps = {
text: {
type: String,
required: true
},
options: {
type: Object,
'default': function _default() {
return null;
}
}
};
const CopyToClipboard = {
name: 'VueCopyToClipboard',
functional: true,
props: CopyToClipboardProps,
render (h, ctx) {
const { props, listeners: { copy: onCopy }, children } = ctx
const { text, options } = props || {}
function handleClick(e) {
// Bypass onClick if it was present
e.preventDefault()
e.stopPropagation()
const result = copy(text, options)
if (onCopy) {
onCopy(text, result)
}
}
return h('span', { on: { 'click': handleClick }}, children);
}
};
/* istanbul ignore next */
CopyToClipboard.install = function (Vue) {
Vue.component(CopyToClipboard.name, CopyToClipboard)
};
export default CopyToClipboard;