Skip to content

Commit b4b577b

Browse files
committed
Only show first three products by default and add option to show all
1 parent 8811f74 commit b4b577b

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,14 @@ export default meta;
2323
type Story = StoryObj<typeof meta>;
2424

2525
export const Default = {} satisfies Story;
26+
27+
export const OnlyThreeProducts = {
28+
args: {
29+
products: exampleAtAGlanceProductArray.slice(0, 3),
30+
format: {
31+
design: ArticleDesign.Standard,
32+
display: ArticleDisplay.Standard,
33+
theme: Pillar.Lifestyle,
34+
},
35+
},
36+
} satisfies Story;
Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,59 @@
11
import { css } from '@emotion/react';
22
import { space } from '@guardian/source/foundations';
3+
import { palette, textSans15 } from '@guardian/source/foundations';
4+
import { useState } from 'react';
35
import type { ArticleFormat } from '../lib/articleFormat';
46
import type { ProductBlockElement } from '../types/content';
57
import { HorizontalSummaryProductCard } from './HorizontalSummaryProductCard';
68

9+
const buttonStyles = css`
10+
${textSans15};
11+
color: ${palette.lifestyle[400]};
12+
font-weight: 700;
13+
background-color: transparent;
14+
padding: ${space[4]}px 0px 0px 0px;
15+
border: none;
16+
border-bottom: 1px solid ${palette.neutral[86]};
17+
`;
18+
719
export const StackedProducts = ({
820
products,
921
format,
1022
}: {
1123
products: ProductBlockElement[];
1224
format: ArticleFormat;
1325
}) => {
26+
const [isExpanded, setIsExpanded] = useState(false);
1427
return (
15-
<div
16-
css={[
17-
css`
18-
display: grid;
19-
gap: ${space[4]}px;
20-
`,
21-
]}
22-
>
23-
{products.map((product: ProductBlockElement, index) => (
24-
<HorizontalSummaryProductCard
25-
key={index}
26-
product={product}
27-
format={format}
28-
/>
29-
))}
28+
<div>
29+
<div
30+
css={[
31+
css`
32+
display: grid;
33+
gap: ${space[4]}px;
34+
`,
35+
]}
36+
>
37+
{products.map(
38+
(product: ProductBlockElement, index) =>
39+
(index < 3 || isExpanded) && (
40+
<HorizontalSummaryProductCard
41+
key={index}
42+
product={product}
43+
format={format}
44+
/>
45+
),
46+
)}
47+
</div>
48+
49+
{products.length > 3 && !isExpanded && (
50+
<button
51+
onClick={() => setIsExpanded(!isExpanded)}
52+
css={buttonStyles}
53+
>
54+
Show all
55+
</button>
56+
)}
3057
</div>
3158
);
3259
};

0 commit comments

Comments
 (0)