Skip to content

Commit 7cfed81

Browse files
authored
Merge pull request #13466 from guardian/sa-add-caption-to-video-atom
Add caption to video atom
2 parents abfad6c + af1c5c4 commit 7cfed81

File tree

3 files changed

+53
-20
lines changed

3 files changed

+53
-20
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { css } from '@emotion/react';
22
import type { Meta, StoryObj } from '@storybook/react';
3+
import { ArticleDesign, ArticleDisplay, Pillar } from '../lib/articleFormat';
34
import { VideoAtom } from './VideoAtom';
45

56
const meta = {
@@ -25,6 +26,13 @@ export const Default = {
2526
mimeType: 'video/mp4',
2627
},
2728
],
29+
isMainMedia: false,
30+
format: {
31+
theme: Pillar.News,
32+
display: ArticleDisplay.Standard,
33+
design: ArticleDesign.Standard,
34+
},
35+
caption: 'This is a video caption',
2836
},
2937
decorators: [
3038
(Story) => (
Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ArticleFormat } from '../lib/articleFormat';
2+
import { Caption } from './Caption';
13
import { MaintainAspectRatio } from './MaintainAspectRatio';
24

35
type AssetType = {
@@ -6,41 +8,61 @@ type AssetType = {
68
};
79

810
interface Props {
11+
format: ArticleFormat;
912
assets: AssetType[];
13+
isMainMedia: boolean;
1014
poster?: string;
15+
caption?: string;
1116
height?: number;
1217
width?: number;
1318
}
1419

1520
export const VideoAtom = ({
21+
format,
1622
assets,
23+
isMainMedia,
1724
poster,
25+
caption,
1826
height = 259,
1927
width = 460,
2028
}: Props) => {
2129
if (assets.length === 0) return null; // Handle empty assets array
2230
return (
23-
<MaintainAspectRatio
24-
height={height}
25-
width={width}
26-
data-spacefinder-role="inline"
27-
>
28-
{/* eslint-disable-next-line jsx-a11y/media-has-caption -- caption not available */}
29-
<video
30-
controls={true}
31-
preload="metadata"
32-
width={width}
31+
<>
32+
<MaintainAspectRatio
3333
height={height}
34-
poster={poster}
34+
width={width}
35+
data-spacefinder-role="inline"
3536
>
36-
{assets.map((asset, index) => (
37-
<source key={index} src={asset.url} type={asset.mimeType} />
38-
))}
39-
<p>
40-
{`Your browser doesn't support HTML5 video. Here is a `}
41-
<a href={assets[0]?.url}>link to the video</a> instead.
42-
</p>
43-
</video>
44-
</MaintainAspectRatio>
37+
{/* eslint-disable-next-line jsx-a11y/media-has-caption -- caption not available */}
38+
<video
39+
controls={true}
40+
preload="metadata"
41+
width={width}
42+
height={height}
43+
poster={poster}
44+
>
45+
{assets.map((asset, index) => (
46+
<source
47+
key={index}
48+
src={asset.url}
49+
type={asset.mimeType}
50+
/>
51+
))}
52+
<p>
53+
{`Your browser doesn't support HTML5 video. Here is a `}
54+
<a href={assets[0]?.url}>link to the video</a> instead.
55+
</p>
56+
</video>
57+
</MaintainAspectRatio>
58+
{!!caption && (
59+
<Caption
60+
captionText={caption}
61+
format={format}
62+
mediaType="Video"
63+
isMainMedia={isMainMedia}
64+
/>
65+
)}
66+
</>
4567
);
4668
};

dotcom-rendering/src/lib/renderElement.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,11 @@ export const renderElement = ({
478478
case 'model.dotcomrendering.pageElements.MediaAtomBlockElement':
479479
return (
480480
<VideoAtom
481+
format={format}
481482
assets={element.assets}
482483
poster={element.posterImage?.[0]?.url}
484+
caption={element.title}
485+
isMainMedia={isMainMedia}
483486
/>
484487
);
485488
case 'model.dotcomrendering.pageElements.MiniProfilesBlockElement':

0 commit comments

Comments
 (0)