@@ -10,7 +10,9 @@ import { throttle } from '~/lib/lodash'
10
10
import { useMarkdownImageRecord } from '~/providers/article/MarkdownImageRecordProvider'
11
11
import { useWrappedElementSize } from '~/providers/shared/WrappedElementProvider'
12
12
13
+ import { MotionButtonBase } from '../button'
13
14
import { FixedZoomedImage } from '../image'
15
+ import { MarkdownImage } from '../markdown/renderers/image'
14
16
import styles from './Gallery.module.css'
15
17
16
18
const IMAGE_CONTAINER_MARGIN_INSET = 60
@@ -139,6 +141,14 @@ export const Gallery: FC<GalleryProps> = (props) => {
139
141
}
140
142
} , [ ] )
141
143
144
+ if ( ! images . length ) {
145
+ return null
146
+ }
147
+ if ( images . length === 1 ) {
148
+ const image = images [ 0 ]
149
+ return < MarkdownImage src = { image . url } alt = { image . footnote } />
150
+ }
151
+
142
152
return (
143
153
< div
144
154
className = { clsx ( 'w-full' , 'relative' , styles [ 'root' ] ) }
@@ -162,6 +172,38 @@ export const Gallery: FC<GalleryProps> = (props) => {
162
172
} ) }
163
173
</ div >
164
174
175
+ { currentIndex > 0 && (
176
+ < div className = "pointer-events-none absolute inset-y-0 left-2 flex items-center [&_*]:duration-200" >
177
+ < MotionButtonBase
178
+ onClick = { ( ) => {
179
+ if ( ! containerRef ) {
180
+ return
181
+ }
182
+ const index = currentIndex - 1
183
+ handleScrollTo ( index )
184
+ } }
185
+ className = "border-border pointer-events-auto flex size-6 rounded-full border bg-base-100 p-1 opacity-80 center hover:opacity-100"
186
+ >
187
+ < i className = "icon-[mingcute--left-fill]" />
188
+ </ MotionButtonBase >
189
+ </ div >
190
+ ) }
191
+ { currentIndex < images . length - 1 && (
192
+ < div className = "pointer-events-none absolute inset-y-0 right-2 flex items-center [&_*]:duration-200" >
193
+ < MotionButtonBase
194
+ onClick = { ( ) => {
195
+ if ( ! containerRef ) {
196
+ return
197
+ }
198
+ const index = currentIndex + 1
199
+ handleScrollTo ( index )
200
+ } }
201
+ className = "border-border pointer-events-auto flex size-6 rounded-full border bg-base-100 p-1 opacity-80 center hover:opacity-100"
202
+ >
203
+ < i className = "icon-[mingcute--right-fill]" />
204
+ </ MotionButtonBase >
205
+ </ div >
206
+ ) }
165
207
< div className = { clsx ( styles [ 'indicator' ] , 'space-x-2' ) } >
166
208
{ Array . from ( {
167
209
length : images . length ,
0 commit comments