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 implementation

Steven Teyfc058897b73c
diff --git a/apps/web/ui/modals/provider.tsx b/apps/web/ui/modals/provider.tsx
index cdb518196e..68a08d906d 100644
--- a/apps/web/ui/modals/provider.tsx
+++ b/apps/web/ui/modals/provider.tsx
@@ -22,6 +22,7 @@ import { useCookies } from "@dub/ui";
import { SimpleLinkProps } from "@/lib/types";
import { toast } from "sonner";
import { useImportRebrandlyModal } from "./import-rebrandly-modal";
+import { TooltipProvider } from "@dub/ui/src/tooltip";
export const ModalContext = createContext<{
setShowAddProjectModal: Dispatch<SetStateAction<boolean>>;
@@ -59,7 +60,6 @@ export default function ModalProvider({ children }: { children: ReactNode }) {
useImportRebrandlyModal();
const params = useParams() as { slug?: string };
- const { slug } = params;
const [hashes, setHashes] = useCookies<SimpleLinkProps[]>("hashes__dub", [], {
domain: !!process.env.NEXT_PUBLIC_VERCEL_URL ? ".dub.co" : undefined,
@@ -97,28 +97,30 @@ export default function ModalProvider({ children }: { children: ReactNode }) {
}, [error]);
return (
- <ModalContext.Provider
- value={{
- setShowAddProjectModal,
- setShowCompleteSetupModal,
- setShowAddEditDomainModal,
- setShowAddEditLinkModal,
- setShowUpgradePlanModal,
- setShowImportBitlyModal,
- setShowImportShortModal,
- setShowImportRebrandlyModal,
- }}
- >
- <AddProjectModal />
- <AcceptInviteModal />
- <CompleteSetupModal />
- <AddEditDomainModal />
- <AddEditLinkModal />
- <UpgradePlanModal />
- <ImportBitlyModal />
- <ImportShortModal />
- <ImportRebrandlyModal />
- {children}
- </ModalContext.Provider>
+ <TooltipProvider>
+ <ModalContext.Provider
+ value={{
+ setShowAddProjectModal,
+ setShowCompleteSetupModal,
+ setShowAddEditDomainModal,
+ setShowAddEditLinkModal,
+ setShowUpgradePlanModal,
+ setShowImportBitlyModal,
+ setShowImportShortModal,
+ setShowImportRebrandlyModal,
+ }}
+ >
+ <AddProjectModal />
+ <AcceptInviteModal />
+ <CompleteSetupModal />
+ <AddEditDomainModal />
+ <AddEditLinkModal />
+ <UpgradePlanModal />
+ <ImportBitlyModal />
+ <ImportShortModal />
+ <ImportRebrandlyModal />
+ {children}
+ </ModalContext.Provider>
+ </TooltipProvider>
);
}
diff --git a/packages/ui/package.json b/packages/ui/package.json
index f20bb6d75a..03ff5f0a4c 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -1,7 +1,7 @@
{
"name": "@dub/ui",
"description": "UI components for Dub.co",
- "version": "0.0.37",
+ "version": "0.0.40",
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.mjs",
@@ -47,7 +47,7 @@
"sonner": "^0.5.0",
"swr": "^2.1.5",
"use-debounce": "^8.0.4",
- "vaul": "^0.6.8"
+ "vaul": "^0.8.0"
},
"author": "Steven Tey <[email protected]>",
"homepage": "https://dub.co",
diff --git a/packages/ui/src/button.tsx b/packages/ui/src/button.tsx
index 5973456439..fc8bc3b451 100644
--- a/packages/ui/src/button.tsx
+++ b/packages/ui/src/button.tsx
@@ -23,7 +23,7 @@ export function Button({
}: ButtonProps) {
if (disabledTooltip) {
return (
- <Tooltip content={disabledTooltip} fullWidth>
+ <Tooltip content={disabledTooltip}>
<div className="flex h-10 w-full cursor-not-allowed items-center justify-center rounded-md border border-gray-200 bg-gray-100 px-4 text-sm text-gray-400 transition-all focus:outline-none">
<p>{text}</p>
</div>
diff --git a/packages/ui/src/tooltip.tsx b/packages/ui/src/tooltip.tsx
index 5d07a1baec..127dc9e1a0 100644
--- a/packages/ui/src/tooltip.tsx
+++ b/packages/ui/src/tooltip.tsx
@@ -4,80 +4,56 @@ import { nFormatter, timeAgo } from "@dub/utils";
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
import { HelpCircle } from "lucide-react";
import Link from "next/link";
-import { ReactNode } from "react";
-import { Drawer } from "vaul";
-import { useMediaQuery } from "./hooks";
+import { ReactNode, useState } from "react";
+
+export function TooltipProvider({ children }: { children: ReactNode }) {
+ return (
+ <TooltipPrimitive.Provider delayDuration={0}>
+ {children}
+ </TooltipPrimitive.Provider>
+ );
+}
export function Tooltip({
children,
content,
side = "top",
- desktopOnly,
- fullWidth,
}: {
children: ReactNode;
content: ReactNode | string;
side?: "top" | "bottom" | "left" | "right";
- desktopOnly?: boolean;
- fullWidth?: boolean;
}) {
- const { isMobile } = useMediaQuery();
+ const [open, setOpen] = useState(false);
- if (isMobile && !desktopOnly) {
- return (
- <Drawer.Root>
- <Drawer.Trigger
- className={`${fullWidth ? "w-full" : "inline-flex"} md: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="sticky top-0 z-20 flex w-full items-center justify-center rounded-t-[10px] bg-inherit">
- <div className="my-3 h-1 w-12 rounded-full bg-gray-300" />
- </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 text-center text-sm text-gray-700">
- {content}
- </span>
- ) : (
- content
- )}
- </div>
- </Drawer.Content>
- <Drawer.Overlay />
- </Drawer.Portal>
- </Drawer.Root>
- );
- }
return (
- <TooltipPrimitive.Provider delayDuration={100}>
- <TooltipPrimitive.Root>
- <TooltipPrimitive.Trigger className="md:inline-flex" asChild>
- {children}
- </TooltipPrimitive.Trigger>
- <TooltipPrimitive.Portal>
- <TooltipPrimitive.Content
- sideOffset={8}
- side={side}
- className="animate-slide-up-fade z-[99] items-center overflow-hidden rounded-md border border-gray-200 bg-white shadow-md md:block"
- >
- {typeof content === "string" ? (
- <span className="block max-w-xs px-4 py-2 text-center text-sm text-gray-700">
- {content}
- </span>
- ) : (
- content
- )}
- </TooltipPrimitive.Content>
- </TooltipPrimitive.Portal>
- </TooltipPrimitive.Root>
- </TooltipPrimitive.Provider>
+ <TooltipPrimitive.Root open={open} onOpenChange={setOpen}>
+ <TooltipPrimitive.Trigger
+ asChild
+ onClick={() => {
+ setOpen(true);
+ }}
+ onBlur={() => {
+ setOpen(false);
+ }}
+ >
+ {children}
+ </TooltipPrimitive.Trigger>
+ <TooltipPrimitive.Portal>
+ <TooltipPrimitive.Content
+ sideOffset={8}
+ side={side}
+ className="animate-slide-up-fade z-[99] items-center overflow-hidden rounded-md border border-gray-200 bg-white shadow-md"
+ >
+ {typeof content === "string" ? (
+ <span className="block max-w-xs px-4 py-2 text-center text-sm text-gray-700">
+ {content}
+ </span>
+ ) : (
+ content
+ )}
+ </TooltipPrimitive.Content>
+ </TooltipPrimitive.Portal>
+ </TooltipPrimitive.Root>
);
}
@@ -95,7 +71,7 @@ export function TooltipContent({
onClick?: () => void;
}) {
return (
- <div className="flex flex-col items-center space-y-3 p-4 text-center md:max-w-xs">
+ <div className="flex max-w-xs flex-col items-center space-y-3 p-4 text-center">
<p className="text-sm text-gray-700">{title}</p>
{cta &&
(href ? (
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index ef6c062a81..7943062984 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -650,7 +650,7 @@ importers:
'@radix-ui/react-dialog':
specifier: 1.0.5
'@radix-ui/react-navigation-menu':
specifier: ^1.1.2
@@ -685,8 +685,8 @@ importers:
specifier: ^8.0.4
version: 8.0.4([email protected])
vaul:
- specifier: ^0.6.8
+ specifier: ^0.8.0
devDependencies:
'@dub/tailwind-config':
specifier: workspace:*
@@ -763,7 +763,7 @@ importers:
version: link:../tsconfig
tsup:
specifier: ^6.1.3
+ version: 6.1.3([email protected])
typescript:
specifier: ^5.1.6
version: 5.1.6
@@ -5418,11 +5418,11 @@ packages:
'@radix-ui/primitive': 1.0.1
'@radix-ui/react-compose-refs': 1.0.1(@types/[email protected])([email protected])
'@radix-ui/react-context': 1.0.1(@types/[email protected])([email protected])
- '@radix-ui/react-dismissable-layer': 1.0.5(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@radix-ui/react-dismissable-layer': 1.0.5(@types/[email protected])([email protected])([email protected])
'@radix-ui/react-focus-guards': 1.0.1(@types/[email protected])([email protected])
- '@radix-ui/react-focus-scope': 1.0.4(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@radix-ui/react-focus-scope': 1.0.4(@types/[email protected])([email protected])([email protected])
'@radix-ui/react-id': 1.0.1(@types/[email protected])([email protected])
- '@radix-ui/react-portal': 1.0.4(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@radix-ui/react-portal': 1.0.4(@types/[email protected])([email protected])([email protected])
'@radix-ui/react-presence': 1.0.1(@types/[email protected])(@types/[email protected])([email protected])([email protected])
'@radix-ui/react-primitive': 1.0.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])
'@radix-ui/react-slot': 1.0.2(@types/[email protected])([email protected])
@@ -5541,6 +5541,30 @@ packages:
react-dom: 18.2.0([email protected])
dev: false
+ resolution: {integrity: sha512-aJeDjQhywg9LBu2t/At58hCvr7pEm0o2Ke1x33B+MhjNmmZ17sy4KImo0KPLgsnc/zN7GPdce8Cnn0SWvwZO7g==}
+ peerDependencies:
+ '@types/react': '*'
+ '@types/react-dom': '*'
+ react: ^16.8 || ^17.0 || ^18.0
+ react-dom: ^16.8 || ^17.0 || ^18.0
+ peerDependenciesMeta:
+ '@types/react':
+ optional: true
+ '@types/react-dom':
+ optional: true
+ dependencies:
+ '@babel/runtime': 7.23.2
+ '@radix-ui/primitive': 1.0.1
+ '@radix-ui/react-compose-refs': 1.0.1(@types/[email protected])([email protected])
+ '@radix-ui/react-primitive': 1.0.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@radix-ui/react-use-callback-ref': 1.0.1(@types/[email protected])([email protected])
+ '@radix-ui/react-use-escape-keydown': 1.0.3(@types/[email protected])([email protected])
+ '@types/react': 18.2.14
+ react: 18.2.0
+ react-dom: 18.2.0([email protected])
+ dev: false
+
resolution: {integrity: sha512-UagjDk4ijOAnGu4WMUPj9ahi7/zJJqNZ9ZAiGPp7waUWJO0O1aWXi/udPphI0IUjvrhBsZJGSN66dR2dsueLWQ==}
peerDependencies:
@@ -5652,6 +5676,28 @@ packages:
react-dom: 18.2.0([email protected])
dev: false
+ resolution: {integrity: sha512-sL04Mgvf+FmyvZeYfNu1EPAaaxD+aw7cYeIB9L9Fvq8+urhltTRaEo5ysKOpHuKPclsZcSUMKlN05x4u+CINpA==}
+ peerDependencies:
+ '@types/react': '*'
+ '@types/react-dom': '*'
+ react: ^16.8 || ^17.0 || ^18.0
+ react-dom: ^16.8 || ^17.0 || ^18.0
+ peerDependenciesMeta:
+ '@types/react':
+ optional: true
+ '@types/react-dom':
+ optional: true
+ dependencies:
+ '@babel/runtime': 7.23.2
+ '@radix-ui/react-compose-refs': 1.0.1(@types/[email protected])([email protected])
+ '@radix-ui/react-primitive': 1.0.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@radix-ui/react-use-callback-ref': 1.0.1(@types/[email protected])([email protected])
+ '@types/react': 18.2.14
+ react: 18.2.0
+ react-dom: 18.2.0([email protected])
+ dev: false
+
resolution: {integrity: sha512-Q6iAB/U7Tq3NTolBBQbHTgclPmGWE3OlktGGqrClPozSw4vkQ1DfQAOtzgRPecKsMdJINE05iaoDUG8tRzCBjw==}
peerDependencies:
@@ -5762,12 +5808,12 @@ packages:
'@radix-ui/primitive': 1.0.1
'@radix-ui/react-compose-refs': 1.0.1(@types/[email protected])([email protected])
'@radix-ui/react-context': 1.0.1(@types/[email protected])([email protected])
- '@radix-ui/react-dismissable-layer': 1.0.5(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@radix-ui/react-dismissable-layer': 1.0.5(@types/[email protected])([email protected])([email protected])
'@radix-ui/react-focus-guards': 1.0.1(@types/[email protected])([email protected])
- '@radix-ui/react-focus-scope': 1.0.4(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@radix-ui/react-focus-scope': 1.0.4(@types/[email protected])([email protected])([email protected])
'@radix-ui/react-id': 1.0.1(@types/[email protected])([email protected])
'@radix-ui/react-popper': 1.1.3(@types/[email protected])([email protected])([email protected])
- '@radix-ui/react-portal': 1.0.4(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@radix-ui/react-portal': 1.0.4(@types/[email protected])([email protected])([email protected])
'@radix-ui/react-presence': 1.0.1(@types/[email protected])(@types/[email protected])([email protected])([email protected])
'@radix-ui/react-primitive': 1.0.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])
'@radix-ui/react-slot': 1.0.2(@types/[email protected])([email protected])
@@ -5896,6 +5942,26 @@ packages:
react-dom: 18.2.0([email protected])
dev: false
+ resolution: {integrity: sha512-Qki+C/EuGUVCQTOTD5vzJzJuMUlewbzuKyUy+/iHM2uwGiru9gZeBJtHAPKAEkB5KWGi9mP/CHKcY0wt1aW45Q==}
+ peerDependencies:
+ '@types/react': '*'
+ '@types/react-dom': '*'
+ react: ^16.8 || ^17.0 || ^18.0
+ react-dom: ^16.8 || ^17.0 || ^18.0
+ peerDependenciesMeta:
+ '@types/react':
+ optional: true
+ '@types/react-dom':
+ optional: true
+ dependencies:
+ '@babel/runtime': 7.23.2
+ '@radix-ui/react-primitive': 1.0.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@types/react': 18.2.14
+ react: 18.2.0
+ react-dom: 18.2.0([email protected])
+ dev: false
+
resolution: {integrity: sha512-A+6XEvN01NfVWiKu38ybawfHsBjWum42MRPnEuqPsBZ4eV7e/7K321B5VgYMPv3Xx5An6o1/l9ZuDBgmcmWK3w==}
peerDependencies:
@@ -6193,10 +6259,10 @@ packages:
'@radix-ui/primitive': 1.0.1
'@radix-ui/react-compose-refs': 1.0.1(@types/[email protected])([email protected])
'@radix-ui/react-context': 1.0.1(@types/[email protected])([email protected])
- '@radix-ui/react-dismissable-layer': 1.0.5(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@radix-ui/react-dismissable-layer': 1.0.5(@types/[email protected])([email protected])([email protected])
'@radix-ui/react-id': 1.0.1(@types/[email protected])([email protected])
'@radix-ui/react-popper': 1.1.3(@types/[email protected])([email protected])([email protected])
- '@radix-ui/react-portal': 1.0.4(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@radix-ui/react-portal': 1.0.4(@types/[email protected])([email protected])([email protected])
'@radix-ui/react-presence': 1.0.1(@types/[email protected])(@types/[email protected])([email protected])([email protected])
'@radix-ui/react-primitive': 1.0.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])
'@radix-ui/react-slot': 1.0.2(@types/[email protected])([email protected])
@@ -16448,6 +16514,42 @@ packages:
- ts-node
dev: true
+ resolution: {integrity: sha512-eRpBnbfpDFng+EJNTQ90N7QAf4HAGGC7O3buHIjroKWK7D1ibk9/YnR/3cS8HsMU5T+6Oi+cnF+yU5WmCnB//Q==}
+ engines: {node: '>=14'}
+ hasBin: true
+ peerDependencies:
+ '@swc/core': ^1
+ postcss: ^8.4.12
+ typescript: ^4.1.0
+ peerDependenciesMeta:
+ '@swc/core':
+ optional: true
+ postcss:
+ optional: true
+ typescript:
+ optional: true
+ dependencies:
+ bundle-require: 3.1.2([email protected])
+ cac: 6.7.14
+ chokidar: 3.5.3
+ debug: 4.3.4
+ esbuild: 0.14.54
+ execa: 5.1.1
+ globby: 11.1.0
+ joycon: 3.1.1
+ postcss-load-config: 3.1.4([email protected])
+ resolve-from: 5.0.0
+ rollup: 2.79.1
+ source-map: 0.8.0-beta.0
+ sucrase: 3.34.0
+ tree-kill: 1.2.2
+ typescript: 5.1.6
+ transitivePeerDependencies:
+ - supports-color
+ - ts-node
+ dev: true
+
resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==}
engines: {node: '>= 6'}
@@ -17123,8 +17225,8 @@ packages:
- '@types/react-dom'
dev: false
- resolution: {integrity: sha512-Fn7Pe8Zm/jqyIf8Nn/iBMoBzQ3L49xB2vXj7Kp8W7RCMRDg33X5rCp/K80g1Q35VNtKP8AgmFSM7lbticurXKA==}
+ resolution: {integrity: sha512-9nUU2jIObJvJZxeQU1oVr/syKo5XqbRoOMoTEt0hHlWify4QZFlqTh6QSN/yxoKzNrMeEQzxbc3XC/vkPLOIqw==}
peerDependencies:
react: ^16.8 || ^17.0 || ^18.0
react-dom: ^16.8 || ^17.0 || ^18.0