1
1
import { css } from '@emotion/react' ;
2
- import { from , space , until } from '@guardian/source/foundations' ;
2
+ import { from , space } from '@guardian/source/foundations' ;
3
3
import {
4
4
Button ,
5
5
Hide ,
@@ -28,10 +28,15 @@ const containerStyles = css`
28
28
}
29
29
` ;
30
30
31
+ const cardGap = 10 ;
32
+ const horizontalPaddingMobile = 10 ;
33
+ const horizontalPaddingMobileLandscape = 20 ;
34
+
31
35
const carouselStyles = css `
32
36
display : grid;
33
- gap : 10px ;
34
- padding : 0 10px ;
37
+ gap : ${ cardGap } px;
38
+ padding : 0 ${ horizontalPaddingMobile } px;
39
+ scroll-padding-left : ${ horizontalPaddingMobile } px;
35
40
grid-auto-columns : 1fr ;
36
41
grid-auto-flow : column;
37
42
overflow-x : auto;
@@ -40,8 +45,11 @@ const carouselStyles = css`
40
45
scroll-behavior : smooth;
41
46
overscroll-behavior-x : contain;
42
47
overscroll-behavior-y : auto;
43
- scroll-padding-left : 10px ;
44
48
49
+ ${ from . mobileLandscape } {
50
+ padding : 0 ${ horizontalPaddingMobileLandscape } px;
51
+ scroll-padding-left : ${ horizontalPaddingMobileLandscape } px;
52
+ }
45
53
${ from . tablet } {
46
54
padding : 0 ;
47
55
scroll-padding-left : 120px ;
@@ -133,20 +141,50 @@ const nextButtonFadeStyles = css`
133
141
* @returns {string } - The CSS styles for the grid layout.
134
142
*/
135
143
const 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 ] ;
137
146
138
147
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
+ );
143
162
${ from . mobileMedium } {
144
163
grid-template-columns : repeat(
145
164
${ 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
+ )
147
186
);
148
187
}
149
-
150
188
${ from . tablet } {
151
189
grid-template-columns : repeat (${ totalCards } , 1fr );
152
190
}
0 commit comments