Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions dotcom-rendering/src/components/SelfHostedVideo.island.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ type Props = {
isExternalLink: boolean;
};
isInLoopClickTestVariant?: boolean;
isInArticle?: boolean;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be renamed to something that describes the behaviour of this component instead of the features of the parent? It can be easier to understand how to use props and predict what they do that follow this pattern

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @domlander, perhaps hasBottomMargin or similar?

};

export const SelfHostedVideo = ({
Expand Down Expand Up @@ -351,6 +352,7 @@ export const SelfHostedVideo = ({
restrictHeightOnDesktop = false,
cardLink,
isInLoopClickTestVariant,
isInArticle = false,
}: Props) => {
const adapted = useShouldAdapt();
const { renderingTarget } = useConfig();
Expand Down Expand Up @@ -1071,13 +1073,22 @@ export const SelfHostedVideo = ({
}
}

const videoStyleFormat = videoStyle.toLocaleLowerCase();

return (
<figure
css={
isInArticle
? css`
margin-bottom: ${space[3]}px;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of adding margins to the child component, instead of the parent controlling the spacing. I think the code can end up a bit messy with this approach.

I see from following the code upwards that it is not easy to add this margin to a parent container and creating a new div seems quite unnecessary. I think my preference is for the latter (and current) of these three options but happy to be overruled.

`
: undefined
Comment on lines +1081 to +1085

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could this style be lifted out into a const? This would be more consistet with the rest of the file and would allow for slightly more readable jsx eg
css={isInArticle && bottomMarginStyles}

}
ref={videoContainerRef}
className={`video-container ${videoStyle.toLocaleLowerCase()} ${
className={`video-container ${videoStyleFormat} ${
role === 'immersive' ? 'element-video-immersive' : ''
}`}
data-component="gu-video-loop"
data-component={`gu-video-${videoStyleFormat}`}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice spot. I would run this change by the Fronts & Curation team. I think their analytics might be relying on this name

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be OK to update this name provided the change is run past Ophan before its merged

>
<div
ref={setNode}
Expand Down
70 changes: 30 additions & 40 deletions dotcom-rendering/src/components/SelfHostedVideoInArticle.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { css } from '@emotion/react';
import { space } from '@guardian/source/foundations';
import type { FEAspectRatio } from '../frontend/feFront';
import { isInteractive } from '../layouts/lib/interactiveLegacyStyling';
import type { ArticleFormat } from '../lib/articleFormat';
Expand All @@ -13,10 +11,6 @@ import type { VideoPlayerFormat } from '../types/mainMedia';
import { Island } from './Island';
import { SelfHostedVideo } from './SelfHostedVideo.island';

const containerStyles = css`
margin-bottom: ${space[3]}px;
`;

type SelfHostedVideoInArticleProps = {
element: MediaAtomBlockElement;
format: ArticleFormat;
Expand Down Expand Up @@ -49,39 +43,35 @@ export const SelfHostedVideoInArticle = ({
}

return (
<div css={containerStyles} data-spacefinder-role="inline">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we OK to drop the data-spacefinder-role attribute?

<Island priority="critical" defer={{ until: 'visible' }}>
<SelfHostedVideo
atomId={element.id}
fallbackImage={posterImageUrl}
fallbackImageAlt={caption}
fallbackImageAspectRatio={
(firstVideoSource?.aspectRatio ??
'5:4') as FEAspectRatio
}
fallbackImageLoading="lazy"
fallbackImageSize="small"
aspectRatio={aspectRatio}
linkTo="Article-embed-MediaAtomBlockElement"
posterImage={posterImageUrl}
posterImageAspectRatio={
firstVideoSource?.aspectRatio ?? '5:4'
}
sources={sources}
subtitleSize="medium"
subtitleSource={getSubtitleAsset(element.assets)}
videoStyle={videoStyle}
uniqueId={element.id}
caption={caption}
format={format}
isMainMedia={isMainMedia}
role={role}
preventAutoplay={videoStyle === 'Default'}
restrictHeightOnDesktop={
isVerticalVideo && !isInteractive(format.design)
}
/>
</Island>
</div>
<Island priority="critical" defer={{ until: 'visible' }}>
<SelfHostedVideo
atomId={element.id}
fallbackImage={posterImageUrl}
fallbackImageAlt={caption}
fallbackImageAspectRatio={
(firstVideoSource?.aspectRatio ?? '5:4') as FEAspectRatio
}
fallbackImageLoading="lazy"
fallbackImageSize="small"
aspectRatio={aspectRatio}
linkTo="Article-embed-MediaAtomBlockElement"
posterImage={posterImageUrl}
posterImageAspectRatio={firstVideoSource?.aspectRatio ?? '5:4'}
sources={sources}
subtitleSize="medium"
subtitleSource={getSubtitleAsset(element.assets)}
videoStyle={videoStyle}
uniqueId={element.id}
caption={caption}
format={format}
isMainMedia={isMainMedia}
role={role}
preventAutoplay={videoStyle === 'Default'}
restrictHeightOnDesktop={
isVerticalVideo && !isInteractive(format.design)
}
isInArticle={true}
/>
</Island>
);
};
Loading