Skip to content

🎥 Make videos programmatically with React

copy templates

Jonny Burgerbe44ed4a7097
diff --git a/packages/docs/src/components/CommandCopyButton.tsx b/packages/docs/src/components/CommandCopyButton.tsx
new file mode 100644
index 0000000000..127028056b
--- /dev/null
+++ b/packages/docs/src/components/CommandCopyButton.tsx
@@ -0,0 +1,34 @@
+import React from "react";
+
+export const CommandCopyButton: React.FC<{
+ copied: boolean;
+}> = ({ copied }) => {
+ return (
+ <>
+ {copied ? (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 448 512"
+ style={{
+ height: 20,
+ }}
+ >
+ <path d="M438.6 105.4C451.1 117.9 451.1 138.1 438.6 150.6L182.6 406.6C170.1 419.1 149.9 419.1 137.4 406.6L9.372 278.6C-3.124 266.1-3.124 245.9 9.372 233.4C21.87 220.9 42.13 220.9 54.63 233.4L159.1 338.7L393.4 105.4C405.9 92.88 426.1 92.88 438.6 105.4H438.6z" />
+ </svg>
+ ) : (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 384 512"
+ style={{
+ height: 20,
+ }}
+ >
+ <path
+ fill="currentColor"
+ d="M320 64h-49.61C262.1 27.48 230.7 0 192 0S121 27.48 113.6 64H64C28.65 64 0 92.66 0 128v320c0 35.34 28.65 64 64 64h256c35.35 0 64-28.66 64-64V128C384 92.66 355.3 64 320 64zM192 48c13.23 0 24 10.77 24 24S205.2 96 192 96S168 85.23 168 72S178.8 48 192 48zM336 448c0 8.82-7.178 16-16 16H64c-8.822 0-16-7.18-16-16V128c0-8.82 7.178-16 16-16h18.26C80.93 117.1 80 122.4 80 128v16C80 152.8 87.16 160 96 160h192c8.836 0 16-7.164 16-16V128c0-5.559-.9316-10.86-2.264-16H320c8.822 0 16 7.18 16 16V448z"
+ />
+ </svg>
+ )}
+ </>
+ );
+};
diff --git a/packages/docs/src/components/Spinner.tsx b/packages/docs/src/components/Spinner.tsx
index 482573c7ab..e8651551cb 100644
--- a/packages/docs/src/components/Spinner.tsx
+++ b/packages/docs/src/components/Spinner.tsx
@@ -8,7 +8,7 @@ export const Spinner: React.FC<SVGProps<SVGSVGElement>> = (props) => {
viewBox="0 0 32 32"
width="32"
height="32"
- fill="black"
+ fill="currentColor"
{...props}
>
<path opacity=".1" d="M14 0 H18 V8 H14 z" transform="rotate(0 16 16)">
diff --git a/packages/docs/src/components/TemplateModalContent.tsx b/packages/docs/src/components/TemplateModalContent.tsx
index e4c248d6bd..ce93aae1ac 100644
--- a/packages/docs/src/components/TemplateModalContent.tsx
+++ b/packages/docs/src/components/TemplateModalContent.tsx
@@ -1,6 +1,7 @@
import { Template } from "create-video";
import React, { useCallback, useMemo, useState } from "react";
import { useElementSize } from "../helpers/use-el-size";
+import { CommandCopyButton } from "./CommandCopyButton";
import { MuxVideo } from "./MuxVideo";
import { Spinner } from "./Spinner";
@@ -28,6 +29,8 @@ const link: React.CSSProperties = {
display: "inline-flex",
flexDirection: "row",
alignItems: "center",
+ cursor: "pointer",
+ userSelect: "none",
};
const description: React.CSSProperties = {
@@ -41,6 +44,7 @@ const githubrow: React.CSSProperties = {
paddingTop: 4,
paddingBottom: 4,
verticalAlign: "middle",
+ paddingRight: 16,
};
const loadingContainer: React.CSSProperties = {
@@ -50,12 +54,8 @@ const loadingContainer: React.CSSProperties = {
display: "flex",
};
-const CommandIcon: React.FC = () => {
- return (
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512" height="18">
- <path d="M96 480c-8.188 0-16.38-3.125-22.62-9.375c-12.5-12.5-12.5-32.75 0-45.25L242.8 256L73.38 86.63c-12.5-12.5-12.5-32.75 0-45.25s32.75-12.5 45.25 0l192 192c12.5 12.5 12.5 32.75 0 45.25l-192 192C112.4 476.9 104.2 480 96 480z" />
- </svg>
- );
+const installCommand: React.CSSProperties = {
+ marginRight: 12,
};
const GithubIcon: React.FC = () => {
@@ -85,9 +85,23 @@ const spinner: React.CSSProperties = {
width: 16,
};
+const separator: React.CSSProperties = {
+ height: 24,
+ backgroundColor: "var(--light-text-color)",
+ opacity: 0.2,
+ borderRadius: 1,
+ width: 1,
+ marginLeft: 10,
+ marginRight: 10,
+};
+
+let copyTimeout: NodeJS.Timeout | null = null;
+
export const TemplateModalContent: React.FC<{
template: Template;
}> = ({ template }) => {
+ const [copied, setCopied] = useState<string | false>(false);
+ const [showPkgManagers, setShowPackageManagers] = useState(false);
const [loaded, setLoaded] = useState(false);
const containerCss: React.CSSProperties = useMemo(() => {
return {
@@ -132,9 +146,37 @@ export const TemplateModalContent: React.FC<{
setLoaded(true);
}, []);
+ const copyCommand = useCallback((command: string) => {
+ clearTimeout(copyTimeout);
+ const permissionName = "clipboard-write" as PermissionName;
+ navigator.permissions
+ .query({ name: permissionName })
+ .then((result) => {
+ if (result.state === "granted" || result.state === "prompt") {
+ // TODO: Customize
+ navigator.clipboard.writeText(command);
+ setCopied(command);
+ }
+ })
+ .catch((err) => {
+ console.log("Could not copy command", err);
+ });
+ copyTimeout = setTimeout(() => {
+ setCopied(false);
+ }, 2000);
+ }, []);
+
+ const togglePkgManagers = useCallback(() => {
+ setShowPackageManagers((s) => !s);
+ }, []);
+
return (
<div style={containerCss}>
- <div>
+ <div
+ style={{
+ display: "inline",
+ }}
+ >
{loaded ? null : (
<div style={loadingStyle}>
<Spinner style={spinner} />
@@ -147,6 +189,9 @@ export const TemplateModalContent: React.FC<{
width={width}
autoPlay
muted
+ style={{
+ display: "inline",
+ }}
onLoadedMetadata={onLoadedMetadata}
/>
</div>
@@ -156,11 +201,52 @@ export const TemplateModalContent: React.FC<{
<br />
<div style={githubrow}>
- <div style={iconContainer}>
- <CommandIcon></CommandIcon>
- </div>
- npm init video
+ <a style={link} onClick={() => copyCommand("npm init video")}>
+ <div style={iconContainer}>
+ <CommandCopyButton
+ copied={copied === "npm init video"}
+ ></CommandCopyButton>
+ </div>
+ <div style={installCommand}>npm init video</div>
+ </a>
+ <div style={{ flex: 1 }}></div>
+ <a style={link} onClick={togglePkgManagers}>
+ <span
+ style={{ whiteSpace: "pre", color: "var(--light-text-color)" }}
+ >
+ Show {showPkgManagers ? "less" : "more"}
+ </span>{" "}
+ </a>
+ <div
+ style={{
+ width: 8,
+ }}
+ ></div>
</div>
+ {showPkgManagers ? (
+ <div style={githubrow}>
+ <a style={link} onClick={() => copyCommand("pnpm create video")}>
+ <div style={iconContainer}>
+ <CommandCopyButton
+ copied={copied === "pnpm create video"}
+ ></CommandCopyButton>
+ </div>
+ <div style={installCommand}>pnpm create video</div>
+ </a>
+ </div>
+ ) : null}
+ {showPkgManagers ? (
+ <div style={githubrow}>
+ <a style={link} onClick={() => copyCommand("yarn create video")}>
+ <div style={iconContainer}>
+ <CommandCopyButton
+ copied={copied === "yarn create video"}
+ ></CommandCopyButton>
+ </div>
+ <div style={installCommand}>yarn create video</div>
+ </a>
+ </div>
+ ) : null}
<div style={githubrow}>
<a
style={link}
@@ -171,15 +257,7 @@ export const TemplateModalContent: React.FC<{
</div>{" "}
Use template
</a>
- <span
- style={{
- whiteSpace: "pre",
- color: "var(--light-text-color)",
- }}
- >
- {" "}
- |{" "}
- </span>
+ <div style={separator}></div>
<a
target={"_blank"}
style={link}
diff --git a/packages/docs/src/pages/index.tsx b/packages/docs/src/pages/index.tsx
index 84a18b6fe8..14c28f46e5 100644
--- a/packages/docs/src/pages/index.tsx
+++ b/packages/docs/src/pages/index.tsx
@@ -23,7 +23,9 @@ const clone: React.CSSProperties = {
textAlign: "center",
paddingBottom: 10,
paddingTop: 10,
+ color: "var(--light-text-color)",
};
+
const NewLanding: React.FC = () => {
return (
<Layout>
@@ -49,7 +51,7 @@ const NewLanding: React.FC = () => {
paddingBottom: 20,
}}
>
- <div style={clone}>Clone a template to get started</div>
+ <div style={clone}>Get started using a template:</div>
<div className={styles.content}>
<ChooseTemplate />