Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutgon committed Jul 15, 2024
1 parent b422848 commit d2669fd
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 159 deletions.
122 changes: 0 additions & 122 deletions packages/web-ui/src/ds/atoms/Dialog/index.tsx

This file was deleted.

131 changes: 131 additions & 0 deletions packages/web-ui/src/ds/atoms/Modal/Primitives/index.tsx
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,
}
41 changes: 41 additions & 0 deletions packages/web-ui/src/ds/atoms/Modal/index.tsx
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>
)
}
3 changes: 3 additions & 0 deletions packages/web-ui/src/ds/atoms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ export * from './Toast'
export * from './Toast/ToastProvider'
export * from './Toast/useToast'
export * from './Icons'
export * from './Command'
export * from './Modal'
export * from './Popover'
Loading

0 comments on commit d2669fd

Please sign in to comment.