-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b422848
commit d2669fd
Showing
5 changed files
with
213 additions
and
159 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
131 changes: 131 additions & 0 deletions
131
packages/web-ui/src/ds/atoms/Modal/Primitives/index.tsx
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,131 @@ | ||
'use client' | ||
|
||
import { | ||
ComponentPropsWithoutRef, | ||
ElementRef, | ||
forwardRef, | ||
HTMLAttributes, | ||
} from 'react' | ||
import { X } from 'lucide-react' | ||
import * as DialogPrimitive from '@radix-ui/react-dialog' | ||
|
||
import Text from '$ui/ds/atoms/Text' | ||
import { cn } from '$ui/lib/utils' | ||
|
||
const Dialog = DialogPrimitive.Root | ||
const DialogTrigger = DialogPrimitive.Trigger | ||
const DialogPortal = DialogPrimitive.Portal | ||
const DialogClose = DialogPrimitive.Close | ||
|
||
const DialogOverlay = forwardRef< | ||
ElementRef<typeof DialogPrimitive.Overlay>, | ||
ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay> | ||
>(({ className: _cn, ...props }, ref) => ( | ||
<DialogPrimitive.Overlay | ||
ref={ref} | ||
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', | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName | ||
|
||
const DialogContent = forwardRef< | ||
ElementRef<typeof DialogPrimitive.Content>, | ||
ComponentPropsWithoutRef<typeof DialogPrimitive.Content> | ||
>(({ className: _cn, children, ...props }, ref) => ( | ||
<DialogPortal> | ||
<DialogOverlay /> | ||
<DialogPrimitive.Content | ||
ref={ref} | ||
className={cn( | ||
'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 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 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg', | ||
)} | ||
{...props} | ||
> | ||
{children} | ||
<DialogPrimitive.Close className='absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground'> | ||
<X className='h-4 w-4' /> | ||
<span className='sr-only'>Close</span> | ||
</DialogPrimitive.Close> | ||
</DialogPrimitive.Content> | ||
</DialogPortal> | ||
)) | ||
DialogContent.displayName = DialogPrimitive.Content.displayName | ||
|
||
const DialogHeader = ({ | ||
className, | ||
...props | ||
}: HTMLAttributes<HTMLDivElement>) => ( | ||
<div | ||
className={cn( | ||
'flex flex-col space-y-1.5 text-center sm:text-left', | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
) | ||
DialogHeader.displayName = 'DialogHeader' | ||
|
||
const DialogFooter = ({ | ||
className, | ||
...props | ||
}: HTMLAttributes<HTMLDivElement>) => ( | ||
<div | ||
className={cn( | ||
'flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2', | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
) | ||
DialogFooter.displayName = 'DialogFooter' | ||
|
||
type DialogTitleProps = Omit< | ||
ComponentPropsWithoutRef<typeof DialogPrimitive.Title>, | ||
'className' | ||
> | ||
const DialogTitle = forwardRef< | ||
ElementRef<typeof DialogPrimitive.Title>, | ||
DialogTitleProps | ||
>(({ children, ...props }, ref) => ( | ||
<DialogPrimitive.Title ref={ref} {...props}> | ||
<Text.H4>{children}</Text.H4> | ||
</DialogPrimitive.Title> | ||
)) | ||
DialogTitle.displayName = DialogPrimitive.Title.displayName | ||
|
||
type DialogDescriptionProps = Omit< | ||
ComponentPropsWithoutRef<typeof DialogPrimitive.Description>, | ||
'className' | ||
> | ||
const DialogDescription = forwardRef< | ||
ElementRef<typeof DialogPrimitive.Description>, | ||
DialogDescriptionProps | ||
>(({ children, ...props }, ref) => ( | ||
<DialogPrimitive.Description | ||
ref={ref} | ||
className='text-sm text-muted-foreground' | ||
{...props} | ||
> | ||
<Text.H4>{children}</Text.H4> | ||
</DialogPrimitive.Description> | ||
)) | ||
|
||
DialogDescription.displayName = DialogPrimitive.Description.displayName | ||
|
||
export { | ||
Dialog, | ||
DialogPortal, | ||
DialogOverlay, | ||
DialogClose, | ||
DialogTrigger, | ||
DialogContent, | ||
DialogHeader, | ||
DialogFooter, | ||
DialogTitle, | ||
DialogDescription, | ||
} |
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,41 @@ | ||
'use client' | ||
|
||
import { ReactNode } from 'react' | ||
|
||
import { | ||
Dialog, | ||
DialogClose, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from './Primitives' | ||
|
||
export const ModalTrigger = DialogTrigger | ||
|
||
export function Modal({ | ||
children, | ||
footer, | ||
}: { | ||
children: ReactNode | ||
footer?: ReactNode | ||
}) { | ||
return ( | ||
<Dialog> | ||
<DialogContent className='sm:max-w-modal'> | ||
<DialogHeader> | ||
<DialogTitle>Are you absolutely sure?</DialogTitle> | ||
<DialogDescription> | ||
This action cannot be undone. This will permanently delete your | ||
account and remove your data from our servers. | ||
</DialogDescription> | ||
</DialogHeader> | ||
<div className='p-4'>{children}</div> | ||
|
||
{footer ? <DialogFooter>{footer}</DialogFooter> : null} | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
} |
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
Oops, something went wrong.