Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
7 changes: 7 additions & 0 deletions dotcom-rendering/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { CardPicture } from '../CardPicture';
import { Island } from '../Island';
import { LatestLinks } from '../LatestLinks.importable';
import { LoopVideo } from '../LoopVideo.importable';
import type { SubtitleSize } from '../LoopVideoPlayer';
import { Pill } from '../Pill';
import { SlideshowCarousel } from '../SlideshowCarousel.importable';
import { Snap } from '../Snap';
Expand Down Expand Up @@ -159,6 +160,7 @@ export type Props = {
showKickerImage?: boolean;
isInAllBoostsTest?: boolean;
fixImageWidth?: boolean;
subtitleSize?: SubtitleSize;
/** Determines if the headline should be positioned within the content or outside the content */
headlinePosition?: 'inner' | 'outer';
/** Feature flag for the labs redesign work */
Expand Down Expand Up @@ -404,6 +406,7 @@ export const Card = ({
isInAllBoostsTest = false,
headlinePosition = 'inner',
showLabsRedesign = false,
subtitleSize = 'small',
}: Props) => {
const hasSublinks = supportingContent && supportingContent.length > 0;
const sublinkPosition = decideSublinkPosition(
Expand Down Expand Up @@ -969,6 +972,10 @@ export const Card = ({
fallbackImageAlt={media.imageAltText}
fallbackImageAspectRatio="5:4"
linkTo={linkTo}
subtitleSource={
media.mainMedia.subtitleSource
}
subtitleSize={subtitleSize}
/>
</Island>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ export const SplashBoostLevels: Story = {

return (
<>
<Section title="Default" boostLevel="default" />
<Section title="Boosted" boostLevel="boost" />
<Section title="Mega boosted" boostLevel="megaboost" />
<Section title="Giga boosted" boostLevel="gigaboost" />
Expand Down
13 changes: 13 additions & 0 deletions dotcom-rendering/src/components/FlexibleGeneral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { ResponsiveFontSize } from './CardHeadline';
import type { Loading } from './CardPicture';
import { FeatureCard } from './FeatureCard';
import { FrontCard } from './FrontCard';
import type { SubtitleSize } from './LoopVideoPlayer';
import type { Alignment } from './SupportingContent';

type Props = {
Expand Down Expand Up @@ -156,6 +157,7 @@ type BoostedSplashProperties = {
supportingContentAlignment: Alignment;
liveUpdatesAlignment: Alignment;
trailTextSize: TrailTextSize;
subtitleSize: SubtitleSize;
avatarUrl?: string;
};

Expand Down Expand Up @@ -186,6 +188,7 @@ const decideSplashCardProperties = (
supportingContentLength >= 4 ? 'horizontal' : 'vertical',
liveUpdatesAlignment: 'vertical',
trailTextSize: 'regular',
subtitleSize: 'medium',
};
case 'boost':
return {
Expand All @@ -201,6 +204,7 @@ const decideSplashCardProperties = (
supportingContentLength >= 4 ? 'horizontal' : 'vertical',
liveUpdatesAlignment: 'vertical',
trailTextSize: 'regular',
subtitleSize: 'medium',
};
case 'megaboost':
return {
Expand All @@ -217,6 +221,7 @@ const decideSplashCardProperties = (
supportingContentAlignment: 'horizontal',
liveUpdatesAlignment: 'horizontal',
trailTextSize: 'large',
subtitleSize: 'large',
};
case 'gigaboost':
return {
Expand All @@ -233,6 +238,7 @@ const decideSplashCardProperties = (
supportingContentAlignment: 'horizontal',
liveUpdatesAlignment: 'horizontal',
trailTextSize: 'large',
subtitleSize: 'large',
};
}
};
Expand Down Expand Up @@ -294,6 +300,7 @@ const SplashCardLayout = ({
supportingContentAlignment,
liveUpdatesAlignment,
trailTextSize,
subtitleSize,
} = decideSplashCardProperties(
card.boostLevel ?? 'default',
card.supportingContent?.length ?? 0,
Expand Down Expand Up @@ -343,6 +350,7 @@ const SplashCardLayout = ({
trailTextSize={trailTextSize}
canPlayInline={true}
showKickerImage={card.format.design === ArticleDesign.Audio}
subtitleSize={subtitleSize}
headlinePosition={card.showLivePlayable ? 'outer' : 'inner'}
showLabsRedesign={showLabsRedesign}
/>
Expand All @@ -356,6 +364,7 @@ type BoostedCardProperties = {
mediaSize: MediaSizeType;
liveUpdatesPosition: Position;
supportingContentAlignment: Alignment;
subtitleSize: SubtitleSize;
};

/**
Expand All @@ -379,6 +388,7 @@ const decideCardProperties = (
liveUpdatesPosition: 'outer',
supportingContentAlignment:
supportingContentLength >= 2 ? 'horizontal' : 'vertical',
subtitleSize: 'medium',
};
case 'boost':
default:
Expand All @@ -392,6 +402,7 @@ const decideCardProperties = (
liveUpdatesPosition: 'inner',
supportingContentAlignment:
supportingContentLength >= 2 ? 'horizontal' : 'vertical',
subtitleSize: 'small',
};
}
};
Expand Down Expand Up @@ -432,6 +443,7 @@ const FullWidthCardLayout = ({
mediaSize,
supportingContentAlignment,
liveUpdatesPosition,
subtitleSize,
} = decideCardProperties(
card.supportingContent?.length ?? 0,
card.boostLevel,
Expand Down Expand Up @@ -497,6 +509,7 @@ const FullWidthCardLayout = ({
canPlayInline={true}
showKickerImage={card.format.design === ArticleDesign.Audio}
showLabsRedesign={showLabsRedesign}
subtitleSize={subtitleSize}
/>
</LI>
</UL>
Expand Down
8 changes: 8 additions & 0 deletions dotcom-rendering/src/components/FlexibleSpecial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { UL } from './Card/components/UL';
import type { ResponsiveFontSize } from './CardHeadline';
import type { Loading } from './CardPicture';
import { FrontCard } from './FrontCard';
import type { SubtitleSize } from './LoopVideoPlayer';
import type { Alignment } from './SupportingContent';

type Props = {
Expand All @@ -42,6 +43,7 @@ type BoostProperties = {
supportingContentAlignment: Alignment;
liveUpdatesAlignment: Alignment;
trailTextSize: TrailTextSize;
subtitleSize: SubtitleSize;
};

/**
Expand Down Expand Up @@ -70,6 +72,7 @@ const determineCardProperties = (
supportingContentLength >= 3 ? 'horizontal' : 'vertical',
liveUpdatesAlignment: 'vertical',
trailTextSize: 'regular',
subtitleSize: 'medium',
};
case 'boost':
return {
Expand All @@ -85,6 +88,7 @@ const determineCardProperties = (
supportingContentLength >= 3 ? 'horizontal' : 'vertical',
liveUpdatesAlignment: 'vertical',
trailTextSize: 'regular',
subtitleSize: 'medium',
};
case 'megaboost':
return {
Expand All @@ -99,6 +103,7 @@ const determineCardProperties = (
supportingContentAlignment: 'horizontal',
liveUpdatesAlignment: 'horizontal',
trailTextSize: 'large',
subtitleSize: 'large',
};
case 'gigaboost':
return {
Expand All @@ -113,6 +118,7 @@ const determineCardProperties = (
supportingContentAlignment: 'horizontal',
liveUpdatesAlignment: 'horizontal',
trailTextSize: 'large',
subtitleSize: 'large',
};
}
};
Expand Down Expand Up @@ -155,6 +161,7 @@ export const OneCardLayout = ({
supportingContentAlignment,
liveUpdatesAlignment,
trailTextSize,
subtitleSize,
} = determineCardProperties(
card.boostLevel ?? 'default',
card.supportingContent?.length ?? 0,
Expand Down Expand Up @@ -195,6 +202,7 @@ export const OneCardLayout = ({
showKickerImage={card.format.design === ArticleDesign.Audio}
headlinePosition={isSplashCard ? 'outer' : 'inner'}
showLabsRedesign={showLabsRedesign}
subtitleSize={subtitleSize}
/>
</LI>
</UL>
Expand Down
36 changes: 35 additions & 1 deletion dotcom-rendering/src/components/LoopVideo.importable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { css } from '@emotion/react';
import { log, storage } from '@guardian/libs';
import { space } from '@guardian/source/foundations';
import { SvgAudio, SvgAudioMute } from '@guardian/source/react-components';
import { useCallback, useEffect, useRef, useState } from 'react';
import {
Expand All @@ -18,8 +19,12 @@ import {
} from '../lib/video';
import { CardPicture, type Props as CardPictureProps } from './CardPicture';
import { useConfig } from './ConfigContext';
import type {
PLAYER_STATES,
PlayerStates,
SubtitleSize,
} from './LoopVideoPlayer';
import { LoopVideoPlayer } from './LoopVideoPlayer';
import type { PLAYER_STATES, PlayerStates } from './LoopVideoPlayer';
import { ophanTrackerWeb } from './YoutubeAtom/eventEmitters';

const videoContainerStyles = css`
Expand Down Expand Up @@ -117,6 +122,8 @@ type Props = {
fallbackImageAlt: CardPictureProps['alt'];
fallbackImageAspectRatio: CardPictureProps['aspectRatio'];
linkTo: string;
subtitleSource?: string;
subtitleSize: SubtitleSize;
};

export const LoopVideo = ({
Expand All @@ -132,6 +139,8 @@ export const LoopVideo = ({
fallbackImageAlt,
fallbackImageAspectRatio,
linkTo,
subtitleSource,
subtitleSize,
}: Props) => {
const adapted = useShouldAdapt();
const { renderingTarget } = useConfig();
Expand Down Expand Up @@ -478,6 +487,28 @@ export const LoopVideo = ({
return FallbackImageComponent;
}

const handleLoadedMetadata = () => {
const video = vidRef.current;
if (!video) return;

const track = video.textTracks[0];
if (!track?.cues) return;
const pxFromBottom = space[3];
const videoHeight =
video.getBoundingClientRect().height ||
video.clientHeight ||
height;
const percentFromTop =
((videoHeight - pxFromBottom) / videoHeight) * 100;

for (const cue of Array.from(track.cues)) {
if (cue instanceof VTTCue) {
cue.snapToLines = false;
cue.line = percentFromTop;
}
}
};

const handleLoadedData = () => {
if (vidRef.current) {
setHasAudio(doesVideoHaveAudio(vidRef.current));
Expand Down Expand Up @@ -617,6 +648,7 @@ export const LoopVideo = ({
isPlayable={isPlayable}
playerState={playerState}
isMuted={isMuted}
handleLoadedMetadata={handleLoadedMetadata}
handleLoadedData={handleLoadedData}
handleCanPlay={handleCanPlay}
handlePlayPauseClick={handlePlayPauseClick}
Expand All @@ -627,6 +659,8 @@ export const LoopVideo = ({
AudioIcon={hasAudio ? AudioIcon : null}
preloadPartialData={preloadPartialData}
showPlayIcon={showPlayIcon}
subtitleSource={subtitleSource}
subtitleSize={subtitleSize}
/>
</figure>
);
Expand Down
Loading
Loading