Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

improved Tooltip to include jsx content

Steven Teyf3cfef51026e
diff --git a/components/app/add-link-modal.tsx b/components/app/add-link-modal.tsx
index 4f3d2a994e..db2aba2505 100644
--- a/components/app/add-link-modal.tsx
+++ b/components/app/add-link-modal.tsx
@@ -18,7 +18,7 @@ import {
import { useDebounce } from "use-debounce";
import TextareaAutosize from "react-textarea-autosize";
import { mutate } from "swr";
-import Tooltip from "@/components/shared/tooltip";
+import Tooltip, { TooltipContent } from "@/components/shared/tooltip";
function AddLinkModal({
showAddLinkModal,
@@ -289,14 +289,34 @@ function AddLinkButton({
exceededUsage: boolean;
setShowAddLinkModal: Dispatch<SetStateAction<boolean>>;
}) {
- return !domainVerified ? (
- <Tooltip content="You can only start adding links after your project domain is configured.">
+ const router = useRouter();
+ const { slug } = router.query as { slug?: string };
+
+ return !domainVerified && slug ? (
+ <Tooltip
+ content={
+ <TooltipContent
+ title="This domain is not correctly configured. Please configure your domain to
+start adding links."
+ cta="Configure Domain"
+ ctaLink={`/${slug}/settings`}
+ />
+ }
+ >
<div className="text-gray-300 cursor-not-allowed font-medium text-sm px-5 py-2 border rounded-md border-gray-200 transition-all duration-75">
Add
</div>
</Tooltip>
- ) : exceededUsage ? (
- <Tooltip content="You have exceeded your usage limit. We're still collecting data on your existing links, but you need to upgrade to add more links.">
+ ) : exceededUsage && slug ? (
+ <Tooltip
+ content={
+ <TooltipContent
+ title="You have exceeded your usage limit. We're still collecting data on your existing links, but you need to upgrade to add more links."
+ cta="Upgrade"
+ ctaLink={`/${slug}/settings`}
+ />
+ }
+ >
<div className="text-gray-300 cursor-not-allowed font-medium text-sm px-5 py-2 border rounded-md border-gray-200 transition-all duration-75">
Add
</div>
diff --git a/components/app/link-card.tsx b/components/app/link-card.tsx
index 6e7591a35a..9e04998a48 100644
--- a/components/app/link-card.tsx
+++ b/components/app/link-card.tsx
@@ -7,7 +7,7 @@ import { fetcher, nFormatter, linkConstructor, timeAgo } from "@/lib/utils";
import Link from "next/link";
import { LinkProps } from "@/lib/types";
import { useEditLinkModal } from "./edit-link-modal";
-import Tooltip from "@/components/shared/tooltip";
+import Tooltip, { TooltipContent } from "@/components/shared/tooltip";
export default function LinkCard({
props,
@@ -81,7 +81,15 @@ export default function LinkCard({
<div className="flex items-center space-x-3">
<p className="text-sm text-gray-500">Added {timeAgo(timestamp)}</p>
{exceededUsage ? (
- <Tooltip content="You have exceeded your usage limit. We're still collecting data on your existing links, but you need to upgrade to edit them.">
+ <Tooltip
+ content={
+ <TooltipContent
+ title="You have exceeded your usage limit. We're still collecting data on your existing links, but you need to upgrade to edit them."
+ cta="Upgrade"
+ ctaLink={`/${slug}/settings`}
+ />
+ }
+ >
<div className="text-gray-300 cursor-not-allowed font-medium text-sm px-5 py-2 border rounded-md border-gray-200 transition-all duration-75">
Edit
</div>
diff --git a/components/app/project-card.tsx b/components/app/project-card.tsx
index 95f5e39974..ce7ae7aa88 100644
--- a/components/app/project-card.tsx
+++ b/components/app/project-card.tsx
@@ -8,7 +8,7 @@ import {
Link as LinkIcon,
} from "@/components/shared/icons";
import BlurImage from "@/components/shared/blur-image";
-import Tooltip from "@/components/shared/tooltip";
+import Tooltip, { TooltipContent } from "@/components/shared/tooltip";
export default function ProjectCard({
name,
@@ -46,7 +46,16 @@ export default function ProjectCard({
</div>
</Tooltip>
) : (
- <Tooltip content="Unverified domain">
+ <Tooltip
+ content={
+ <TooltipContent
+ title="This domain is not correctly configured. Please configure your domain to
+ start adding links."
+ cta="Configure Domain"
+ ctaLink={`/${slug}/settings`}
+ />
+ }
+ >
<div className="w-8 flex justify-center">
<XCircleFill className="w-5 h-5 text-gray-300" />
</div>
diff --git a/components/home/globe.tsx b/components/home/globe.tsx
index 86b1dbe6f1..11d7ea0f87 100644
--- a/components/home/globe.tsx
+++ b/components/home/globe.tsx
@@ -54,7 +54,7 @@ export default function Globe() {
onRender: (state) => {
// Called on every animation frame.
// `state` will be an empty object, return updated params.
- phi += 0.003;
+ phi += 0.002;
state.phi = phi + r.get();
state.width = width * 2;
state.height = width * 2;
diff --git a/components/home/link-card.tsx b/components/home/link-card.tsx
index 520a2d0657..afd2aefa89 100644
--- a/components/home/link-card.tsx
+++ b/components/home/link-card.tsx
@@ -48,50 +48,53 @@ export default function LinkCard({
}, [onKeyDown]);
return (
- <motion.li
- variants={FRAMER_MOTION_LIST_ITEM_VARIANTS}
- className="flex items-center border border-gray-200 hover:border-black bg-white p-3 max-w-md rounded-md transition-all"
- >
- <StatsModal />
- <BlurImage
- src={`https://logo.clearbit.com/${urlHostname}`}
- alt={urlHostname}
- className="w-10 h-10 rounded-full mr-2 border border-gray-200"
- width={20}
- height={20}
- />
- <div>
- <div className="flex items-center space-x-2 mb-1">
- <a
- className="text-blue-800 font-semibold"
- href={linkConstructor({ key })}
- target="_blank"
- rel="noreferrer"
- >
- {linkConstructor({ key, pretty: true })}
- </a>
- <CopyButton url={linkConstructor({ key })} />
- <Link
- href={{ pathname: "/", query: { key } }}
- as={`/stats/${encodeURI(key)}`}
- shallow
- scroll={false}
- >
- <a className="flex items-center space-x-1 rounded-md bg-gray-100 px-2 py-0.5 hover:scale-105 active:scale-95 transition-all duration-75">
- <Chart className="w-4 h-4" />
- <p className="text-sm text-gray-500">
- {isValidating || !clicks ? (
- <LoadingDots color="#71717A" />
- ) : (
- nFormatter(parseInt(clicks))
- )}{" "}
- clicks
- </p>
+ <motion.li variants={FRAMER_MOTION_LIST_ITEM_VARIANTS}>
+ <motion.div
+ drag="x"
+ dragConstraints={{ left: 0, right: 0 }}
+ className="cursor-grab active:cursor-grabbing flex items-center border border-gray-200 hover:border-black bg-white p-3 max-w-md rounded-md transition-[border-color]"
+ >
+ <StatsModal />
+ <BlurImage
+ src={`https://logo.clearbit.com/${urlHostname}`}
+ alt={urlHostname}
+ className="w-10 h-10 rounded-full mr-2 border border-gray-200 pointer-events-none"
+ width={20}
+ height={20}
+ />
+ <div>
+ <div className="flex items-center space-x-2 mb-1">
+ <a
+ className="text-blue-800 font-semibold"
+ href={linkConstructor({ key })}
+ target="_blank"
+ rel="noreferrer"
+ >
+ {linkConstructor({ key, pretty: true })}
</a>
- </Link>
+ <CopyButton url={linkConstructor({ key })} />
+ <Link
+ href={{ pathname: "/", query: { key } }}
+ as={`/stats/${encodeURI(key)}`}
+ shallow
+ scroll={false}
+ >
+ <a className="flex items-center space-x-1 rounded-md bg-gray-100 px-2 py-0.5 hover:scale-105 active:scale-95 transition-all duration-75">
+ <Chart className="w-4 h-4" />
+ <p className="text-sm text-gray-500">
+ {isValidating || !clicks ? (
+ <LoadingDots color="#71717A" />
+ ) : (
+ nFormatter(parseInt(clicks))
+ )}{" "}
+ clicks
+ </p>
+ </a>
+ </Link>
+ </div>
+ <p className="text-sm text-gray-500 truncate w-72">{url}</p>
</div>
- <p className="text-sm text-gray-500 truncate w-72">{url}</p>
- </div>
+ </motion.div>
</motion.li>
);
}
diff --git a/components/shared/tooltip.tsx b/components/shared/tooltip.tsx
index 41e42d27f5..ebd97bd0b5 100644
--- a/components/shared/tooltip.tsx
+++ b/components/shared/tooltip.tsx
@@ -1,13 +1,13 @@
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
import { ReactNode } from "react";
-const Tooltip = ({
+export default function Tooltip({
children,
content,
}: {
children: ReactNode;
- content: ReactNode;
-}) => {
+ content: ReactNode | string;
+}) {
return (
<TooltipPrimitive.Provider delayDuration={100}>
<TooltipPrimitive.Root>
@@ -18,14 +18,42 @@ const Tooltip = ({
className="animate-slide-up-fade inline-flex items-center rounded-md px-4 py-2.5 z-20 bg-white border border-gray-200 drop-shadow-lg"
>
<TooltipPrimitive.Arrow className="fill-current text-white" />
- <span className="block text-sm text-center text-gray-700 max-w-xs">
- {content}
- </span>
+ {typeof content === "string" ? (
+ <span className="block text-sm text-center text-gray-700 max-w-xs">
+ {content}
+ </span>
+ ) : (
+ content
+ )}
<TooltipPrimitive.Arrow className="fill-current text-white" />
</TooltipPrimitive.Content>
</TooltipPrimitive.Root>
</TooltipPrimitive.Provider>
);
-};
+}
-export default Tooltip;
+/***********************************/
+/* Tooltip Contents */
+
+import Link from "next/link";
+
+export function TooltipContent({
+ title,
+ cta,
+ ctaLink,
+}: {
+ title: string;
+ cta: string;
+ ctaLink: string;
+}) {
+ return (
+ <div className="max-w-xs flex flex-col text-center items-center space-y-3 py-2">
+ <p className="text-sm text-gray-700">{title}</p>
+ <Link href={ctaLink}>
+ <a className="py-1.5 px-3 bg-black hover:bg-white rounded-full border border-black text-sm text-white hover:text-black transition-all mt-4">
+ {cta}
+ </a>
+ </Link>
+ </div>
+ );
+}
diff --git a/pages/about.tsx b/pages/about.tsx
index 032a1ec095..8a1485d4f2 100644
--- a/pages/about.tsx
+++ b/pages/about.tsx
@@ -1,6 +1,6 @@
import HomeLayout from "@/components/layout/home";
import MaxWidthWrapper from "@/components/shared/max-width-wrapper";
-import Globe from "@/components/home/about/globe";
+import Globe from "@/components/home/globe";
export default function About() {
return (
diff --git a/pages/index.tsx b/pages/index.tsx
index d8652085ea..a1aeae1dbc 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -10,17 +10,18 @@ import {
Twitter,
CheckCircleFill,
} from "@/components/shared/icons";
-import { motion } from "framer-motion";
+import { motion, AnimatePresence } from "framer-motion";
import { LinkProps } from "@/lib/types";
import MaxWidthWrapper from "@/components/shared/max-width-wrapper";
import Globe from "@/components/home/globe";
+import Tooltip, { TooltipContent } from "@/components/shared/tooltip";
export default function Home() {
return (
<HomeLayout>
<Hero />
<Demo />
- <Globe />
+ {/* <Globe /> */}
<Features />
</HomeLayout>
);
@@ -109,15 +110,34 @@ const Demo = () => {
required
className="peer shadow-sm focus:outline-none focus:ring-0 bg-white border focus:border-black block w-full p-2 text-sm border-gray-200 rounded-md pl-3 pr-12"
/>
- <button
- type="submit"
- disabled={saving}
- className={`${
- saving ? "cursor-not-allowed" : ""
- } absolute inset-y-0 right-0 w-10 flex justify-center items-center my-1.5 mr-1.5 border border-gray-200 hover:border-gray-700 peer-focus:border-gray-700 rounded text-sm font-sans font-medium text-gray-400 hover:text-gray-700 peer-focus:text-gray-700`}
- >
- {saving ? <LoadingDots color="#e5e7eb" /> : <p>↵</p>}
- </button>
+ {hashes.length >= 4 ? (
+ <Tooltip
+ content={
+ <TooltipContent
+ title="Maximum number of links reached. Swipe to delete existing links or
+ create a free account."
+ cta="Start For Free"
+ ctaLink="https://app.dub.sh"
+ />
+ }
+ >
+ <div className="cursor-not-allowed absolute inset-y-0 right-0 w-10 flex justify-center items-center my-1.5 mr-1.5 border border-gray-200 rounded text-sm font-sans font-medium text-gray-400">
+ <p>↵</p>
+ </div>
+ </Tooltip>
+ ) : (
+ <button
+ type="submit"
+ disabled={saving}
+ className={`${
+ saving
+ ? "cursor-not-allowed"
+ : "hover:border-gray-700 peer-focus:border-gray-700 hover:text-gray-700 peer-focus:text-gray-700"
+ } absolute inset-y-0 right-0 w-10 flex justify-center items-center my-1.5 mr-1.5 border border-gray-200 rounded text-sm font-sans font-medium text-gray-400`}
+ >
+ {saving ? <LoadingDots color="#e5e7eb" /> : <p>↵</p>}
+ </button>
+ )}
</div>
</form>
@@ -140,13 +160,14 @@ const Demo = () => {
_key="github"
url={"https://github.com/steven-tey/dub"}
/>
- {hashes.length > 0
- ? hashes.map(({ key, url }) => (
- <LinkCard key={key} _key={key} url={url} />
- ))
- : Array.from({ length: 3 }).map((_, i) => (
- <PlaceholderCard key={i} />
- ))}
+ <AnimatePresence>
+ {hashes.map(({ key, url }) => (
+ <LinkCard key={key} _key={key} url={url} />
+ ))}
+ </AnimatePresence>
+ {Array.from({ length: 3 - hashes.length }).map((_, i) => (
+ <PlaceholderCard key={i} />
+ ))}
</motion.ul>
</div>
);