Skip to content

Commit 1a91154

Browse files
committed
Replace css with Hide component
1 parent f61abae commit 1a91154

File tree

4 files changed

+27
-60
lines changed

4 files changed

+27
-60
lines changed

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

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -421,20 +421,6 @@ const crosswordBannerMobileAdStyles = css`
421421
min-height: ${getMinHeight(adSizes.mobilesticky.height)}px;
422422
`;
423423

424-
const galleryInlineAdContainerStyles = css`
425-
${until.tablet} {
426-
margin: 0 auto;
427-
display: none;
428-
}
429-
`;
430-
431-
const galleryInlineAdMobileContainerStyles = css`
432-
${from.tablet} {
433-
margin: 0 auto;
434-
display: none;
435-
}
436-
`;
437-
438424
const galleryInlineAdStyles = css`
439425
margin: ${space[3]}px auto;
440426
min-height: ${getMinHeight(adSizes.mpu.height)}px;
@@ -948,13 +934,7 @@ export const AdSlot = ({
948934
case 'gallery-inline': {
949935
const advertId = `inline${index + 1}`;
950936
return (
951-
<AdSlotWrapper
952-
css={[
953-
galleryInlineAdContainerStyles,
954-
labelStyles,
955-
galleryInlineAdLabelStyles,
956-
]}
957-
>
937+
<AdSlotWrapper css={[labelStyles, galleryInlineAdLabelStyles]}>
958938
<div
959939
id={`dfp-ad--${advertId}`}
960940
className={[
@@ -979,13 +959,7 @@ export const AdSlot = ({
979959
case 'gallery-inline-mobile': {
980960
const advertId = index === 0 ? 'top-above-nav' : `inline${index}`;
981961
return (
982-
<AdSlotWrapper
983-
css={[
984-
galleryInlineAdMobileContainerStyles,
985-
labelStyles,
986-
galleryInlineAdLabelStyles,
987-
]}
988-
>
962+
<AdSlotWrapper css={[labelStyles, galleryInlineAdLabelStyles]}>
989963
<div
990964
id={`dfp-ad--${advertId}--mobile`}
991965
className={[
@@ -1003,7 +977,7 @@ export const AdSlot = ({
1003977
data-name={advertId}
1004978
aria-hidden="true"
1005979
data-label-show="true"
1006-
data-testid="slot" //doesn't exist in Frontend so do we need it in DCR?
980+
data-testid="slot"
1007981
/>
1008982
</AdSlotWrapper>
1009983
);

dotcom-rendering/src/components/GalleryAdSlots.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const MobileAdSlot = ({
1818
);
1919
};
2020

21-
export const GalleryDesktopAdSlot = ({
21+
export const DesktopAdSlot = ({
2222
renderAds,
2323
adSlotIndex,
2424
}: {

dotcom-rendering/src/layouts/GalleryLayout.tsx

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ import { ArticleMeta } from '../components/ArticleMeta.web';
1414
import { ArticleTitle } from '../components/ArticleTitle';
1515
import { Caption } from '../components/Caption';
1616
import { Footer } from '../components/Footer';
17-
import {
18-
GalleryDesktopAdSlot,
19-
MobileAdSlot,
20-
} from '../components/GalleryAdSlots';
17+
import { DesktopAdSlot, MobileAdSlot } from '../components/GalleryAdSlots';
2118
import { GalleryImage } from '../components/GalleryImage';
2219
import { HeaderAdSlot } from '../components/HeaderAdSlot';
20+
import { Hide } from '../components/Hide';
2321
import { Island } from '../components/Island';
2422
import { MainMediaGallery } from '../components/MainMediaGallery';
2523
import { Masthead } from '../components/Masthead/Masthead';
@@ -278,29 +276,24 @@ export const GalleryLayout = (props: WebProps | AppProps) => {
278276
webTitle={frontendData.webTitle}
279277
/>
280278
{isWeb && shouldShowAds && (
281-
<div
282-
className={[
283-
'gallery__item gallery__item--advert',
284-
].join(' ')}
285-
css={galleryItemAdvertStyles}
286-
>
287-
<div
288-
className="gallery__img-container"
289-
css={galleryInlineAdContainerStyles}
290-
>
291-
<GalleryDesktopAdSlot
292-
renderAds={renderAds}
293-
adSlotIndex={adPositions.indexOf(
294-
index,
295-
)}
296-
/>
297-
298-
<MobileAdSlot
299-
renderAds={renderAds}
300-
adSlotIndex={adPositions.indexOf(
301-
index,
302-
)}
303-
/>
279+
<div css={galleryItemAdvertStyles}>
280+
<div css={galleryInlineAdContainerStyles}>
281+
<Hide when="below" breakpoint="tablet">
282+
<DesktopAdSlot
283+
renderAds={renderAds}
284+
adSlotIndex={adPositions.indexOf(
285+
index,
286+
)}
287+
/>
288+
</Hide>
289+
<Hide when="above" breakpoint="tablet">
290+
<MobileAdSlot
291+
renderAds={renderAds}
292+
adSlotIndex={adPositions.indexOf(
293+
index,
294+
)}
295+
/>
296+
</Hide>
304297
</div>
305298
<div css={galleryBorder}></div>
306299
</div>

dotcom-rendering/src/lib/getGalleryAdPositions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { ImageBlockElement } from '../types/content';
22

33
/**
4-
* @param images - An array of ImageBlockElement objects representing the images in the gallery.
5-
* @description This function calculates the positions in the gallery where ads should be placed.
4+
* This function calculates the positions in the gallery where ads should be placed.
65
* The ad position will be the same for all breakpoints, after every 4 images will have an ad slot.
7-
* What make the difference between mobile and desktop slot ids are in GalleryAdSlots.tsx and AdSlot.web.tsx.
6+
* The logic difference between mobile and desktop slot ids is in GalleryAdSlots.tsx and AdSlot.web.tsx.
7+
* @param images - An array of ImageBlockElement objects representing the images in the gallery.
88
* @returns An array of numbers representing the positions where ads should be placed.
99
*/
1010
const getAdPositions = (images: ImageBlockElement[]): number[] => {

0 commit comments

Comments
 (0)