Skip to content

Commit 1052984

Browse files
committed
Add share tooltip functionality to Profile component with styling
1 parent 849c524 commit 1052984

File tree

2 files changed

+118
-25
lines changed

2 files changed

+118
-25
lines changed

src/components/Profile/Profile.jsx

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ import {
1919
FaReddit,
2020
FaShareAlt,
2121
} from 'react-icons/fa';
22-
import { FaHandshake } from 'react-icons/fa';
22+
import { FaHandshake, FaCopy, FaTimes } from 'react-icons/fa';
2323
import { FaXTwitter, FaLocationDot } from 'react-icons/fa6';
2424
import { SiLeetcode, SiCodeforces, SiHashnode, SiReplit, SiHackerrank } from 'react-icons/si';
25+
import './ProfileShareTooltip.css';
2526

2627
const UnstopIcon = () => (
2728
<svg width="24" height="24" viewBox="0 0 225 225" xmlns="http://www.w3.org/2000/svg">
@@ -53,17 +54,17 @@ function Profile({ data }) {
5354
function Card({ data }) {
5455
const cardRef = React.useRef();
5556
const [showFallback, setShowFallback] = React.useState(false);
57+
const [showTooltip, setShowTooltip] = React.useState(false);
58+
const shareBtnRef = React.useRef();
5659

5760
const handleWheel = (event) => {
5861
event.stopPropagation();
5962
event.preventDefault();
6063
let container = event.target;
6164
if (!container) return false;
62-
6365
while (!container.classList.contains('skills-container')) {
6466
container = container.parentNode;
6567
}
66-
6768
const delta = event.deltaX || event.deltaY;
6869
container.scrollLeft += delta;
6970
};
@@ -72,6 +73,41 @@ function Card({ data }) {
7273
cardRef.current.addEventListener('wheel', handleWheel, { passive: false });
7374
}, []);
7475

76+
React.useEffect(() => {
77+
if (!showTooltip) return;
78+
function handleClickOutside(e) {
79+
if (
80+
shareBtnRef.current &&
81+
!shareBtnRef.current.contains(e.target)
82+
) {
83+
setShowTooltip(false);
84+
}
85+
}
86+
document.addEventListener('mousedown', handleClickOutside);
87+
return () => {
88+
document.removeEventListener('mousedown', handleClickOutside);
89+
};
90+
}, [showTooltip]);
91+
92+
const profileFileName = data.fileName.replace('.json', '');
93+
const shareUrl = `https://www.devdisplay.org/profile/${profileFileName}`;
94+
95+
// Tooltip share actions
96+
const handleShareX = () => {
97+
const caption = encodeURIComponent(`🚀 Check out my DevDisplay profile! #DevDisplay\n${shareUrl}`);
98+
window.open(`https://x.com/intent/tweet?text=${caption}`, '_blank');
99+
setShowTooltip(false);
100+
};
101+
const handleShareLinkedIn = () => {
102+
const caption = encodeURIComponent(`Check out my DevDisplay profile!\n${shareUrl}`);
103+
window.open(`https://www.linkedin.com/sharing/share-offsite/?url=${shareUrl}&summary=${caption}`, '_blank');
104+
setShowTooltip(false);
105+
};
106+
const handleCopy = () => {
107+
navigator.clipboard.writeText(shareUrl);
108+
setShowTooltip(false);
109+
alert(`URL copied to clipboard: ${shareUrl}`);
110+
};
75111
return (
76112
<div className="mb-6 h-auto rounded-lg bg-white p-4 shadow dark:bg-textPrimary">
77113
<div className="relative flex gap-4">
@@ -154,28 +190,31 @@ function Card({ data }) {
154190
</div>
155191
</div>
156192
<div className="flex items-center justify-end md:absolute md:right-0 md:top-0">
157-
<FaShareAlt
158-
className="mr-4 cursor-pointer text-xl text-blue-600 duration-300 hover:scale-125"
159-
onClick={(e) => {
160-
const profileFileName = data.fileName.replace('.json', '');
161-
const shareUrl = `https://www.devdisplay.org/profile/${profileFileName}`;
162-
console.log('Share URL:', shareUrl); // Log the share URL
163-
164-
if (navigator.share) {
165-
navigator
166-
.share({
167-
title: 'Check out this profile!',
168-
text: 'Check out my DevDisplay profile!',
169-
url: shareUrl,
170-
})
171-
.then(() => console.log('Successful share'))
172-
.catch((error) => console.log('Error sharing', error));
173-
} else {
174-
navigator.clipboard.writeText(shareUrl);
175-
alert(`URL copied to clipboard: ${shareUrl}`);
176-
}
177-
}}
178-
/>
193+
<div className="relative" ref={shareBtnRef}>
194+
<FaShareAlt
195+
className="mr-4 cursor-pointer text-xl text-blue-600 duration-300 hover:scale-125"
196+
onClick={() => setShowTooltip(true)}
197+
/>
198+
{showTooltip && (
199+
<div className="profile-share-tooltip">
200+
<button className="profile-share-close" onClick={() => setShowTooltip(false)}>
201+
<FaTimes />
202+
</button>
203+
<div className="profile-share-row" onClick={handleShareX}>
204+
<FaXTwitter className="text-xl" />
205+
<span>Share on X</span>
206+
</div>
207+
<div className="profile-share-row" onClick={handleShareLinkedIn}>
208+
<FaLinkedin className="text-xl" />
209+
<span>Share on LinkedIn</span>
210+
</div>
211+
<div className="profile-share-row" onClick={handleCopy}>
212+
<FaCopy className="text-xl" />
213+
<span>Copy Link</span>
214+
</div>
215+
</div>
216+
)}
217+
</div>
179218
<a
180219
href={data.portfolio}
181220
className={`flex w-28 items-center gap-2 ${
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* Tooltip styles for Profile share button */
2+
.profile-share-tooltip {
3+
position: absolute;
4+
top: 40px;
5+
right: 0;
6+
z-index: 50;
7+
background: #091224;
8+
color: #00A6FB;
9+
border-radius: 0.75rem;
10+
box-shadow: 0 4px 24px rgba(13,25,53,0.15);
11+
padding: 1rem 1.25rem;
12+
min-width: 220px;
13+
display: flex;
14+
flex-direction: column;
15+
gap: 1rem;
16+
animation: tooltipFadeIn 0.3s cubic-bezier(0.4,0,0.2,1);
17+
}
18+
19+
@keyframes tooltipFadeIn {
20+
0% { opacity: 0; transform: translateY(-10px) scale(0.95); }
21+
100% { opacity: 1; transform: translateY(0) scale(1); }
22+
}
23+
24+
.profile-share-tooltip .profile-share-row {
25+
display: flex;
26+
align-items: center;
27+
gap: 0.75rem;
28+
cursor: pointer;
29+
padding: 0.5rem 0.75rem;
30+
border-radius: 0.5rem;
31+
transition: background 0.2s, transform 0.2s;
32+
}
33+
34+
.profile-share-tooltip .profile-share-row:hover {
35+
background: #0ea5e9;
36+
color: #fff;
37+
transform: scale(1.05);
38+
}
39+
40+
.profile-share-tooltip .profile-share-close {
41+
position: absolute;
42+
top: 0.5rem;
43+
right: 0.5rem;
44+
background: transparent;
45+
border: none;
46+
color: #00A6FB;
47+
font-size: 1.25rem;
48+
cursor: pointer;
49+
transition: color 0.2s;
50+
}
51+
52+
.profile-share-tooltip .profile-share-close:hover {
53+
color: #fff;
54+
}

0 commit comments

Comments
 (0)