Skip to content

Commit

Permalink
Put lightbox behind a switch
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverlloyd committed Jul 6, 2023
1 parent d76e316 commit 460e83d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dotcom-rendering/src/components/ArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const ArticlePage = (props: WebProps | AppProps) => {
/>
<SkipTo id="maincontent" label="Skip to main content" />
<SkipTo id="navigation" label="Skip to navigation" />
{article.imagesForLightbox && (
{article.config.switches.lightbox && article.imagesForLightbox && (
<>
<LightboxLayout
imageCount={article.imagesForLightbox.length}
Expand Down
6 changes: 5 additions & 1 deletion dotcom-rendering/src/components/ImageBlockComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ImageBlockElement } from '../types/content';
import type { Switches } from '../types/config';
import type { ImageBlockElement } from '../types/content';
import { ImageComponent } from './ImageComponent';

type Props = {
Expand All @@ -9,6 +10,7 @@ type Props = {
isMainMedia?: boolean;
starRating?: number;
isAvatar?: boolean;
switches?: Switches;
};

export const ImageBlockComponent = ({
Expand All @@ -19,6 +21,7 @@ export const ImageBlockComponent = ({
isMainMedia,
starRating,
isAvatar,
switches,
}: Props) => {
const { role } = element;
return (
Expand All @@ -31,6 +34,7 @@ export const ImageBlockComponent = ({
role={role}
title={title}
isAvatar={isAvatar}
switches={switches}
/>
);
};
12 changes: 9 additions & 3 deletions dotcom-rendering/src/components/ImageComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
until,
} from '@guardian/source-foundations';
import { decidePalette } from '../lib/decidePalette';
import type { Switches } from '../types/config';
import type { Image, ImageBlockElement, RoleType } from '../types/content';
import type { Palette } from '../types/palette';
import { Caption } from './Caption';
Expand All @@ -26,6 +27,7 @@ type Props = {
starRating?: number;
title?: string;
isAvatar?: boolean;
switches?: Switches;
};

const starsWrapper = css`
Expand Down Expand Up @@ -233,6 +235,7 @@ export const ImageComponent = ({
starRating,
title,
isAvatar,
switches,
}: Props) => {
// Its possible the tools wont send us any images urls
// if so, don't try to render
Expand Down Expand Up @@ -329,7 +332,8 @@ export const ImageComponent = ({
{!!title && (
<ImageTitle title={title} role={role} palette={palette} />
)}
{parseInt(imageWidth, 10) > 620 &&
{switches?.lightbox === true &&
parseInt(imageWidth, 10) > 620 &&
element.position !== undefined && (
<LightboxLink
role={role}
Expand Down Expand Up @@ -378,7 +382,8 @@ export const ImageComponent = ({
{!!title && (
<ImageTitle title={title} role={role} palette={palette} />
)}
{parseInt(imageWidth, 10) > 620 &&
{switches?.lightbox === true &&
parseInt(imageWidth, 10) > 620 &&
element.position !== undefined && (
<LightboxLink
role={role}
Expand Down Expand Up @@ -466,7 +471,8 @@ export const ImageComponent = ({
<ImageTitle title={title} role={role} palette={palette} />
)}

{parseInt(imageWidth, 10) > 620 &&
{switches?.lightbox === true &&
parseInt(imageWidth, 10) > 620 &&
element.position !== undefined && (
<LightboxLink
role={role}
Expand Down
39 changes: 37 additions & 2 deletions dotcom-rendering/src/components/MultiImageBlockComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { css } from '@emotion/react';
import { from, space, until } from '@guardian/source-foundations';
import type { Switches } from '../types/config';
import type { ImageBlockElement } from '../types/content';
import { Caption } from './Caption';
import { GridItem } from './GridItem';
Expand All @@ -9,6 +10,7 @@ type Props = {
images: ImageBlockElement[];
format: ArticleFormat;
caption?: string;
switches?: Switches;
};

const ieFallback = css`
Expand Down Expand Up @@ -102,17 +104,20 @@ const OneImage = ({
images,
format,
caption,
switches,
}: {
images: [ImageBlockElement];
format: ArticleFormat;
caption?: string;
switches?: Switches;
}) => (
<div css={wrapper}>
<ImageComponent
format={format}
element={images[0]}
hideCaption={true}
role={images[0].role}
switches={switches}
/>
{!!caption && (
<Caption
Expand All @@ -128,10 +133,12 @@ const TwoImage = ({
images,
format,
caption,
switches,
}: {
images: [ImageBlockElement, ImageBlockElement];
format: ArticleFormat;
caption?: string;
switches?: Switches;
}) => (
<div css={wrapper}>
<SideBySideGrid>
Expand All @@ -141,6 +148,7 @@ const TwoImage = ({
format={format}
hideCaption={true}
role={images[0].role}
switches={switches}
/>
</GridItem>
<GridItem area="second">
Expand All @@ -149,6 +157,7 @@ const TwoImage = ({
format={format}
hideCaption={true}
role={images[1].role}
switches={switches}
/>
</GridItem>
</SideBySideGrid>
Expand All @@ -166,10 +175,12 @@ const ThreeImage = ({
images,
format,
caption,
switches,
}: {
images: [ImageBlockElement, ImageBlockElement, ImageBlockElement];
format: ArticleFormat;
caption?: string;
switches?: Switches;
}) => (
<div css={wrapper}>
<OneAboveTwoGrid>
Expand All @@ -179,6 +190,7 @@ const ThreeImage = ({
format={format}
hideCaption={true}
role={images[0].role}
switches={switches}
/>
</GridItem>
<GridItem area="second">
Expand All @@ -187,6 +199,7 @@ const ThreeImage = ({
format={format}
hideCaption={true}
role={images[1].role}
switches={switches}
/>
</GridItem>
<GridItem area="third">
Expand All @@ -195,6 +208,7 @@ const ThreeImage = ({
format={format}
hideCaption={true}
role={images[2].role}
switches={switches}
/>
</GridItem>
</OneAboveTwoGrid>
Expand All @@ -212,6 +226,7 @@ const FourImage = ({
images,
format,
caption,
switches,
}: {
images: [
ImageBlockElement,
Expand All @@ -221,6 +236,7 @@ const FourImage = ({
];
format: ArticleFormat;
caption?: string;
switches?: Switches;
}) => (
<div css={wrapper}>
<GridOfFour>
Expand All @@ -230,6 +246,7 @@ const FourImage = ({
format={format}
hideCaption={true}
role={images[0].role}
switches={switches}
/>
</GridItem>
<GridItem area="second">
Expand All @@ -238,6 +255,7 @@ const FourImage = ({
format={format}
hideCaption={true}
role={images[1].role}
switches={switches}
/>
</GridItem>
<GridItem area="third">
Expand All @@ -246,6 +264,7 @@ const FourImage = ({
format={format}
hideCaption={true}
role={images[2].role}
switches={switches}
/>
</GridItem>
<GridItem area="forth">
Expand All @@ -254,6 +273,7 @@ const FourImage = ({
format={format}
hideCaption={true}
role={images[3].role}
switches={switches}
/>
</GridItem>
</GridOfFour>
Expand All @@ -271,6 +291,7 @@ export const MultiImageBlockComponent = ({
images,
format,
caption,
switches,
}: Props) => {
const [one, two, three, four] = images;

Expand All @@ -280,6 +301,7 @@ export const MultiImageBlockComponent = ({
images={[one, two, three, four]}
format={format}
caption={caption}
switches={switches}
/>
);
}
Expand All @@ -290,18 +312,31 @@ export const MultiImageBlockComponent = ({
images={[one, two, three]}
format={format}
caption={caption}
switches={switches}
/>
);
}

if (one && two) {
return (
<TwoImage images={[one, two]} format={format} caption={caption} />
<TwoImage
images={[one, two]}
format={format}
caption={caption}
switches={switches}
/>
);
}

if (one) {
return <OneImage images={[one]} format={format} caption={caption} />;
return (
<OneImage
images={[one]}
format={format}
caption={caption}
switches={switches}
/>
);
}

return null;
Expand Down
2 changes: 2 additions & 0 deletions dotcom-rendering/src/lib/renderElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ export const renderElement = ({
starRating={starRating ?? element.starRating}
title={element.title}
isAvatar={element.isAvatar}
switches={switches}
/>
);
case 'model.dotcomrendering.pageElements.InstagramBlockElement':
Expand Down Expand Up @@ -448,6 +449,7 @@ export const renderElement = ({
key={index}
images={element.images}
caption={element.caption}
switches={switches}
/>
);
case 'model.dotcomrendering.pageElements.NewsletterSignupBlockElement':
Expand Down

0 comments on commit 460e83d

Please sign in to comment.