forked from Weaverse/pilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create Modal component with trigger and close functionality usi…
…ng Radix UI and Phosphor icons
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { X } from "@phosphor-icons/react"; | ||
import { | ||
Close, | ||
Content, | ||
type DialogCloseProps, | ||
type DialogContentProps, | ||
type DialogProps, | ||
type DialogTriggerProps, | ||
Overlay, | ||
Portal, | ||
Root, | ||
Trigger, | ||
} from "@radix-ui/react-dialog"; | ||
import type React from "react"; | ||
import { forwardRef } from "react"; | ||
import { cn } from "~/lib/cn"; | ||
|
||
export let Modal: React.FC<DialogProps> = Root; | ||
|
||
export let ModalTrigger = forwardRef<HTMLButtonElement, DialogTriggerProps>( | ||
({ asChild = true, ...rest }, ref) => { | ||
return <Trigger asChild={asChild} {...rest} ref={ref} />; | ||
} | ||
); | ||
|
||
interface ModalContentProps extends DialogContentProps {} | ||
|
||
export let ModalContent = forwardRef<HTMLDivElement, ModalContentProps>( | ||
({ children, className, ...rest }, ref) => { | ||
return ( | ||
<Portal> | ||
<Overlay className="fixed inset-0 z-10" /> | ||
<Content | ||
{...rest} | ||
ref={ref} | ||
className={cn( | ||
"data-[state='open']:animate-slide-down-and-fade", | ||
"fixed inset-0 z-10 flex items-center overflow-x-hidden bg-gray-900/50 px-4" | ||
)} | ||
> | ||
<div | ||
style={{ maxHeight: "90vh" }} | ||
className={cn( | ||
"animate-slide-down-and-fade relative overflow-hidden", | ||
"w-full mx-auto h-auto max-w-screen-xl" | ||
)} | ||
> | ||
<ModalClose /> | ||
<div className={cn("bg-white shadow p-6", className)}> | ||
{children} | ||
</div> | ||
</div> | ||
</Content> | ||
</Portal> | ||
); | ||
} | ||
); | ||
|
||
export let ModalClose = forwardRef<HTMLButtonElement, DialogCloseProps>( | ||
({ asChild, children, ...rest }, ref) => { | ||
return ( | ||
<Close asChild {...rest} ref={ref}> | ||
<X className="absolute right-3 top-3 cursor-pointer" size={20} /> | ||
</Close> | ||
); | ||
} | ||
); |