Skip to content

Commit a19d654

Browse files
committed
Fix styling
1 parent 4486c65 commit a19d654

File tree

3 files changed

+60
-26
lines changed

3 files changed

+60
-26
lines changed

dotcom-rendering/src/components/FeatureCard.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,6 @@ import { YoutubeBlockComponent } from './YoutubeBlockComponent.importable';
4949

5050
export type Position = 'inner' | 'outer' | 'none';
5151

52-
// type Media =
53-
// | {
54-
// type: 'picture';
55-
// imageUrl: string;
56-
// imageAltText?: string;
57-
// }
58-
// | {
59-
// type: 'youtube-video';
60-
// mainMedia: YoutubeVideo;
61-
// };
62-
6352
const baseCardStyles = css`
6453
display: flex;
6554
flex-direction: column;
@@ -547,6 +536,9 @@ export const FeatureCard = ({
547536
uniqueId={uniqueId}
548537
height={media.mainMedia.height}
549538
width={media.mainMedia.width}
539+
containerAspectRatio={
540+
isImmersive ? 5 / 3 : 4 / 5
541+
}
550542
// Only cinemagraphs are currently supported in feature cards
551543
videoStyle="Cinemagraph"
552544
posterImage={
@@ -569,6 +561,7 @@ export const FeatureCard = ({
569561
}
570562
subtitleSize="large"
571563
enableHls={false}
564+
isFeatureCard={true}
572565
/>
573566
</Island>
574567
)}

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

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,20 @@ const videoContainerStyles = (
3434
isCinemagraph: boolean,
3535
aspectRatio: number,
3636
containerAspectRatio?: number, // The aspect ratio of the container
37+
isFeatureCard?: boolean,
3738
) => css`
3839
position: relative;
3940
display: flex;
4041
justify-content: space-around;
4142
background-color: ${palette('--video-background')};
4243
${!isCinemagraph && `z-index: ${getZIndex('video-container')}`};
4344
45+
${!isFeatureCard &&
46+
css`
47+
max-height: 100vh;
48+
max-height: 100svh;
49+
`}
50+
4451
/**
4552
* If the video and its containing slot have different dimensions, the slot will use the aspect
4653
* ratio of the video on mobile, so that the video can take up the full width of the screen.
@@ -55,20 +62,35 @@ const videoContainerStyles = (
5562
}
5663
`;
5764

58-
const figureStyles = (aspectRatio: number) => css`
65+
const figureStyles = (
66+
aspectRatio: number,
67+
containerAspectRatio?: number,
68+
isFeatureCard?: boolean,
69+
) => css`
5970
position: relative;
6071
aspect-ratio: ${aspectRatio};
6172
height: 100%;
62-
max-height: 100vh;
63-
max-height: 100svh;
6473
max-width: 100%;
65-
${from.tablet} {
66-
/**
67-
* The value "80" is derived from the aspect ratio of the 5:4 slot.
68-
* When other slots are used for self-hosted videos, this will need to be adjusted.
69-
*/
70-
max-width: ${aspectRatio * 80}%;
71-
}
74+
75+
${!isFeatureCard &&
76+
css`
77+
max-height: 100vh;
78+
max-height: 100svh;
79+
80+
${from.tablet} {
81+
${typeof containerAspectRatio === 'number' &&
82+
`max-width: ${aspectRatio * (1 / containerAspectRatio) * 100}%;`}
83+
}
84+
`}
85+
86+
${isFeatureCard &&
87+
css`
88+
width: 100%;
89+
display: flex;
90+
flex-direction: column;
91+
justify-content: center;
92+
overflow: hidden;
93+
`}
7294
`;
7395

7496
/**
@@ -150,6 +172,7 @@ type Props = {
150172
subtitleSource?: string;
151173
subtitleSize: SubtitleSize;
152174
enableHls: boolean;
175+
isFeatureCard?: boolean;
153176
};
154177

155178
export const SelfHostedVideo = ({
@@ -170,6 +193,7 @@ export const SelfHostedVideo = ({
170193
subtitleSource,
171194
subtitleSize,
172195
enableHls,
196+
isFeatureCard = false,
173197
}: Props) => {
174198
const adapted = useShouldAdapt();
175199
const { renderingTarget } = useConfig();
@@ -699,11 +723,16 @@ export const SelfHostedVideo = ({
699723
isCinemagraph,
700724
aspectRatio,
701725
containerAspectRatio,
726+
isFeatureCard,
702727
)}
703728
>
704729
<figure
705730
ref={setNode}
706-
css={figureStyles(aspectRatio)}
731+
css={figureStyles(
732+
aspectRatio,
733+
containerAspectRatio,
734+
isFeatureCard,
735+
)}
707736
className={`video-container ${videoStyle.toLocaleLowerCase()}`}
708737
data-component="gu-video-loop"
709738
>
@@ -737,6 +766,7 @@ export const SelfHostedVideo = ({
737766
subtitleSize={subtitleSize}
738767
activeCue={activeCue}
739768
enableHls={enableHls}
769+
isFeatureCard={isFeatureCard}
740770
/>
741771
</figure>
742772
</div>

dotcom-rendering/src/components/SelfHostedVideoPlayer.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,25 @@ import { VideoProgressBar } from './VideoProgressBar';
2323

2424
export type SubtitleSize = 'small' | 'medium' | 'large';
2525

26-
const videoStyles = (aspectRatio: number) => css`
26+
const videoStyles = (aspectRatio: number, isFeatureCard: boolean) => css`
2727
position: relative;
2828
display: block;
2929
height: auto;
3030
width: 100%;
31-
max-height: 100vh;
32-
max-height: 100svh;
3331
cursor: pointer;
3432
/* Prevents CLS by letting the browser know the space the video will take up. */
3533
aspect-ratio: ${aspectRatio};
34+
35+
${!isFeatureCard &&
36+
css`
37+
max-height: 100vh;
38+
max-height: 100svh;
39+
`}
40+
41+
${isFeatureCard &&
42+
css`
43+
object-fit: cover;
44+
`}
3645
`;
3746

3847
const subtitleStyles = (subtitleSize: SubtitleSize | undefined) => css`
@@ -127,6 +136,7 @@ type Props = {
127136
/* used in custom subtitle overlays */
128137
activeCue?: ActiveCue | null;
129138
enableHls: boolean;
139+
isFeatureCard: boolean;
130140
};
131141

132142
/**
@@ -169,6 +179,7 @@ export const SelfHostedVideoPlayer = forwardRef(
169179
subtitleSize,
170180
activeCue,
171181
enableHls,
182+
isFeatureCard,
172183
}: Props,
173184
ref: React.ForwardedRef<HTMLVideoElement>,
174185
) => {
@@ -199,7 +210,7 @@ export const SelfHostedVideoPlayer = forwardRef(
199210
<video
200211
id={videoId}
201212
css={[
202-
videoStyles(aspectRatio),
213+
videoStyles(aspectRatio, isFeatureCard),
203214
showSubtitles && subtitleStyles(subtitleSize),
204215
]}
205216
crossOrigin="anonymous"

0 commit comments

Comments
 (0)