Skip to content

Commit b98c18f

Browse files
Tidying
1 parent 4b025e2 commit b98c18f

1 file changed

Lines changed: 48 additions & 50 deletions

File tree

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

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,8 @@ export type Area =
1818

1919
type Breakpoint = 'mobile' | 'tablet' | 'desktop' | 'leftCol';
2020

21-
type RowPlacement = {
22-
start: number;
23-
span?: number;
24-
};
25-
26-
type LayoutRows = Partial<
27-
Record<Area, Partial<Record<Breakpoint, RowPlacement>>>
28-
>;
29-
30-
type BreakpointRows = Area[][];
31-
32-
type LayoutDefinition = {
33-
mobile?: BreakpointRows;
34-
tablet?: BreakpointRows;
35-
desktop?: BreakpointRows;
36-
leftCol?: BreakpointRows;
37-
};
38-
39-
const tabletVanillaRows: BreakpointRows = [
21+
// Rows config
22+
const tabletVanillaRows: Rows = [
4023
['title'],
4124
['headline'],
4225
['standfirst'],
@@ -45,7 +28,7 @@ const tabletVanillaRows: BreakpointRows = [
4528
['body'],
4629
];
4730

48-
const desktopVanillaRows: BreakpointRows = [
31+
const desktopVanillaRows: Rows = [
4932
['title', 'right-column'],
5033
['headline', 'right-column'],
5134
['standfirst', 'right-column'],
@@ -54,6 +37,15 @@ const desktopVanillaRows: BreakpointRows = [
5437
['body', 'right-column'],
5538
];
5639

40+
const mediaRowsUntilDesktop: Rows = [
41+
['title'],
42+
['headline'],
43+
['main-media'],
44+
['standfirst'],
45+
['meta'],
46+
['body'],
47+
];
48+
5749
const furnitureRowLayouts: Record<LayoutType, LayoutDefinition> = {
5850
standard: {
5951
tablet: tabletVanillaRows,
@@ -78,22 +70,8 @@ const furnitureRowLayouts: Record<LayoutType, LayoutDefinition> = {
7870
},
7971

8072
media: {
81-
mobile: [
82-
['title'],
83-
['headline'],
84-
['main-media'],
85-
['standfirst'],
86-
['meta'],
87-
['body'],
88-
],
89-
tablet: [
90-
['title'],
91-
['headline'],
92-
['main-media'],
93-
['standfirst'],
94-
['meta'],
95-
['body'],
96-
],
73+
mobile: mediaRowsUntilDesktop,
74+
tablet: mediaRowsUntilDesktop,
9775
desktop: [
9876
['title'],
9977
['headline'],
@@ -111,12 +89,7 @@ const furnitureRowLayouts: Record<LayoutType, LayoutDefinition> = {
11189
},
11290
};
11391

114-
type BreakpointColumns = Partial<
115-
Record<Breakpoint, ColumnPreset | [Line | number, Line | number]>
116-
>;
117-
118-
type ColumnLayoutMap = Partial<Record<Area, BreakpointColumns>>;
119-
92+
// Columns config
12093
const furnitureColumnDefaults: ColumnLayoutMap = {
12194
title: { leftCol: 'left' },
12295
meta: { leftCol: 'left' },
@@ -140,13 +113,36 @@ const furnitureColumnLayouts: Record<LayoutType, ColumnLayoutMap> = {
140113
matchReport: furnitureColumnDefaults,
141114
};
142115

143-
const buildRowMap = (layout: LayoutDefinition): LayoutRows => {
144-
const map: LayoutRows = {};
116+
// Types
117+
type RowPlacement = {
118+
start: number;
119+
span?: number;
120+
};
121+
122+
type CompiledLayout = Partial<
123+
Record<Area, Partial<Record<Breakpoint, RowPlacement>>>
124+
>;
145125

146-
const apply = (
147-
rows: BreakpointRows | undefined,
148-
breakpoint: Breakpoint,
149-
) => {
126+
type Rows = Area[][];
127+
128+
type LayoutDefinition = {
129+
mobile?: Rows;
130+
tablet?: Rows;
131+
desktop?: Rows;
132+
leftCol?: Rows;
133+
};
134+
135+
type BreakpointColumns = Partial<
136+
Record<Breakpoint, ColumnPreset | [Line | number, Line | number]>
137+
>;
138+
139+
type ColumnLayoutMap = Partial<Record<Area, BreakpointColumns>>;
140+
141+
// Guardian Grid CSS generation
142+
const buildRowMap = (layout: LayoutDefinition): CompiledLayout => {
143+
const map: CompiledLayout = {};
144+
145+
const apply = (rows: Rows | undefined, breakpoint: Breakpoint) => {
150146
if (!rows) return;
151147

152148
const areaRows: Record<string, number[]> = {};
@@ -187,7 +183,7 @@ const rowMaps = Object.fromEntries(
187183
name,
188184
buildRowMap(layout),
189185
]),
190-
) as Record<LayoutType, LayoutRows>;
186+
) as Record<LayoutType, CompiledLayout>;
191187

192188
const breakpointQueries = {
193189
mobile: until.tablet,
@@ -203,11 +199,13 @@ export const gridCss = (
203199
layoutType: LayoutType,
204200
columnsOverride?: ColumnConfig,
205201
): SerializedStyles => {
202+
const defaultColumn = grid.column.centre;
203+
206204
const rows = rowMaps[layoutType][area] ?? {};
207205
const columns = furnitureColumnLayouts[layoutType][area] ?? {};
208206

209207
return css([
210-
grid.column.centre, // default
208+
defaultColumn,
211209
Object.entries(rows).map(([bp, placement]) => {
212210
const rowValue =
213211
placement.span != null

0 commit comments

Comments
 (0)