Files
newsui/packages/components/src/Media/Video.tsx
T

33 lines
1000 B
TypeScript
Raw Normal View History

2026-05-20 01:30:41 +08:00
'use client';
import React, { CSSProperties } from 'react';
import { clampSpan, cx } from '@newspaperui/utils';
import { useSection } from '../layout/Section';
import { Caption } from '../text/Caption';
2026-05-19 21:09:56 +08:00
export interface VideoProps {
src: string;
poster?: string;
caption?: string;
2026-05-20 01:30:41 +08:00
credit?: string;
span?: number;
controls?: boolean;
className?: string;
style?: CSSProperties;
2026-05-19 21:09:56 +08:00
}
export const Video: React.FC<VideoProps> = ({
2026-05-20 01:30:41 +08:00
src, poster, caption, credit, span, controls = true, className, style,
2026-05-19 21:09:56 +08:00
}) => {
const section = useSection();
2026-05-20 01:30:41 +08:00
const cols = span ? clampSpan(span, section.columns) : undefined;
2026-05-19 21:09:56 +08:00
return (
2026-05-20 01:30:41 +08:00
<figure
className={cx('nui-video nui-avoid-break', className)}
style={{ margin: 0, gridColumn: cols ? `span ${cols}` : undefined, ...style }}
2026-05-19 21:09:56 +08:00
>
2026-05-20 01:30:41 +08:00
<video src={src} poster={poster} controls={controls} style={{ width: '100%', height: 'auto' }} />
{(caption || credit) && <Caption credit={credit}>{caption}</Caption>}
</figure>
2026-05-19 21:09:56 +08:00
);
};