The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add comments badge
Tim Wilsonec36f7c2d1e1
diff --git a/apps/web/ui/links/link-title-column.tsx b/apps/web/ui/links/link-title-column.tsxindex 723389b67b..8c29afc688 100644--- a/apps/web/ui/links/link-title-column.tsx+++ b/apps/web/ui/links/link-title-column.tsx@@ -5,13 +5,15 @@ import { DomainProps, UserProps } from "@/lib/types";import {ArrowTurnRight2,Avatar,+ CardList,CopyButton,LinkLogo,Tooltip,TooltipContent,useIntersectionObserver,+ useMediaQuery,} from "@dub/ui";-import { ArrowRight } from "@dub/ui/src/icons";+import { ArrowRight, Page2 } from "@dub/ui/src/icons";import {cn,fetcher,@@ -20,15 +22,20 @@ import {isDubDomain,} from "@dub/utils";import { formatDate } from "date-fns";+import { AnimatePresence, motion } from "framer-motion";import { Mail } from "lucide-react";-import { PropsWithChildren, useRef } from "react";+import { PropsWithChildren, useContext, useRef } from "react";import useSWR from "swr";import { ResponseLink } from "./links-container";export function LinkTitleColumn({ link }: { link: ResponseLink }) {- const { url, domain, user, createdAt } = link;+ const { url, domain } = link;const path = link.key === "_root" ? "" : `/${link.key}`;+ const { isMobile } = useMediaQuery();++ const { hovered } = useContext(CardList.Card.Context);+const ref = useRef<HTMLDivElement>(null);// Use intersection observer for basic "virtualization" to improve transition performance@@ -62,24 +69,45 @@ export function LinkTitleColumn({ link }: { link: ResponseLink }) {className="flex items-center font-medium"title={`${domain}${path}`}>- <span className="truncate">{domain + path}</span>-- <div className="transition-all group-hover/card:w-[22px] group-hover/card:translate-x-0 group-hover/card:opacity-100 sm:w-0 sm:-translate-x-1 sm:opacity-0">- <CopyButton- value={domain + path}- variant="neutral"- className="ml-1 translate-y-px p-0.5"- />- </div>+ <span className="truncate leading-6">{domain + path}</span>++ <AnimatePresence>+ {(hovered || isMobile) && (+ <motion.div+ initial={{+ width: 0,+ opacity: 0,+ }}+ animate={{+ width: "auto",+ opacity: 1,+ }}+ exit={{+ width: 0,+ opacity: 0,+ }}+ transition={{ duration: 0.15 }}+ className="-mt-px ml-1 flex translate-y-px items-center justify-end gap-1 overflow-visible [mask-image:linear-gradient(to_right,transparent,black_4px)]"+ >+ <div className="w-0" /> {/* Spacer for masking */}+ {link.comments && (+ <CommentsBadge comments={link.comments} />+ )}+ <CopyButton+ value={domain + path}+ variant="neutral"+ className="p-1"+ />+ </motion.div>+ )}+ </AnimatePresence></span></UnverifiedTooltip></div><Details link={link} compact /></div>- <div className="mt-1">- <Details link={link} />- </div>+ <Details link={link} /></div></>)}@@ -117,12 +145,35 @@ function UnverifiedTooltip({);}+function CommentsBadge({ comments }: { comments: string }) {+ return (+ <div className="hidden sm:block">+ <Tooltip+ content={+ <div className="divide-y-gray-200 divide-y text-sm">+ <div className="flex items-center gap-2 px-4 py-3">+ <Page2 className="h-3.5 w-3.5" />+ <span className="text-gray-500">Link comments</span>+ </div>+ <p className="max-w-[300px] px-5 py-3 text-gray-700">{comments}</p>+ </div>+ }+ side="bottom"+ >+ <div className="rounded-full bg-gray-100 p-1 hover:bg-gray-200">+ <Page2 className="h-3.5 w-3.5" />+ </div>+ </Tooltip>+ </div>+ );+}+function Details({ link, compact }: { link: ResponseLink; compact?: boolean }) {const { url, user, createdAt } = link;return (<divclassName={cn(- "min-w-0 items-center gap-1.5 text-xs transition-[opacity,display] delay-[0s,150ms] duration-[150ms,0s] md:gap-3",+ "min-w-0 items-center gap-1.5 text-sm transition-[opacity,display] delay-[0s,150ms] duration-[150ms,0s] md:gap-3",compact? "hidden opacity-0 group-data-[variant=compact]/card-list:flex group-data-[variant=compact]/card-list:opacity-100": "hidden opacity-0 group-data-[variant=loose]/card-list:flex group-data-[variant=loose]/card-list:opacity-100",diff --git a/packages/ui/src/card-list/card-list-card.tsx b/packages/ui/src/card-list/card-list-card.tsxindex 4c0b3c04c3..4e55203220 100644--- a/packages/ui/src/card-list/card-list-card.tsx+++ b/packages/ui/src/card-list/card-list-card.tsx@@ -1,6 +1,6 @@import { cn } from "@dub/utils";import { cva } from "class-variance-authority";-import { PropsWithChildren, useContext } from "react";+import { PropsWithChildren, createContext, useContext, useState } from "react";import { CardListContext } from "./card-list";const cardListCardVariants = cva(@@ -17,15 +17,27 @@ const cardListCardVariants = cva(},);+export const CardContext = createContext<{+ hovered: boolean;+}>({ hovered: false });+export function CardListCard({className,children,}: PropsWithChildren<{ className?: string }>) {const { variant } = useContext(CardListContext);+ const [hovered, setHovered] = useState(false);+return (- <li className={cn(cardListCardVariants({ variant }), className)}>- {children}+ <li+ className={cn(cardListCardVariants({ variant }), className)}+ onPointerEnter={() => setHovered(true)}+ onPointerLeave={() => setHovered(false)}+ >+ <CardContext.Provider value={{ hovered }}>+ {children}+ </CardContext.Provider></li>);}diff --git a/packages/ui/src/card-list/index.ts b/packages/ui/src/card-list/index.tsindex 050ba7d3ed..2ba4581e67 100644--- a/packages/ui/src/card-list/index.ts+++ b/packages/ui/src/card-list/index.ts@@ -1,9 +1,11 @@import { CardList as CardListComponent, CardListContext } from "./card-list";-import { CardListCard } from "./card-list-card";+import { CardContext, CardListCard } from "./card-list-card";import { CardListPagination } from "./card-list-pagination";const CardList = Object.assign(CardListComponent, {- Card: CardListCard,+ Card: Object.assign(CardListCard, {+ Context: CardContext,+ }),Context: CardListContext,Pagination: CardListPagination,});diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.tsindex 3fee1fc428..a71029eb34 100644--- a/packages/ui/src/icons/nucleo/index.ts+++ b/packages/ui/src/icons/nucleo/index.ts@@ -36,6 +36,7 @@ export * from "./lines-y";export * from "./magnifier";export * from "./mobile-phone";export * from "./office-building";+export * from "./page2";export * from "./paintbrush";export * from "./pen-writing";export * from "./qrcode";diff --git a/packages/ui/src/icons/nucleo/page2.tsx b/packages/ui/src/icons/nucleo/page2.tsxnew file mode 100644index 0000000000..d7fc051add--- /dev/null+++ b/packages/ui/src/icons/nucleo/page2.tsx@@ -0,0 +1,62 @@+import { SVGProps } from "react";++export function Page2(props: SVGProps<SVGSVGElement>) {+ return (+ <svg+ height="18"+ width="18"+ viewBox="0 0 18 18"+ xmlns="http://www.w3.org/2000/svg"+ {...props}+ >+ <g fill="currentColor">+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="5.75"+ x2="9"+ y1="11.25"+ y2="11.25"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="5.75"+ x2="12.25"+ y1="8.25"+ y2="8.25"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="5.75"+ x2="12.25"+ y1="5.25"+ y2="5.25"+ />+ <rect+ height="14.5"+ width="12.5"+ fill="none"+ rx="2"+ ry="2"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x="2.75"+ y="1.75"+ />+ </g>+ </svg>+ );+}