11import { css } from '@emotion/react' ;
2- import { from , space , until } from '@guardian/source/foundations' ;
2+ import { from , space } from '@guardian/source/foundations' ;
33import {
44 Button ,
55 Hide ,
@@ -19,16 +19,24 @@ type Props = {
1919} ;
2020
2121const containerStyles = css `
22+ padding : ${ space [ 2 ] } px 0 ${ space [ 3 ] } px;
2223 ${ from . tablet } {
23- padding : 0 ${ space [ 5 ] } px;
24+ padding : ${ space [ 2 ] } px ${ space [ 5 ] } px;
2425 }
2526 ${ from . wide } {
2627 padding-right : 100px ;
2728 }
2829` ;
2930
31+ const cardGap = 10 ;
32+ const horizontalPaddingMobile = 10 ;
33+ const horizontalPaddingMobileLandscape = 20 ;
34+
3035const carouselStyles = css `
3136 display : grid;
37+ gap : ${ cardGap } px;
38+ padding : 0 ${ horizontalPaddingMobile } px;
39+ scroll-padding-left : ${ horizontalPaddingMobile } px;
3240 grid-auto-columns : 1fr ;
3341 grid-auto-flow : column;
3442 overflow-x : auto;
@@ -37,11 +45,15 @@ const carouselStyles = css`
3745 scroll-behavior : smooth;
3846 overscroll-behavior-x : contain;
3947 overscroll-behavior-y : auto;
40- ${ until . tablet } {
41- scroll-padding-left : 10px ;
48+
49+ ${ from . mobileLandscape } {
50+ padding : 0 ${ horizontalPaddingMobileLandscape } px;
51+ scroll-padding-left : ${ horizontalPaddingMobileLandscape } px;
4252 }
4353 ${ from . tablet } {
54+ padding : 0 ;
4455 scroll-padding-left : 120px ;
56+ gap : ${ space [ 5 ] } px;
4557 }
4658 ${ from . desktop } {
4759 scroll-padding-left : 240px ;
@@ -70,29 +82,20 @@ const itemStyles = css`
7082 scroll-snap-align : start;
7183 grid-area : span 1 ;
7284 position : relative;
73- margin : ${ space [ 2 ] } px 10px ${ space [ 3 ] } px;
74- : first-child {
75- ${ from . tablet } {
76- margin-left : 0 ;
77- }
78- }
79- : last-child {
80- ${ from . tablet } {
81- margin-right : 0 ;
82- }
83- }
8485` ;
8586
8687const verticalLineStyles = css `
87- : not (: last-child )::after {
88- content : '' ;
89- position : absolute;
90- top : 0 ;
91- bottom : 0 ;
92- right : -10px ;
93- width : 1px ;
94- background-color : ${ palette ( '--highlights-container-separator' ) } ;
95- transform : translateX (-50% );
88+ ${ from . tablet } {
89+ : not (: first-child )::before {
90+ content : '' ;
91+ position : absolute;
92+ top : 0 ;
93+ bottom : 0 ;
94+ left : -10px ;
95+ width : 1px ;
96+ background-color : ${ palette ( '--highlights-container-separator' ) } ;
97+ transform : translateX (-50% );
98+ }
9699 }
97100` ;
98101
@@ -138,20 +141,50 @@ const nextButtonFadeStyles = css`
138141 * @returns {string } - The CSS styles for the grid layout.
139142 */
140143const generateCarouselColumnStyles = ( totalCards : number ) => {
141- const peepingCardWidth = space [ 8 ] ;
144+ const peepingCardWidthMobile = 150 ; // Screens below 375px. Only one card is fully visible;
145+ const peepingCardWidthMobileMedium = space [ 8 ] ;
142146
143147 return css `
144- ${ until . mobileMedium } {
145- grid-template-columns : repeat (${ totalCards } , 70% ) max (30% );
146- }
147-
148+ grid-template-columns : repeat(
149+ ${ totalCards } ,
150+ max (
151+ 180px ,
152+ calc (
153+ 100vw -
154+ (
155+ ${ horizontalPaddingMobile +
156+ cardGap +
157+ peepingCardWidthMobile } px
158+ )
159+ )
160+ )
161+ );
148162 ${ from . mobileMedium } {
149163 grid-template-columns : repeat(
150164 ${ totalCards } ,
151- calc ((100% - ${ peepingCardWidth } px) / 2 )
165+ calc (
166+ (
167+ 100vw -
168+ ${ horizontalPaddingMobile +
169+ 2 * cardGap +
170+ peepingCardWidthMobileMedium } px
171+ ) / 2
172+ )
173+ );
174+ }
175+ ${ from . mobileLandscape } {
176+ grid-template-columns : repeat(
177+ ${ totalCards } ,
178+ calc (
179+ (
180+ 100vw -
181+ ${ horizontalPaddingMobileLandscape +
182+ 2 * cardGap +
183+ peepingCardWidthMobileMedium } px
184+ ) / 2
185+ )
152186 );
153187 }
154-
155188 ${ from . tablet } {
156189 grid-template-columns : repeat (${ totalCards } , 1fr );
157190 }
0 commit comments