The Coline design system: accessible React components for Coline Apps, themed live by the host workspace, and for Coline Sites in light and dark. Tailwind v4 stylesheet included. MIT.
| 5 |
| 6 | import { cn } from "../lib/utils"; |
| 7 | import { Button } from "./button"; |
| 8 | import { IconX } from "@tabler/icons-react"; |
| 9 | import { liquidMenuSurfaceClasses } from "./liquid-menu-surface"; |
| 10 |
| 11 | function Dialog({ |
| 12 | ...props |
| 13 | }: React.ComponentProps<typeof DialogPrimitive.Root>) { |
| 14 | return <DialogPrimitive.Root data-slot="dialog" {...props} />; |
| 15 | } |
| 16 |
| 17 | function DialogTrigger({ |
| 18 | ...props |
| 19 | }: React.ComponentProps<typeof DialogPrimitive.Trigger>) { |
| 20 | return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />; |
| 21 | } |
| 22 |
| 23 | function DialogPortal({ |
| 24 | ...props |
| 25 | }: React.ComponentProps<typeof DialogPrimitive.Portal>) { |
| 26 | return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />; |
| 27 | } |
| 28 |
| 29 | function DialogClose({ |
| 30 | ...props |
| 31 | }: React.ComponentProps<typeof DialogPrimitive.Close>) { |
| 32 | return <DialogPrimitive.Close data-slot="dialog-close" {...props} />; |
| 33 | } |
| 34 |
| 35 | function DialogOverlay({ |
| 36 | className, |
| 37 | ...props |
| 38 | }: React.ComponentProps<typeof DialogPrimitive.Overlay>) { |
| 39 | return ( |
| 40 | <DialogPrimitive.Overlay |
| 41 | data-slot="dialog-overlay" |
| 42 | className={cn( |
| 43 | "coline-dialog-overlay fixed inset-0 isolate z-50 bg-black/30 supports-backdrop-filter:backdrop-blur-sm", |
| 44 | className, |
| 45 | )} |
| 46 | {...props} |
| 47 | /> |
| 48 | ); |
| 49 | } |
| 50 |
| 51 | function DialogContent({ |
| 52 | className, |
| 53 | children, |
| 54 | showCloseButton = true, |
| 55 | ...props |
| 56 | }: React.ComponentProps<typeof DialogPrimitive.Content> & { |
| 57 | showCloseButton?: boolean; |
| 58 | }) { |
| 59 | return ( |
| 60 | <DialogPortal> |
| 61 | <DialogOverlay /> |
| 62 | <DialogPrimitive.Content |
| 63 | data-slot="dialog-content" |
| 64 | className={cn( |
| 65 | // Mobile: bottom-sheet style, pinned to bottom with slide-up |
| 66 | "coline-dialog-content fixed z-50 grid w-full gap-4 p-4 text-sm outline-none", |
| 67 | liquidMenuSurfaceClasses, |
| 68 | "inset-x-0 bottom-0 max-h-[85dvh] overflow-y-auto rounded-b-none pb-[max(1rem,env(safe-area-inset-bottom))]", |
| 69 | // Desktop: centered modal |
| 70 | "sm:inset-x-auto sm:bottom-auto sm:top-1/2 sm:left-1/2 sm:max-w-md sm:max-h-[calc(100dvh-4rem)] sm:-translate-x-1/2 sm:-translate-y-1/2 sm:rounded-2xl sm:p-6 sm:gap-6 sm:pb-6", |
| 71 | className, |
| 72 | )} |
| 73 | {...props} |
| 74 | > |
| 75 | {/* Mobile drag indicator */} |
| 76 | <div className="mx-auto h-1 w-10 shrink-0 rounded-full bg-muted-foreground/30 sm:hidden" aria-hidden="true" /> |
| 77 | {children} |
| 78 | {showCloseButton && ( |
| 79 | <DialogPrimitive.Close data-slot="dialog-close" asChild> |
| 80 | <Button |
| 81 | variant="ghost" |
| 82 | className="absolute top-4 right-4" |
| 83 | size="icon-sm" |
| 84 | > |
| 85 | <IconX /> |
| 86 | <span className="sr-only">Close</span> |
| 87 | </Button> |
| 88 | </DialogPrimitive.Close> |
| 89 | )} |
| 90 | </DialogPrimitive.Content> |
| 91 | </DialogPortal> |
| 92 | ); |
| 93 | } |
| 94 |
| 95 | function DialogHeader({ className, ...props }: React.ComponentProps<"div">) { |
| 96 | return ( |
| 97 | <div |
| 98 | data-slot="dialog-header" |
| 99 | className={cn("flex flex-col gap-2 pr-8", className)} |
| 100 | {...props} |
| 101 | /> |
| 102 | ); |
| 103 | } |
| 104 |
| 105 | function DialogFooter({ |
| 106 | className, |
| 107 | showCloseButton = false, |
| 108 | children, |
| 109 | ...props |
| 110 | }: React.ComponentProps<"div"> & { |
| 111 | showCloseButton?: boolean; |
| 112 | }) { |
| 113 | return ( |
| 114 | <div |
| 115 | data-slot="dialog-footer" |
| 116 | className={cn( |
| 117 | "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", |
| 118 | className, |
| 119 | )} |
| 120 | {...props} |
| 121 | > |
| 122 | {children} |
| 123 | {showCloseButton && ( |
| 124 | <DialogPrimitive.Close asChild> |
| 125 | <Button variant="outline">Close</Button> |
| 126 | </DialogPrimitive.Close> |
| 127 | )} |
| 128 | </div> |
| 129 | ); |
| 130 | } |
| 131 |
| 132 | function DialogTitle({ |
| 133 | className, |
| 134 | ...props |
| 135 | }: React.ComponentProps<typeof DialogPrimitive.Title>) { |
| 136 | return ( |
| 137 | <DialogPrimitive.Title |
| 138 | data-slot="dialog-title" |
| 139 | className={cn("text-base leading-none font-medium", className)} |
| 140 | {...props} |
| 141 | /> |
| 142 | ); |
| 143 | } |
| 144 |
| 145 | function DialogDescription({ |
| 146 | className, |
| 147 | ...props |
| 148 | }: React.ComponentProps<typeof DialogPrimitive.Description>) { |
| 149 | return ( |
| 150 | <DialogPrimitive.Description |
| 151 | data-slot="dialog-description" |
| 152 | className={cn( |
| 153 | "text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground", |
| 154 | className, |
| 155 | )} |
| 156 | {...props} |
| 157 | /> |
| 158 | ); |
| 159 | } |
| 160 |
| 161 | export { |
| 162 | Dialog, |
| 163 | DialogClose, |
| 164 | DialogContent, |
| 165 | DialogDescription, |
| 166 | DialogFooter, |
| 167 | DialogHeader, |
| 168 | DialogOverlay, |
| 169 | DialogPortal, |
| 170 | DialogTitle, |
| 171 | DialogTrigger, |
| 172 | }; |
| 173 |