Skip to content

🎥 Make videos programmatically with React

website updates

Jonny Burger8d5061916372
diff --git a/packages/docs/components/LandingPage/GetStartedStrip.tsx b/packages/docs/components/LandingPage/GetStartedStrip.tsx
index 37ac52cd68..0e1d782b58 100644
--- a/packages/docs/components/LandingPage/GetStartedStrip.tsx
+++ b/packages/docs/components/LandingPage/GetStartedStrip.tsx
@@ -7,54 +7,52 @@ export const GetStarted: React.FC = () => {
const [clicked, setClicked] = useState<number | null>(null);
return (
- <>
- <div className={styles.myrow}>
- <div style={{ position: "relative" }}>
- {clicked ? (
- <div key={clicked} className={styles.copied}>
- Copied!
- </div>
- ) : null}
- <div
- className={styles.codeblock}
- onClick={() => {
- navigator.clipboard.writeText("npm init video");
-
- setClicked(Date.now());
- }}
- title="Click to copy"
- >
- $ npm init video
+ <div className={styles.myrow}>
+ <div style={{ position: "relative" }}>
+ {clicked ? (
+ <div key={clicked} className={styles.copied}>
+ Copied!
</div>
- </div>
- <div style={{ width: 10 }} />
- <a className={styles.a} href="/docs">
- <BlueButton size="sm" loading={false} fullWidth={false}>
- Docs
- </BlueButton>
- </a>
- <div style={{ width: 10 }} />
- <a
- className={styles.a}
- href="https://www.youtube.com/watch?v=deg8bOoziaE"
+ ) : null}
+ <div
+ className={styles.codeblock}
+ onClick={() => {
+ navigator.clipboard.writeText("npm init video");
+
+ setClicked(Date.now());
+ }}
+ title="Click to copy"
>
- <BlueButton size="sm" loading={false} fullWidth={false}>
- Watch demo
- </BlueButton>
- </a>
- <div style={{ width: 10 }} />
- <a className={styles.a} href="/docs">
- <BlueButton size="sm" loading={false} fullWidth={false}>
- Discord
- </BlueButton>
- </a>
- <div style={{ width: 10 }} />
- <a className={styles.a} href="https://github.com/remotion-dev/remotion">
- <BlueButton size="sm" loading={false} fullWidth={false}>
- <GithubButton />
- </BlueButton>
- </a>
+ $ npm init video
+ </div>
</div>
- </>
+ <div style={{ width: 10 }} />
+ <a className={styles.a} href="/docs">
+ <BlueButton size="sm" loading={false} fullWidth={false}>
+ Docs
+ </BlueButton>
+ </a>
+ <div style={{ width: 10 }} />
+ <a
+ className={styles.a}
+ href="https://www.youtube.com/watch?v=deg8bOoziaE"
+ >
+ <BlueButton size="sm" loading={false} fullWidth={false}>
+ Watch demo
+ </BlueButton>
+ </a>
+ <div style={{ width: 10 }} />
+ <a className={styles.a} href="/docs">
+ <BlueButton size="sm" loading={false} fullWidth={false}>
+ Discord
+ </BlueButton>
+ </a>
+ <div style={{ width: 10 }} />
+ <a className={styles.a} href="https://github.com/remotion-dev/remotion">
+ <BlueButton size="sm" loading={false} fullWidth={false}>
+ <GithubButton />
+ </BlueButton>
+ </a>
+ </div>
);
};
diff --git a/packages/docs/src/components/ArrowRight.tsx b/packages/docs/src/components/ArrowRight.tsx
new file mode 100644
index 0000000000..bb2768ff46
--- /dev/null
+++ b/packages/docs/src/components/ArrowRight.tsx
@@ -0,0 +1,87 @@
+import React from "react";
+
+const commonStyle: React.CSSProperties = {
+ height: 40,
+ width: 40,
+ borderRadius: 20,
+ boxShadow: "0 0 6px rgba(0, 0, 0, 0.2)",
+ position: "absolute",
+ backgroundColor: "white",
+ top: 24,
+ color: "var(--light-text-color)",
+ justifyContent: "center",
+ alignItems: "center",
+ display: "flex",
+ cursor: "pointer",
+ transition: `transform 0.3s`,
+};
+
+const rightStyle: React.CSSProperties = {
+ ...commonStyle,
+ right: 0,
+};
+
+const leftStyle: React.CSSProperties = {
+ ...commonStyle,
+ left: 0,
+};
+
+const icon: React.CSSProperties = {
+ height: 22,
+};
+
+export const NavigateRight: React.FC<{
+ onClick: () => void;
+ visible: boolean;
+}> = ({ onClick, visible }) => {
+ return (
+ <a
+ style={{
+ ...rightStyle,
+ transform: `scale(
+ ${Number(visible)}
+ )`,
+ }}
+ onClick={onClick}
+ >
+ <svg
+ style={icon}
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 448 512"
+ >
+ <path
+ fill="currentColor"
+ d="M438.6 278.6l-160 160C272.4 444.9 264.2 448 256 448s-16.38-3.125-22.62-9.375c-12.5-12.5-12.5-32.75 0-45.25L338.8 288H32C14.33 288 .0016 273.7 .0016 256S14.33 224 32 224h306.8l-105.4-105.4c-12.5-12.5-12.5-32.75 0-45.25s32.75-12.5 45.25 0l160 160C451.1 245.9 451.1 266.1 438.6 278.6z"
+ />
+ </svg>
+ </a>
+ );
+};
+
+export const NavigateLeft: React.FC<{
+ onClick: () => void;
+ visible: boolean;
+}> = ({ onClick, visible }) => {
+ return (
+ <a
+ style={{
+ ...leftStyle,
+ transform: `scale(
+ ${Number(visible)}
+ )`,
+ }}
+ onClick={onClick}
+ >
+ <svg
+ style={icon}
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 448 512"
+ >
+ <path
+ fill="currentColor"
+ d="M447.1 256C447.1 273.7 433.7 288 416 288H109.3l105.4 105.4c12.5 12.5 12.5 32.75 0 45.25C208.4 444.9 200.2 448 192 448s-16.38-3.125-22.62-9.375l-160-160c-12.5-12.5-12.5-32.75 0-45.25l160-160c12.5-12.5 32.75-12.5 45.25 0s12.5 32.75 0 45.25L109.3 224H416C433.7 224 447.1 238.3 447.1 256z"
+ />
+ </svg>{" "}
+ </a>
+ );
+};
diff --git a/packages/docs/src/components/ChooseTemplate.tsx b/packages/docs/src/components/ChooseTemplate.tsx
index 507d75425e..32fdf24d55 100644
--- a/packages/docs/src/components/ChooseTemplate.tsx
+++ b/packages/docs/src/components/ChooseTemplate.tsx
@@ -1,4 +1,4 @@
-import React, { useCallback, useState } from "react";
+import React, { useCallback, useEffect, useRef, useState } from "react";
import type { Template } from "create-video";
import { CreateVideoInternals } from "create-video";
import { TemplateModal } from "./TemplateModal";
@@ -12,6 +12,8 @@ import { Waveform } from "./icons/waveform";
import { TemplateIcon } from "./TemplateIcon";
import { chunk } from "../helpers/chunk";
import { useElementSize } from "../helpers/use-el-size";
+import { NavigateLeft, NavigateRight } from "./ArrowRight";
+import { useMobileLayout } from "../helpers/mobile-layout";
const IconForTemplate: React.FC<{
template: Template;
@@ -98,10 +100,7 @@ const IconForTemplate: React.FC<{
export const ChooseTemplate: React.FC = () => {
const [modal, setModal] = useState<Template | null>(null);
- const containerSize = useElementSize(
- typeof document === "undefined" ? null : document.body
- );
- const mobileLayout = (containerSize?.width ?? Infinity) < 900;
+ const mobileLayout = useMobileLayout();
const onClick = useCallback((template: Template) => {
setModal(template);
@@ -111,8 +110,45 @@ export const ChooseTemplate: React.FC = () => {
setModal(null);
}, []);
+ const [rightVisible, setRightVisible] = useState(true);
+ const [leftVisible, setLeftVisible] = useState(false);
+
const chunks = chunk(CreateVideoInternals.FEATURED_TEMPLATES, 4);
+ const scrollable = useRef<HTMLDivElement>(null);
+ const inner = useRef<HTMLDivElement>(null);
+
+ const onClickRight = useCallback(() => {
+ scrollable.current.scrollTo({
+ left: 1000,
+ });
+ }, []);
+
+ const onClickLeft = useCallback(() => {
+ scrollable.current.scrollTo({
+ left: 0,
+ });
+ }, []);
+
+ useEffect(() => {
+ const listener = (e: Event) => {
+ const scrollLeft = (e.target as HTMLDivElement).scrollLeft as number;
+ const { width } = (e.target as HTMLDivElement).getClientRects()[0];
+ const { width: innerWidth } = inner.current.getClientRects()[0];
+ const fromRight = width - innerWidth - scrollLeft;
+ setRightVisible(fromRight > 40);
+ setLeftVisible(scrollLeft > 20);
+ };
+
+ const { current } = scrollable;
+
+ current.addEventListener("scroll", listener);
+
+ return () => {
+ current.removeEventListener("scroll", listener);
+ };
+ }, []);
+
return (
<div
style={{
@@ -125,38 +161,54 @@ export const ChooseTemplate: React.FC = () => {
) : null}
<div
style={{
- display: "flex",
- flexDirection: "row",
- justifyContent: mobileLayout ? "flex-start" : "center",
- maxWidth: "100%",
- overflowX: "auto",
+ position: "relative",
}}
>
- {chunks.map((c) => {
- return (
- <div
- key={c.map((_) => _.cliId).join("-")}
- style={{
- display: "flex",
- flexDirection: "row",
- marginBottom: mobileLayout ? 8 : 0,
- marginTop: mobileLayout ? 8 : 0,
- }}
- >
- {c.map((template) => {
- return (
- <TemplateIcon
- key={template.cliId}
- onClick={() => onClick(template)}
- label={template.homePageLabel}
- >
- <IconForTemplate template={template} />
- </TemplateIcon>
- );
- })}
- </div>
- );
- })}
+ <div
+ ref={scrollable}
+ className="no-scroll-bar"
+ style={{
+ display: "flex",
+ flexDirection: "row",
+ justifyContent: mobileLayout ? "flex-start" : "center",
+ maxWidth: "100%",
+ overflowX: "auto",
+ scrollBehavior: "smooth",
+ }}
+ >
+ {chunks.map((c) => {
+ return (
+ <div
+ ref={inner}
+ key={c.map((_) => _.cliId).join("-")}
+ style={{
+ display: "flex",
+ flexDirection: "row",
+ marginBottom: mobileLayout ? 8 : 0,
+ marginTop: mobileLayout ? 8 : 0,
+ }}
+ >
+ {c.map((template) => {
+ return (
+ <TemplateIcon
+ key={template.cliId}
+ onClick={() => onClick(template)}
+ label={template.homePageLabel}
+ >
+ <IconForTemplate template={template} />
+ </TemplateIcon>
+ );
+ })}
+ </div>
+ );
+ })}
+ </div>
+ {mobileLayout ? (
+ <NavigateLeft visible={leftVisible} onClick={onClickLeft} />
+ ) : null}
+ {mobileLayout ? (
+ <NavigateRight visible={rightVisible} onClick={onClickRight} />
+ ) : null}
</div>
</div>
);
diff --git a/packages/docs/src/components/TemplateModalContent.tsx b/packages/docs/src/components/TemplateModalContent.tsx
index 169dbebeaa..4d36d1935d 100644
--- a/packages/docs/src/components/TemplateModalContent.tsx
+++ b/packages/docs/src/components/TemplateModalContent.tsx
@@ -1,5 +1,6 @@
import type { Template } from "create-video";
import React, { useCallback, useMemo, useState } from "react";
+import { useMobileLayout } from "../helpers/mobile-layout";
import { useElementSize } from "../helpers/use-el-size";
import { CommandCopyButton } from "./CommandCopyButton";
import { MuxVideo } from "./MuxVideo";
@@ -108,7 +109,7 @@ export const TemplateModalContent: React.FC<{
const containerSize = useElementSize(
typeof document === "undefined" ? null : document.body
);
- const mobileLayout = (containerSize?.width ?? Infinity) < 900;
+ const mobileLayout = useMobileLayout();
const containerCss: React.CSSProperties = useMemo(() => {
return {
diff --git a/packages/docs/src/components/VideoPlayer.tsx b/packages/docs/src/components/VideoPlayer.tsx
index 711535190e..dcba2c6cdd 100644
--- a/packages/docs/src/components/VideoPlayer.tsx
+++ b/packages/docs/src/components/VideoPlayer.tsx
@@ -1,5 +1,6 @@
import React, { useEffect, useMemo, useRef } from "react";
import type { ShowcaseVideo } from "../data/showcase-videos";
+import { useMobileLayout } from "../helpers/mobile-layout";
import { useElementSize } from "../helpers/use-el-size";
import { CancelIcon, IconLeft, IconRight } from "../icons/arrows";
import { VideoPlayerContent } from "./VideoPlayerContent";
@@ -65,10 +66,7 @@ export const VideoPlayer: React.FC<{
hasPrevious,
userHasInteractedWithPage,
}) => {
- const containerSize = useElementSize(
- typeof document === "undefined" ? null : document.body
- );
- const mobileLayout = (containerSize?.width ?? Infinity) < 900;
+ const mobileLayout = useMobileLayout();
const containerWithDirection: React.CSSProperties = useMemo(() => {
return {
diff --git a/packages/docs/src/components/VideoPlayerContent.tsx b/packages/docs/src/components/VideoPlayerContent.tsx
index 59c1c85afa..4a364b4639 100644
--- a/packages/docs/src/components/VideoPlayerContent.tsx
+++ b/packages/docs/src/components/VideoPlayerContent.tsx
@@ -6,6 +6,7 @@ import React, {
useState,
} from "react";
import type { ShowcaseVideo } from "../data/showcase-videos";
+import { useMobileLayout } from "../helpers/mobile-layout";
import { useElementSize } from "../helpers/use-el-size";
import { PausedIcon } from "../icons/arrows";
import { MuxVideo } from "./MuxVideo";
@@ -65,7 +66,7 @@ export const VideoPlayerContent: React.FC<{
const containerSize = useElementSize(
typeof document === "undefined" ? null : document.body
);
- const mobileLayout = (containerSize?.width ?? Infinity) < 900;
+ const mobileLayout = useMobileLayout();
const possibleVideoWidth = mobileLayout
? containerSize?.width
diff --git a/packages/docs/src/css/custom.css b/packages/docs/src/css/custom.css
index 4cf8d2a9e7..4450770c0a 100644
--- a/packages/docs/src/css/custom.css
+++ b/packages/docs/src/css/custom.css
@@ -125,3 +125,7 @@ code {
text-underline-position: under;
text-decoration: underline;
}
+
+.no-scroll-bar::-webkit-scrollbar {
+ display: none;
+}
diff --git a/packages/docs/src/helpers/mobile-layout.ts b/packages/docs/src/helpers/mobile-layout.ts
new file mode 100644
index 0000000000..d83be5ac22
--- /dev/null
+++ b/packages/docs/src/helpers/mobile-layout.ts
@@ -0,0 +1,8 @@
+import { useElementSize } from "./use-el-size";
+
+export const useMobileLayout = () => {
+ const containerSize = useElementSize(
+ typeof document === "undefined" ? null : document.body
+ );
+ return (containerSize?.width ?? Infinity) < 900;
+};
diff --git a/packages/docs/src/pages/showcase/index.tsx b/packages/docs/src/pages/showcase/index.tsx
index b923998fbc..e6216fd574 100644
--- a/packages/docs/src/pages/showcase/index.tsx
+++ b/packages/docs/src/pages/showcase/index.tsx
@@ -4,13 +4,13 @@ import clsx from "clsx";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import { VideoPlayer } from "../../components/VideoPlayer";
import { VideoPreview } from "../../components/VideoPreview";
-import type {
- ShowcaseVideo} from "../../data/showcase-videos";
+import type { ShowcaseVideo } from "../../data/showcase-videos";
import {
showcaseVideos,
shuffledShowcaseVideos,
} from "../../data/showcase-videos";
import { chunk } from "../../helpers/chunk";
+import { useMobileLayout } from "../../helpers/mobile-layout";
import { useElementSize } from "../../helpers/use-el-size";
import headerStyles from "./header.module.css";
import styles from "./styles.module.css";
@@ -44,7 +44,7 @@ const Showcase = () => {
const containerSize = useElementSize(
typeof document === "undefined" ? null : document.body
);
- const mobileLayout = (containerSize?.width ?? Infinity) < 1200;
+ const mobileLayout = useMobileLayout();
const mobileHeight = mobileLayout ? containerSize.width : null;
const [userHasInteractedWithPage, setUserHasInteractedWithPage] =