Skip to content

Commit 8bf7b82

Browse files
committed
Update SponsoredContentLabel component to replace Badge with it
1 parent cf7bcdf commit 8bf7b82

File tree

7 files changed

+139
-67
lines changed

7 files changed

+139
-67
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ export const Card = ({
441441
const isVideoMainMedia =
442442
mainMedia?.type === 'Video' && format.design !== ArticleDesign.Video;
443443

444+
const isLabs = format.theme === ArticleSpecial.Labs;
445+
444446
const decideAge = () => {
445447
if (!webPublicationDate) return undefined;
446448
const withinTwelveHours = isWithinTwelveHours(webPublicationDate);
@@ -784,6 +786,7 @@ export const Card = ({
784786
alignment="end"
785787
ophanComponentLink={dataAttributes?.ophanComponentLink}
786788
ophanComponentName={dataAttributes?.ophanComponentName}
789+
isLabs={isLabs}
787790
/>
788791
</div>
789792
{/** Tablet sized screens have vertical orientation */}
@@ -804,6 +807,7 @@ export const Card = ({
804807
alignment="end"
805808
ophanComponentLink={dataAttributes?.ophanComponentLink}
806809
ophanComponentName={dataAttributes?.ophanComponentName}
810+
isLabs={isLabs}
807811
/>
808812
</div>
809813
</>

dotcom-rendering/src/components/FeatureCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ export const FeatureCard = ({
741741
ophanComponentName={
742742
labsDataAttributes?.ophanComponentName
743743
}
744+
isLabs={isLabs}
744745
/>
745746
)}
746747
</div>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ export const WithPaidContentForWholeFront = {
385385
};
386386

387387
export const GuardianLabs = {
388-
name: 'Guardian Labs',
388+
name: 'guardian Labs',
389389
args: {
390390
title: 'Section',
391391
collectionBranding: {

dotcom-rendering/src/components/FrontSection.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ export const FrontSection = ({
838838
ophanComponentName={
839839
labsDataAttributes?.ophanComponentName
840840
}
841+
isLabs={isLabs}
841842
/>
842843
</div>
843844
)}

dotcom-rendering/src/components/FrontSectionTitle.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Hide } from '@guardian/source/react-components';
99
import { assertUnreachable } from '../lib/assert-unreachable';
1010
import { palette } from '../palette';
1111
import type { CollectionBranding } from '../types/branding';
12-
import { Badge } from './Badge';
12+
import { SponsoredContentLabel } from './SponsoredContentLabel';
1313

1414
type Props = {
1515
title: React.ReactNode;
@@ -90,12 +90,16 @@ export const FrontSectionTitle = ({ title, collectionBranding }: Props) => {
9090
<>
9191
<Hide until="leftCol">
9292
<p css={[labelStyles]}>{logo.label}</p>
93-
<Badge imageSrc={logo.src} href={logo.link} />
93+
<SponsoredContentLabel
94+
branding={collectionBranding.branding}
95+
/>
9496
</Hide>
9597
<div css={titleStyle}>
9698
<Hide from="leftCol">
9799
<p css={[labelStyles]}>{logo.label}</p>
98-
<Badge imageSrc={logo.src} href={logo.link} />
100+
<SponsoredContentLabel
101+
branding={collectionBranding.branding}
102+
/>
99103
</Hide>
100104
{title}
101105
<a href={aboutThisLink} css={[aboutThisLinkStyles]}>
@@ -109,11 +113,7 @@ export const FrontSectionTitle = ({ title, collectionBranding }: Props) => {
109113
return <div css={titleStyle}>{title}</div>;
110114
}
111115
case 'paid-content': {
112-
const {
113-
isFrontBranding,
114-
isContainerBranding,
115-
branding: { logo },
116-
} = collectionBranding;
116+
const { isFrontBranding, isContainerBranding } = collectionBranding;
117117

118118
if (isFrontBranding || isContainerBranding) {
119119
return (
@@ -134,7 +134,9 @@ export const FrontSectionTitle = ({ title, collectionBranding }: Props) => {
134134
`}
135135
>
136136
Paid for by
137-
<Badge imageSrc={logo.src} href={logo.link} />
137+
<SponsoredContentLabel
138+
branding={collectionBranding.branding}
139+
/>
138140
</div>
139141
</div>
140142
);
@@ -143,11 +145,15 @@ export const FrontSectionTitle = ({ title, collectionBranding }: Props) => {
143145
return (
144146
<>
145147
<Hide until="leftCol">
146-
<Badge imageSrc={logo.src} href={logo.link} />
148+
<SponsoredContentLabel
149+
branding={collectionBranding.branding}
150+
/>
147151
</Hide>
148152
<div css={titleStyle}>
149153
<Hide from="leftCol">
150-
<Badge imageSrc={logo.src} href={logo.link} />
154+
<SponsoredContentLabel
155+
branding={collectionBranding.branding}
156+
/>
151157
</Hide>
152158
{title}
153159
</div>
@@ -185,9 +191,8 @@ export const FrontSectionTitle = ({ title, collectionBranding }: Props) => {
185191
>
186192
{logo.label}
187193
</p>
188-
<Badge
189-
imageSrc={logo.src}
190-
href={logo.link}
194+
<SponsoredContentLabel
195+
branding={collectionBranding.branding}
191196
isAdvertisingPartner={
192197
isAdvertisingPartnerOrExclusive
193198
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const meta: Meta<typeof SponsoredContentLabel> = {
3333
sponsorName: 'Guardian Org',
3434
aboutThisLink: '#about',
3535
},
36+
isLabs: true,
3637
},
3738
};
3839

dotcom-rendering/src/components/SponsoredContentLabel.tsx

Lines changed: 112 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { css } from '@emotion/react';
22
import {
3+
between,
4+
from,
35
space,
46
textSansBold12,
57
visuallyHidden,
@@ -18,6 +20,8 @@ type SponsoredContentLabelProps = {
1820
containerPalette?: DCRContainerPalette;
1921
ophanComponentLink?: string;
2022
ophanComponentName?: string;
23+
isLabs?: boolean;
24+
isAdvertisingPartner?: boolean;
2125
};
2226

2327
const logoImageStyle = css`
@@ -65,6 +69,36 @@ const linkStyles = css`
6569
justify-content: center;
6670
`;
6771

72+
const badgeLink = css`
73+
text-decoration: none;
74+
`;
75+
76+
const imageStyles = css`
77+
display: block;
78+
width: auto;
79+
max-width: 100%;
80+
object-fit: contain;
81+
`;
82+
83+
const frontsSectionBadgeSizingStyles = css`
84+
height: auto;
85+
width: 120px;
86+
87+
${from.tablet} {
88+
width: 140px;
89+
}
90+
91+
${from.leftCol} {
92+
width: 200px;
93+
}
94+
`;
95+
96+
const imageAdvertisingPartnerStyles = css`
97+
${between.leftCol.and.wide} {
98+
max-width: 130px;
99+
}
100+
`;
101+
68102
/**
69103
* Component used to display "paid for" label alonside the sponsor logo
70104
* for a particular set of branding
@@ -79,64 +113,90 @@ export const SponsoredContentLabel = ({
79113
containerPalette,
80114
ophanComponentLink,
81115
ophanComponentName,
116+
isLabs = false,
117+
isAdvertisingPartner = false,
82118
}: SponsoredContentLabelProps) => {
83119
const { darkModeAvailable } = useConfig();
84120
const logo = decideBrandingLogo(branding, containerPalette);
85121

86-
return (
87-
<div
88-
css={[
89-
wrapperStyles,
90-
orientation === 'vertical'
91-
? verticalStyles[alignment]
92-
: horizontalStyles,
93-
]}
94-
>
95-
<div css={labelStyles}>{logo.label}</div>
96-
<span
97-
css={css`
98-
${visuallyHidden};
99-
`}
122+
if (isLabs) {
123+
return (
124+
<div
125+
css={[
126+
wrapperStyles,
127+
orientation === 'vertical'
128+
? verticalStyles[alignment]
129+
: horizontalStyles,
130+
]}
100131
>
101-
{branding.sponsorName
102-
? `This content was paid for by ${branding.sponsorName} and produced by the Guardian Labs team.`
103-
: 'This content has been paid for by an advertiser and produced by the Guardian Labs team.'}
104-
</span>
105-
<a
106-
css={linkStyles}
107-
href={logo.link}
108-
data-sponsor={branding.sponsorName.toLowerCase()}
109-
rel="nofollow"
110-
aria-label={`Visit the ${branding.sponsorName} website`}
111-
data-testid="branding-logo"
112-
data-component={ophanComponentName}
113-
data-link-name={ophanComponentLink}
114-
className="branding-logo"
115-
>
116-
<picture>
117-
{darkModeAvailable && branding.logoForDarkBackground && (
118-
<source
119-
width={
120-
branding.logoForDarkBackground.dimensions.width
121-
}
122-
height={
123-
branding.logoForDarkBackground.dimensions.height
124-
}
125-
srcSet={encodeURI(
126-
branding.logoForDarkBackground.src,
132+
<div css={labelStyles}>{logo.label}</div>
133+
134+
<span
135+
css={css`
136+
${visuallyHidden};
137+
`}
138+
>
139+
{branding.sponsorName
140+
? `This content was paid for by ${branding.sponsorName} and produced by the Guardian Labs team.`
141+
: 'This content has been paid for by an advertiser and produced by the Guardian Labs team.'}
142+
</span>
143+
<a
144+
css={linkStyles}
145+
href={logo.link}
146+
data-sponsor={branding.sponsorName.toLowerCase()}
147+
rel="nofollow"
148+
aria-label={`Visit the ${branding.sponsorName} website`}
149+
data-testid="branding-logo"
150+
data-component={ophanComponentName}
151+
data-link-name={ophanComponentLink}
152+
className="branding-logo"
153+
>
154+
<picture>
155+
{darkModeAvailable &&
156+
branding.logoForDarkBackground && (
157+
<source
158+
width={
159+
branding.logoForDarkBackground
160+
.dimensions.width
161+
}
162+
height={
163+
branding.logoForDarkBackground
164+
.dimensions.height
165+
}
166+
srcSet={encodeURI(
167+
branding.logoForDarkBackground.src,
168+
)}
169+
media={'(prefers-color-scheme: dark)'}
170+
/>
127171
)}
128-
media={'(prefers-color-scheme: dark)'}
172+
<img
173+
css={logoImageStyle}
174+
src={logo.src}
175+
alt={branding.sponsorName}
176+
width={logo.dimensions.width}
177+
height={logo.dimensions.height}
129178
/>
130-
)}
131-
<img
132-
css={logoImageStyle}
133-
src={logo.src}
134-
alt={branding.sponsorName}
135-
width={logo.dimensions.width}
136-
height={logo.dimensions.height}
137-
/>
138-
</picture>
139-
</a>
140-
</div>
179+
</picture>
180+
</a>
181+
</div>
182+
);
183+
}
184+
return (
185+
<a
186+
href={logo.link}
187+
data-link-name={ophanComponentLink}
188+
data-component={ophanComponentName}
189+
css={badgeLink}
190+
>
191+
<img
192+
css={[
193+
imageStyles,
194+
frontsSectionBadgeSizingStyles,
195+
isAdvertisingPartner && imageAdvertisingPartnerStyles,
196+
]}
197+
src={logo.src}
198+
alt={''}
199+
/>
200+
</a>
141201
);
142202
};

0 commit comments

Comments
 (0)