Skip to content

Commit 165c321

Browse files
authored
use entire branding object rather than href and imageSrc alone in the SponsoredContentLabel component (#14596)
1 parent 5a10d24 commit 165c321

File tree

6 files changed

+127
-31
lines changed

6 files changed

+127
-31
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
visuallyHidden,
66
} from '@guardian/source/foundations';
77
import { useConfig } from '../../../components/ConfigContext';
8-
import { decideCardLogo } from '../../../lib/decideLogo';
8+
import { decideBrandingLogo } from '../../../lib/decideLogo';
99
import { getZIndex } from '../../../lib/getZIndex';
1010
import { getOphanComponents } from '../../../lib/labs';
1111
import { palette as themePalette } from '../../../palette';
@@ -48,7 +48,7 @@ export const CardBranding = ({
4848
onwardsSource,
4949
containerPalette,
5050
}: Props) => {
51-
const logo = decideCardLogo(branding, containerPalette);
51+
const logo = decideBrandingLogo(branding, containerPalette);
5252

5353
const { darkModeAvailable } = useConfig();
5454

dotcom-rendering/src/components/FrontSection.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { css } from '@emotion/react';
22
import { isString } from '@guardian/libs';
33
import { between, from, space, until } from '@guardian/source/foundations';
44
import { pageSkinContainer } from '../layouts/lib/pageSkin';
5-
import { badgeFromBranding } from '../lib/branding';
65
import { type EditionId, isNetworkFront } from '../lib/edition';
76
import { hideAge } from '../lib/hideAge';
7+
import { getOphanComponents } from '../lib/labs';
88
import { palette as schemePalette } from '../palette';
99
import type { CollectionBranding } from '../types/branding';
1010
import type {
@@ -634,7 +634,13 @@ export const FrontSection = ({
634634
!!isNextCollectionPrimary || isAboveDesktopAd;
635635

636636
const showSectionColours = isNetworkFront(pageId ?? '');
637-
const badge = badgeFromBranding(collectionBranding);
637+
638+
const labsDataAttributes = collectionBranding?.branding
639+
? getOphanComponents({
640+
branding: collectionBranding.branding,
641+
locationPrefix: 'front-container',
642+
})
643+
: undefined;
638644

639645
/**
640646
* id is being used to set the containerId in @see {ShowMore.importable.tsx}
@@ -807,12 +813,17 @@ export const FrontSection = ({
807813
) : null}
808814
{isLabs &&
809815
collectionBranding?.kind === 'paid-content' &&
810-
badge && (
816+
!collectionBranding.hasMultipleBranding && (
811817
<div css={sponsoredContentLabelWrapper}>
812818
<SponsoredContentLabel
813-
imageSrc={badge.imageSrc}
814-
href={badge.href}
815-
ophanComponentName={ophanComponentName}
819+
branding={collectionBranding.branding}
820+
containerPalette={containerPalette}
821+
ophanComponentLink={
822+
labsDataAttributes?.ophanComponentLink
823+
}
824+
ophanComponentName={
825+
labsDataAttributes?.ophanComponentName
826+
}
816827
/>
817828
</div>
818829
)}

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,28 @@ const meta: Meta<typeof SponsoredContentLabel> = {
1111
},
1212
},
1313
args: {
14-
href: '#',
15-
imageSrc:
16-
'https://static.theguardian.com/commercial/sponsor/22/Aug/2025/52dc0276-c2d9-405c-a686-2577c12914d4-ecover_pos_280.png',
17-
ophanComponentName: 'example',
14+
branding: {
15+
logo: {
16+
src: 'https://static.theguardian.com/commercial/sponsor/22/Aug/2025/52dc0276-c2d9-405c-a686-2577c12914d4-ecover_pos_280.png',
17+
link: '#',
18+
label: 'Paid for by',
19+
dimensions: {
20+
width: 120,
21+
height: 60,
22+
},
23+
},
24+
logoForDarkBackground: {
25+
src: 'https://static.theguardian.com/commercial/sponsor/22/Aug/2025/52dc0276-c2d9-405c-a686-2577c12914d4-ecover_pos_280.png',
26+
link: '#',
27+
label: 'Paid for by',
28+
dimensions: {
29+
width: 120,
30+
height: 60,
31+
},
32+
},
33+
sponsorName: 'Guardian Org',
34+
aboutThisLink: '#about',
35+
},
1836
},
1937
};
2038

dotcom-rendering/src/components/SponsoredContentLabel.tsx

Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
import { css } from '@emotion/react';
2-
import { space, textSansBold12 } from '@guardian/source/foundations';
2+
import {
3+
space,
4+
textSansBold12,
5+
visuallyHidden,
6+
} from '@guardian/source/foundations';
7+
import { decideBrandingLogo } from '../lib/decideLogo';
38
import { palette } from '../palette';
4-
import type { DCRBadgeType } from '../types/badge';
5-
import { Badge } from './Badge';
9+
import type { Branding } from '../types/branding';
10+
import type { DCRContainerPalette } from '../types/front';
11+
import { useConfig } from './ConfigContext';
612

7-
type SponsoredContentLabelProps = DCRBadgeType & {
13+
type SponsoredContentLabelProps = {
14+
branding: Branding;
815
alignment?: 'start' | 'end';
9-
ophanComponentName?: string;
1016
orientation?: 'horizontal' | 'vertical';
17+
containerPalette?: DCRContainerPalette;
18+
ophanComponentLink?: string;
19+
ophanComponentName?: string;
1120
};
1221

13-
const paidForByStyles = css`
22+
const logoImageStyle = css`
23+
max-height: 60px;
24+
max-width: 120px;
25+
vertical-align: middle;
26+
height: auto;
27+
width: auto;
28+
`;
29+
30+
const labelStyles = css`
1431
${textSansBold12};
1532
color: ${palette('--labs-header-label-text')};
1633
`;
@@ -35,13 +52,24 @@ const verticalStyles = {
3552
`,
3653
};
3754

55+
/**
56+
* Component used to display "paid for" label alonside the sponsor logo
57+
* for a particular set of branding
58+
*
59+
* This is used for front container level branding for labs content and
60+
* should replace `CardBranding` eventually
61+
*/
3862
export const SponsoredContentLabel = ({
63+
branding,
3964
alignment = 'start',
40-
imageSrc,
41-
href,
42-
ophanComponentName,
4365
orientation = 'horizontal',
66+
containerPalette,
67+
ophanComponentLink,
68+
ophanComponentName,
4469
}: SponsoredContentLabelProps) => {
70+
const { darkModeAvailable } = useConfig();
71+
const logo = decideBrandingLogo(branding, containerPalette);
72+
4573
return (
4674
<div
4775
css={[
@@ -51,14 +79,49 @@ export const SponsoredContentLabel = ({
5179
: horizontalStyles,
5280
]}
5381
>
54-
<div css={paidForByStyles}>Paid for by</div>
55-
<Badge
56-
href={href}
57-
imageSrc={imageSrc}
58-
isInLabsSection={true}
59-
ophanComponentLink={`labs-logo | ${ophanComponentName}`}
60-
ophanComponentName={`labs-logo-${ophanComponentName}`}
61-
/>
82+
<div css={labelStyles}>{logo.label}</div>
83+
<span
84+
css={css`
85+
${visuallyHidden};
86+
`}
87+
>
88+
{branding.sponsorName
89+
? `This content was paid for by ${branding.sponsorName} and produced by the Guardian Labs team.`
90+
: 'This content has been paid for by an advertiser and produced by the Guardian Labs team.'}
91+
</span>
92+
<a
93+
href={logo.link}
94+
data-sponsor={branding.sponsorName.toLowerCase()}
95+
rel="nofollow"
96+
aria-label={`Visit the ${branding.sponsorName} website`}
97+
data-testid="branding-logo"
98+
data-component={ophanComponentName}
99+
data-link-name={ophanComponentLink}
100+
>
101+
<picture>
102+
{darkModeAvailable && branding.logoForDarkBackground && (
103+
<source
104+
width={
105+
branding.logoForDarkBackground.dimensions.width
106+
}
107+
height={
108+
branding.logoForDarkBackground.dimensions.height
109+
}
110+
srcSet={encodeURI(
111+
branding.logoForDarkBackground.src,
112+
)}
113+
media={'(prefers-color-scheme: dark)'}
114+
/>
115+
)}
116+
<img
117+
css={logoImageStyle}
118+
src={logo.src}
119+
alt={branding.sponsorName}
120+
width={logo.dimensions.width}
121+
height={logo.dimensions.height}
122+
/>
123+
</picture>
124+
</a>
62125
</div>
63126
);
64127
};

dotcom-rendering/src/lib/decideLogo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Branding } from '../types/branding';
22
import type { DCRContainerPalette } from '../types/front';
33
import { cardHasDarkBackground } from './cardHelpers';
44

5-
export const decideCardLogo = (
5+
export const decideBrandingLogo = (
66
branding: Branding,
77
containerPalette?: DCRContainerPalette,
88
): Branding['logo'] => {

dotcom-rendering/src/lib/labs.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ export const getOphanComponents = ({
99
/**
1010
* Allows clicks to be attributed to different areas of content
1111
*/
12-
locationPrefix: 'article-meta' | 'article-related-content';
12+
locationPrefix:
13+
| 'article-meta'
14+
| 'article-related-content'
15+
| 'front-card'
16+
| 'front-container';
1317
}): { ophanComponentName: string; ophanComponentLink: string } => {
1418
const formattedSponsorName = branding.sponsorName
1519
.toLowerCase()

0 commit comments

Comments
 (0)