@@ -5,13 +5,17 @@ import { nestedOphanComponents } from '../lib/ophan-helpers';
5
5
import { palette } from '../palette' ;
6
6
import { CarouselNavigationButtons } from './CarouselNavigationButtons' ;
7
7
8
+ type GapSize = 'small' | 'medium' | 'large' ;
9
+ type GapSizes = { row : GapSize ; column : GapSize } ;
10
+
8
11
type Props = {
9
12
children : React . ReactNode ;
10
13
carouselLength : number ;
11
14
visibleCardsOnMobile : number ;
12
15
visibleCardsOnTablet : number ;
13
16
sectionId ?: string ;
14
17
shouldStackCards ?: { desktop : boolean ; mobile : boolean } ;
18
+ gapSizes ?: GapSizes ;
15
19
} ;
16
20
17
21
/**
@@ -53,7 +57,6 @@ const carouselStyles = css`
53
57
width : 100% ;
54
58
grid-auto-columns : 1fr ;
55
59
grid-auto-flow : column;
56
- gap : 20px ;
57
60
overflow-x : auto;
58
61
overflow-y : hidden;
59
62
scroll-snap-type : x mandatory;
@@ -87,6 +90,13 @@ const carouselStyles = css`
87
90
}
88
91
` ;
89
92
93
+ const carouselGapStyles = ( column : number , row : number ) => {
94
+ return css `
95
+ column-gap : ${ column } px;
96
+ row-gap : ${ row } px;
97
+ ` ;
98
+ } ;
99
+
90
100
const itemStyles = css `
91
101
display : flex;
92
102
scroll-snap-align : start;
@@ -194,6 +204,17 @@ const generateCarouselColumnStyles = (
194
204
` ;
195
205
} ;
196
206
207
+ const getGapSize = ( gap : GapSize ) => {
208
+ switch ( gap ) {
209
+ case 'small' :
210
+ return space [ 3 ] ;
211
+ case 'medium' :
212
+ return space [ 4 ] ;
213
+ case 'large' :
214
+ return space [ 5 ] ;
215
+ }
216
+ } ;
217
+
197
218
/**
198
219
* A component used in the carousel fronts containers (e.g. small/medium/feature)
199
220
*/
@@ -204,6 +225,7 @@ export const ScrollableCarousel = ({
204
225
visibleCardsOnTablet,
205
226
sectionId,
206
227
shouldStackCards = { desktop : false , mobile : false } ,
228
+ gapSizes = { column : 'large' , row : 'large' } ,
207
229
} : Props ) => {
208
230
const carouselRef = useRef < HTMLOListElement | null > ( null ) ;
209
231
const [ previousButtonEnabled , setPreviousButtonEnabled ] = useState ( false ) ;
@@ -223,6 +245,9 @@ export const ScrollableCarousel = ({
223
245
} ) ;
224
246
} ;
225
247
248
+ const rowGap = getGapSize ( gapSizes . row ) ;
249
+ const columnGap = getGapSize ( gapSizes . column ) ;
250
+
226
251
/**
227
252
* Updates state of navigation buttons based on carousel's scroll position.
228
253
*
@@ -284,6 +309,7 @@ export const ScrollableCarousel = ({
284
309
ref = { carouselRef }
285
310
css = { [
286
311
carouselStyles ,
312
+ carouselGapStyles ( columnGap , rowGap ) ,
287
313
generateCarouselColumnStyles (
288
314
carouselLength ,
289
315
visibleCardsOnMobile ,
0 commit comments