Skip to content

Commit f21f751

Browse files
Incorporate grid rows into furniture layout config
1 parent 825d214 commit f21f751

File tree

2 files changed

+106
-73
lines changed

2 files changed

+106
-73
lines changed

dotcom-rendering/src/layouts/StandardLayout.tsx

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,6 @@ const stretchLines = css`
8484
}
8585
`;
8686

87-
const rightColumnCss = (isMedia: boolean) => css`
88-
display: none;
89-
${from.desktop} {
90-
display: block;
91-
padding-top: 6px;
92-
grid-row: ${isMedia ? 3 : 1} / span 999;
93-
}
94-
${from.leftCol} {
95-
grid-row: ${isMedia ? 2 : 1} / span 999;
96-
}
97-
`;
98-
9987
interface GridItemProps {
10088
area: Area;
10189
layoutType: LayoutType;
@@ -652,28 +640,34 @@ export const StandardLayout = (props: WebProps | AppProps) => {
652640
area="right-column"
653641
layoutType={layoutType}
654642
columns={{ desktop: 'right' }}
655-
customCss={rightColumnCss(isMedia)}
643+
customCss={css`
644+
padding-top: 6px;
645+
`}
656646
element="aside"
657647
>
658-
<Island
659-
priority="feature"
660-
defer={{
661-
until: 'visible',
662-
// Provide a much higher value for the top margin for the intersection observer
663-
// This is because the most viewed would otherwise only be lazy loaded when the
664-
// bottom of the container intersects with the viewport
665-
rootMargin: '700px 100px',
666-
}}
667-
>
668-
<MostViewedRightWithAd
669-
format={format}
670-
isPaidContent={article.pageType.isPaidContent}
671-
renderAds={isWeb && renderAds}
672-
shouldHideReaderRevenue={
673-
!!article.config.shouldHideReaderRevenue
674-
}
675-
/>
676-
</Island>
648+
<Hide until="desktop">
649+
<Island
650+
priority="feature"
651+
defer={{
652+
until: 'visible',
653+
// Provide a much higher value for the top margin for the intersection observer
654+
// This is because the most viewed would otherwise only be lazy loaded when the
655+
// bottom of the container intersects with the viewport
656+
rootMargin: '700px 100px',
657+
}}
658+
>
659+
<MostViewedRightWithAd
660+
format={format}
661+
isPaidContent={
662+
article.pageType.isPaidContent
663+
}
664+
renderAds={isWeb && renderAds}
665+
shouldHideReaderRevenue={
666+
!!article.config.shouldHideReaderRevenue
667+
}
668+
/>
669+
</Island>
670+
</Hide>
677671
</GridItem>
678672
</article>
679673

dotcom-rendering/src/layouts/lib/furnitureLayouts.ts

Lines changed: 80 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
1926
type 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

2630
type 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+
3548
const 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+
89113
type 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

96117
type ColumnLayoutMap = Partial<Record<Area, BreakpointColumns>>;
@@ -112,22 +133,37 @@ const furnitureColumnLayouts: Record<LayoutType, ColumnLayoutMap> = {
112133
};
113134

114135
const 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-
157191
type ColumnConfig = Partial<Record<'tablet' | 'desktop' | 'leftCol', Column>>;
158192

159193
export 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

Comments
 (0)