File tree Expand file tree Collapse file tree
src/components/PostDetail Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import Markdown from '@uiw/react-markdown-preview' ;
44import rehypeHighlight from 'rehype-highlight' ;
5+ import { useState } from 'react' ;
6+ import ImageZoomModal from '@/components/Common/ImageZoomModal' ;
7+ import CodeBlock from '@/components/Common/CodeBlock' ;
58
69export function PostDetailBody ( { content } : { content : string } ) {
10+ const [ zoomedImage , setZoomedImage ] = useState < { src : string ; alt : string } | null > ( null ) ;
11+
712 return (
8- < div data-color-mode = "light" className = "prose prose-sm sm:prose-base max-w-none md:p-6 font-sans" >
9- < Markdown
10- source = { content }
11- rehypePlugins = { [ [ rehypeHighlight , { detect : true } ] ] }
12- components = { {
13- img : ( props ) => < img { ...props } style = { { maxWidth : '100%' } } /> ,
14- } }
13+ < >
14+ < div data-color-mode = "light" className = "prose prose-sm sm:prose-base max-w-none md:p-6 font-sans" >
15+ < Markdown
16+ source = { content }
17+ rehypePlugins = { [ [ rehypeHighlight , { detect : true } ] ] }
18+ components = { {
19+ img : ( props ) => (
20+ < img
21+ { ...props }
22+ style = { { maxWidth : '100%' , cursor : 'zoom-in' } }
23+ onClick = { ( ) => setZoomedImage ( {
24+ src : typeof props . src === 'string' ? props . src : '' ,
25+ alt : props . alt || ''
26+ } ) }
27+ className = "rounded-lg hover:opacity-90 transition-opacity"
28+ alt = { props . alt || '' }
29+ />
30+ ) ,
31+ pre : ( props ) => (
32+ < CodeBlock className = { props . className } >
33+ { props . children }
34+ </ CodeBlock >
35+ ) ,
36+ } }
37+ />
38+ </ div >
39+
40+ < ImageZoomModal
41+ isOpen = { ! ! zoomedImage }
42+ onClose = { ( ) => setZoomedImage ( null ) }
43+ imageSrc = { zoomedImage ?. src || '' }
44+ imageAlt = { zoomedImage ?. alt }
1545 />
16- </ div >
46+ </ >
1747 ) ;
1848}
You can’t perform that action at this time.
0 commit comments