Skip to content

Commit b41424c

Browse files
authored
Merge pull request #14299 from guardian/md/insert-galleries-ads
Insert ads in Galleries
2 parents 790ed28 + 704f7c3 commit b41424c

File tree

5 files changed

+326
-42
lines changed

5 files changed

+326
-42
lines changed

dotcom-rendering/src/components/AdSlot.web.tsx

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ type IndexedSlot =
2222
| 'fronts-banner'
2323
| 'liveblog-inline'
2424
| 'liveblog-inline-mobile'
25-
| 'mobile-front';
25+
| 'mobile-front'
26+
| 'gallery-inline'
27+
| 'gallery-inline-mobile';
2628

2729
// TODO move to commercial
2830
type SlotNamesWithPageSkin = SlotName | 'pageskin';
@@ -424,6 +426,29 @@ const crosswordBannerMobileAdStyles = css`
424426
min-height: ${getMinHeight(adSizes.mobilesticky.height)}px;
425427
`;
426428

429+
const galleryInlineAdStyles = css`
430+
margin: ${space[3]}px auto;
431+
min-height: ${getMinHeight(adSizes.mpu.height)}px;
432+
433+
&.ad-slot--fluid {
434+
margin: ${space[3]}px auto;
435+
}
436+
`;
437+
438+
/*** The top-above-nav-mobile and inline slots label should be dark even in light mode.
439+
* Other slots will stay the same as the mentioned ad slots are
440+
* the only ones to overlay the dark section of Gallery pages.
441+
*/
442+
const galleryInlineAdLabelStyles = css`
443+
.ad-slot--dark[data-label-show='true']:not(
444+
.ad-slot--interscroller
445+
)::before {
446+
background-color: ${schemedPalette('--ad-background-article-inner')};
447+
border-top-color: ${schemedPalette('--ad-border-article-inner')};
448+
color: ${schemedPalette('--ad-labels-text-article-inner')};
449+
}
450+
`;
451+
427452
const AdSlotWrapper = ({
428453
children,
429454
css: additionalCss,
@@ -911,6 +936,57 @@ export const AdSlot = ({
911936
</AdSlotWrapper>
912937
);
913938
}
939+
case 'gallery-inline': {
940+
const advertId = `inline${index + 1}`;
941+
return (
942+
<AdSlotWrapper css={[labelStyles, galleryInlineAdLabelStyles]}>
943+
<div
944+
id={`dfp-ad--${advertId}`}
945+
className={[
946+
'js-ad-slot',
947+
'ad-slot',
948+
`ad-slot--${advertId}`,
949+
'ad-slot--gallery-inline',
950+
'ad-slot--dark',
951+
'hide-until-tablet',
952+
'ad-slot--rendered',
953+
].join(' ')}
954+
css={galleryInlineAdStyles}
955+
data-link-name={`ad slot ${advertId}`}
956+
data-name={advertId}
957+
aria-hidden="true"
958+
data-label-show="true"
959+
data-testid="slot"
960+
/>
961+
</AdSlotWrapper>
962+
);
963+
}
964+
case 'gallery-inline-mobile': {
965+
const advertId = index === 0 ? 'top-above-nav' : `inline${index}`;
966+
return (
967+
<AdSlotWrapper css={[labelStyles, galleryInlineAdLabelStyles]}>
968+
<div
969+
id={`dfp-ad--${advertId}--mobile`}
970+
className={[
971+
'js-ad-slot',
972+
'ad-slot',
973+
`ad-slot--${advertId}`,
974+
'ad-slot--gallery-inline',
975+
'ad-slot--dark',
976+
'ad-slot--mobile',
977+
'mobile-only',
978+
'ad-slot--rendered',
979+
].join(' ')}
980+
css={galleryInlineAdStyles}
981+
data-link-name={`ad slot ${advertId}`}
982+
data-name={advertId}
983+
aria-hidden="true"
984+
data-label-show="true"
985+
data-testid="slot"
986+
/>
987+
</AdSlotWrapper>
988+
);
989+
}
914990
}
915991
};
916992

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { AdSlot } from './AdSlot.web';
2+
3+
export const MobileAdSlot = ({
4+
renderAds,
5+
adSlotIndex,
6+
}: {
7+
renderAds: boolean;
8+
adSlotIndex: number;
9+
}) => {
10+
return (
11+
renderAds && (
12+
<AdSlot
13+
data-print-layout="hide"
14+
position="gallery-inline-mobile"
15+
index={adSlotIndex}
16+
/>
17+
)
18+
);
19+
};
20+
21+
export const DesktopAdSlot = ({
22+
renderAds,
23+
adSlotIndex,
24+
}: {
25+
renderAds: boolean;
26+
adSlotIndex: number;
27+
}) => {
28+
return (
29+
renderAds && (
30+
<AdSlot
31+
data-print-layout="hide"
32+
position="gallery-inline"
33+
index={adSlotIndex}
34+
/>
35+
)
36+
);
37+
};

0 commit comments

Comments
 (0)