File tree Expand file tree Collapse file tree 2 files changed +53
-15
lines changed
dotcom-rendering/src/components Expand file tree Collapse file tree 2 files changed +53
-15
lines changed Original file line number Diff line number Diff line change @@ -23,3 +23,14 @@ export default meta;
2323type Story = StoryObj < typeof meta > ;
2424
2525export 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 ;
Original file line number Diff line number Diff line change 11import { css } from '@emotion/react' ;
22import { space } from '@guardian/source/foundations' ;
3+ import { palette , textSans15 } from '@guardian/source/foundations' ;
4+ import { useState } from 'react' ;
35import type { ArticleFormat } from '../lib/articleFormat' ;
46import type { ProductBlockElement } from '../types/content' ;
57import { 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+ bor der: none;
16+ bor der- botto m: 1px solid ${ palette . neutral [ 86 ] } ;
17+ ` ;
18+
719export 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+ dis play: 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} ;
You can’t perform that action at this time.
0 commit comments