Skip to content

Commit 45689e1

Browse files
authored
Move branding outside of standard footer for labs cards in new containers (#14600)
1 parent 1562f1a commit 45689e1

File tree

2 files changed

+98
-28
lines changed

2 files changed

+98
-28
lines changed

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

Lines changed: 91 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { css } from '@emotion/react';
22
import { isUndefined } from '@guardian/libs';
33
import {
4+
between,
45
from,
56
palette as sourcePalette,
67
space,
8+
until,
79
} from '@guardian/source/foundations';
810
import { Hide, Link, SvgCamera } from '@guardian/source/react-components';
911
import {
@@ -15,6 +17,7 @@ import { isMediaCard } from '../../lib/cardHelpers';
1517
import { isWithinTwelveHours, secondsToDuration } from '../../lib/formatTime';
1618
import { appendLinkNameMedia } from '../../lib/getDataLinkName';
1719
import { getZIndex } from '../../lib/getZIndex';
20+
import { getOphanComponents } from '../../lib/labs';
1821
import { DISCUSSION_ID_DATA_ATTRIBUTE } from '../../lib/useCommentCount';
1922
import { BETA_CONTAINERS } from '../../model/enhanceCollections';
2023
import { palette } from '../../palette';
@@ -43,6 +46,7 @@ import { Pill } from '../Pill';
4346
import { SlideshowCarousel } from '../SlideshowCarousel.importable';
4447
import { Snap } from '../Snap';
4548
import { SnapCssSandbox } from '../SnapCssSandbox';
49+
import { SponsoredContentLabel } from '../SponsoredContentLabel';
4650
import { StarRating } from '../StarRating/StarRating';
4751
import type { Alignment } from '../SupportingContent';
4852
import { SupportingContent } from '../SupportingContent';
@@ -725,6 +729,80 @@ export const Card = ({
725729
return undefined;
726730
};
727731

732+
/**
733+
* Decides which branding design to apply based on the labs redesign feature switch
734+
* Adds appropriate Ophan data attributes based on card context
735+
* Results in a clickable brand logo and sponsorship label
736+
*/
737+
const LabsBranding = () => {
738+
if (!branding) return;
739+
const getLocationPrefix = () => {
740+
if (!onwardsSource) {
741+
return 'front-card';
742+
}
743+
if (onwardsSource === 'related-content') {
744+
return 'article-related-content';
745+
} else {
746+
return undefined;
747+
}
748+
};
749+
const locationPrefix = getLocationPrefix();
750+
const dataAttributes = locationPrefix
751+
? getOphanComponents({
752+
branding,
753+
locationPrefix,
754+
})
755+
: undefined;
756+
757+
return showLabsRedesign ? (
758+
<>
759+
{/** All screen sizes apart from tablet have horizontal orientation */}
760+
<div
761+
css={css`
762+
${between.tablet.and.desktop} {
763+
display: none;
764+
}
765+
`}
766+
>
767+
<SponsoredContentLabel
768+
branding={branding}
769+
containerPalette={containerPalette}
770+
orientation="horizontal"
771+
alignment="end"
772+
ophanComponentLink={dataAttributes?.ophanComponentLink}
773+
ophanComponentName={dataAttributes?.ophanComponentName}
774+
/>
775+
</div>
776+
{/** Tablet sized screens have vertical orientation */}
777+
<div
778+
css={css`
779+
${until.tablet} {
780+
display: none;
781+
}
782+
${from.desktop} {
783+
display: none;
784+
}
785+
`}
786+
>
787+
<SponsoredContentLabel
788+
branding={branding}
789+
containerPalette={containerPalette}
790+
orientation="vertical"
791+
alignment="end"
792+
ophanComponentLink={dataAttributes?.ophanComponentLink}
793+
ophanComponentName={dataAttributes?.ophanComponentName}
794+
/>
795+
</div>
796+
</>
797+
) : (
798+
<CardBranding
799+
branding={branding}
800+
containerPalette={containerPalette}
801+
onwardsSource={onwardsSource}
802+
/>
803+
);
804+
};
805+
728806
return (
729807
<CardWrapper
730808
format={format}
@@ -1109,17 +1187,10 @@ export const Card = ({
11091187
{showPill ? (
11101188
<>
11111189
<MediaOrNewsletterPill />
1112-
{format.theme === ArticleSpecial.Labs &&
1113-
branding && (
1114-
<CardBranding
1115-
branding={branding}
1116-
onwardsSource={
1117-
onwardsSource
1118-
}
1119-
containerPalette={
1120-
containerPalette
1121-
}
1122-
/>
1190+
{!showLabsRedesign &&
1191+
format.theme ===
1192+
ArticleSpecial.Labs && (
1193+
<LabsBranding />
11231194
)}
11241195
</>
11251196
) : (
@@ -1128,16 +1199,9 @@ export const Card = ({
11281199
age={decideAge()}
11291200
commentCount={<CommentCount />}
11301201
cardBranding={
1131-
branding ? (
1132-
<CardBranding
1133-
branding={branding}
1134-
onwardsSource={
1135-
onwardsSource
1136-
}
1137-
containerPalette={
1138-
containerPalette
1139-
}
1140-
/>
1202+
isOnwardContent ||
1203+
!showLabsRedesign ? (
1204+
<LabsBranding />
11411205
) : undefined
11421206
}
11431207
showLivePlayable={showLivePlayable}
@@ -1187,6 +1251,7 @@ export const Card = ({
11871251
</ContentWrapper>
11881252
</CardLayout>
11891253

1254+
{/** This div contains content that sits "outside" of the standard card layout */}
11901255
<div
11911256
css={
11921257
/** We allow this area to take up more space so that cards without
@@ -1231,12 +1296,7 @@ export const Card = ({
12311296
age={decideAge()}
12321297
commentCount={<CommentCount />}
12331298
cardBranding={
1234-
branding ? (
1235-
<CardBranding
1236-
branding={branding}
1237-
onwardsSource={onwardsSource}
1238-
/>
1239-
) : undefined
1299+
!showLabsRedesign ? <LabsBranding /> : undefined
12401300
}
12411301
showLivePlayable={showLivePlayable}
12421302
shouldReserveSpace={{
@@ -1246,6 +1306,10 @@ export const Card = ({
12461306
/>
12471307
)}
12481308
</div>
1309+
1310+
{showLabsRedesign &&
1311+
!isOnwardContent &&
1312+
format.theme === ArticleSpecial.Labs && <LabsBranding />}
12491313
</CardWrapper>
12501314
);
12511315
};

dotcom-rendering/src/components/SponsoredContentLabel.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ const labelStyles = css`
3434
`;
3535

3636
const wrapperStyles = css`
37+
padding-top: ${space[1]}px;
3738
display: flex;
38-
gap: ${space[2]}px;
3939
justify-content: end;
4040
`;
4141

4242
const horizontalStyles = css`
4343
align-items: center;
44+
gap: ${space[2]}px;
4445
`;
4546

4647
const verticalStyles = {
@@ -54,8 +55,13 @@ const verticalStyles = {
5455
};
5556

5657
const linkStyles = css`
58+
height: 60px;
5759
/* See: https://css-tricks.com/nested-links/ */
5860
z-index: ${getZIndex('card-nested-link')};
61+
/** Vertically center the branding within the link */
62+
display: flex;
63+
flex-direction: column;
64+
justify-content: center;
5965
`;
6066

6167
/**

0 commit comments

Comments
 (0)