Skip to content

Commit 73dc10a

Browse files
authored
Seperate left border carousel styles so that can be applied differently when the carousel has stacked rows or not. (#13812)
This mean that we never have a left border on cards in the first column.
1 parent e0eee06 commit 73dc10a

File tree

2 files changed

+76
-12
lines changed

2 files changed

+76
-12
lines changed

dotcom-rendering/src/components/ScrollableCarousel.tsx

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { css } from '@emotion/react';
2-
import { from, space } from '@guardian/source/foundations';
2+
import { from, space, until } from '@guardian/source/foundations';
33
import { useEffect, useRef, useState } from 'react';
44
import { nestedOphanComponents } from '../lib/ophan-helpers';
55
import { palette } from '../palette';
@@ -92,15 +92,35 @@ const itemStyles = css`
9292
scroll-snap-align: start;
9393
grid-area: span 1;
9494
position: relative;
95+
`;
96+
97+
const leftBorderStyles = css`
98+
content: '';
99+
position: absolute;
100+
top: 0;
101+
bottom: 0;
102+
left: -10px;
103+
width: 1px;
104+
background-color: ${palette('--card-border-top')};
105+
transform: translateX(-50%);
106+
`;
107+
108+
const singleRowLeftBorderStyles = css`
95109
:not(:first-child)::before {
96-
content: '';
97-
position: absolute;
98-
top: 0;
99-
bottom: 0;
100-
left: -10px;
101-
width: 1px;
102-
background-color: ${palette('--card-border-top')};
103-
transform: translateX(-50%);
110+
${leftBorderStyles}
111+
}
112+
`;
113+
114+
const stackedRowLeftBorderStyles = css`
115+
${from.tablet} {
116+
:not(:first-child)::before {
117+
${leftBorderStyles}
118+
}
119+
}
120+
${until.tablet} {
121+
:not(:first-child):not(:nth-child(2))::before {
122+
${leftBorderStyles}
123+
}
104124
}
105125
`;
106126

@@ -297,6 +317,21 @@ export const ScrollableCarousel = ({
297317
);
298318
};
299319

300-
ScrollableCarousel.Item = ({ children }: { children: React.ReactNode }) => (
301-
<li css={itemStyles}>{children}</li>
320+
ScrollableCarousel.Item = ({
321+
isStackingCarousel = false,
322+
children,
323+
}: {
324+
isStackingCarousel?: boolean;
325+
children: React.ReactNode;
326+
}) => (
327+
<li
328+
css={[
329+
itemStyles,
330+
isStackingCarousel
331+
? stackedRowLeftBorderStyles
332+
: singleRowLeftBorderStyles,
333+
]}
334+
>
335+
{children}
336+
</li>
302337
);

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,32 @@ type Props = {
1818
sectionId: string;
1919
};
2020

21+
/**
22+
* The scrollable small container displays in the following ways:
23+
* It is limited to 4 cards maximum and displays in a 2x2 grid.
24+
* It is scrollable on mobile and static on tablet and desktop.
25+
* On mobile, each column is scrollable
26+
*
27+
* The layout of cards within the 2x2 grid differs between breakpoints:
28+
*
29+
* On mobile, the layout is:
30+
*
31+
* +--------+--------+
32+
* | Card 0 | Card 2 |
33+
* +--------+--------+
34+
* | Card 1 | Card 3 |
35+
* +--------+--------+
36+
*
37+
* On tablet and above, the layout is:
38+
*
39+
* +--------+--------+
40+
* | Card 0 | Card 1 |
41+
* +--------+--------+
42+
* | Card 2 | Card 3 |
43+
* +--------+--------+
44+
*
45+
*/
46+
2147
/**
2248
* A container used on fronts to display a carousel of small cards
2349
*
@@ -47,7 +73,10 @@ export const ScrollableSmall = ({
4773
>
4874
{trails.map((trail, index) => {
4975
return (
50-
<ScrollableCarousel.Item key={trail.url}>
76+
<ScrollableCarousel.Item
77+
key={trail.url}
78+
isStackingCarousel={true}
79+
>
5180
<FrontCard
5281
trail={trail}
5382
imageLoading={imageLoading}

0 commit comments

Comments
 (0)