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.

fix ButtonTooltip

Steven Tey24ca4112c2a3
diff --git a/apps/web/ui/links/short-link-input.tsx b/apps/web/ui/links/short-link-input.tsx
index c24ccf977a..f3cad55f84 100644
--- a/apps/web/ui/links/short-link-input.tsx
+++ b/apps/web/ui/links/short-link-input.tsx
@@ -74,8 +74,7 @@ export const ShortLinkInput = forwardRef<HTMLInputElement, ShortLinkInputProps>(
id: workspaceId,
slug,
mutate: mutateWorkspace,
- aiUsage,
- aiLimit,
+ exceededAI,
nextPlan,
} = useWorkspace();
@@ -190,13 +189,14 @@ export const ShortLinkInput = forwardRef<HTMLInputElement, ShortLinkInputProps>(
<Lock className="h-3 w-3" />
</button>
) : (
- <div className="flex items-center">
+ <div className="flex items-center gap-1">
<ButtonTooltip
tabIndex={-1}
- tooltipContent="Generate a random key"
+ tooltipProps={{
+ content: "Generate a random key",
+ }}
onClick={generateRandomKey}
disabled={generatingRandomKey || generatingAIKey}
- className="flex h-6 w-6 items-center justify-center rounded-md text-gray-500 transition-colors duration-75 hover:bg-gray-100 active:bg-gray-200 disabled:cursor-not-allowed"
>
{generatingRandomKey ? (
<LoadingCircle />
@@ -206,15 +206,20 @@ export const ShortLinkInput = forwardRef<HTMLInputElement, ShortLinkInputProps>(
</ButtonTooltip>
<ButtonTooltip
tabIndex={-1}
- tooltipContent="Generate a key using AI"
+ tooltipProps={{
+ content: exceededAI
+ ? "You've exceeded your AI usage limit."
+ : !data.url
+ ? "Enter a URL to generate a key using AI."
+ : "Generate a key using AI.",
+ }}
onClick={generateAIKey}
disabled={
generatingRandomKey ||
generatingAIKey ||
- (aiLimit && aiUsage && aiUsage >= aiLimit) ||
+ exceededAI ||
!data.url
}
- className="flex h-6 w-6 items-center justify-center rounded-md text-gray-500 transition-colors duration-75 hover:bg-gray-100 active:bg-gray-200 disabled:cursor-not-allowed"
>
{generatingAIKey ? (
<LoadingCircle />
diff --git a/apps/web/ui/modals/add-edit-link-modal/og-section.tsx b/apps/web/ui/modals/add-edit-link-modal/og-section.tsx
index b089db314d..a15ee06a10 100644
--- a/apps/web/ui/modals/add-edit-link-modal/og-section.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/og-section.tsx
@@ -191,9 +191,10 @@ export default function OGSection({
<p className="block text-sm font-medium text-gray-700">Image</p>
<div className="flex items-center justify-between">
<ButtonTooltip
- tooltipContent="Paste a URL to an image."
+ tooltipProps={{
+ content: "Paste a URL to an image.",
+ }}
onClick={() => setShowPromptModal(true)}
- className="flex h-6 w-6 items-center justify-center rounded-md text-gray-500 transition-colors duration-75 hover:bg-gray-100 active:bg-gray-200 disabled:cursor-not-allowed"
>
<Link2 className="h-4 w-4 text-gray-500" />
</ButtonTooltip>
@@ -265,10 +266,15 @@ export default function OGSection({
{title?.length || 0}/120
</p>
<ButtonTooltip
- tooltipContent="Generate an optimized title using AI."
+ tooltipProps={{
+ content: exceededAI
+ ? "You've exceeded your AI usage limit"
+ : !title
+ ? "Enter a title to generate a preview"
+ : "Generate an optimized title using AI.",
+ }}
onClick={generateTitle}
- disabled={generatingTitle || !title || exceededAI}
- className="flex h-6 w-6 items-center justify-center rounded-md text-gray-500 transition-colors duration-75 hover:bg-gray-100 active:bg-gray-200 disabled:cursor-not-allowed"
+ disabled={generatingTitle || exceededAI || !title}
>
{generatingTitle ? (
<LoadingCircle />
@@ -310,10 +316,15 @@ export default function OGSection({
{description?.length || 0}/240
</p>
<ButtonTooltip
- tooltipContent="Generate an optimized description using AI."
+ tooltipProps={{
+ content: exceededAI
+ ? "You've exceeded your AI usage limit"
+ : !description
+ ? "Enter a description to generate a preview"
+ : "Generate an optimized description using AI.",
+ }}
onClick={generateDescription}
- disabled={generatingDescription || !description}
- className="flex h-6 w-6 items-center justify-center rounded-md text-gray-500 transition-colors duration-75 hover:bg-gray-100 active:bg-gray-200 disabled:cursor-not-allowed"
+ disabled={generatingDescription || exceededAI || !description}
>
{generatingDescription ? (
<LoadingCircle />
diff --git a/apps/web/ui/modals/add-edit-link-modal/password-section.tsx b/apps/web/ui/modals/add-edit-link-modal/password-section.tsx
index ba1d73ecb0..90d9caef4f 100644
--- a/apps/web/ui/modals/add-edit-link-modal/password-section.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/password-section.tsx
@@ -53,7 +53,9 @@ export default function PasswordSection({
<div className="flex items-center gap-2">
{enabled && (
<ButtonTooltip
- tooltipContent="Generate a random password"
+ tooltipProps={{
+ content: "Generate a random password",
+ }}
onClick={() => {
setData({ ...data, password: nanoid(24) });
}}
diff --git a/apps/web/ui/modals/link-builder/link-preview.tsx b/apps/web/ui/modals/link-builder/link-preview.tsx
index 29336fd4e9..3b9ca43151 100644
--- a/apps/web/ui/modals/link-builder/link-preview.tsx
+++ b/apps/web/ui/modals/link-builder/link-preview.tsx
@@ -120,7 +120,6 @@ export function LinkPreview() {
icon={<Pen2 className="mx-px size-4" />}
className="h-7 w-fit px-1"
onClick={() => setShowOGModal(true)}
- disabledTooltip={isValidUrl ? undefined : "Enter a URL to customize"}
/>
</div>
<div className="mt-2.5 grid grid-cols-4 gap-2">
diff --git a/apps/web/ui/modals/link-builder/og-modal.tsx b/apps/web/ui/modals/link-builder/og-modal.tsx
index 7cc6a5f660..4da45bc475 100644
--- a/apps/web/ui/modals/link-builder/og-modal.tsx
+++ b/apps/web/ui/modals/link-builder/og-modal.tsx
@@ -248,7 +248,7 @@ function OGModalInner({
<span className="block text-sm font-medium text-gray-700">
Image
</span>
- <div className="flex items-center gap-2 md:gap-4">
+ <div className="flex items-center gap-2">
{image && (
<button
type="button"
@@ -262,10 +262,10 @@ function OGModalInner({
</button>
)}
<ButtonTooltip
- type="button"
- className="text-gray-700 transition-colors hover:text-gray-950"
onClick={() => setShowPromptModal(true)}
- tooltipContent="Paste a URL to an image"
+ tooltipProps={{
+ content: "Paste a URL to an image",
+ }}
>
<Link className="size-4" />
</ButtonTooltip>
@@ -285,10 +285,11 @@ function OGModalInner({
<div>
<ButtonTooltip
onClick={() => setOpenUnsplashPopover(true)}
- className="text-gray-700 transition-colors hover:text-gray-950"
- tooltipContent="Choose an image from Unsplash"
+ tooltipProps={{
+ content: "Choose an image from Unsplash",
+ }}
>
- <Unsplash className="size-3.5 text-gray-500" />
+ <Unsplash className="size-3 text-gray-500" />
</ButtonTooltip>
</div>
</Popover>
@@ -331,15 +332,20 @@ function OGModalInner({
{title?.length || 0}/120
</p>
<ButtonTooltip
- tooltipContent="Generate an optimized title using AI."
+ tooltipProps={{
+ content: exceededAI
+ ? "You've exceeded your AI usage limit"
+ : !title
+ ? "Enter a title to generate a preview"
+ : "Generate an optimized title using AI.",
+ }}
onClick={generateTitle}
- disabled={generatingTitle || !title || exceededAI}
- className="flex h-6 w-6 items-center justify-center rounded-md text-gray-500 transition-colors duration-75 hover:bg-gray-100 active:bg-gray-200 disabled:cursor-not-allowed"
+ disabled={generatingTitle || exceededAI || !title}
>
{generatingTitle ? (
<LoadingCircle />
) : (
- <Magic className="h-4 w-4" />
+ <Magic className="size-4" />
)}
</ButtonTooltip>
</div>
@@ -378,15 +384,22 @@ function OGModalInner({
{description?.length || 0}/240
</p>
<ButtonTooltip
- tooltipContent="Generate an optimized description using AI."
+ tooltipProps={{
+ content: exceededAI
+ ? "You've exceeded your AI usage limit"
+ : !description
+ ? "Enter a description to generate a preview"
+ : "Generate an optimized description using AI.",
+ }}
onClick={generateDescription}
- disabled={generatingDescription || !description}
- className="flex h-6 w-6 items-center justify-center rounded-md text-gray-500 transition-colors duration-75 hover:bg-gray-100 active:bg-gray-200 disabled:cursor-not-allowed"
+ disabled={
+ generatingDescription || exceededAI || !description
+ }
>
{generatingDescription ? (
<LoadingCircle />
) : (
- <Magic className="h-4 w-4" />
+ <Magic className="size-4" />
)}
</ButtonTooltip>
</div>
diff --git a/apps/web/ui/modals/link-builder/password-modal.tsx b/apps/web/ui/modals/link-builder/password-modal.tsx
index c01486ed03..b9b308253f 100644
--- a/apps/web/ui/modals/link-builder/password-modal.tsx
+++ b/apps/web/ui/modals/link-builder/password-modal.tsx
@@ -106,10 +106,9 @@ function PasswordModal({
</span>
<div className="flex items-center gap-2">
<ButtonTooltip
- className="text-gray-500 transition-colors hover:text-gray-800"
- tooltipContent={
- showPassword ? "Hide password" : "Reveal password"
- }
+ tooltipProps={{
+ content: showPassword ? "Hide password" : "Reveal password",
+ }}
onClick={() => setShowPassword((s) => !s)}
>
{showPassword ? (
@@ -119,8 +118,9 @@ function PasswordModal({
)}
</ButtonTooltip>
<ButtonTooltip
- className="text-gray-500 transition-colors hover:text-gray-800"
- tooltipContent="Generate a random password"
+ tooltipProps={{
+ content: "Generate a random password",
+ }}
onClick={() => {
setValue("password", nanoid(24), { shouldDirty: true });
}}
diff --git a/apps/web/ui/modals/link-builder/qr-code-preview.tsx b/apps/web/ui/modals/link-builder/qr-code-preview.tsx
index e6043df026..cc2e3fe44e 100644
--- a/apps/web/ui/modals/link-builder/qr-code-preview.tsx
+++ b/apps/web/ui/modals/link-builder/qr-code-preview.tsx
@@ -93,7 +93,7 @@ export function QRCodePreview() {
<div className="flex size-full flex-col items-center justify-center gap-2">
<QRCodeIcon className="size-5 text-gray-700" />
<p className="max-w-32 text-center text-xs text-gray-700">
- Enter a short link to generate a preview
+ Enter a short link to generate a QR code
</p>
</div>
)}
diff --git a/apps/web/ui/modals/link-builder/utm-builder.tsx b/apps/web/ui/modals/link-builder/utm-builder.tsx
index 018261c549..d6cad6bda1 100644
--- a/apps/web/ui/modals/link-builder/utm-builder.tsx
+++ b/apps/web/ui/modals/link-builder/utm-builder.tsx
@@ -68,15 +68,6 @@ export function UTMBuilder() {
const { watch, setValue } = useFormContext<LinkFormData>();
const url = watch("url");
- const isValidUrl = useMemo(() => {
- try {
- new URL(url);
- return true;
- } catch (e) {
- return false;
- }
- }, [url]);
-
const params = useMemo(() => getParamsFromURL(url), [url]);
const [toggledParams, setToggledParams] = useState<string[]>(
@@ -146,7 +137,6 @@ export function UTMBuilder() {
key={key}
type="button"
aria-pressed={enabled}
- disabled={!isValidUrl}
className={cn(
"flex items-center gap-1 px-2.5 py-1.5 text-sm drop-shadow-sm transition-all",
"rounded-md border border-gray-300 bg-white text-gray-700",
diff --git a/apps/web/ui/webhooks/webhook-events.tsx b/apps/web/ui/webhooks/webhook-events.tsx
index 63d8ffcce0..9cfa009eed 100644
--- a/apps/web/ui/webhooks/webhook-events.tsx
+++ b/apps/web/ui/webhooks/webhook-events.tsx
@@ -95,7 +95,9 @@ const WebhookEvent = ({ event }: { event: WebhookEventProps }) => {
<div className="group flex items-center gap-2">
<p className="font-mono text-sm text-gray-500">{event.event_id}</p>
<ButtonTooltip
- tooltipContent="Copy event ID"
+ tooltipProps={{
+ content: "Copy event ID",
+ }}
onClick={() => {
navigator.clipboard.writeText(event.event_id);
toast.success("Copied to clipboard");
diff --git a/packages/ui/src/tooltip.tsx b/packages/ui/src/tooltip.tsx
index 22cbc57b0b..18c294d40c 100644
--- a/packages/ui/src/tooltip.tsx
+++ b/packages/ui/src/tooltip.tsx
@@ -207,20 +207,25 @@ export function BadgeTooltip({ children, content, ...props }: TooltipProps) {
}
export function ButtonTooltip({
- tooltipContent,
children,
+ tooltipProps,
...props
}: {
- tooltipContent: ReactNode | string;
children: ReactNode;
+ tooltipProps: TooltipProps;
} & ButtonProps) {
return (
- <Tooltip content={tooltipContent}>
- <div className="flex cursor-pointer items-center">
- <button type="button" {...props}>
- {children}
- </button>
- </div>
+ <Tooltip {...tooltipProps}>
+ <button
+ type="button"
+ {...props}
+ className={cn(
+ "flex h-6 w-6 items-center justify-center rounded-md text-gray-500 transition-colors duration-75 hover:bg-gray-100 active:bg-gray-200 disabled:cursor-not-allowed disabled:hover:bg-transparent",
+ props.className,
+ )}
+ >
+ {children}
+ </button>
</Tooltip>
);
}