@@ -16,11 +16,15 @@ export type Area =
1616 // Match report specific area
1717 | 'match-summary' ;
1818
19+ type Breakpoint = 'mobile' | 'tablet' | 'desktop' | 'leftCol' ;
20+
21+ type RowPlacement = {
22+ start : number ;
23+ span ?: number ;
24+ } ;
25+
1926type LayoutRows = Partial <
20- Record <
21- Area ,
22- { mobile ?: number ; tablet ?: number ; desktop ?: number ; leftCol ?: number }
23- >
27+ Record < Area , Partial < Record < Breakpoint , RowPlacement > > >
2428> ;
2529
2630type BreakpointRows = Area [ ] [ ] ;
@@ -32,65 +36,82 @@ type LayoutDefinition = {
3236 leftCol ?: BreakpointRows ;
3337} ;
3438
39+ const tabletVanillaRows : BreakpointRows = [
40+ [ 'title' ] ,
41+ [ 'headline' ] ,
42+ [ 'standfirst' ] ,
43+ [ 'main-media' ] ,
44+ [ 'meta' ] ,
45+ [ 'body' ] ,
46+ ] ;
47+
3548const furnitureRowLayouts : Record < LayoutType , LayoutDefinition > = {
3649 standard : {
37- tablet : [
38- [ 'title' ] ,
39- [ 'headline' ] ,
40- [ 'standfirst' ] ,
41- [ 'main-media' ] ,
42- [ 'meta' ] ,
50+ tablet : tabletVanillaRows ,
51+ desktop : [
52+ [ 'title' , 'right-column' ] ,
53+ [ 'headline' , 'right-column' ] ,
54+ [ 'standfirst' , 'right-column' ] ,
55+ [ 'main-media' , 'right-column' ] ,
56+ [ 'meta' , 'right-column' ] ,
57+ [ 'body' , 'right-column' ] ,
4358 ] ,
44-
4559 leftCol : [
46- [ 'title' , 'headline' ] ,
47- [ 'standfirst' ] ,
48- [ 'meta' , 'main-media' ] ,
60+ [ 'title' , 'headline' , 'right-column' ] ,
61+ [ 'standfirst' , 'right-column' ] ,
62+ [ 'meta' , 'main-media' , 'right-column' ] ,
63+ [ 'body' , 'right-column' ] ,
4964 ] ,
5065 } ,
66+
5167 matchReport : {
52- tablet : [
53- [ 'match-summary' ] ,
54- [ 'title' ] ,
55- [ 'headline' ] ,
56- [ 'standfirst' ] ,
57- [ 'main-media' ] ,
58- [ 'meta' ] ,
59- ] ,
68+ tablet : [ [ 'match-summary' ] , ...tabletVanillaRows ] ,
6069 leftCol : [
6170 [ 'title' , 'match-summary' ] ,
6271 [ 'headline' ] ,
6372 [ 'meta' , 'main-media' ] ,
73+ [ 'body' , 'right-column' ] ,
6474 ] ,
6575 } ,
76+
6677 media : {
6778 mobile : [
6879 [ 'title' ] ,
6980 [ 'headline' ] ,
7081 [ 'main-media' ] ,
7182 [ 'standfirst' ] ,
7283 [ 'meta' ] ,
84+ [ 'body' ] ,
7385 ] ,
7486 tablet : [
7587 [ 'title' ] ,
7688 [ 'headline' ] ,
7789 [ 'main-media' ] ,
7890 [ 'standfirst' ] ,
7991 [ 'meta' ] ,
92+ [ 'body' ] ,
93+ ] ,
94+ desktop : [
95+ [ 'title' ] ,
96+ [ 'headline' ] ,
97+ [ 'main-media' , 'right-column' ] ,
98+ [ 'standfirst' , 'right-column' ] ,
99+ [ 'meta' , 'right-column' ] ,
100+ [ 'body' , 'right-column' ] ,
80101 ] ,
81102 leftCol : [
82103 [ 'title' , 'headline' ] ,
83- [ 'meta' , 'main-media' ] ,
84- [ 'standfirst' ] ,
104+ [ 'meta' , 'main-media' , 'right-column' ] ,
105+ [ 'meta' , 'standfirst' , 'right-column' ] ,
106+ [ 'body' , 'right-column' ] ,
85107 ] ,
86108 } ,
87109} ;
88110
111+ type Column = 'left' | 'centre' | 'right' ;
112+
89113type BreakpointColumns = Partial <
90- Record <
91- 'mobile' | 'tablet' | 'desktop' | 'leftCol' ,
92- Column | [ Line | number , Line | number ]
93- >
114+ Record < Breakpoint , Column | [ Line | number , Line | number ] >
94115> ;
95116
96117type ColumnLayoutMap = Partial < Record < Area , BreakpointColumns > > ;
@@ -112,22 +133,37 @@ const furnitureColumnLayouts: Record<LayoutType, ColumnLayoutMap> = {
112133} ;
113134
114135const buildRowMap = ( layout : LayoutDefinition ) : LayoutRows => {
115- const map : LayoutRows = { } as LayoutRows ;
136+ const map : LayoutRows = { } ;
116137
117138 const apply = (
118- rows : Area [ ] [ ] | undefined ,
119- breakpoint : 'mobile' | 'tablet' | 'desktop' | 'leftCol' ,
139+ rows : BreakpointRows | undefined ,
140+ breakpoint : Breakpoint ,
120141 ) => {
121142 if ( ! rows ) return ;
122143
144+ const areaRows : Record < string , number [ ] > = { } ;
145+
123146 for ( const [ index , areas ] of rows . entries ( ) ) {
124147 const row = index + 1 ;
125148
126149 for ( const area of areas ) {
127- map [ area ] ??= { } ;
128- map [ area ] [ breakpoint ] = row ;
150+ areaRows [ area ] ??= [ ] ;
151+ areaRows [ area ] . push ( row ) ;
129152 }
130153 }
154+
155+ for ( const [ area , rowList ] of Object . entries ( areaRows ) as [
156+ Area ,
157+ number [ ] ,
158+ ] [ ] ) {
159+ const start = rowList [ 0 ] ;
160+ const span = rowList . length > 1 ? rowList . length : undefined ;
161+
162+ if ( start == null ) continue ;
163+
164+ map [ area ] ??= { } ;
165+ map [ area ] [ breakpoint ] = { start, span } ;
166+ }
131167 } ;
132168
133169 apply ( layout . mobile , 'mobile' ) ;
@@ -152,8 +188,6 @@ const breakpointQueries = {
152188 desktop : from . desktop ,
153189} as const ;
154190
155- type Column = 'left' | 'centre' | 'right' ;
156-
157191type ColumnConfig = Partial < Record < 'tablet' | 'desktop' | 'leftCol' , Column > > ;
158192
159193export const gridCss = (
@@ -166,13 +200,18 @@ export const gridCss = (
166200
167201 return css ( [
168202 grid . column . centre , // default
169- Object . entries ( rows ) . map (
170- ( [ bp , row ] ) => css `
171- ${ breakpointQueries [ bp as keyof typeof breakpointQueries ] } {
172- grid-row : ${ row } ;
203+ Object . entries ( rows ) . map ( ( [ bp , placement ] ) => {
204+ const rowValue =
205+ placement . span != null
206+ ? `${ placement . start } / span ${ placement . span } `
207+ : placement . start ;
208+
209+ return css `
210+ ${ breakpointQueries [ bp as Breakpoint ] } {
211+ grid-row : ${ rowValue } ;
173212 }
174- ` ,
175- ) ,
213+ ` ;
214+ } ) ,
176215 Object . entries ( columns ) . map ( ( [ bp , colOrSpan ] ) => {
177216 const colStyle = Array . isArray ( colOrSpan )
178217 ? grid . between ( colOrSpan [ 0 ] , colOrSpan [ 1 ] )
0 commit comments