Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Refactor dialog components to use ResponsiveDialog for consistency

Bill Yang57e7991c5a84
diff --git a/client/src/app/[site]/components/shared/StandardSection/StandardSectionDialog.tsx b/client/src/app/[site]/components/shared/StandardSection/StandardSectionDialog.tsx
index d7cecf3f9..215afa16c 100644
--- a/client/src/app/[site]/components/shared/StandardSection/StandardSectionDialog.tsx
+++ b/client/src/app/[site]/components/shared/StandardSection/StandardSectionDialog.tsx
@@ -1,4 +1,9 @@
-import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
+import {
+ ResponsiveDialog,
+ ResponsiveDialogContent,
+ ResponsiveDialogHeader,
+ ResponsiveDialogTitle,
+} from "@/components/ui/responsive-dialog";
import { Input } from "@/components/ui/input";
import { TableSortIndicator } from "@/components/ui/table";
import { FilterParameter } from "@rybbit/shared";
@@ -191,23 +196,23 @@ export function StandardSectionDialog({
if (isLoading || !data) {
return (
- <Dialog open={expanded} onOpenChange={close}>
- <DialogContent className="max-w-[1000px] w-[calc(100vw-2rem)] p-2 sm:p-4">
+ <ResponsiveDialog open={expanded} onOpenChange={close}>
+ <ResponsiveDialogContent className="max-w-[1000px] w-[calc(100vw-2rem)] p-2 sm:p-4">
<div className="flex justify-center items-center h-40">
<Loader2 className="h-8 w-8 animate-spin text-neutral-600 dark:text-neutral-400" />
</div>
- </DialogContent>
- </Dialog>
+ </ResponsiveDialogContent>
+ </ResponsiveDialog>
);
}
const totalCount = data.pages[0]?.totalCount || 0;
return (
- <Dialog open={expanded} onOpenChange={close}>
- <DialogContent className="max-w-[1000px] w-screen max-h-[1000px] h-[calc(100vh-2rem)] p-2 sm:p-4 flex flex-col gap-2">
- <DialogHeader>
- <DialogTitle>{title}</DialogTitle>
- </DialogHeader>
+ <ResponsiveDialog open={expanded} onOpenChange={close}>
+ <ResponsiveDialogContent className="max-w-[1000px] w-screen max-h-[1000px] h-[calc(100vh-2rem)] p-2 sm:p-4 flex flex-col gap-2">
+ <ResponsiveDialogHeader>
+ <ResponsiveDialogTitle>{title}</ResponsiveDialogTitle>
+ </ResponsiveDialogHeader>
<Input
type="text"
placeholder={`Filter ${allItems.length} items...`}
@@ -292,7 +297,7 @@ export function StandardSectionDialog({
</div>
)}
</div>
- </DialogContent>
- </Dialog>
+ </ResponsiveDialogContent>
+ </ResponsiveDialog>
);
}
diff --git a/client/src/app/[site]/main/components/sections/Events.tsx b/client/src/app/[site]/main/components/sections/Events.tsx
index 1ad21da2f..45ab18069 100644
--- a/client/src/app/[site]/main/components/sections/Events.tsx
+++ b/client/src/app/[site]/main/components/sections/Events.tsx
@@ -50,7 +50,7 @@ function OutboundLinks({ expanded, close }: { expanded: boolean; close: () => vo
<div>Outbound Links</div>
<div>Clicks</div>
</div>
- <OutboundLinksList outboundLinks={(outboundLinksData || []).slice(0, 10)} isLoading={isLoadingOutboundLinks} />
+ <OutboundLinksList outboundLinks={outboundLinksData || []} isLoading={isLoadingOutboundLinks} />
<OutboundLinksDialog outboundLinks={outboundLinksData || []} expanded={expanded} close={close} />
</div>
</>
diff --git a/client/src/app/[site]/main/components/sections/OutboundLinksDialog.tsx b/client/src/app/[site]/main/components/sections/OutboundLinksDialog.tsx
index 2d9c52a55..43e625618 100644
--- a/client/src/app/[site]/main/components/sections/OutboundLinksDialog.tsx
+++ b/client/src/app/[site]/main/components/sections/OutboundLinksDialog.tsx
@@ -1,6 +1,11 @@
"use client";
-import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
+import {
+ ResponsiveDialog,
+ ResponsiveDialogContent,
+ ResponsiveDialogHeader,
+ ResponsiveDialogTitle,
+} from "@/components/ui/responsive-dialog";
import { Input } from "@/components/ui/input";
import { getTimezone } from "@/lib/store";
import { useDebounce, useIntersectionObserver } from "@uidotdev/usehooks";
@@ -86,11 +91,11 @@ export function OutboundLinksDialog({ outboundLinks, expanded, close }: Outbound
}
return (
- <Dialog open={expanded} onOpenChange={close}>
- <DialogContent className="max-w-[1000px] w-[calc(100vw-2rem)] p-2 sm:p-4">
- <DialogHeader>
- <DialogTitle>Outbound Links</DialogTitle>
- </DialogHeader>
+ <ResponsiveDialog open={expanded} onOpenChange={close}>
+ <ResponsiveDialogContent className="max-w-[1000px] w-[calc(100vw-2rem)] p-2 sm:p-4 space-y-2">
+ <ResponsiveDialogHeader>
+ <ResponsiveDialogTitle>Outbound Links</ResponsiveDialogTitle>
+ </ResponsiveDialogHeader>
<div className="relative mb-2">
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-neutral-600 dark:text-neutral-400" />
<Input
@@ -205,7 +210,7 @@ export function OutboundLinksDialog({ outboundLinks, expanded, close }: Outbound
)}
</div>
</div>
- </DialogContent>
- </Dialog>
+ </ResponsiveDialogContent>
+ </ResponsiveDialog>
);
}
diff --git a/client/src/app/[site]/main/components/sections/SearchConsoleDialog.tsx b/client/src/app/[site]/main/components/sections/SearchConsoleDialog.tsx
index 7cce28c6d..d81875fcb 100644
--- a/client/src/app/[site]/main/components/sections/SearchConsoleDialog.tsx
+++ b/client/src/app/[site]/main/components/sections/SearchConsoleDialog.tsx
@@ -1,4 +1,9 @@
-import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
+import {
+ ResponsiveDialog,
+ ResponsiveDialogContent,
+ ResponsiveDialogHeader,
+ ResponsiveDialogTitle,
+} from "@/components/ui/responsive-dialog";
import { Input } from "@/components/ui/input";
import {
createColumnHelper,
@@ -95,22 +100,22 @@ export function SearchConsoleDialog({ title, dimension, renderName, expanded, cl
if (isLoading || !data) {
return (
- <Dialog open={expanded} onOpenChange={close}>
- <DialogContent className="max-w-[1000px] w-[calc(100vw-2rem)] p-2 sm:p-4">
+ <ResponsiveDialog open={expanded} onOpenChange={close}>
+ <ResponsiveDialogContent className="max-w-[1000px] w-[calc(100vw-2rem)] p-2 sm:p-4 space-y-2">
<div className="flex justify-center items-center h-40">
<Loader2 className="h-8 w-8 animate-spin text-neutral-600 dark:text-neutral-400" />
</div>
- </DialogContent>
- </Dialog>
+ </ResponsiveDialogContent>
+ </ResponsiveDialog>
);
}
return (
- <Dialog open={expanded} onOpenChange={close}>
- <DialogContent className="max-w-[1000px] w-[calc(100vw-2rem)] p-2 sm:p-4">
- <DialogHeader>
- <DialogTitle>{title}</DialogTitle>
- </DialogHeader>
+ <ResponsiveDialog open={expanded} onOpenChange={close}>
+ <ResponsiveDialogContent className="max-w-[1000px] w-[calc(100vw-2rem)] p-2 sm:p-4 space-y-2">
+ <ResponsiveDialogHeader>
+ <ResponsiveDialogTitle>{title}</ResponsiveDialogTitle>
+ </ResponsiveDialogHeader>
<div className="relative">
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-neutral-600 dark:text-neutral-400" />
<Input
@@ -179,7 +184,7 @@ export function SearchConsoleDialog({ title, dimension, renderName, expanded, cl
)}
</div>
</div>
- </DialogContent>
- </Dialog>
+ </ResponsiveDialogContent>
+ </ResponsiveDialog>
);
}
diff --git a/client/src/components/SiteSettings/SiteConfiguration.tsx b/client/src/components/SiteSettings/SiteConfiguration.tsx
index a137acfd2..3fff6c21e 100644
--- a/client/src/components/SiteSettings/SiteConfiguration.tsx
+++ b/client/src/components/SiteSettings/SiteConfiguration.tsx
@@ -297,7 +297,7 @@ export function SiteConfiguration({ siteMetadata, disabled = false, onClose }: S
);
return (
- <div className="pt-4 space-y-6 max-h-[70vh] overflow-y-auto">
+ <div className="pt-4 pb-6 space-y-6 max-h-[70vh] overflow-y-auto">
{/* Privacy & Security Settings */}
<div className="space-y-4">{renderToggleSection(privacyToggles, "Privacy & Security")}</div>
diff --git a/client/src/components/SiteSettings/SiteSettings.tsx b/client/src/components/SiteSettings/SiteSettings.tsx
index 24ba23480..0506dc8b7 100644
--- a/client/src/components/SiteSettings/SiteSettings.tsx
+++ b/client/src/components/SiteSettings/SiteSettings.tsx
@@ -5,22 +5,20 @@ import { useState } from "react";
import { Button } from "@/components/ui/button";
import {
- Dialog,
- DialogClose,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- DialogTrigger,
-} from "@/components/ui/dialog";
+ ResponsiveDialog,
+ ResponsiveDialogContent,
+ ResponsiveDialogDescription,
+ ResponsiveDialogHeader,
+ ResponsiveDialogTitle,
+ ResponsiveDialogTrigger,
+} from "@/components/ui/responsive-dialog";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
-import { SiteResponse, useGetSite } from "@/api/admin/sites";
import { useUserOrganizations } from "@/api/admin/organizations";
+import { SiteResponse, useGetSite } from "@/api/admin/sites";
+import { ImportManager } from "./ImportManager";
import { ScriptBuilder } from "./ScriptBuilder";
import { SiteConfiguration } from "./SiteConfiguration";
-import { ImportManager } from "./ImportManager";
export function SiteSettings({ siteId, trigger }: { siteId: number; trigger?: React.ReactNode }) {
const { data: siteMetadata, isLoading, error } = useGetSite(siteId);
@@ -44,19 +42,19 @@ function SiteSettingsInner({ siteMetadata, trigger }: { siteMetadata: SiteRespon
}
return (
- <Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
- <DialogTrigger asChild>
+ <ResponsiveDialog open={dialogOpen} onOpenChange={setDialogOpen}>
+ <ResponsiveDialogTrigger asChild>
{trigger ?? (
<Button variant="ghost" size="icon">
<Settings className="h-4 w-4" />
</Button>
)}
- </DialogTrigger>
- <DialogContent className="sm:max-w-[750px]">
- <DialogHeader>
- <DialogTitle>Site Settings</DialogTitle>
- <DialogDescription>Manage settings for {siteMetadata.domain}</DialogDescription>
- </DialogHeader>
+ </ResponsiveDialogTrigger>
+ <ResponsiveDialogContent className="sm:max-w-[750px] p-4 sm:p-6 space-y-2">
+ <ResponsiveDialogHeader>
+ <ResponsiveDialogTitle>Site Settings</ResponsiveDialogTitle>
+ <ResponsiveDialogDescription>Manage settings for {siteMetadata.domain}</ResponsiveDialogDescription>
+ </ResponsiveDialogHeader>
<Tabs value={activeTab} onValueChange={setActiveTab} className="pb-4">
<TabsList className="grid w-full grid-cols-3">
<TabsTrigger value="settings">Site Settings</TabsTrigger>
@@ -76,13 +74,13 @@ function SiteSettingsInner({ siteMetadata, trigger }: { siteMetadata: SiteRespon
<SiteConfiguration siteMetadata={siteMetadata} disabled={disabled} onClose={() => setDialogOpen(false)} />
</TabsContent>
</Tabs>
-
- <DialogFooter>
- <DialogClose asChild>
+ {/*
+ <ResponsiveDialogFooter className="pb-4">
+ <ResponsiveDialogClose asChild>
<Button variant="outline">Close</Button>
- </DialogClose>
- </DialogFooter>
- </DialogContent>
- </Dialog>
+ </ResponsiveDialogClose>
+ </ResponsiveDialogFooter> */}
+ </ResponsiveDialogContent>
+ </ResponsiveDialog>
);
}
diff --git a/client/src/components/ui/hooks/useMediaQuery.ts b/client/src/components/ui/hooks/useMediaQuery.ts
new file mode 100644
index 000000000..150ec9bf7
--- /dev/null
+++ b/client/src/components/ui/hooks/useMediaQuery.ts
@@ -0,0 +1,22 @@
+"use client";
+
+import { useEffect, useState } from "react";
+
+const useMediaQuery = (query: string) => {
+ const [matches, setMatches] = useState<boolean | null>(null);
+
+ useEffect(() => {
+ const media = window.matchMedia(query);
+
+ if (media.matches !== matches) setMatches(media.matches);
+
+ const listener = () => setMatches(media.matches);
+
+ window.addEventListener("resize", listener);
+ return () => window.removeEventListener("resize", listener);
+ }, [query, matches]);
+
+ return matches;
+};
+
+export default useMediaQuery;
diff --git a/client/src/components/ui/responsive-dialog.tsx b/client/src/components/ui/responsive-dialog.tsx
new file mode 100644
index 000000000..40151dd83
--- /dev/null
+++ b/client/src/components/ui/responsive-dialog.tsx
@@ -0,0 +1,338 @@
+"use client";
+
+import * as React from "react";
+
+import * as DialogPrimitive from "@radix-ui/react-dialog";
+import { Drawer as DrawerPrimitive, Content as VaulDrawerContent } from "vaul";
+import { X } from "lucide-react";
+import { cva } from "class-variance-authority";
+
+import { cn } from "@/lib/utils";
+import useMediaQuery from "./hooks/useMediaQuery";
+
+export type ResponsiveDialogProps = React.ComponentProps<typeof DrawerPrimitive.Root>;
+
+type ResponsiveDialogContextProps = {
+ modal?: boolean;
+ dismissible?: boolean;
+ direction?: "top" | "right" | "bottom" | "left";
+ onlyDrawer?: boolean;
+ onlyDialog?: boolean;
+ alert?: boolean;
+};
+
+type ResponsiveDialogProviderProps = {
+ children: React.ReactNode;
+} & ResponsiveDialogContextProps;
+
+const ResponsiveDialogContext = React.createContext<ResponsiveDialogContextProps | null>(null);
+const MOBILE_BREAKPOINT = "(min-width: 640px)";
+
+const ResponsiveDialogProvider = ({
+ modal = true,
+ dismissible = true,
+ direction = "bottom",
+ onlyDrawer = false,
+ onlyDialog = false,
+ alert = false,
+ children,
+}: ResponsiveDialogProviderProps) => {
+ return (
+ <ResponsiveDialogContext.Provider value={{ modal, dismissible, direction, onlyDrawer, onlyDialog, alert }}>
+ {children}
+ </ResponsiveDialogContext.Provider>
+ );
+};
+
+export const useResponsiveDialog = () => {
+ const context = React.useContext(ResponsiveDialogContext);
+
+ if (!context) {
+ throw new Error("useResponsiveDialog must be used within a <ResponsiveDialog />");
+ }
+
+ return context;
+};
+
+const ResponsiveDialog = ({
+ modal = true,
+ dismissible = true,
+ direction = "bottom",
+ onlyDrawer = false,
+ onlyDialog = false,
+ alert = false,
+ shouldScaleBackground = true,
+ open: controlledOpen,
+ onOpenChange: controlledOnOpenChange,
+ ...props
+}: ResponsiveDialogProps & { onlyDrawer?: boolean; onlyDialog?: boolean; alert?: boolean }) => {
+ const [internalState, setInternalState] = React.useState<boolean>(false);
+
+ const isControlledOpen = typeof controlledOpen === "undefined";
+ const toggleInternalState = () => setInternalState(prev => !prev);
+
+ const open = isControlledOpen ? internalState : controlledOpen;
+ const onOpenChange = isControlledOpen ? toggleInternalState : controlledOnOpenChange;
+
+ const isDesktop = useMediaQuery(MOBILE_BREAKPOINT);
+
+ const shouldUseDialog = onlyDialog || (!onlyDrawer && isDesktop);
+
+ const ResponsiveDialog = shouldUseDialog ? DialogPrimitive.Root : DrawerPrimitive.Root;
+
+ const effectiveModal = alert ? true : modal;
+ const effectiveDismissible = alert ? true : dismissible;
+
+ return (
+ <ResponsiveDialogProvider
+ modal={effectiveModal}
+ dismissible={effectiveDismissible}
+ direction={direction}
+ onlyDrawer={onlyDrawer}
+ onlyDialog={onlyDialog}
+ alert={alert}
+ >
+ <ResponsiveDialog
+ modal={effectiveModal}
+ direction={direction}
+ dismissible={effectiveDismissible}
+ shouldScaleBackground={shouldScaleBackground}
+ open={open}
+ onOpenChange={onOpenChange}
+ {...props}
+ />
+ </ResponsiveDialogProvider>
+ );
+};
+ResponsiveDialog.displayName = "ResponsiveDialog";
+
+const ResponsiveDialogTrigger = ({ ...props }: React.ComponentProps<typeof DialogPrimitive.Trigger>) => {
+ const { onlyDrawer, onlyDialog } = useResponsiveDialog();
+ const isDesktop = useMediaQuery(MOBILE_BREAKPOINT);
+
+ const shouldUseDialog = onlyDialog || (!onlyDrawer && isDesktop);
+ const ResponsiveDialogTrigger = shouldUseDialog ? DialogPrimitive.Trigger : DrawerPrimitive.Trigger;
+ return <ResponsiveDialogTrigger {...props} />;
+};
+ResponsiveDialogTrigger.displayName = "ResponsiveDialogTrigger";
+
+const ResponsiveDialogPortal = ({ ...props }: React.ComponentProps<typeof DialogPrimitive.Portal>) => {
+ const { onlyDrawer, onlyDialog } = useResponsiveDialog();
+ const isDesktop = useMediaQuery(MOBILE_BREAKPOINT);
+
+ const shouldUseDialog = onlyDialog || (!onlyDrawer && isDesktop);
+ const ResponsiveDialogPortal = shouldUseDialog ? DialogPrimitive.Portal : DrawerPrimitive.Portal;
+ return <ResponsiveDialogPortal {...props} />;
+};
+ResponsiveDialogPortal.displayName = "ResponsiveDialogPortal";
+
+const ResponsiveDialogOverlay = ({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Overlay>) => {
+ const { onlyDrawer, onlyDialog } = useResponsiveDialog();
+ const isDesktop = useMediaQuery(MOBILE_BREAKPOINT);
+
+ const shouldUseDialog = onlyDialog || (!onlyDrawer && isDesktop);
+ const ResponsiveDialogOverlay = shouldUseDialog ? DialogPrimitive.Overlay : DrawerPrimitive.Overlay;
+ return (
+ <ResponsiveDialogOverlay
+ {...props}
+ className={cn(
+ "fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
+ className
+ )}
+ />
+ );
+};
+ResponsiveDialogOverlay.displayName = "ResponsiveDialogOverlay";
+
+const ResponsiveDialogClose = ({ ...props }: React.ComponentProps<typeof DialogPrimitive.Close>) => {
+ const { dismissible, alert, onlyDrawer, onlyDialog } = useResponsiveDialog();
+ const isDesktop = useMediaQuery(MOBILE_BREAKPOINT);
+
+ const shouldUseDialog = onlyDialog || (!onlyDrawer && isDesktop);
+ const ResponsiveDialogClose = shouldUseDialog ? DialogPrimitive.Close : DrawerPrimitive.Close;
+
+ const shouldPreventClose = !dismissible && !alert;
+
+ return (
+ <ResponsiveDialogClose
+ aria-label="Close"
+ {...(shouldPreventClose && { onClick: e => e.preventDefault() })}
+ {...props}
+ />
+ );
+};
+ResponsiveDialogClose.displayName = "ResponsiveDialogClose";
+
+const ResponsiveDialogContentVariants = cva("fixed z-[9999] bg-background", {
+ variants: {
+ device: {
+ desktop:
+ "left-1/2 top-1/2 grid max-h-[calc(100%-4rem)] w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-lg border shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",
+ mobile: "flex ",
+ },
+ direction: {
+ bottom: "",
+ top: "",
+ left: "",
+ right: "",
+ },
+ },
+ defaultVariants: {
+ device: "desktop",
+ direction: "bottom",
+ },
+ compoundVariants: [
+ {
+ device: "mobile",
+ direction: "bottom",
+ className:
+ "!inset-x-0 !w-full !max-w-full bottom-0 mt-24 h-fit max-h-[85%] flex-col rounded-t-[10px] border border-b-0 border-primary/10",
+ },
+ {
+ device: "mobile",
+ direction: "top",
+ className:
+ "!inset-x-0 !w-full !max-w-full top-0 mb-24 h-fit max-h-[85%] flex-col rounded-b-[10px] border border-b-0 border-primary/10",
+ },
+ {
+ device: "mobile",
+ direction: "left",
+ className:
+ "bottom-2 left-2 top-2 flex w-[310px] bg-transparent outline-none [--initial-transform:calc(100%+8px)]",
+ },
+ {
+ device: "mobile",
+ direction: "right",
+ className: "bottom-2 right-2 top-2 w-[310px] bg-transparent outline-none [--initial-transform:calc(100%+8px)]",
+ },
+ ],
+});
+
+const ResponsiveDialogContent = React.forwardRef<
+ HTMLDivElement,
+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
+ showCloseButton?: boolean;
+ /** Styles for the built in close button */
+ closeButtonClassName?: string;
+ /** Styles for the drag handle */
+ dragHandleClassName?: string;
+ }
+>(({ className, children, showCloseButton = true, closeButtonClassName, dragHandleClassName, ...props }, ref) => {
+ const { direction, modal, dismissible, alert, onlyDrawer, onlyDialog } = useResponsiveDialog();
+
+ const isDesktop = useMediaQuery(MOBILE_BREAKPOINT);
+ const shouldUseDialog = onlyDialog || (!onlyDrawer && isDesktop);
+ const ResponsiveDialogContent = shouldUseDialog ? DialogPrimitive.Content : VaulDrawerContent;
+
+ const shouldShowCloseButton = !alert && showCloseButton;
+ const shouldPreventEscape = !dismissible && !alert;
+ const shouldPreventOutsideInteraction = !modal || (!dismissible && !alert) || alert;
+
+ return (
+ <ResponsiveDialogPortal>
+ <ResponsiveDialogOverlay />
+ <ResponsiveDialogContent
+ ref={ref}
+ {...props}
+ {...(shouldPreventEscape && shouldUseDialog && { onEscapeKeyDown: e => e.preventDefault() })}
+ {...(shouldPreventOutsideInteraction &&
+ shouldUseDialog && {
+ onInteractOutside: e => e.preventDefault(),
+ })}
+ {...(!shouldUseDialog &&
+ shouldPreventOutsideInteraction && {
+ onPointerDownOutside: e => e.preventDefault(),
+ onInteractOutside: e => e.preventDefault(),
+ })}
+ className={cn(
+ ResponsiveDialogContentVariants({
+ device: shouldUseDialog ? "desktop" : "mobile",
+ direction,
+ }),
+ className
+ )}
+ >
+ {!shouldUseDialog && direction === "bottom" && (
+ <div
+ className={cn(
+ "mx-auto my-4 h-1.5 w-14 rounded-full bg-muted-foreground/25 pb-1.5 data-[vaul-handle]:h-1.5 data-[vaul-handle]:w-14 data-[vaul-handle]:pb-1.5 dark:bg-muted",
+ dragHandleClassName
+ )}
+ />
+ )}
+ {children}
+ {shouldShowCloseButton && (
+ <ResponsiveDialogClose
+ className={cn(
+ "absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background backdrop-blur-sm transition-opacity hover:opacity-100 focus:outline-none focus:ring-offset-2 focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-white",
+ closeButtonClassName
+ )}
+ >
+ <X className="size-4" />
+ <span className="sr-only">close</span>
+ </ResponsiveDialogClose>
+ )}
+ </ResponsiveDialogContent>
+ </ResponsiveDialogPortal>
+ );
+});
+ResponsiveDialogContent.displayName = "ResponsiveDialogContent";
+
+const ResponsiveDialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => {
+ return <div className={cn("flex flex-col gap-1.5 text-center sm:text-left", className)} {...props} />;
+};
+ResponsiveDialogHeader.displayName = "ResponsiveDialogHeader";
+
+const ResponsiveDialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => {
+ return <footer className={cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", className)} {...props} />;
+};
+ResponsiveDialogFooter.displayName = "ResponsiveDialogFooter";
+
+const ResponsiveDialogTitle = React.forwardRef<
+ React.ComponentRef<typeof DialogPrimitive.Title>,
+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
+>(({ className, ...props }, ref) => {
+ const { onlyDrawer, onlyDialog } = useResponsiveDialog();
+ const isDesktop = useMediaQuery(MOBILE_BREAKPOINT);
+
+ const shouldUseDialog = onlyDialog || (!onlyDrawer && isDesktop);
+ const ResponsiveDialogTitle = shouldUseDialog ? DialogPrimitive.Title : DrawerPrimitive.Title;
+ return (
+ <ResponsiveDialogTitle
+ ref={ref}
+ className={cn("text-lg font-semibold leading-none tracking-tight", className)}
+ {...props}
+ />
+ );
+});
+
+ResponsiveDialogTitle.displayName = "ResponsiveDialogTitle";
+
+const ResponsiveDialogDescription = React.forwardRef<
+ React.ComponentRef<typeof DialogPrimitive.Description>,
+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
+>(({ className, ...props }, ref) => {
+ const { onlyDrawer, onlyDialog } = useResponsiveDialog();
+ const isDesktop = useMediaQuery(MOBILE_BREAKPOINT);
+
+ const shouldUseDialog = onlyDialog || (!onlyDrawer && isDesktop);
+ const ResponsiveDialogDescription = shouldUseDialog ? DialogPrimitive.Description : DrawerPrimitive.Description;
+ return (
+ <ResponsiveDialogDescription ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />
+ );
+});
+
+ResponsiveDialogDescription.displayName = "ResponsiveDialogDescription";
+
+export {
+ ResponsiveDialog,
+ ResponsiveDialogClose,
+ ResponsiveDialogContent,
+ ResponsiveDialogDescription,
+ ResponsiveDialogFooter,
+ ResponsiveDialogHeader,
+ ResponsiveDialogOverlay,
+ ResponsiveDialogPortal,
+ ResponsiveDialogTitle,
+ ResponsiveDialogTrigger,
+};
diff --git a/docs/tailwind.config.ts b/docs/tailwind.config.ts
index a5d5a05f8..814fd1146 100644
--- a/docs/tailwind.config.ts
+++ b/docs/tailwind.config.ts
@@ -1,29 +1,27 @@
-import type { Config } from 'tailwindcss'
+import type { Config } from "tailwindcss";
const config: Config = {
- darkMode: 'class',
- content: [
- './src/**/*.{js,ts,jsx,tsx,mdx}',
- ],
+ darkMode: "class",
+ content: ["./src/**/*.{js,ts,jsx,tsx,mdx}"],
theme: {
extend: {
animation: {
- 'marquee': 'marquee var(--duration) linear infinite',
- 'marquee-vertical': 'marquee-vertical var(--duration) linear infinite',
+ marquee: "marquee var(--duration) linear infinite",
+ "marquee-vertical": "marquee-vertical var(--duration) linear infinite",
},
keyframes: {
marquee: {
- from: { transform: 'translateX(0)' },
- to: { transform: 'translateX(calc(-100% - var(--gap)))' },
+ from: { transform: "translateX(0)" },
+ to: { transform: "translateX(calc(-100% - var(--gap)))" },
},
- 'marquee-vertical': {
- from: { transform: 'translateY(0)' },
- to: { transform: 'translateY(calc(-100% - var(--gap)))' },
+ "marquee-vertical": {
+ from: { transform: "translateY(0)" },
+ to: { transform: "translateY(calc(-100% - var(--gap)))" },
},
},
},
},
plugins: [],
-}
+};
-export default config
\ No newline at end of file
+export default config;