🎥 Make videos programmatically with React
keyboard shortcuts + permalinks
Jonny Burger65e4d30073f6
diff --git a/packages/docs/src/components/VideoPlayer.tsx b/packages/docs/src/components/VideoPlayer.tsxindex ffe20e7bdd..8709dcc52a 100644--- a/packages/docs/src/components/VideoPlayer.tsx+++ b/packages/docs/src/components/VideoPlayer.tsx@@ -106,6 +106,31 @@ export const VideoPlayer: React.FC<{};}, [dismiss, video]);+ useEffect(() => {+ if (!video) {+ return;+ }++ const onKeyPress = (e: KeyboardEvent) => {+ if (hasNext && e.key === "ArrowRight") {+ toNext();+ }++ if (hasPrevious && e.key === "ArrowLeft") {+ toPrevious();+ }++ if (hasPrevious && e.key === "Escape") {+ dismiss();+ }+ };++ window.addEventListener("keyup", onKeyPress);+ return () => {+ window.removeEventListener("keyup", onKeyPress);+ };+ }, [dismiss, hasNext, hasPrevious, toNext, toPrevious, video]);+if (!video) {return null;}diff --git a/packages/docs/src/pages/showcase/index.tsx b/packages/docs/src/pages/showcase/index.tsxindex 0c3ff01a4d..c5e139f6fd 100644--- a/packages/docs/src/pages/showcase/index.tsx+++ b/packages/docs/src/pages/showcase/index.tsx@@ -1,6 +1,6 @@import Layout from "@theme/Layout";import clsx from "clsx";-import React, { useCallback, useMemo, useState } from "react";+import React, { useCallback, useEffect, useMemo, useState } from "react";import { VideoPlayer } from "../../components/VideoPlayer";import { VideoPreview } from "../../components/VideoPreview";import { ShowcaseVideo, showcaseVideos } from "../../data/showcase-videos";@@ -13,8 +13,8 @@ const PageHeader: React.FC = () => {<div style={{ flex: 1 }}><h1 className={headerStyles.title}>Showcase</h1><p>- Use your React knowledge to create real MP4 videos. Feel free to pull- request your creations!+ Some awesome creations from the community, many with source code. Have+ you made your own video with Remotion? Add it to the showcase!</p></div></div>@@ -22,7 +22,17 @@ const PageHeader: React.FC = () => {};const Showcase = () => {- const [video, setVideo] = useState<ShowcaseVideo | null>(null);+ const [video, setVideo] = useState<ShowcaseVideo | null>(() => {+ if (!window.location.hash) {+ return null;+ }++ return (+ showcaseVideos.find(+ (v) => v.muxId === window.location.hash.replace("#", "")+ ) ?? null+ );+ });const currentIndex = useMemo(() => {if (video === null) {@@ -32,6 +42,12 @@ const Showcase = () => {return showcaseVideos.findIndex((v) => v.muxId === video.muxId);}, [video]);+ useEffect(() => {+ if (video) {+ window.location.hash = video.muxId;+ }+ }, [video]);+const hasNext = currentIndex < showcaseVideos.length - 1;const hasPrevious = currentIndex > 0;@@ -57,7 +73,7 @@ const Showcase = () => {return (<Layout- title="Write videos in React"+ title="Showcase"description="Create MP4 motion graphics in React. Leverage CSS, SVG, WebGL and more technologies to render videos programmatically!"><header className={clsx("hero ", styles.heroBanner)}>diff --git a/packages/docs/src/pages/showcase/styles.module.css b/packages/docs/src/pages/showcase/styles.module.cssindex 5cce09705c..db81c698d8 100644--- a/packages/docs/src/pages/showcase/styles.module.css+++ b/packages/docs/src/pages/showcase/styles.module.css@@ -6,7 +6,8 @@*/.heroBanner {- padding: 4rem 0;+ padding-top: 4rem;+ padding-bottom: 0;text-align: center;position: relative;overflow: hidden;