Skip to content

Commit 8b5db37

Browse files
committed
Handle copying...
1 parent abc535d commit 8b5db37

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

src/components/base64/Base64.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const Base64 = () => {
77
const [string, setString] = useState(true);
88
const [output, setOutput] = useState(btoa('Raw data'));
99
const [opening, setOpening] = useState(false);
10+
const [copied, setCopied] = useState(false);
1011

1112
const handleChangeInput = (evt: { target: { value: string } }) =>
1213
setInput(evt.target.value);
@@ -27,7 +28,9 @@ const Base64 = () => {
2728
};
2829

2930
const handleCopyOutput = () => {
31+
setCopied(true);
3032
clipboard.write({ text: output });
33+
setTimeout(() => setCopied(false), 500);
3134
};
3235

3336
useEffect(() => {
@@ -57,8 +60,8 @@ const Base64 = () => {
5760
>
5861
Open...
5962
</button>
60-
<div className="flex space-x-4 items-center">
61-
<label htmlFor="string" className="flex items-center space-x-2">
63+
<div className="flex space-x-2 items-center">
64+
<label htmlFor="string" className="flex items-center space-x-1">
6265
<input
6366
type="radio"
6467
className="btn"
@@ -69,7 +72,7 @@ const Base64 = () => {
6972
/>
7073
<p>Text</p>
7174
</label>
72-
<label htmlFor="raw" className="flex items-center space-x-2">
75+
<label htmlFor="raw" className="flex items-center space-x-1">
7376
<input
7477
type="radio"
7578
className="btn"
@@ -84,7 +87,7 @@ const Base64 = () => {
8487
</span>
8588
<span className="flex space-x-4">
8689
<div className="flex space-x-4 items-center">
87-
<label htmlFor="encoder" className="flex items-center space-x-2">
90+
<label htmlFor="encoder" className="flex items-center space-x-1">
8891
<input
8992
type="radio"
9093
className="btn"
@@ -95,7 +98,7 @@ const Base64 = () => {
9598
/>
9699
<p>Encode</p>
97100
</label>
98-
<label htmlFor="decoder" className="flex items-center space-x-2">
101+
<label htmlFor="decoder" className="flex items-center space-x-1">
99102
<input
100103
type="radio"
101104
className="btn"
@@ -107,8 +110,13 @@ const Base64 = () => {
107110
<p>Decode</p>
108111
</label>
109112
</div>
110-
<button type="button" className="btn" onClick={handleCopyOutput}>
111-
Copy
113+
<button
114+
type="button"
115+
className="btn"
116+
onClick={handleCopyOutput}
117+
disabled={copied}
118+
>
119+
{copied ? 'Copied' : 'Copy'}
112120
</button>
113121
</span>
114122
</div>

src/components/md-to-html/MarkdownToHtml.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const Md2Html = () => {
77
const [md, setMd] = useState('# Hello\n> This is a quote');
88
const [preview, setPreview] = useState(true);
99
const [opening, setOpening] = useState(false);
10+
const [copied, setCopied] = useState(false);
1011

1112
const handleChange = (evt: { target: { value: string } }) =>
1213
setMd(evt.target.value);
@@ -26,7 +27,9 @@ const Md2Html = () => {
2627
};
2728

2829
const handleCopy = () => {
30+
setCopied(true);
2931
clipboard.write({ text: marked(md) });
32+
setTimeout(() => setCopied(false), 500);
3033
};
3134

3235
return (
@@ -53,8 +56,13 @@ const Md2Html = () => {
5356
>
5457
{preview ? 'Raw HTML' : 'Preview'}
5558
</button>
56-
<button type="button" className="btn" onClick={handleCopy}>
57-
Copy
59+
<button
60+
type="button"
61+
className="btn"
62+
onClick={handleCopy}
63+
disabled={copied}
64+
>
65+
{copied ? 'Copied' : 'Copy'}
5866
</button>
5967
</span>
6068
</div>

src/components/unix-timestamp/UnixTimestamp.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const UnixTimestampConverter = () => {
3939
const handleCopy = () => {
4040
clipboard.write({ text: `${date.unix()}` });
4141
setCopied(true);
42-
setTimeout(() => setCopied(false), 1_000);
42+
setTimeout(() => setCopied(false), 500);
4343
};
4444

4545
const handleChangeEpoch = (evt: { target: { value: string } }) => {
@@ -183,7 +183,7 @@ const UnixTimestampConverter = () => {
183183
onClick={handleCopy}
184184
disabled={copied}
185185
>
186-
Copy
186+
{copied ? 'Copied' : 'Copy'}
187187
</button>
188188
</section>
189189
</div>

0 commit comments

Comments
 (0)