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 ,
@@ -28,10 +28,15 @@ const containerStyles = css`
2828 }
2929` ;
3030
31+ const cardGap = 10 ;
32+ const horizontalPaddingMobile = 10 ;
33+ const horizontalPaddingMobileLandscape = 20 ;
34+
3135const carouselStyles = css `
3236 display : grid;
33- gap : 10px ;
34- padding : 0 10px ;
37+ gap : ${ cardGap } px;
38+ padding : 0 ${ horizontalPaddingMobile } px;
39+ scroll-padding-left : ${ horizontalPaddingMobile } px;
3540 grid-auto-columns : 1fr ;
3641 grid-auto-flow : column;
3742 overflow-x : auto;
@@ -40,8 +45,11 @@ const carouselStyles = css`
4045 scroll-behavior : smooth;
4146 overscroll-behavior-x : contain;
4247 overscroll-behavior-y : auto;
43- scroll-padding-left : 10px ;
4448
49+ ${ from . mobileLandscape } {
50+ padding : 0 ${ horizontalPaddingMobileLandscape } px;
51+ scroll-padding-left : ${ horizontalPaddingMobileLandscape } px;
52+ }
4553 ${ from . tablet } {
4654 padding : 0 ;
4755 scroll-padding-left : 120px ;
@@ -133,20 +141,50 @@ const nextButtonFadeStyles = css`
133141 * @returns {string } - The CSS styles for the grid layout.
134142 */
135143const generateCarouselColumnStyles = ( totalCards : number ) => {
136- const peepingCardWidth = space [ 8 ] ;
144+ const peepingCardWidthMobile = 150 ; // Screens below 375px. Only one card is fully visible;
145+ const peepingCardWidthMobileMedium = space [ 8 ] ;
137146
138147 return css `
139- ${ until . mobileMedium } {
140- grid-template-columns : repeat (${ totalCards } , 70% ) max (30% );
141- }
142-
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+ );
143162 ${ from . mobileMedium } {
144163 grid-template-columns : repeat(
145164 ${ totalCards } ,
146- 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+ )
147186 );
148187 }
149-
150188 ${ from . tablet } {
151189 grid-template-columns : repeat (${ totalCards } , 1fr );
152190 }
0 commit comments