-
-
Notifications
You must be signed in to change notification settings - Fork 79
feat: add ShareButton component and sonner(Snackbar for notify users) #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,69 @@ | ||||||||||||||||||
| "use client"; | ||||||||||||||||||
|
|
||||||||||||||||||
| import { useState, useEffect } from "react"; | ||||||||||||||||||
| import { Share2, Check } from "lucide-react"; | ||||||||||||||||||
| import { toast } from "sonner"; | ||||||||||||||||||
| import { | ||||||||||||||||||
| Tooltip, | ||||||||||||||||||
| TooltipContent, | ||||||||||||||||||
| TooltipTrigger, | ||||||||||||||||||
| } from "@/components/ui/tooltip"; | ||||||||||||||||||
|
|
||||||||||||||||||
| export default function ShareButton({ username }: { username: string }) { | ||||||||||||||||||
| const [copied, setCopied] = useState(false); | ||||||||||||||||||
|
AnitusA marked this conversation as resolved.
|
||||||||||||||||||
|
|
||||||||||||||||||
| const handleShare = async () => { | ||||||||||||||||||
| const shareData = { | ||||||||||||||||||
| title: `${username}'s Portfolio`, | ||||||||||||||||||
| text: `Check out ${username}'s professional developer portfolio on devb.io!`, | ||||||||||||||||||
| url: window.location.href, | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| if (navigator.share) { | ||||||||||||||||||
| try { | ||||||||||||||||||
| await navigator.share(shareData); | ||||||||||||||||||
| } catch (err) { | ||||||||||||||||||
| console.error("Error sharing:", err); | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+25
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When using
Suggested change
|
||||||||||||||||||
| } else { | ||||||||||||||||||
| // Fallback: Copy to clipboard | ||||||||||||||||||
| try { | ||||||||||||||||||
| await navigator.clipboard.writeText(window.location.href); | ||||||||||||||||||
| setCopied(true); | ||||||||||||||||||
| toast.success("Link copied to clipboard!", { | ||||||||||||||||||
| style: { | ||||||||||||||||||
| backgroundColor: "#B9FF66", | ||||||||||||||||||
| color: "black", | ||||||||||||||||||
| border: "1px solid black", | ||||||||||||||||||
| fontWeight: "bold", | ||||||||||||||||||
| }, | ||||||||||||||||||
|
AnitusA marked this conversation as resolved.
|
||||||||||||||||||
| }); | ||||||||||||||||||
| setTimeout(() => setCopied(false), 2000); | ||||||||||||||||||
|
AnitusA marked this conversation as resolved.
|
||||||||||||||||||
| } catch (err) { | ||||||||||||||||||
| console.error("Failed to copy:", err); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| return ( | ||||||||||||||||||
| <Tooltip> | ||||||||||||||||||
| <TooltipTrigger asChild> | ||||||||||||||||||
| <button | ||||||||||||||||||
| onClick={handleShare} | ||||||||||||||||||
| className="group relative w-12 h-12 flex items-center justify-center bg-white rounded-2xl border border-black hover:bg-[#B9FF66] transition-all duration-300 cursor-pointer" | ||||||||||||||||||
| > | ||||||||||||||||||
| <span className="w-6 h-6 group-hover:rotate-12 transition-transform duration-300"> | ||||||||||||||||||
| {copied ? ( | ||||||||||||||||||
| <Check size={24} className="text-green-600" /> | ||||||||||||||||||
| ) : ( | ||||||||||||||||||
| <Share2 size={24} className="text-black" /> | ||||||||||||||||||
| )} | ||||||||||||||||||
| </span> | ||||||||||||||||||
| </button> | ||||||||||||||||||
| </TooltipTrigger> | ||||||||||||||||||
| <TooltipContent> | ||||||||||||||||||
| {copied ? "Link Copied!" : "Share Portfolio"} | ||||||||||||||||||
| </TooltipContent> | ||||||||||||||||||
| </Tooltip> | ||||||||||||||||||
| ); | ||||||||||||||||||
| } | ||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better readability and maintainability, it's a good practice to define component props using an interface or a type alias instead of an inline type.