Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5:4 video images #12614

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions dotcom-rendering/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ export const Card = ({
: imageSize
}
enableAds={false}
aspectRatio={aspectRatio}
/>
</Island>
</div>
Expand Down
51 changes: 32 additions & 19 deletions dotcom-rendering/src/components/MaintainAspectRatio.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
import { css } from '@emotion/react';
import type { AspectRatio } from './CardPicture';

type Props = {
height: number;
width: number;
aspectRatio?: AspectRatio;
children: React.ReactNode;
};

export const MaintainAspectRatio = ({ height, width, children }: Props) => (
export const MaintainAspectRatio = ({
height,
width,
aspectRatio,
children,
}: Props) => {
/* https://css-tricks.com/aspect-ratio-boxes/ */
<div
css={css`
/* position relative to contain the absolutely positioned iframe plus any Overlay image */
position: relative;
padding-bottom: ${(height / width) * 100}%;
const paddingBottom =
aspectRatio === '5:4'
? `${(4 / 5) * 100}%`
: `${(height / width) * 100}%`;

& > iframe,
& > video {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
`}
>
{children}
</div>
);
return (
<div
css={css`
/* position relative to contain the absolutely positioned iframe plus any Overlay image */
position: relative;
padding-bottom: ${paddingBottom};
& > iframe,
& > video {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
`}
>
{children}
</div>
);
};
10 changes: 9 additions & 1 deletion dotcom-rendering/src/components/YoutubeAtom/YoutubeAtom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
ImagePositionType,
ImageSizeType,
} from '../Card/components/ImageWrapper';
import type { AspectRatio } from '../CardPicture';
import { MaintainAspectRatio } from '../MaintainAspectRatio';
import type { VideoCategory } from './YoutubeAtomOverlay';
import { YoutubeAtomOverlay } from './YoutubeAtomOverlay';
Expand Down Expand Up @@ -51,6 +52,7 @@ export type Props = {
imageSize: ImageSizeType;
imagePositionOnMobile: ImagePositionType;
renderingTarget: RenderingTarget;
aspectRatio?: AspectRatio;
};

export const YoutubeAtom = ({
Expand Down Expand Up @@ -79,6 +81,7 @@ export const YoutubeAtom = ({
imageSize,
imagePositionOnMobile,
renderingTarget,
aspectRatio,
}: Props): JSX.Element => {
const [overlayClicked, setOverlayClicked] = useState<boolean>(false);
const [playerReady, setPlayerReady] = useState<boolean>(false);
Expand Down Expand Up @@ -196,7 +199,11 @@ export const YoutubeAtom = ({
setIsClosed={setIsClosed}
shouldPauseOutOfView={shouldPauseOutOfView}
>
<MaintainAspectRatio height={height} width={width}>
<MaintainAspectRatio
height={height}
width={width}
aspectRatio={aspectRatio}
>
{
/**
* Consent and ad targeting are initially undefined and set by subsequent re-renders
Expand Down Expand Up @@ -246,6 +253,7 @@ export const YoutubeAtom = ({
showTextOverlay={showTextOverlay}
imageSize={imageSize}
imagePositionOnMobile={imagePositionOnMobile}
aspectRatio={aspectRatio}
/>
)}
{showPlaceholder && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
ImageSizeType,
} from '../Card/components/ImageWrapper';
import { PlayIcon } from '../Card/components/PlayIcon';
import type { AspectRatio } from '../CardPicture';
import { FormatBoundary } from '../FormatBoundary';
import { Kicker } from '../Kicker';
import { secondsToDuration } from '../MediaDuration';
Expand All @@ -38,6 +39,7 @@ type Props = {
showTextOverlay?: boolean;
imageSize: ImageSizeType;
imagePositionOnMobile: ImagePositionType;
aspectRatio?: AspectRatio;
};

const overlayStyles = css`
Expand Down Expand Up @@ -149,6 +151,7 @@ export const YoutubeAtomOverlay = ({
showTextOverlay,
imageSize,
imagePositionOnMobile,
aspectRatio,
}: Props) => {
const id = `youtube-overlay-${uniqueId}`;
const hasDuration = !isUndefined(duration) && duration > 0;
Expand All @@ -173,6 +176,7 @@ export const YoutubeAtomOverlay = ({
alt={alt}
height={height}
width={width}
aspectRatio={aspectRatio}
/>
)}
{showPill && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,27 @@ type Props = {
alt: string;
height: number;
width: number;
aspectRatio?: string;
};

export const YoutubeAtomPicture = ({ image, alt, height, width }: Props) => {
const sources = generateSources(getSourceImageUrl(image), [
{ breakpoint: breakpoints.mobile, width: 465 },
{ breakpoint: breakpoints.mobileLandscape, width: 645 },
{ breakpoint: breakpoints.phablet, width: 620 },
{ breakpoint: breakpoints.tablet, width: 700 },
{ breakpoint: breakpoints.desktop, width: 620 },
]);
export const YoutubeAtomPicture = ({
image,
alt,
height,
width,
aspectRatio,
}: Props) => {
const sources = generateSources(
getSourceImageUrl(image),
[
{ breakpoint: breakpoints.mobile, width: 465 },
{ breakpoint: breakpoints.mobileLandscape, width: 645 },
{ breakpoint: breakpoints.phablet, width: 620 },
{ breakpoint: breakpoints.tablet, width: 700 },
{ breakpoint: breakpoints.desktop, width: 620 },
],
aspectRatio,
);
const fallbackSource = getFallbackSource(sources);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
ImagePositionType,
ImageSizeType,
} from './Card/components/ImageWrapper';
import type { AspectRatio } from './CardPicture';
import { useConfig } from './ConfigContext';
import { ophanTrackerApps, ophanTrackerWeb } from './YoutubeAtom/eventEmitters';
import { YoutubeAtom } from './YoutubeAtom/YoutubeAtom';
Expand Down Expand Up @@ -40,6 +41,7 @@ type Props = {
imageSize?: ImageSizeType;
imagePositionOnMobile?: ImagePositionType;
enableAds: boolean;
aspectRatio?: AspectRatio;
};

/**
Expand Down Expand Up @@ -81,6 +83,7 @@ export const YoutubeBlockComponent = ({
imageSize = 'large',
imagePositionOnMobile = 'none',
enableAds,
aspectRatio,
}: Props) => {
const [consentState, setConsentState] = useState<ConsentState | undefined>(
undefined,
Expand Down Expand Up @@ -173,6 +176,7 @@ export const YoutubeBlockComponent = ({
imageSize={imageSize}
imagePositionOnMobile={imagePositionOnMobile}
renderingTarget={renderingTarget}
aspectRatio={aspectRatio}
/>
{!hideCaption && (
<Caption
Expand Down
Loading