Skip to content

Commit 4c28d31

Browse files
committed
WIP
1 parent a124656 commit 4c28d31

File tree

4 files changed

+59
-11
lines changed

4 files changed

+59
-11
lines changed

dotcom-rendering/src/components/FeatureCard.stories.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ export const WithSelfHostedVideo = {
393393
mimeType: 'video/mp4',
394394
},
395395
],
396-
width: 576,
397396
height: 720,
397+
width: 576,
398398
duration: 18,
399399
},
400400
},
@@ -412,8 +412,22 @@ export const WithSelfHostedImmersiveVideo = {
412412
mimeType: 'video/mp4',
413413
},
414414
],
415-
width: 1200,
416415
height: 720,
416+
width: 1200,
417+
},
418+
},
419+
} satisfies Story;
420+
421+
export const WithSelfHostedVideoOnShortScreen = {
422+
args: {
423+
...WithSelfHostedVideo.args,
424+
},
425+
parameters: {
426+
viewport: {
427+
shortViewport: {
428+
name: 'Short viewport',
429+
styles: { height: '1000px', width: '700px' },
430+
},
417431
},
418432
},
419433
} satisfies Story;

dotcom-rendering/src/components/FeatureCard.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,12 @@ export const FeatureCard = ({
520520
sources={media.mainMedia.sources}
521521
atomId={media.mainMedia.atomId}
522522
uniqueId={uniqueId}
523-
height={media.mainMedia.height}
524-
width={media.mainMedia.width}
523+
// height={media.mainMedia.height}
524+
// width={media.mainMedia.width}
525+
height={2 * 720}
526+
width={
527+
2 * (isImmersive ? 1200 : 576)
528+
}
525529
// Only cinemagraphs are currently supported in feature cards
526530
videoStyle="Cinemagraph"
527531
posterImage={

dotcom-rendering/src/components/SelfHostedVideo.importable.tsx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { css } from '@emotion/react';
22
import { log, storage } from '@guardian/libs';
3-
import { from, space } from '@guardian/source/foundations';
3+
import { from, space, until } from '@guardian/source/foundations';
44
import { SvgAudio, SvgAudioMute } from '@guardian/source/react-components';
55
import { useCallback, useEffect, useRef, useState } from 'react';
66
import {
@@ -38,14 +38,16 @@ const videoAndBackgroundStyles = (isCinemagraph: boolean) => css`
3838
${!isCinemagraph && `z-index: ${getZIndex('video-container')}`};
3939
`;
4040

41-
const videoContainerStyles = (width: number, height: number) => css`
41+
const videoContainerStyles = css`
4242
position: relative;
4343
height: 100%;
44+
/** TODO Remove for feature cards */
4445
max-height: 100vh;
4546
max-height: 100svh;
4647
max-width: 100%;
47-
${from.tablet} {
48-
max-width: ${(width / height) * 80}%;
48+
49+
${until.tablet} {
50+
width: 100%; // Safari
4951
}
5052
`;
5153

@@ -672,11 +674,38 @@ export const SelfHostedVideo = ({
672674
? getOptimisedPosterImage(posterImage)
673675
: undefined;
674676

677+
const aspectRatioOfCard = (aspectRatioOfImage: string | undefined) => {
678+
if (!aspectRatioOfImage) return null;
679+
680+
const aspectRatio = aspectRatioOfImage.split(':');
681+
if (!aspectRatio[0] || !aspectRatio[1]) return null;
682+
683+
const aspectRatioWidth = parseInt(aspectRatio[0]);
684+
const aspectRatioHeight = parseInt(aspectRatio[1]);
685+
686+
return aspectRatioWidth / aspectRatioHeight;
687+
};
688+
689+
const containerAspectRatio = aspectRatioOfCard(fallbackImageAspectRatio);
690+
675691
return (
676692
<div css={videoAndBackgroundStyles(isCinemagraph)}>
677693
<figure
678694
ref={setNode}
679-
css={videoContainerStyles(width, height)}
695+
css={[
696+
videoContainerStyles,
697+
containerAspectRatio !== null &&
698+
css`
699+
${from.tablet} {
700+
/** If the video is thinner (i.e. taller) than the container, ensure that it
701+
takes up enough width such that the height is the same as the container and the
702+
aspect ratio is maintained */
703+
max-width: ${(width / height) *
704+
(1 / containerAspectRatio) *
705+
100}%;
706+
}
707+
`,
708+
]}
680709
className={`video-container ${videoStyle.toLocaleLowerCase()}`}
681710
data-component="gu-video-loop"
682711
>

dotcom-rendering/src/components/SelfHostedVideoPlayer.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ export type SubtitleSize = 'small' | 'medium' | 'large';
2626
const videoStyles = (width: number, height: number) => css`
2727
position: relative;
2828
display: block;
29-
height: auto;
29+
height: 100%;
3030
width: 100%;
31+
/** TODO Remove for feature cards */
3132
max-height: 100vh;
3233
max-height: 100svh;
3334
cursor: pointer;
@@ -194,7 +195,7 @@ export const SelfHostedVideoPlayer = forwardRef(
194195
videoStyles(width, height),
195196
showSubtitles && subtitleStyles(subtitleSize),
196197
]}
197-
crossOrigin="anonymous"
198+
// crossOrigin="anonymous"
198199
ref={ref}
199200
tabIndex={0}
200201
data-testid="self-hosted-video-player"

0 commit comments

Comments
 (0)