Skip to content

🎥 Make videos programmatically with React

looks okay on mobile

Jonny Burger977a0077cf4f
diff --git a/packages/docs/src/components/ChooseTemplate.tsx b/packages/docs/src/components/ChooseTemplate.tsx
index ee8abc96b5..609485ef08 100644
--- a/packages/docs/src/components/ChooseTemplate.tsx
+++ b/packages/docs/src/components/ChooseTemplate.tsx
@@ -9,6 +9,8 @@ import { TypeScriptIcon } from "../pages/icons/ts";
import { TTSIcon } from "../pages/icons/tts";
import { Waveform } from "../pages/icons/waveform";
import { TemplateIcon } from "../pages/template-icon";
+import { chunk } from "../helpers/chunk";
+import { useElementSize } from "../helpers/use-el-size";
const IconForTemplate: React.FC<{
template: Template;
@@ -93,6 +95,11 @@ 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 onClick = useCallback((template: Template) => {
setModal(template);
}, []);
@@ -101,6 +108,8 @@ export const ChooseTemplate: React.FC = () => {
setModal(null);
}, []);
+ const chunks = chunk(CreateVideoInternals.FEATURED_TEMPLATES, 4);
+
return (
<div
style={{
@@ -118,18 +127,32 @@ export const ChooseTemplate: React.FC = () => {
<div
style={{
display: "flex",
- flexDirection: "row",
+ flexDirection: mobileLayout ? "column" : "row",
justifyContent: "center",
}}
>
- {CreateVideoInternals.FEATURED_TEMPLATES.map((template) => {
+ {chunks.map((c) => {
return (
- <TemplateIcon
- onClick={() => onClick(template)}
- label={template.homePageLabel}
+ <div
+ style={{
+ display: "flex",
+ flexDirection: "row",
+ justifyContent: "center",
+ marginBottom: mobileLayout ? 8 : 0,
+ marginTop: mobileLayout ? 8 : 0,
+ }}
>
- <IconForTemplate template={template} />
- </TemplateIcon>
+ {c.map((template) => {
+ return (
+ <TemplateIcon
+ onClick={() => onClick(template)}
+ label={template.homePageLabel}
+ >
+ <IconForTemplate template={template} />
+ </TemplateIcon>
+ );
+ })}
+ </div>
);
})}
</div>
diff --git a/packages/docs/src/components/TemplateModal.tsx b/packages/docs/src/components/TemplateModal.tsx
index b577ef9919..da7d846815 100644
--- a/packages/docs/src/components/TemplateModal.tsx
+++ b/packages/docs/src/components/TemplateModal.tsx
@@ -54,6 +54,7 @@ export const TemplateModal: React.FC<{
<div ref={inner}>
<TemplateModalContent
template={selectedTemplate}
+ onDismiss={onDismiss}
></TemplateModalContent>
</div>
</div>
diff --git a/packages/docs/src/components/TemplateModalContent.tsx b/packages/docs/src/components/TemplateModalContent.tsx
index 26e342889b..262859df45 100644
--- a/packages/docs/src/components/TemplateModalContent.tsx
+++ b/packages/docs/src/components/TemplateModalContent.tsx
@@ -99,7 +99,8 @@ let copyTimeout: NodeJS.Timeout | null = null;
export const TemplateModalContent: React.FC<{
template: Template;
-}> = ({ template }) => {
+ onDismiss: () => void;
+}> = ({ template, onDismiss }) => {
const [copied, setCopied] = useState<string | false>(false);
const [showPkgManagers, setShowPackageManagers] = useState(false);
const [loaded, setLoaded] = useState(false);
@@ -151,22 +152,22 @@ export const TemplateModalContent: React.FC<{
setLoaded(true);
}, []);
- const copyCommand = useCallback((command: string) => {
+ const copyCommand = useCallback(async (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) => {
- alert("Copying is not supported on this device");
- console.log("Could not copy command", err);
+ try {
+ const result = await navigator.permissions.query({
+ name: permissionName,
});
+ if (result.state === "granted" || result.state === "prompt") {
+ navigator.clipboard.writeText(command);
+ setCopied(command);
+ }
+ console.log(result.state);
+ } catch (err) {
+ alert("Copying is not supported on this device");
+ console.log("Could not copy command", err);
+ }
copyTimeout = setTimeout(() => {
setCopied(false);
}, 2000);
@@ -202,13 +203,53 @@ export const TemplateModalContent: React.FC<{
onLoadedMetadata={onLoadedMetadata}
/>
</div>
- <div style={column}>
- <h1>{template.shortName}</h1>
+ <div
+ style={{
+ ...column,
+ width: mobileLayout ? "100%" : RESERVED_FOR_SIDEBAR,
+ }}
+ >
+ <div
+ style={{
+ display: "flex",
+ flexDirection: "row",
+ alignItems: "center",
+ }}
+ >
+ <div style={{ flex: 1 }}>
+ <h1
+ style={{
+ marginTop: 0,
+ marginBottom: 0,
+ }}
+ >
+ {template.shortName}
+ </h1>
+ </div>
+ <a
+ style={{
+ cursor: "pointer",
+ opacity: 0.4,
+ display: "inline-flex",
+ }}
+ onClick={onDismiss}
+ >
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 320 512"
+ style={{
+ height: 24,
+ }}
+ >
+ <path d="M310.6 361.4c12.5 12.5 12.5 32.75 0 45.25C304.4 412.9 296.2 416 288 416s-16.38-3.125-22.62-9.375L160 301.3L54.63 406.6C48.38 412.9 40.19 416 32 416S15.63 412.9 9.375 406.6c-12.5-12.5-12.5-32.75 0-45.25l105.4-105.4L9.375 150.6c-12.5-12.5-12.5-32.75 0-45.25s32.75-12.5 45.25 0L160 210.8l105.4-105.4c12.5-12.5 32.75-12.5 45.25 0s12.5 32.75 0 45.25l-105.4 105.4L310.6 361.4z" />
+ </svg>
+ </a>
+ </div>
+ <br></br>
<div style={description}>{template.longerDescription}</div>
<br />
-
<div style={githubrow}>
- <a style={link} onClick={() => copyCommand("npm init video")}>
+ <a style={link} onPointerDown={() => copyCommand("npm init video")}>
<div style={iconContainer}>
<CommandCopyButton
copied={copied === "npm init video"}
@@ -217,7 +258,7 @@ export const TemplateModalContent: React.FC<{
<div style={installCommand}>npm init video</div>
</a>
<div style={{ flex: 1 }}></div>
- <a style={link} onClick={togglePkgManagers}>
+ <a style={link} onPointerDown={togglePkgManagers}>
<span
style={{ whiteSpace: "pre", color: "var(--light-text-color)" }}
>
@@ -232,7 +273,10 @@ export const TemplateModalContent: React.FC<{
</div>
{showPkgManagers ? (
<div style={githubrow}>
- <a style={link} onClick={() => copyCommand("pnpm create video")}>
+ <a
+ style={link}
+ onPointerDown={() => copyCommand("pnpm create video")}
+ >
<div style={iconContainer}>
<CommandCopyButton
copied={copied === "pnpm create video"}
@@ -244,7 +288,11 @@ export const TemplateModalContent: React.FC<{
) : null}
{showPkgManagers ? (
<div style={githubrow}>
- <a style={link} onClick={() => copyCommand("yarn create video")}>
+ <a
+ target={"_blank"}
+ style={link}
+ onPointerDown={() => copyCommand("yarn create video")}
+ >
<div style={iconContainer}>
<CommandCopyButton
copied={copied === "yarn create video"}
@@ -256,6 +304,7 @@ export const TemplateModalContent: React.FC<{
) : null}
<div style={githubrow}>
<a
+ target={"_blank"}
style={link}
href={`https://github.com/${template.org}/${template.repoName}/generate`}
>
diff --git a/packages/docs/src/pages/index.tsx b/packages/docs/src/pages/index.tsx
index 14c28f46e5..9fe17c2ba0 100644
--- a/packages/docs/src/pages/index.tsx
+++ b/packages/docs/src/pages/index.tsx
@@ -30,7 +30,7 @@ const NewLanding: React.FC = () => {
return (
<Layout>
<Head>
- <title>Write videos in React</title>
+ <title>Remotion | Write videos in React</title>
<meta
name="description"
content="Create MP4 motion graphics in React. Leverage CSS, SVG, WebGL and more