Skip to content

Commit f1d8f24

Browse files
committed
conditionally moves branding outside of the standard footer component for the labs redesign
1 parent 4e695ea commit f1d8f24

File tree

2 files changed

+65
-29
lines changed

2 files changed

+65
-29
lines changed

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

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { isMediaCard } from '../../lib/cardHelpers';
1515
import { isWithinTwelveHours, secondsToDuration } from '../../lib/formatTime';
1616
import { appendLinkNameMedia } from '../../lib/getDataLinkName';
1717
import { getZIndex } from '../../lib/getZIndex';
18+
import { getOphanComponents } from '../../lib/labs';
1819
import { DISCUSSION_ID_DATA_ATTRIBUTE } from '../../lib/useCommentCount';
1920
import { BETA_CONTAINERS } from '../../model/enhanceCollections';
2021
import { palette } from '../../palette';
@@ -43,6 +44,7 @@ import { Pill } from '../Pill';
4344
import { SlideshowCarousel } from '../SlideshowCarousel.importable';
4445
import { Snap } from '../Snap';
4546
import { SnapCssSandbox } from '../SnapCssSandbox';
47+
import { SponsoredContentLabel } from '../SponsoredContentLabel';
4648
import { StarRating } from '../StarRating/StarRating';
4749
import type { Alignment } from '../SupportingContent';
4850
import { SupportingContent } from '../SupportingContent';
@@ -725,6 +727,47 @@ export const Card = ({
725727
return undefined;
726728
};
727729

730+
/**
731+
* Decides which branding design to apply based on the labs redesign feature switch
732+
* Adds appropriate Ophan data attributes based on card context
733+
* Results in a clickable brand logo and sponsorship label
734+
*/
735+
const getBranding = () => {
736+
if (!branding) return;
737+
const getLocationPrefix = () => {
738+
if (!onwardsSource) {
739+
return 'front-card';
740+
}
741+
if (onwardsSource === 'related-content') {
742+
return 'article-related-content';
743+
} else {
744+
return undefined;
745+
}
746+
};
747+
const locationPrefix = getLocationPrefix();
748+
const dataAttributes = locationPrefix
749+
? getOphanComponents({
750+
branding,
751+
locationPrefix,
752+
})
753+
: undefined;
754+
755+
return showLabsRedesign ? (
756+
<SponsoredContentLabel
757+
branding={branding}
758+
containerPalette={containerPalette}
759+
ophanComponentLink={dataAttributes?.ophanComponentLink}
760+
ophanComponentName={dataAttributes?.ophanComponentName}
761+
/>
762+
) : (
763+
<CardBranding
764+
branding={branding}
765+
containerPalette={containerPalette}
766+
onwardsSource={onwardsSource}
767+
/>
768+
);
769+
};
770+
728771
return (
729772
<CardWrapper
730773
format={format}
@@ -1109,36 +1152,21 @@ export const Card = ({
11091152
{showPill ? (
11101153
<>
11111154
<MediaOrNewsletterPill />
1112-
{format.theme === ArticleSpecial.Labs &&
1113-
branding && (
1114-
<CardBranding
1115-
branding={branding}
1116-
onwardsSource={
1117-
onwardsSource
1118-
}
1119-
containerPalette={
1120-
containerPalette
1121-
}
1122-
/>
1123-
)}
1155+
{!showLabsRedesign &&
1156+
format.theme ===
1157+
ArticleSpecial.Labs &&
1158+
branding &&
1159+
getBranding()}
11241160
</>
11251161
) : (
11261162
<CardFooter
11271163
format={format}
11281164
age={decideAge()}
11291165
commentCount={<CommentCount />}
11301166
cardBranding={
1131-
branding ? (
1132-
<CardBranding
1133-
branding={branding}
1134-
onwardsSource={
1135-
onwardsSource
1136-
}
1137-
containerPalette={
1138-
containerPalette
1139-
}
1140-
/>
1141-
) : undefined
1167+
!showLabsRedesign && branding
1168+
? getBranding()
1169+
: undefined
11421170
}
11431171
showLivePlayable={showLivePlayable}
11441172
/>
@@ -1187,6 +1215,7 @@ export const Card = ({
11871215
</ContentWrapper>
11881216
</CardLayout>
11891217

1218+
{/** This div contains content that sits "outside" of the standard card layout */}
11901219
<div
11911220
css={
11921221
/** We allow this area to take up more space so that cards without
@@ -1231,12 +1260,9 @@ export const Card = ({
12311260
age={decideAge()}
12321261
commentCount={<CommentCount />}
12331262
cardBranding={
1234-
branding ? (
1235-
<CardBranding
1236-
branding={branding}
1237-
onwardsSource={onwardsSource}
1238-
/>
1239-
) : undefined
1263+
!showLabsRedesign && branding
1264+
? getBranding()
1265+
: undefined
12401266
}
12411267
showLivePlayable={showLivePlayable}
12421268
shouldReserveSpace={{
@@ -1246,6 +1272,11 @@ export const Card = ({
12461272
/>
12471273
)}
12481274
</div>
1275+
1276+
{showLabsRedesign &&
1277+
format.theme === ArticleSpecial.Labs &&
1278+
branding &&
1279+
getBranding()}
12491280
</CardWrapper>
12501281
);
12511282
};

dotcom-rendering/src/components/SponsoredContentLabel.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
visuallyHidden,
66
} from '@guardian/source/foundations';
77
import { decideBrandingLogo } from '../lib/decideLogo';
8+
import { getZIndex } from '../lib/getZIndex';
89
import { palette } from '../palette';
910
import type { Branding } from '../types/branding';
1011
import type { DCRContainerPalette } from '../types/front';
@@ -36,6 +37,10 @@ const wrapperStyles = css`
3637
display: flex;
3738
gap: ${space[2]}px;
3839
justify-content: end;
40+
a {
41+
/* See: https://css-tricks.com/nested-links/ */
42+
z-index: ${getZIndex('card-nested-link')};
43+
}
3944
`;
4045

4146
const horizontalStyles = css`

0 commit comments

Comments
 (0)