Skip to content

🎥 Make videos programmatically with React

play button

Jonny Burgerbe9df7990238
diff --git a/packages/docs/src/components/VideoPlayerContent.tsx b/packages/docs/src/components/VideoPlayerContent.tsx
index a84e37e94f..beb8cfd649 100644
--- a/packages/docs/src/components/VideoPlayerContent.tsx
+++ b/packages/docs/src/components/VideoPlayerContent.tsx
@@ -8,6 +8,7 @@ import React, {
} from "react";
import { ShowcaseVideo } from "../data/showcase-videos";
import { useElementSize } from "../helpers/use-el-size";
+import { PausedIcon } from "../icons/arrows";
import { Spinner } from "./Spinner";
import { SHOWCASE_MOBILE_HEADER_HEIGHT } from "./VideoPlayerHeader";
import { VideoSidebar } from "./VideoSidebar";
@@ -35,6 +36,17 @@ const loadingContainer: React.CSSProperties = {
display: "flex",
};
+const pausedContainer: React.CSSProperties = {
+ ...loadingContainer,
+ pointerEvents: "none",
+};
+
+const pausedIconStyle: React.CSSProperties = {
+ color: "white",
+ width: 50,
+ filter: `drop-shadow(0 0 5px rgba(0, 0, 0, 0.3))`,
+};
+
export const PAGINATE_ICON_WIDTH = 24;
export const PAGINATE_ICON_PADDING = 20;
export const PAGINATE_BUTTONS_WIDTH =
@@ -56,6 +68,8 @@ export const VideoPlayerContent: React.FC<{ video: ShowcaseVideo }> = ({
const container = useRef<HTMLDivElement>(null);
const vidUrl = getVideoToPlayUrl(video);
+ const [paused, setPaused] = useState(false);
+
const containerSize = useElementSize(
typeof document === "undefined" ? null : document.body
);
@@ -129,6 +143,37 @@ export const VideoPlayerContent: React.FC<{ video: ShowcaseVideo }> = ({
};
}, [height, width]);
+ useEffect(() => {
+ const { current } = videoRef;
+
+ if (!current) {
+ return;
+ }
+
+ const onClick = () => {
+ if (videoRef.current.paused) {
+ videoRef.current.play();
+ setPaused(false);
+ } else {
+ videoRef.current.pause();
+ setPaused(true);
+ }
+ };
+
+ current.addEventListener("click", onClick);
+ return () => {
+ current.removeEventListener("click", onClick);
+ };
+ }, []);
+
+ const loadingContainerStyle: React.CSSProperties = useMemo(() => {
+ return {
+ ...pausedContainer,
+ height,
+ width,
+ };
+ }, [height, width]);
+
return (
<div ref={container} style={containerCss}>
{mobileLayout ? (
@@ -149,6 +194,12 @@ export const VideoPlayerContent: React.FC<{ video: ShowcaseVideo }> = ({
width={width}
autoPlay
/>
+ {paused ? (
+ <div style={loadingContainerStyle}>
+ <PausedIcon style={pausedIconStyle} />
+ </div>
+ ) : null}
+
<div style={sidebar}>
<VideoSidebar video={video} />
</div>
diff --git a/packages/docs/src/icons/arrows.tsx b/packages/docs/src/icons/arrows.tsx
index 5ccf9be813..47a7c63a9c 100644
--- a/packages/docs/src/icons/arrows.tsx
+++ b/packages/docs/src/icons/arrows.tsx
@@ -28,7 +28,7 @@ export const CancelIcon: React.FC<SVGProps<SVGSVGElement>> = (props) => {
role="img"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 352 512"
- {...props}>
+ {...props}
>
<path
fill="currentColor"
@@ -37,3 +37,24 @@ export const CancelIcon: React.FC<SVGProps<SVGSVGElement>> = (props) => {
</svg>
);
};
+
+export const PausedIcon: React.FC<SVGProps<SVGSVGElement>> = (props) => {
+ return (
+ <svg
+ aria-hidden="true"
+ focusable="false"
+ data-prefix="fas"
+ data-icon="play"
+ className="svg-inline--fa fa-play fa-w-14"
+ role="img"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 448 512"
+ {...props}
+ >
+ <path
+ fill="currentColor"
+ d="M424.4 214.7L72.4 6.6C43.8-10.3 0 6.1 0 47.9V464c0 37.5 40.7 60.1 72.4 41.3l352-208c31.4-18.5 31.5-64.1 0-82.6z"
+ />
+ </svg>
+ );
+};