Skip to content

Commit 7a3a5c3

Browse files
authored
Scrollable small stacked redesign (#13789)
* Add ability to stack cards into 2 rows in the scrollable carousel * Always stack cards on mobile and stack cards on desktop if there are more than 2 cards * Display a top bar on desktop and mobile for the cards in the bottom row * Round up carousel column card such that 3 cards === 2 columns and 1 card === 1 column * use column auto-flow from tablet and above if the consumer does not want to stack cards * Remove multicard story as this is not longer relevant as the container cannot have more than 4 cards
1 parent e3bee54 commit 7a3a5c3

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

dotcom-rendering/src/components/ScrollableCarousel.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Props = {
1111
visibleCardsOnMobile: number;
1212
visibleCardsOnTablet: number;
1313
sectionId?: string;
14+
shouldStackCards?: { desktop: boolean; mobile: boolean };
1415
};
1516

1617
/**
@@ -103,6 +104,20 @@ const itemStyles = css`
103104
}
104105
`;
105106

107+
const stackedCardRowsStyles = ({
108+
mobile,
109+
desktop,
110+
}: {
111+
mobile: boolean;
112+
desktop: boolean;
113+
}) => css`
114+
grid-template-rows: ${mobile ? `1fr 1fr` : `1fr`};
115+
${from.tablet} {
116+
grid-auto-flow: ${desktop ? `row` : `column`};
117+
grid-template-rows: ${desktop ? `1fr 1fr` : `1fr`};
118+
}
119+
`;
120+
106121
/**
107122
* Generates CSS styles for a grid layout used in a carousel.
108123
*
@@ -168,6 +183,7 @@ export const ScrollableCarousel = ({
168183
visibleCardsOnMobile,
169184
visibleCardsOnTablet,
170185
sectionId,
186+
shouldStackCards = { desktop: false, mobile: false },
171187
}: Props) => {
172188
const carouselRef = useRef<HTMLOListElement | null>(null);
173189
const [previousButtonEnabled, setPreviousButtonEnabled] = useState(false);
@@ -253,6 +269,7 @@ export const ScrollableCarousel = ({
253269
visibleCardsOnMobile,
254270
visibleCardsOnTablet,
255271
),
272+
stackedCardRowsStyles(shouldStackCards),
256273
]}
257274
data-heatphan-type="carousel"
258275
>

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ export const ScrollableSmall = ({
3535
aspectRatio,
3636
sectionId,
3737
}: Props) => {
38+
const mobileBottomCards = [1, 3];
39+
const desktopBottomCards = [2, 3];
3840
return (
3941
<ScrollableCarousel
40-
carouselLength={trails.length}
42+
carouselLength={Math.ceil(trails.length / 2)}
4143
visibleCardsOnMobile={1}
4244
visibleCardsOnTablet={2}
4345
sectionId={sectionId}
46+
shouldStackCards={{ desktop: trails.length > 2, mobile: true }}
4447
>
45-
{trails.map((trail) => {
48+
{trails.map((trail, index) => {
4649
return (
4750
<ScrollableCarousel.Item key={trail.url}>
4851
<FrontCard
@@ -64,8 +67,10 @@ export const ScrollableSmall = ({
6467
aspectRatio={aspectRatio}
6568
kickerText={trail.kickerText}
6669
showLivePlayable={trail.showLivePlayable}
67-
showTopBarDesktop={false}
68-
showTopBarMobile={false}
70+
showTopBarDesktop={desktopBottomCards.includes(
71+
index,
72+
)}
73+
showTopBarMobile={mobileBottomCards.includes(index)}
6974
canPlayInline={false}
7075
/>
7176
</ScrollableCarousel.Item>

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ export default meta;
4343

4444
type Story = StoryObj<typeof ScrollableSmall>;
4545

46-
export const WithMultipleCards = {};
47-
4846
export const WithFourCards = {
4947
args: {
5048
trails: trails.slice(0, 4),
@@ -57,15 +55,15 @@ export const WithThreeCards = {
5755
},
5856
};
5957

60-
export const WithOneCard = {
58+
export const WithTwoCards = {
6159
args: {
62-
trails: trails.slice(0, 1),
60+
trails: trails.slice(0, 2),
6361
},
6462
};
6563

66-
export const WithTwoCards = {
64+
export const WithOneCard = {
6765
args: {
68-
trails: trails.slice(0, 2),
66+
trails: trails.slice(0, 1),
6967
},
7068
};
7169

0 commit comments

Comments
 (0)