Skip to content

Commit 6fc3c6b

Browse files
committed
Replace react-copy-to-clipboard with our own implementation
It didn't specify compatibility with the new version of React and is small enough to rewrite.
1 parent 3000253 commit 6fc3c6b

File tree

3 files changed

+19
-53
lines changed

3 files changed

+19
-53
lines changed

ui/frontend/Output/Gist.tsx

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import React, { Fragment } from 'react';
2-
import { CopyToClipboard } from 'react-copy-to-clipboard';
1+
import React, { Fragment, useCallback, useState } from 'react';
32

43
import { ClipboardIcon } from '../Icon';
54
import * as selectors from '../selectors';
@@ -34,33 +33,27 @@ interface CopiedProps {
3433
href: string;
3534
}
3635

37-
interface CopiedState {
38-
copied: boolean;
39-
}
36+
const Copied: React.FC<CopiedProps> = ({ children, href }) => {
37+
const [copied, setCopied] = useState(false);
4038

41-
class Copied extends React.PureComponent<CopiedProps, CopiedState> {
42-
public constructor(props: CopiedProps) {
43-
super(props);
44-
this.state = { copied: false };
45-
}
39+
const startCopy = useCallback(() => {
40+
setCopied(true);
4641

47-
public render() {
48-
return (
49-
<p className={this.state.copied ? styles.active : styles.container}>
50-
<a href={this.props.href}>{this.props.children}</a>
51-
<CopyToClipboard text={this.props.href} onCopy={this.copied}>
52-
<button className={styles.button}><ClipboardIcon /></button>
53-
</CopyToClipboard>
54-
<span className={styles.text}>Copied!</span>
55-
</p>
56-
);
57-
}
42+
setTimeout(() => {
43+
setCopied(false);
44+
}, 1000);
45+
}, []);
5846

59-
private copied = () => {
60-
this.setState({ copied: true });
61-
setTimeout(() => { this.setState({ copied: false }); }, 1000);
62-
}
63-
}
47+
return (
48+
<p className={copied ? styles.active : styles.container}>
49+
<a href={href}>{children}</a>
50+
<button className={styles.button} onClick={startCopy}>
51+
<ClipboardIcon />
52+
</button>
53+
<span className={styles.text}>Copied!</span>
54+
</p>
55+
);
56+
};
6457

6558
const Links: React.FC = () => {
6659
const codeUrl = useAppSelector(selectors.codeUrlSelector);

ui/frontend/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"prismjs": "^1.6.0",
1717
"qs": "^6.4.0",
1818
"react": "^19.0.0",
19-
"react-copy-to-clipboard": "^5.0.1",
2019
"react-dom": "^19.0.0",
2120
"react-portal": "^4.1.4",
2221
"react-redux": "^9.0.2",

ui/frontend/pnpm-lock.yaml

Lines changed: 0 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)