Skip to content

Commit f59ec08

Browse files
authored
Refactor headline positioning logic (#14399)
* Refactor headline positioning logic * Remove loop video card from snap group of story as this is inaccurate.
1 parent c401707 commit f59ec08

File tree

5 files changed

+42
-64
lines changed

5 files changed

+42
-64
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const basicCardProps: CardProps = {
4848
discussionApiUrl: 'https://discussion.theguardian.com/discussion-api/',
4949
showVideo: true,
5050
absoluteServerTimes: true,
51+
headlinePosition: 'inner',
5152
};
5253

5354
const aBasicLink = {

dotcom-rendering/src/components/Card/Card.tsx

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ export type Props = {
147147
trailTextSize?: TrailTextSize;
148148
/** A kicker image is seperate to the main media and renders as part of the kicker */
149149
showKickerImage?: boolean;
150+
/** Determines if the headline should be positioned within the content or outside the content */
151+
headlinePosition?: 'inner' | 'outer';
150152
isInLoopingVideoTestVariant?: boolean;
151153
isInLoopingVideoTestControl?: boolean;
152154
};
@@ -326,36 +328,6 @@ const decideSublinkPosition = (
326328
return alignment === 'vertical' ? 'inner' : 'outer';
327329
};
328330

329-
const getHeadlinePosition = ({
330-
isFlexSplash,
331-
containerType,
332-
showLivePlayable,
333-
isMediaCardOrNewsletter,
334-
}: {
335-
containerType?: DCRContainerType;
336-
isFlexSplash?: boolean;
337-
showLivePlayable: boolean;
338-
isMediaCardOrNewsletter: boolean;
339-
}) => {
340-
if (isMediaCardOrNewsletter) {
341-
return 'inner';
342-
}
343-
344-
if (containerType === 'flexible/special' && isFlexSplash) {
345-
return 'outer';
346-
}
347-
348-
if (
349-
containerType === 'flexible/general' &&
350-
isFlexSplash &&
351-
showLivePlayable
352-
) {
353-
return 'outer';
354-
}
355-
356-
return 'inner';
357-
};
358-
359331
const liveBulletStyles = css`
360332
width: 9px;
361333
height: 9px;
@@ -420,6 +392,7 @@ export const Card = ({
420392
showTopBarMobile = true,
421393
trailTextSize,
422394
showKickerImage = false,
395+
headlinePosition = 'inner',
423396
isInLoopingVideoTestVariant = false,
424397
isInLoopingVideoTestControl = false,
425398
}: Props) => {
@@ -616,13 +589,6 @@ export const Card = ({
616589
return { mobile: 'medium' };
617590
};
618591

619-
const headlinePosition = getHeadlinePosition({
620-
containerType,
621-
isFlexSplash,
622-
showLivePlayable,
623-
isMediaCardOrNewsletter,
624-
});
625-
626592
const hideTrailTextUntil = () => {
627593
if (isFlexibleContainer) {
628594
return undefined;

dotcom-rendering/src/components/FlexibleGeneral.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ const SplashCardLayout = ({
339339
trailTextSize={trailTextSize}
340340
canPlayInline={true}
341341
showKickerImage={card.format.design === ArticleDesign.Audio}
342+
headlinePosition={card.showLivePlayable ? 'outer' : 'inner'}
342343
isInLoopingVideoTestVariant={isInLoopingVideoTestVariant}
343344
isInLoopingVideoTestControl={isInLoopingVideoTestControl}
344345
/>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export const LoopVideoCards: Story = {
285285
frontSectionTitle: 'Looping video',
286286
groupedTrails: {
287287
...emptyGroupedTrails,
288-
snap: [loopVideoCard],
288+
snap: [],
289289
standard: [loopVideoCard],
290290
},
291291
collectionId: 1,

dotcom-rendering/src/components/FlexibleSpecial.tsx

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ type OneCardLayoutProps = {
119119
isLastRow: boolean;
120120
isFirstRow: boolean;
121121
containerLevel: DCRContainerLevel;
122+
isSplashCard?: boolean;
122123
isInLoopingVideoTestVariant?: boolean;
123124
isInLoopingVideoTestControl?: boolean;
124125
};
@@ -133,6 +134,7 @@ export const OneCardLayout = ({
133134
isLastRow,
134135
isFirstRow,
135136
containerLevel,
137+
isSplashCard,
136138
isInLoopingVideoTestVariant = false,
137139
isInLoopingVideoTestControl = false,
138140
}: OneCardLayoutProps) => {
@@ -183,6 +185,7 @@ export const OneCardLayout = ({
183185
trailTextSize={trailTextSize}
184186
canPlayInline={true}
185187
showKickerImage={card.format.design === ArticleDesign.Audio}
188+
headlinePosition={isSplashCard ? 'outer' : 'inner'}
186189
isInLoopingVideoTestVariant={isInLoopingVideoTestVariant}
187190
isInLoopingVideoTestControl={isInLoopingVideoTestControl}
188191
/>
@@ -299,32 +302,39 @@ export const FlexibleSpecial = ({
299302

300303
return (
301304
<>
302-
<OneCardLayout
303-
cards={snaps}
304-
containerPalette={containerPalette}
305-
showAge={showAge}
306-
absoluteServerTimes={absoluteServerTimes}
307-
imageLoading={imageLoading}
308-
aspectRatio={aspectRatio}
309-
isFirstRow={true}
310-
isLastRow={splash.length === 0 && cards.length === 0}
311-
containerLevel={containerLevel}
312-
isInLoopingVideoTestVariant={isInLoopingVideoTestVariant}
313-
isInLoopingVideoTestControl={isInLoopingVideoTestControl}
314-
/>
315-
<OneCardLayout
316-
cards={splash}
317-
containerPalette={containerPalette}
318-
showAge={showAge}
319-
absoluteServerTimes={absoluteServerTimes}
320-
imageLoading={imageLoading}
321-
aspectRatio={aspectRatio}
322-
isLastRow={cards.length === 0}
323-
isFirstRow={!isNonEmptyArray(snaps)}
324-
containerLevel={containerLevel}
325-
isInLoopingVideoTestVariant={isInLoopingVideoTestVariant}
326-
isInLoopingVideoTestControl={isInLoopingVideoTestControl}
327-
/>
305+
{isNonEmptyArray(snaps) && (
306+
<OneCardLayout
307+
cards={snaps}
308+
containerPalette={containerPalette}
309+
showAge={showAge}
310+
absoluteServerTimes={absoluteServerTimes}
311+
imageLoading={imageLoading}
312+
aspectRatio={aspectRatio}
313+
isFirstRow={true}
314+
isLastRow={splash.length === 0 && cards.length === 0}
315+
containerLevel={containerLevel}
316+
isSplashCard={false}
317+
isInLoopingVideoTestVariant={isInLoopingVideoTestVariant}
318+
isInLoopingVideoTestControl={isInLoopingVideoTestControl}
319+
/>
320+
)}
321+
{isNonEmptyArray(splash) && (
322+
<OneCardLayout
323+
cards={splash}
324+
containerPalette={containerPalette}
325+
showAge={showAge}
326+
absoluteServerTimes={absoluteServerTimes}
327+
imageLoading={imageLoading}
328+
aspectRatio={aspectRatio}
329+
isLastRow={cards.length === 0}
330+
isFirstRow={!isNonEmptyArray(snaps)}
331+
containerLevel={containerLevel}
332+
isSplashCard={true}
333+
isInLoopingVideoTestVariant={isInLoopingVideoTestVariant}
334+
isInLoopingVideoTestControl={isInLoopingVideoTestControl}
335+
/>
336+
)}
337+
328338
<TwoOrFourCardLayout
329339
cards={cards}
330340
containerPalette={containerPalette}

0 commit comments

Comments
 (0)