import * as React from "react" import * as DialogPrimitive from "@radix-ui/react-dialog" import { X } from "lucide-react" import { cn } from "@/lib/utils" import { useSwipeBack } from '@/hooks/useMobile' const Dialog = DialogPrimitive.Root const DialogTrigger = DialogPrimitive.Trigger const DialogPortal = DialogPrimitive.Portal const DialogClose = DialogPrimitive.Close const DialogOverlay = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) DialogOverlay.displayName = DialogPrimitive.Overlay.displayName interface DialogContentProps extends Omit, 'onOpenChange'> { hideCloseButton?: boolean fullscreen?: boolean mobileFullscreen?: boolean mobileSwipeToClose?: boolean onOpenChange?: (open: boolean) => void overlayClassName?: string } const DialogContent = React.forwardRef< React.ElementRef, DialogContentProps >(({ className, children, hideCloseButton, fullscreen, mobileFullscreen, mobileSwipeToClose, overlayClassName, ...props }, ref) => { const isMobileFullscreenMode = fullscreen || mobileFullscreen const swipeContainerRef = React.useRef(null) const contentRef = React.useRef(null) const closeTriggerRef = React.useRef(null) const combinedRef = React.useCallback((node: HTMLDivElement | null) => { contentRef.current = node swipeContainerRef.current = node if (typeof ref === 'function') { ref(node) } else if (ref) { ref.current = node } }, [ref]) const [isMobile, setIsMobile] = React.useState(() => typeof window !== 'undefined' ? window.innerWidth < 768 : false) React.useEffect(() => { const check = () => setIsMobile(window.innerWidth < 768) window.addEventListener('resize', check) return () => window.removeEventListener('resize', check) }, []) const { bind: swipeBind } = useSwipeBack( () => closeTriggerRef.current?.click(), { enabled: isMobileFullscreenMode && mobileSwipeToClose === true && isMobile } ) React.useEffect(() => { if (isMobileFullscreenMode && mobileSwipeToClose && isMobile) { return swipeBind(swipeContainerRef.current) } return undefined }, [isMobileFullscreenMode, mobileSwipeToClose, isMobile, swipeBind]) return ( {!fullscreen && } {children} {mobileSwipeToClose && isMobileFullscreenMode && ( )} {!hideCloseButton && !fullscreen && ( Close )} ) }) DialogContent.displayName = DialogPrimitive.Content.displayName const DialogHeader = ({ className, ...props }: React.HTMLAttributes) => (
) DialogHeader.displayName = "DialogHeader" const DialogFooter = ({ className, ...props }: React.HTMLAttributes) => (
) DialogFooter.displayName = "DialogFooter" const DialogTitle = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) DialogTitle.displayName = DialogPrimitive.Title.displayName const DialogDescription = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) DialogDescription.displayName = DialogPrimitive.Description.displayName export { Dialog, DialogPortal, DialogOverlay, DialogClose, DialogTrigger, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription, }