g1t/apps/web/app/components/ui/dialog.tsx
Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Workspace names and icons, and a component kit for every control | 1 | import { X } from "lucide-react"; |
| 2 | import { Dialog as Primitive } from "radix-ui"; | |
| 3 | import type { ComponentProps } from "react"; | |
| 4 | ||
| 5 | import { cn } from "../../lib/cn"; | |
| 6 | ||
| 7 | // shadcn/ui's dialog, styled with g1t's tokens. | |
| 8 | ||
| 9 | export const Dialog = Primitive.Root; | |
| 10 | export const DialogTrigger = Primitive.Trigger; | |
| 11 | export const DialogClose = Primitive.Close; | |
| 12 | export const DialogPortal = Primitive.Portal; | |
| 13 | ||
| 14 | export function DialogOverlay({ className, ...props }: ComponentProps<typeof Primitive.Overlay>) { | |
| 15 | return ( | |
| 16 | <Primitive.Overlay | |
| 17 | className={cn( | |
| 18 | "fixed inset-0 z-50 bg-black/60 backdrop-blur-[2px]", | |
| 19 | "data-[state=open]:animate-fade-in data-[state=closed]:animate-fade-out motion-reduce:animate-none", | |
| 20 | className, | |
| 21 | )} | |
| 22 | {...props} | |
| 23 | /> | |
| 24 | ); | |
| 25 | } | |
| 26 | ||
| 27 | /** The panel, centred; on a phone it fills the width less a gutter. */ | |
| 28 | export const DIALOG_PANEL = | |
| 29 | "fixed top-1/2 left-1/2 z-50 grid max-h-[calc(100dvh-2rem)] w-[calc(100vw-2rem)] max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 overflow-y-auto rounded-xl border border-line-strong bg-surface p-6 text-fg shadow-2xl shadow-black/60 outline-none data-[state=open]:animate-dialog-in data-[state=closed]:animate-dialog-out motion-reduce:animate-none"; | |
| 30 | ||
| 31 | export function DialogContent({ | |
| 32 | className, | |
| 33 | children, | |
| 34 | showClose = true, | |
| 35 | ...props | |
| 36 | }: ComponentProps<typeof Primitive.Content> & { showClose?: boolean }) { | |
| 37 | return ( | |
| 38 | <Primitive.Portal> | |
| 39 | <DialogOverlay /> | |
| 40 | <Primitive.Content className={cn(DIALOG_PANEL, className)} {...props}> | |
| 41 | {children} | |
| 42 | {showClose && ( | |
| 43 | <Primitive.Close | |
| 44 | aria-label="Close" | |
| 45 | className="absolute top-4 right-4 rounded-md p-1 text-faint transition-colors hover:bg-raised hover:text-fg" | |
| 46 | > | |
| 47 | <X size={16} /> | |
| 48 | </Primitive.Close> | |
| 49 | )} | |
| 50 | </Primitive.Content> | |
| 51 | </Primitive.Portal> | |
| 52 | ); | |
| 53 | } | |
| 54 | ||
| 55 | export function DialogHeader({ className, ...props }: ComponentProps<"div">) { | |
| 56 | return <div className={cn("flex flex-col gap-1.5 pr-6", className)} {...props} />; | |
| 57 | } | |
| 58 | ||
| 59 | export function DialogFooter({ className, ...props }: ComponentProps<"div">) { | |
| 60 | return <div className={cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", className)} {...props} />; | |
| 61 | } | |
| 62 | ||
| 63 | export function DialogTitle({ className, ...props }: ComponentProps<typeof Primitive.Title>) { | |
| 64 | return <Primitive.Title className={cn("text-base font-semibold tracking-tight", className)} {...props} />; | |
| 65 | } | |
| 66 | ||
| 67 | export function DialogDescription({ className, ...props }: ComponentProps<typeof Primitive.Description>) { | |
| 68 | return <Primitive.Description className={cn("text-sm text-muted", className)} {...props} />; | |
| 69 | } |