-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCopyToClipboard.jsx
108 lines (100 loc) · 2.33 KB
/
CopyToClipboard.jsx
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import React, { useRef } from "react";
function CopyToClipboard({
title,
emoji,
missingLabel,
collectedLabel,
list,
selected,
}) {
const missingList = list
.filter((item) => !selected.includes(item.id))
.map((item) => `${emoji} · ${item.name}`)
.join("\n");
emoji;
const caughtList = list
.filter((item) => selected.includes(item.id))
.map((item) => `${emoji} · ${item.name}`)
.join("\n");
const filteredList = {
missing: missingList,
caught: caughtList,
};
const missing = useRef(null);
const caught = useRef(null);
function copyToClipboard(input) {
input.current.value = filteredList[input.current.name];
input.current.select();
document.execCommand("copy");
alert("Copied");
}
return (
<div className="textCenter">
<h2>{title}</h2>
<p>
<button className="button" onClick={() => copyToClipboard(missing)}>
{missingLabel}
</button>
</p>
<p>
<button
className="button buttonSecondary"
onClick={() => copyToClipboard(caught)}
>
{collectedLabel}
</button>
<label
style={{
position: "absolute",
left: "-100vw",
width: 0,
height: 0,
padding: 0,
}}
>
{missingLabel}
<textarea
name="missing"
ref={missing}
defaultValue={missingList}
style={{
position: "absolute",
left: "-100vw",
width: 0,
height: 0,
padding: 0,
fontSize: "1em",
}}
/>
</label>
<label
style={{
position: "absolute",
left: "-100vw",
opactiy: 0,
width: 0,
height: 0,
padding: 0,
}}
>
{collectedLabel}
<textarea
name="caught"
ref={caught}
style={{
position: "absolute",
left: "-100vw",
opactiy: 0,
width: 0,
height: 0,
padding: 0,
fontSize: "1em",
}}
defaultValue={caughtList}
/>
</label>
</p>
</div>
);
}
export default CopyToClipboard;