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.

convert tooltip to use Vaul Drawer

Steven Teyd9c21084569a
diff --git a/app/ui/popover.tsx b/app/ui/popover.tsx
index 3b2352ee81..a5f4890fe2 100644
--- a/app/ui/popover.tsx
+++ b/app/ui/popover.tsx
@@ -1,6 +1,6 @@
"use client";
-import { ReactNode } from "react";
+import { Dispatch, ReactNode, SetStateAction } from "react";
import * as PopoverPrimitive from "@radix-ui/react-popover";
import { Drawer } from "vaul";
import useWindowSize from "#/lib/hooks/use-window-size";
@@ -15,8 +15,8 @@ export default function Popover({
children: ReactNode;
content: ReactNode | string;
align?: "center" | "start" | "end";
- openPopover;
- setOpenPopover;
+ openPopover: boolean;
+ setOpenPopover: Dispatch<SetStateAction<boolean>>;
}) {
const { isMobile } = useWindowSize();
diff --git a/app/ui/tooltip.tsx b/app/ui/tooltip.tsx
index 3bcbb12a30..9791c4a908 100644
--- a/app/ui/tooltip.tsx
+++ b/app/ui/tooltip.tsx
@@ -4,15 +4,15 @@
/* Tooltip Contents */
import Link from "next/link";
-import { ReactNode, useRef, useState } from "react";
+import { ReactNode, useState } from "react";
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
-import { AnimatePresence, motion, useAnimation } from "framer-motion";
-import BlurImage from "#/ui/blur-image";
import Button from "./button";
import Script from "next/script";
import { ExternalLink, Globe, GlobeIcon, HelpCircle } from "lucide-react";
import { DomainProps } from "#/lib/types";
import { CheckCircleFill, XCircleFill } from "@/components/shared/icons";
+import { Drawer } from "vaul";
+import useWindowSize from "#/lib/hooks/use-window-size";
export default function Tooltip({
children,
@@ -23,111 +23,63 @@ export default function Tooltip({
content: ReactNode | string;
fullWidth?: boolean;
}) {
- const [openTooltip, setOpenTooltip] = useState(false);
- const mobileTooltipRef = useRef(null);
+ const { isMobile } = useWindowSize();
- const controls = useAnimation();
- const transitionProps = { type: "spring", stiffness: 500, damping: 30 };
-
- async function handleDragEnd(_, info) {
- const offset = info.offset.y;
- const velocity = info.velocity.y;
- // @ts-ignore
- const height = mobileTooltipRef.current.getBoundingClientRect().height;
- if (offset > height / 2 || velocity > 800) {
- await controls.start({ y: "100%", transition: transitionProps });
- setOpenTooltip(false);
- } else {
- controls.start({ y: 0, transition: transitionProps });
- }
- }
-
- return (
- <>
- <button
- type="button"
- className={`${fullWidth ? "w-full" : "inline-flex"} sm:hidden`}
- onClick={(e) => {
- e.preventDefault();
- e.stopPropagation();
- setOpenTooltip(true);
- }}
- >
- <span className="sr-only">Open tooltip</span>
- {children}
- </button>
- <AnimatePresence>
- {openTooltip && (
- <>
- <motion.div
- ref={mobileTooltipRef}
- key="mobile-tooltip"
- className="group fixed inset-x-0 bottom-0 z-40 w-screen cursor-grab active:cursor-grabbing sm:hidden"
- initial={{ y: "100%" }}
- animate={{
- y: openTooltip ? 0 : "100%",
- transition: transitionProps,
- }}
- exit={{ y: "100%" }}
- transition={transitionProps}
- drag="y"
- dragDirectionLock
- onDragEnd={handleDragEnd}
- dragElastic={{ top: 0, bottom: 1 }}
- dragConstraints={{ top: 0, bottom: 0 }}
- >
- <div
- className={`rounded-t-4xl -mb-1 flex h-7 w-full items-center justify-center border-t border-gray-200 bg-white`}
- >
- <div className="-mr-1 h-1 w-6 rounded-full bg-gray-300 transition-all group-active:rotate-12" />
- <div className="h-1 w-6 rounded-full bg-gray-300 transition-all group-active:-rotate-12" />
- </div>
- <div className="flex min-h-[150px] w-full items-center justify-center overflow-hidden bg-white align-middle shadow-xl">
- {typeof content === "string" ? (
- <span className="block max-w-xs text-center text-sm text-gray-700">
- {content}
- </span>
- ) : (
- content
- )}
- </div>
- </motion.div>
- <motion.div
- key="mobile-tooltip-backdrop"
- className="fixed inset-0 z-30 bg-gray-100 bg-opacity-10 backdrop-blur sm:hidden"
- initial={{ opacity: 0 }}
- animate={{ opacity: 1 }}
- exit={{ opacity: 0 }}
- onClick={() => setOpenTooltip(false)}
- />
- </>
- )}
- </AnimatePresence>
- <TooltipPrimitive.Provider delayDuration={100}>
- <TooltipPrimitive.Root>
- <TooltipPrimitive.Trigger className="hidden sm:inline-flex" asChild>
- {children}
- </TooltipPrimitive.Trigger>
- <TooltipPrimitive.Portal>
- <TooltipPrimitive.Content
- sideOffset={8}
- side="top"
- className="z-50 hidden animate-slide-up-fade items-center overflow-hidden rounded-md border border-gray-100 bg-white shadow-md sm:block"
- >
+ if (isMobile) {
+ return (
+ <Drawer.Root shouldScaleBackground>
+ <Drawer.Trigger
+ className={`${fullWidth ? "w-full" : "inline-flex"} sm:hidden`}
+ onClick={(e) => {
+ e.stopPropagation();
+ }}
+ >
+ {children}
+ </Drawer.Trigger>
+ <Drawer.Overlay className="fixed inset-0 z-40 bg-gray-100 bg-opacity-10 backdrop-blur" />
+ <Drawer.Portal>
+ <Drawer.Content className="fixed bottom-0 left-0 right-0 z-50 mt-24 rounded-t-[10px] border-t border-gray-200 bg-white">
+ <div className="mx-auto my-3 h-1 w-12 rounded-full bg-gray-300" />
+ <div className="flex min-h-[150px] w-full items-center justify-center overflow-hidden bg-white align-middle shadow-xl">
{typeof content === "string" ? (
- <div className="px-4 py-2">
- <span className="block max-w-xs text-center text-sm text-gray-700">
- {content}
- </span>
- </div>
+ <span className="block text-center text-sm text-gray-700">
+ {content}
+ </span>
) : (
content
)}
- </TooltipPrimitive.Content>
- </TooltipPrimitive.Portal>
- </TooltipPrimitive.Root>
- </TooltipPrimitive.Provider>
- </>
+ </div>
+ </Drawer.Content>
+ <Drawer.Overlay />
+ </Drawer.Portal>
+ </Drawer.Root>
+ );
+ }
+ return (
+ <TooltipPrimitive.Provider delayDuration={100}>
+ <TooltipPrimitive.Root>
+ <TooltipPrimitive.Trigger className="hidden sm:inline-flex" asChild>
+ {children}
+ </TooltipPrimitive.Trigger>
+ <TooltipPrimitive.Portal>
+ <TooltipPrimitive.Content
+ sideOffset={8}
+ side="top"
+ className="z-50 hidden animate-slide-up-fade items-center overflow-hidden rounded-md border border-gray-100 bg-white shadow-md sm:block"
+ >
+ {typeof content === "string" ? (
+ <div className="px-4 py-2">
+ <span className="block max-w-xs text-center text-sm text-gray-700">
+ {content}
+ </span>
+ </div>
+ ) : (
+ content
+ )}
+ </TooltipPrimitive.Content>
+ </TooltipPrimitive.Portal>
+ </TooltipPrimitive.Root>
+ </TooltipPrimitive.Provider>
);
}
@@ -143,7 +95,7 @@ export function TooltipContent({
onClick?: () => void;
}) {
return (
- <div className="flex max-w-xs flex-col items-center space-y-3 p-4 text-center">
+ <div className="flex flex-col items-center space-y-3 p-4 text-center sm:max-w-xs">
<p className="text-sm text-gray-700">{title}</p>
{cta &&
(href ? (