diff --git a/public/images/hackernews.svg b/public/images/hackernews.svg new file mode 100644 index 000000000..ae8caccca --- /dev/null +++ b/public/images/hackernews.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/public/images/reddit.svg b/public/images/reddit.svg new file mode 100644 index 000000000..062a4936b --- /dev/null +++ b/public/images/reddit.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/components/RoadmapHeader.astro b/src/components/RoadmapHeader.astro index ca0bb36c3..3cc9e224c 100644 --- a/src/components/RoadmapHeader.astro +++ b/src/components/RoadmapHeader.astro @@ -10,6 +10,9 @@ import { MarkFavorite } from './FeaturedItems/MarkFavorite'; import { TeamVersions } from './TeamVersions/TeamVersions'; import { CreateVersion } from './CreateVersion/CreateVersion'; import { type RoadmapFrontmatter } from '../lib/roadmap'; +import { ShareRoadmapButton } from './ShareRoadmapButton'; +import { Share2 } from 'lucide-react'; +import ShareIcons from './ShareIcons/ShareIcons.astro'; export interface Props { title: string; @@ -96,6 +99,12 @@ const hasTnsBanner = !!tnsBannerLink; ← All Roadmaps + + {isRoadmapReady && ( <> > )} - - - - Subscribe - > ) } diff --git a/src/components/ShareRoadmapButton.tsx b/src/components/ShareRoadmapButton.tsx new file mode 100644 index 000000000..d70d2661b --- /dev/null +++ b/src/components/ShareRoadmapButton.tsx @@ -0,0 +1,135 @@ +import { Check, Copy, Facebook, Linkedin, Share2, Twitter } from 'lucide-react'; +import { useRef, useState } from 'react'; +import { useOutsideClick } from '../hooks/use-outside-click.ts'; +import { useCopyText } from '../hooks/use-copy-text.ts'; +import { cn } from '../lib/classname.ts'; + +type ShareRoadmapButtonProps = { + description: string; + pageUrl: string; +}; + +export function ShareRoadmapButton(props: ShareRoadmapButtonProps) { + const { description, pageUrl } = props; + + const { isCopied, copyText } = useCopyText(); + + const containerRef = useRef(null); + const [isDropdownOpen, setIsDropdownOpen] = useState(false); + + const twitterUrl = `https://twitter.com/intent/tweet?text=${description}&url=${pageUrl}`; + const fbUrl = `https://www.facebook.com/sharer/sharer.php?quote=${description}&u=${pageUrl}`; + const hnUrl = `https://news.ycombinator.com/submitlink?t=${description}&u=${pageUrl}`; + const redditUrl = `https://www.reddit.com/submit?title=${description}&url=${pageUrl}`; + const linkedinUrl = `https://www.linkedin.com/shareArticle?mini=true&url=${pageUrl}&title=${description}`; + + useOutsideClick(containerRef, () => { + setIsDropdownOpen(false); + }); + + return ( + + setIsDropdownOpen(!isDropdownOpen)} + className={cn( + 'inline-flex items-center justify-center rounded-md bg-yellow-400 px-3 py-1.5 text-xs font-medium hover:bg-yellow-500 sm:text-sm', + { + 'bg-yellow-500': isDropdownOpen, + 'bg-green-400': isCopied, + }, + )} + aria-label="Share Roadmap" + > + {!isCopied && ( + <> + + Share + > + )} + {isCopied && ( + <> + + Copied + > + )} + + + {isDropdownOpen && ( + + + { + copyText(pageUrl); + setIsDropdownOpen(false); + }} + className="flex w-full items-center gap-2 px-2 py-2 text-sm text-slate-100 hover:bg-slate-700" + > + + + + Copy Link + + + + + + Share on Twitter + + + + + + Facebook + + + + + + Hacker News + + + + + + Reddit + + + + + + LinkedIn + + + + )} + + ); +}