|
1 | 1 | import * as React from "react"; |
2 | 2 | import ReactMarkdown, { type Components } from "react-markdown"; |
| 3 | +import * as DialogPrimitive from "@radix-ui/react-dialog"; |
3 | 4 | import remarkBreaks from "remark-breaks"; |
4 | 5 | import remarkGfm from "remark-gfm"; |
5 | 6 |
|
@@ -131,11 +132,42 @@ function createMarkdownComponents( |
131 | 132 | ); |
132 | 133 | } |
133 | 134 | return ( |
134 | | - <img |
135 | | - alt={alt} |
136 | | - className="max-h-96 rounded-2xl border border-border/70 object-cover" |
137 | | - src={resolvedSrc} |
138 | | - /> |
| 135 | + <DialogPrimitive.Root> |
| 136 | + <DialogPrimitive.Trigger asChild> |
| 137 | + <img |
| 138 | + alt={alt} |
| 139 | + className="mt-4 max-h-96 max-w-lg cursor-pointer rounded-2xl border border-border/70 object-cover transition-opacity hover:opacity-90" |
| 140 | + src={resolvedSrc} |
| 141 | + /> |
| 142 | + </DialogPrimitive.Trigger> |
| 143 | + <DialogPrimitive.Portal> |
| 144 | + <DialogPrimitive.Overlay className="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" /> |
| 145 | + <DialogPrimitive.Content |
| 146 | + className="fixed inset-0 z-50 flex items-center justify-center p-8" |
| 147 | + // Let clicks on the backdrop (the content container itself) close the lightbox |
| 148 | + onPointerDownOutside={(e) => e.preventDefault()} |
| 149 | + onInteractOutside={(e) => e.preventDefault()} |
| 150 | + > |
| 151 | + <DialogPrimitive.Title className="sr-only"> |
| 152 | + {alt || "Image preview"} |
| 153 | + </DialogPrimitive.Title> |
| 154 | + <DialogPrimitive.Description className="sr-only"> |
| 155 | + Full-size image preview. Press Escape or click outside the image to close. |
| 156 | + </DialogPrimitive.Description> |
| 157 | + {/* Close region: clicking anywhere except the image closes the dialog */} |
| 158 | + <DialogPrimitive.Close className="absolute inset-0 cursor-default" aria-label="Close lightbox" /> |
| 159 | + <img |
| 160 | + alt={alt} |
| 161 | + className="relative max-h-[90vh] max-w-[90vw] rounded-lg object-contain" |
| 162 | + src={resolvedSrc} |
| 163 | + /> |
| 164 | + <DialogPrimitive.Close className="absolute right-4 top-4 rounded-full bg-black/50 p-2 text-white/80 transition-colors hover:bg-black/70 hover:text-white focus:outline-none focus:ring-2 focus:ring-white/30"> |
| 165 | + <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" /></svg> |
| 166 | + <span className="sr-only">Close</span> |
| 167 | + </DialogPrimitive.Close> |
| 168 | + </DialogPrimitive.Content> |
| 169 | + </DialogPrimitive.Portal> |
| 170 | + </DialogPrimitive.Root> |
139 | 171 | ); |
140 | 172 | }, |
141 | 173 | li: ({ children }) => <li className={listItemClassName}>{children}</li>, |
|
0 commit comments