@@ -23,7 +23,7 @@ const emptyItems: GalleryItemProps[] = [];
23
23
24
24
export type GalleryProps = {
25
25
className ?: string ;
26
- children ?: React . ReactElement < GalleryItemProps > [ ] ;
26
+ children ?: React . ReactElement < GalleryItemProps > [ ] | React . ReactElement < GalleryItemProps > ;
27
27
emptyMessage ?: string ;
28
28
} & Pick < ModalProps , 'open' | 'container' | 'onOpenChange' > &
29
29
Pick < UseNavigationProps , 'initialItemIndex' > ;
@@ -79,6 +79,8 @@ export const Gallery = ({
79
79
80
80
const activeItem = items [ activeItemIndex ] || items [ 0 ] ;
81
81
82
+ const withNavigation = items . length > 1 ;
83
+
82
84
return (
83
85
< Modal
84
86
container = { container }
@@ -89,7 +91,7 @@ export const Gallery = ({
89
91
< div className = { cnGallery ( 'content' ) } >
90
92
< div className = { cnGallery ( 'header' ) } >
91
93
< div className = { cnGallery ( 'active-item-info' ) } > { activeItem ?. name } </ div >
92
- { items . length > 0 && (
94
+ { withNavigation && (
93
95
< div className = { cnGallery ( 'navigation' ) } >
94
96
< Button size = "l" view = "flat" onClick = { handleGoToPrevious } >
95
97
< Icon data = { direction === 'rtl' ? ArrowRight : ArrowLeft } />
@@ -151,7 +153,7 @@ export const Gallery = ({
151
153
</ GalleryFallbackText >
152
154
) }
153
155
{ activeItem ?. view }
154
- { activeItem && ! activeItem . interactive && (
156
+ { withNavigation && activeItem && ! activeItem . interactive && (
155
157
< React . Fragment >
156
158
< NavigationButton onClick = { handleGoToPrevious } position = "start" />
157
159
< NavigationButton onClick = { handleGoToNext } position = "end" />
@@ -160,27 +162,29 @@ export const Gallery = ({
160
162
</ div >
161
163
{ ! fullScreen && (
162
164
< div className = { cnGallery ( 'footer' ) } >
163
- < div className = { cnGallery ( 'preview-list' ) } >
164
- { items . map ( ( item , index ) => {
165
- const handleClick = ( ) => {
166
- setActiveItemIndex ( index ) ;
167
- } ;
168
-
169
- const selected = activeItemIndex === index ;
170
-
171
- return (
172
- < button
173
- ref = { itemRefs [ index ] }
174
- type = "button"
175
- key = { index }
176
- onClick = { handleClick }
177
- className = { cnGallery ( 'preview-list-item' , { selected} ) }
178
- >
179
- { item . thumbnail }
180
- </ button >
181
- ) ;
182
- } ) }
183
- </ div >
165
+ { withNavigation && (
166
+ < div className = { cnGallery ( 'preview-list' ) } >
167
+ { items . map ( ( item , index ) => {
168
+ const handleClick = ( ) => {
169
+ setActiveItemIndex ( index ) ;
170
+ } ;
171
+
172
+ const selected = activeItemIndex === index ;
173
+
174
+ return (
175
+ < button
176
+ ref = { itemRefs [ index ] }
177
+ type = "button"
178
+ key = { index }
179
+ onClick = { handleClick }
180
+ className = { cnGallery ( 'preview-list-item' , { selected} ) }
181
+ >
182
+ { item . thumbnail }
183
+ </ button >
184
+ ) ;
185
+ } ) }
186
+ </ div >
187
+ ) }
184
188
</ div >
185
189
) }
186
190
</ div >
0 commit comments