Skip to content

Commit 8dc8f17

Browse files
committed
feat(src): Add copy to clipboard functionality
1 parent 8bfd322 commit 8dc8f17

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

test/src/index.jsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ scan({
1010
production: true,
1111
});
1212

13+
const copyToClipboard = (text) => {
14+
navigator.clipboard.writeText(text).then(() => {
15+
const button = document.querySelector('.copy-button');
16+
if (button) {
17+
button.textContent = 'Copied!';
18+
setTimeout(() => {
19+
button.textContent = 'Copy';
20+
}, 2000);
21+
}
22+
});
23+
};
24+
1325
export const App = () => {
1426
const [tasks, setTasks] = useState([]);
1527

@@ -50,7 +62,7 @@ export const App = () => {
5062

5163
<div className="task-section">
5264
<p>Try interacting with this input to see it in action:</p>
53-
<AddTask
65+
<AddTaskBar
5466
onCreate={(value) => {
5567
if (!value) return;
5668
setTasks([...tasks, value]);
@@ -67,12 +79,18 @@ export const App = () => {
6779

6880
<div className="sticky-footer">
6981
<p>Get started by adding this script to your app:</p>
70-
<p>
82+
<div className="code-container">
7183
<code>
7284
&lt;script
7385
src=&quot;https://unpkg.com/react-scan/dist/auto.global.js&quot;&gt;&lt;/script&gt;
7486
</code>
75-
</p>
87+
<button
88+
className="copy-button"
89+
onClick={() => copyToClipboard('<script src="https://unpkg.com/react-scan/dist/auto.global.js"></script>')}
90+
>
91+
Copy
92+
</button>
93+
</div>
7694
<p>
7795
<small>
7896
<strong>Important:</strong> Add this before any other scripts run!
@@ -128,7 +146,7 @@ export const Button = ({ onClick, children }) => {
128146
);
129147
};
130148

131-
export const AddTask = ({ onCreate }) => {
149+
export const AddTaskBar = ({ onCreate }) => {
132150
const [value, setValue] = useState('');
133151
const [id, setId] = useState(0);
134152
return (

test/src/styles.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,30 @@ aside {
115115
position: sticky;
116116
bottom: 0;
117117
}
118+
119+
.code-container {
120+
position: relative;
121+
display: flex;
122+
align-items: center;
123+
gap: 0.5rem;
124+
}
125+
126+
.copy-button {
127+
padding: 0.25rem 0.5rem;
128+
border: 1px solid #e0e0e0;
129+
background: white;
130+
border-radius: 0.25rem;
131+
font-size: 0.8rem;
132+
color: #666;
133+
cursor: pointer;
134+
transition: all 0.2s ease;
135+
}
136+
137+
.copy-button:hover {
138+
background: #f5f5f5;
139+
color: #000;
140+
}
141+
142+
.copy-button:active {
143+
background: #eee;
144+
}

0 commit comments

Comments
 (0)