From e446f3172faed70289b4cf04562f865d59104ee4 Mon Sep 17 00:00:00 2001 From: ner Date: Mon, 25 Mar 2024 16:32:53 +0200 Subject: [PATCH] fix: modal animation --- components/ui/dialog.tsx | 116 ++++++++++++++++++++++++++------------- 1 file changed, 78 insertions(+), 38 deletions(-) diff --git a/components/ui/dialog.tsx b/components/ui/dialog.tsx index 6ac7ded..9c5e3e9 100644 --- a/components/ui/dialog.tsx +++ b/components/ui/dialog.tsx @@ -3,55 +3,86 @@ import * as React from 'react'; import { useState } from 'react'; import * as DialogPrimitive from '@radix-ui/react-dialog'; -import { X } from 'lucide-react'; import { cn } from '@/lib/utils'; const Dialog = DialogPrimitive.Root; -const DialogPortal = ({ ...props }: DialogPrimitive.DialogPortalProps) => ; -DialogPortal.displayName = DialogPrimitive.Portal.displayName; +const DialogTrigger = DialogPrimitive.Trigger; + +const DialogPortal = DialogPrimitive.Portal; + +const DialogClose = DialogPrimitive.Close; const DialogOverlay = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef ->(({ className, children, ...props }, ref) => ( - -
- {children} -
+>(({ className, ...props }, ref) => ( + + {props?.children} )); DialogOverlay.displayName = DialogPrimitive.Overlay.displayName; const DialogContent = React.forwardRef< React.ElementRef, - React.ComponentPropsWithoutRef & { onClose?: () => void } ->(({ className, children, ...props }, ref) => { - return ( - - -
- - {children} -
- -
- - - ); -}); + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + + + + {children} +
+ + + +)); 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; + const Modal: React.FC<{ children: React.ReactNode; className?: string; @@ -60,18 +91,27 @@ const Modal: React.FC<{ const [open, setOpen] = useState(true); const handleClose = () => { - console.log(onClose()); - console.log('closing'); + onClose?.(); setOpen(false); }; return ( - - {children} - + {children} ); }; -export { Dialog, DialogContent, Modal }; +export { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogOverlay, + DialogPortal, + DialogTitle, + DialogTrigger, + Modal +};