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 ,
@@ -19,16 +19,24 @@ type Props = {
19
19
} ;
20
20
21
21
const containerStyles = css `
22
+ padding : ${ space [ 2 ] } px 0 ${ space [ 3 ] } px;
22
23
${ from . tablet } {
23
- padding : 0 ${ space [ 5 ] } px;
24
+ padding : ${ space [ 2 ] } px ${ space [ 5 ] } px;
24
25
}
25
26
${ from . wide } {
26
27
padding-right : 100px ;
27
28
}
28
29
` ;
29
30
31
+ const cardGap = 10 ;
32
+ const horizontalPaddingMobile = 10 ;
33
+ const horizontalPaddingMobileLandscape = 20 ;
34
+
30
35
const carouselStyles = css `
31
36
display : grid;
37
+ gap : ${ cardGap } px;
38
+ padding : 0 ${ horizontalPaddingMobile } px;
39
+ scroll-padding-left : ${ horizontalPaddingMobile } px;
32
40
grid-auto-columns : 1fr ;
33
41
grid-auto-flow : column;
34
42
overflow-x : auto;
@@ -37,11 +45,15 @@ const carouselStyles = css`
37
45
scroll-behavior : smooth;
38
46
overscroll-behavior-x : contain;
39
47
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;
42
52
}
43
53
${ from . tablet } {
54
+ padding : 0 ;
44
55
scroll-padding-left : 120px ;
56
+ gap : ${ space [ 5 ] } px;
45
57
}
46
58
${ from . desktop } {
47
59
scroll-padding-left : 240px ;
@@ -70,29 +82,20 @@ const itemStyles = css`
70
82
scroll-snap-align : start;
71
83
grid-area : span 1 ;
72
84
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
- }
84
85
` ;
85
86
86
87
const 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
+ }
96
99
}
97
100
` ;
98
101
@@ -138,20 +141,50 @@ const nextButtonFadeStyles = css`
138
141
* @returns {string } - The CSS styles for the grid layout.
139
142
*/
140
143
const 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 ] ;
142
146
143
147
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
+ );
148
162
${ from . mobileMedium } {
149
163
grid-template-columns : repeat(
150
164
${ 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
+ )
152
186
);
153
187
}
154
-
155
188
${ from . tablet } {
156
189
grid-template-columns : repeat (${ totalCards } , 1fr );
157
190
}
0 commit comments