Skip to content

Commit ca2b4fe

Browse files
committed
Add content link support to VideoPlayer
- Add `alt` field to Video type for DatoCMS Content Link integration - Pass `alt` as `data-datocms-content-link-source` attribute to enable click-to-edit overlays - Document how custom data-* attributes can be passed to the underlying <mux-player> web component (kebab-case or camelCase)
1 parent 8ada688 commit ca2b4fe

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/VideoPlayer/index.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type Possibly<T> = Maybe<T> | undefined;
3737
export type Video = {
3838
/** Title attribute (`title`) for the video */
3939
title?: Possibly<string>;
40+
/** Alt attribute used for content link integration (passed as data-datocms-content-link-source) */
41+
alt?: Possibly<string>;
4042
/** The height of the video */
4143
height?: Possibly<number>;
4244
/** The width of the video */
@@ -92,6 +94,26 @@ export const VideoPlayer: (
9294
...styleFromProps,
9395
};
9496

97+
// Extract alt for DatoCMS Content Link integration
98+
// See: https://github.com/datocms/content-link
99+
const { alt } = data;
100+
101+
// Note: Custom data-* attributes can be passed to the underlying <mux-player> web component
102+
// in two ways:
103+
//
104+
// 1. Kebab-case (passes through as-is):
105+
// <VideoPlayer data-player-id="my-player" />
106+
//
107+
// 2. CamelCase (auto-converts to kebab-case):
108+
// <VideoPlayer dataPlayerId="my-player" />
109+
//
110+
// Both result in: <mux-player data-player-id="my-player">
111+
//
112+
// The MuxPlayer React component transforms camelCase props to kebab-case to match
113+
// web component attribute conventions. Any props not explicitly handled by VideoPlayer
114+
// are spread via {...rest} and forwarded to MuxPlayer, which then applies them to
115+
// the underlying <mux-player> element.
116+
95117
return (
96118
<MuxPlayer
97119
ref={ref}
@@ -103,6 +125,7 @@ export const VideoPlayer: (
103125
playbackId={playbackId}
104126
style={style}
105127
placeholder={placeholder}
128+
data-datocms-content-link-source={alt}
106129
{...rest}
107130
/>
108131
);

0 commit comments

Comments
 (0)