Skip to content

Commit 5be464d

Browse files
JamieB-gumarjisound
andcommitted
Refactor MoreGalleries
Removed and re-organised the styles, and shortened the components. Also hardcoded the heading, data attributes and links because they won't change. Co-authored-by: Marjan Kalanaki <[email protected]>
1 parent 840d815 commit 5be464d

File tree

3 files changed

+69
-107
lines changed

3 files changed

+69
-107
lines changed

dotcom-rendering/src/components/FetchMoreGalleriesData.importable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export const FetchMoreGalleriesData = ({
166166
absoluteServerTimes={absoluteServerTimes}
167167
trails={buildTrails(data.trails, limit, isAdFreeUser)}
168168
discussionApiUrl={discussionApiUrl}
169-
headingLink={`${guardianBaseUrl}/inpictures/all`}
169+
guardianBaseUrl={guardianBaseUrl}
170170
/>
171171
</div>
172172
);

dotcom-rendering/src/components/MoreGalleries.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const MoreGalleries = {
1616
args: {
1717
absoluteServerTimes: false,
1818
discussionApiUrl: 'https://discussion.theguardian.com/discussion-api',
19-
headingLink: 'https://www.theguardian.com/inpictures/all',
19+
guardianBaseUrl: 'https://www.theguardian.com',
2020
trails: [
2121
{
2222
url: 'https://www.theguardian.com/environment/gallery/2025/aug/22/week-in-wildlife-a-clumsy-fox-swinging-orangutang-and-rescued-jaguarundi-cub',

dotcom-rendering/src/components/MoreGalleries.tsx

Lines changed: 67 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import {
88
} from '@guardian/source/foundations';
99
import { StraightLines } from '@guardian/source-development-kitchen/react-components';
1010
import { grid } from '../grid';
11-
import { formatAttrString } from '../lib/formatAttrString';
1211
import { palette } from '../palette';
13-
import { type OnwardsSource } from '../types/onwards';
1412
import { type TrailType } from '../types/trails';
1513
import { Card } from './Card/Card';
1614
import type { Props as CardProps } from './Card/Card';
@@ -19,53 +17,41 @@ type Props = {
1917
absoluteServerTimes: boolean;
2018
trails: TrailType[];
2119
discussionApiUrl: string;
22-
headingLink?: string;
20+
guardianBaseUrl: string;
2321
};
2422

2523
const standardCardStyles = css`
2624
flex: 1;
27-
2825
position: relative;
2926
display: flex;
3027
padding: ${space[2]}px;
3128
background-color: ${palette('--onward-card-background')};
3229
33-
:not(:first-child)::before {
34-
content: '';
35-
position: absolute;
36-
top: 0;
37-
bottom: 0;
38-
left: -10px; /* shift into the gap */
39-
width: 1px;
40-
background: ${palette('--onward-content-border')};
41-
}
42-
`;
43-
44-
const titleGridStyle = css`
45-
${grid.column.centre}
46-
color: ${palette('--caption-text')};
47-
align-self: start;
48-
49-
${from.leftCol} {
50-
${grid.column.left}
30+
${from.tablet} {
31+
:not(:first-child)::before {
32+
content: '';
33+
position: absolute;
34+
top: 0;
35+
bottom: 0;
36+
left: -10px; /* shift into the gap */
37+
width: 1px;
38+
background: ${palette('--onward-content-border')};
39+
}
5140
}
5241
`;
5342

5443
const standardCardsListStyles = css`
5544
width: 100%;
5645
display: flex;
57-
flex-direction: row;
46+
flex-direction: column;
5847
gap: 20px;
5948
margin-bottom: ${space[6]}px;
6049
6150
${from.tablet} {
51+
flex-direction: row;
6252
padding-top: ${space[2]}px;
6353
}
6454
65-
${until.tablet} {
66-
flex-direction: column;
67-
width: 100%;
68-
}
6955
${from.leftCol} {
7056
&::before {
7157
content: '';
@@ -80,9 +66,8 @@ const standardCardsListStyles = css`
8066
`;
8167

8268
const cardsContainerStyles = css`
83-
display: inline;
84-
position: relative;
8569
${grid.column.centre}
70+
position: relative;
8671
8772
${from.desktop} {
8873
${grid.between('centre-column-start', 'right-column-end')}
@@ -93,29 +78,6 @@ const cardsContainerStyles = css`
9378
}
9479
`;
9580

96-
const headerStyles = css`
97-
color: ${palette('--carousel-text')};
98-
${headlineBold24};
99-
padding-bottom: ${space[3]}px;
100-
padding-top: ${space[1]}px;
101-
margin-left: 0;
102-
103-
${from.tablet} {
104-
${headlineBold28};
105-
}
106-
`;
107-
108-
const headerStylesWithUrl = css`
109-
:hover {
110-
text-decoration: underline;
111-
}
112-
`;
113-
114-
const titleStyle = css`
115-
color: ${palette('--onward-text')};
116-
display: inline-block;
117-
`;
118-
11981
const getDefaultCardProps = (
12082
trail: TrailType,
12183
absoluteServerTimes: boolean,
@@ -159,39 +121,40 @@ export const MoreGalleries = (props: Props) => {
159121
const [firstTrail, ...standardCards] = props.trails;
160122
if (!firstTrail) return null;
161123

162-
const heading = 'More galleries';
163-
const onwardsSource: OnwardsSource = 'more-galleries';
164-
165-
const defaultProps = getDefaultCardProps(
166-
firstTrail,
167-
props.absoluteServerTimes,
168-
props.discussionApiUrl,
169-
);
170-
171124
return (
172125
<section
173-
data-component={onwardsSource}
174-
data-link={formatAttrString(heading)}
126+
data-component="more-galleries"
127+
data-link="more-galleries"
175128
css={css`
176129
${grid.paddedContainer}
177-
178130
background-color: ${palette('--onward-background')};
179-
180-
${until.tablet} {
181-
padding-top: ${space[1]}px;
182-
}
131+
padding-top: ${space[1]}px;
183132
184133
${from.tablet} {
134+
padding-top: 0;
185135
border-left: 1px solid ${palette('--onward-content-border')};
186136
border-right: 1px solid
187137
${palette('--onward-content-border')};
188138
}
189139
`}
190140
>
191-
<Title title={heading} url={props.headingLink} />
192-
<MoreGalleriesSplashCard defaultProps={defaultProps} />
141+
<Title guardianBaseUrl={props.guardianBaseUrl} />
142+
<MoreGalleriesSplashCard
143+
defaultProps={getDefaultCardProps(
144+
firstTrail,
145+
props.absoluteServerTimes,
146+
props.discussionApiUrl,
147+
)}
148+
/>
193149
<StraightLines
194-
cssOverrides={cardsContainerStyles}
150+
cssOverrides={[
151+
cardsContainerStyles,
152+
css`
153+
${until.tablet} {
154+
display: none;
155+
}
156+
`,
157+
]}
195158
count={1}
196159
color={palette('--onward-content-border')}
197160
/>
@@ -209,19 +172,6 @@ export const MoreGalleries = (props: Props) => {
209172
</li>
210173
))}
211174
</ul>
212-
<StraightLines
213-
cssOverrides={css`
214-
${grid.column.all}
215-
padding-left: ${space[5]}px;
216-
padding-right: ${space[5]}px;
217-
${from.leftCol} {
218-
padding-left: ${space[2]}px;
219-
padding-right: ${space[2]}px;
220-
}
221-
`}
222-
count={1}
223-
color={palette('--onward-content-border')}
224-
/>
225175
</section>
226176
);
227177
};
@@ -271,24 +221,36 @@ const MoreGalleriesSplashCard = ({
271221
);
272222
};
273223

274-
const Title = ({ title, url }: { title: string; url?: string }) =>
275-
url ? (
276-
<a
277-
css={[
278-
titleGridStyle,
279-
css`
280-
text-decoration: none;
281-
`,
282-
]}
283-
href={url}
284-
data-link-name="section heading"
285-
>
286-
<h2 css={headerStyles}>
287-
<span css={[headerStylesWithUrl, titleStyle]}>{title}</span>
288-
</h2>
289-
</a>
290-
) : (
291-
<h2 css={[titleGridStyle, headerStyles]}>
292-
<span css={titleStyle}>{title}</span>
293-
</h2>
294-
);
224+
const Title = ({ guardianBaseUrl }: { guardianBaseUrl: string }) => (
225+
<a
226+
css={css`
227+
${grid.column.centre}
228+
color: ${palette('--caption-text')};
229+
text-decoration: none;
230+
align-self: start;
231+
232+
${from.leftCol} {
233+
${grid.column.left}
234+
}
235+
`}
236+
href={`${guardianBaseUrl}/inpictures/all`}
237+
data-link-name="section heading"
238+
>
239+
<h2 css={headerStyles}>More galleries</h2>
240+
</a>
241+
);
242+
243+
const headerStyles = css`
244+
color: ${palette('--carousel-text')};
245+
${headlineBold24};
246+
padding-bottom: ${space[3]}px;
247+
padding-top: ${space[1]}px;
248+
249+
:hover {
250+
text-decoration: underline;
251+
}
252+
253+
${from.tablet} {
254+
${headlineBold28};
255+
}
256+
`;

0 commit comments

Comments
 (0)