-
Notifications
You must be signed in to change notification settings - Fork 12
/
App.tsx
125 lines (113 loc) · 3.65 KB
/
App.tsx
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import React, { useState, useEffect } from 'react';
import '../styles/ui.css';
import catSvg from '../../images/cat.svg';
// Add this new component above the App function
const Stars: React.FC = () => {
// Create stars on component mount
useEffect(() => {
const starsContainer = document.querySelector('.stars');
if (!starsContainer) return;
// Create 50 stars with random positions and animations
for (let i = 0; i < 50; i++) {
const star = document.createElement('div');
star.className = 'star';
// Random star properties
const size = Math.random() * 2 + 1;
const x = Math.random() * 100;
const y = Math.random() * 100;
const duration = Math.random() * 3 + 2;
// Apply styles
star.style.cssText = `
width: ${size}px;
height: ${size}px;
left: ${x}%;
top: ${y}%;
--duration: ${duration}s;
`;
starsContainer.appendChild(star);
}
}, []);
return <div className="stars" />;
};
function App() {
const [selectedName, setSelectedName] = useState<string | null>(null);
const [buttonText, setButtonText] = useState('Copy to cursor');
const onCopyToCursor = () => {
parent.postMessage({ pluginMessage: { type: 'copy-to-clipboard' } }, '*');
};
const copyToClipboard = (text: string) => {
const textArea = document.createElement('textarea');
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
try {
document.execCommand('copy');
console.log('Data copied to clipboard');
setButtonText('Copied!');
} catch (err) {
console.error('Failed to copy data: ', err);
setButtonText('Copy failed');
}
document.body.removeChild(textArea);
setTimeout(() => setButtonText('Copy to cursor'), 2000);
};
useEffect(() => {
window.onmessage = (event) => {
const { type, name, data } = event.data.pluginMessage;
if (type === 'selection-change') {
setSelectedName(name);
} else if (type === 'clipboard-data') {
if (data) {
copyToClipboard(data);
} else {
console.error('No data to copy');
setButtonText('No data');
setTimeout(() => setButtonText('Copy to cursor'), 2000);
}
}
};
}, []);
return (
<>
<Stars />
<div className="app">
{selectedName ? (
<div className="selected-element">
<h3 className="subtitle">Selected Element</h3>
<div className="element-name">{selectedName}</div>
<button className="copy-button" onClick={onCopyToCursor}>
{buttonText}
</button>
</div>
) : (
<div className="frame-preview">
<div className="frame-content">
<img
src={catSvg}
alt="Cat illustration"
style={{ width: '59px', height: '68.5px', marginBottom: '16px' }}
/>
<p>Select a frame or group to start</p>
<p style={{ fontSize: '12px', marginTop: '8px', opacity: 0.8 }}>
Made with ☕️ by{' '}
<a
href="https://designwithprompts.com"
target="_blank"
rel="noopener noreferrer"
style={{
background: 'linear-gradient(90deg, #FF6B6B 0%, #4ECDC4 100%)',
WebkitBackgroundClip: 'text',
WebkitTextFillColor: 'transparent',
}}
>
ash
</a>
</p>
</div>
</div>
)}
</div>
</>
);
}
export default App;