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