Skip to content

Commit 1ba0dd2

Browse files
committed
feat(markdown): image preview max-width + click-to-open lightbox
Timeline images now render at max-w-lg (~512px) as clickable thumbnails with cursor-pointer and a subtle hover opacity transition. Clicking opens a scrimmed lightbox (bg-black/80) showing the full-res image at up to 90vh/90vw. Clicking the backdrop or pressing Escape closes the lightbox. Includes accessible Title and Description for Radix Dialog, and an explicit close button. Video rendering left unchanged.
1 parent e4aa3cc commit 1ba0dd2

1 file changed

Lines changed: 37 additions & 5 deletions

File tree

‎desktop/src/shared/ui/markdown.tsx‎

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from "react";
22
import ReactMarkdown, { type Components } from "react-markdown";
3+
import * as DialogPrimitive from "@radix-ui/react-dialog";
34
import remarkBreaks from "remark-breaks";
45
import remarkGfm from "remark-gfm";
56

@@ -131,11 +132,42 @@ function createMarkdownComponents(
131132
);
132133
}
133134
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>
139171
);
140172
},
141173
li: ({ children }) => <li className={listItemClassName}>{children}</li>,

0 commit comments

Comments
 (0)