Skip to content

Commit 8860125

Browse files
authored
Allow consumers to control the column and row gap sizing based on a small, medium, large model. (#13813)
1 parent 73dc10a commit 8860125

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

dotcom-rendering/src/components/ScrollableCarousel.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ import { nestedOphanComponents } from '../lib/ophan-helpers';
55
import { palette } from '../palette';
66
import { CarouselNavigationButtons } from './CarouselNavigationButtons';
77

8+
type GapSize = 'small' | 'medium' | 'large';
9+
type GapSizes = { row: GapSize; column: GapSize };
10+
811
type Props = {
912
children: React.ReactNode;
1013
carouselLength: number;
1114
visibleCardsOnMobile: number;
1215
visibleCardsOnTablet: number;
1316
sectionId?: string;
1417
shouldStackCards?: { desktop: boolean; mobile: boolean };
18+
gapSizes?: GapSizes;
1519
};
1620

1721
/**
@@ -53,7 +57,6 @@ const carouselStyles = css`
5357
width: 100%;
5458
grid-auto-columns: 1fr;
5559
grid-auto-flow: column;
56-
gap: 20px;
5760
overflow-x: auto;
5861
overflow-y: hidden;
5962
scroll-snap-type: x mandatory;
@@ -87,6 +90,13 @@ const carouselStyles = css`
8790
}
8891
`;
8992

93+
const carouselGapStyles = (column: number, row: number) => {
94+
return css`
95+
column-gap: ${column}px;
96+
row-gap: ${row}px;
97+
`;
98+
};
99+
90100
const itemStyles = css`
91101
display: flex;
92102
scroll-snap-align: start;
@@ -194,6 +204,17 @@ const generateCarouselColumnStyles = (
194204
`;
195205
};
196206

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+
197218
/**
198219
* A component used in the carousel fronts containers (e.g. small/medium/feature)
199220
*/
@@ -204,6 +225,7 @@ export const ScrollableCarousel = ({
204225
visibleCardsOnTablet,
205226
sectionId,
206227
shouldStackCards = { desktop: false, mobile: false },
228+
gapSizes = { column: 'large', row: 'large' },
207229
}: Props) => {
208230
const carouselRef = useRef<HTMLOListElement | null>(null);
209231
const [previousButtonEnabled, setPreviousButtonEnabled] = useState(false);
@@ -223,6 +245,9 @@ export const ScrollableCarousel = ({
223245
});
224246
};
225247

248+
const rowGap = getGapSize(gapSizes.row);
249+
const columnGap = getGapSize(gapSizes.column);
250+
226251
/**
227252
* Updates state of navigation buttons based on carousel's scroll position.
228253
*
@@ -284,6 +309,7 @@ export const ScrollableCarousel = ({
284309
ref={carouselRef}
285310
css={[
286311
carouselStyles,
312+
carouselGapStyles(columnGap, rowGap),
287313
generateCarouselColumnStyles(
288314
carouselLength,
289315
visibleCardsOnMobile,

dotcom-rendering/src/components/ScrollableSmall.importable.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export const ScrollableSmall = ({
7070
visibleCardsOnTablet={2}
7171
sectionId={sectionId}
7272
shouldStackCards={{ desktop: trails.length > 2, mobile: true }}
73+
gapSizes={{ column: 'large', row: 'medium' }}
7374
>
7475
{trails.map((trail, index) => {
7576
return (

0 commit comments

Comments
 (0)