Skip to content

🎥 Make videos programmatically with React

refactor installation component

JonnyBurger4f16c0a838d5
diff --git a/packages/docs/components/Installation.tsx b/packages/docs/components/Installation.tsx
index a57c4bcb1d..8145c2bdc9 100644
--- a/packages/docs/components/Installation.tsx
+++ b/packages/docs/components/Installation.tsx
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, {useState} from 'react';
// @ts-expect-error
import CodeBlock from '@theme/CodeBlock';
// @ts-expect-error
@@ -33,8 +33,17 @@ export const Installation: React.FC<{
throw new Error('pkg is undefined');
}
- const packages = pkg
- .split(' ')
+ const pkgList = pkg.split(' ');
+
+ const allRemotionOnly = pkgList.every(
+ (p) => p.startsWith('@remotion/') || p === 'remotion',
+ );
+ const showRemotionCli =
+ allRemotionOnly &&
+ !pkgList.includes('remotion') &&
+ !pkgList.includes('@remotion/cli');
+
+ const packages = pkgList
.map((p) => {
if (p.startsWith('@remotion') || p === 'remotion') {
return `${p}@${VERSION}`;
@@ -44,19 +53,38 @@ export const Installation: React.FC<{
})
.join(' ');
+ const remotionCliPackages = pkgList.join(' ');
+
const isRemotionPackage = packages.includes('remotion');
+ const [selectedTab, setSelectedTab] = useState(
+ showRemotionCli ? 'remotion-cli' : 'npm',
+ );
+
+ const showVersionWarning = isRemotionPackage && selectedTab !== 'remotion-cli';
+
+ const tabs = [
+ ...(showRemotionCli
+ ? [{label: 'Remotion CLI', value: 'remotion-cli'}]
+ : []),
+ {label: 'npm', value: 'npm'},
+ {label: 'bun', value: 'bun'},
+ {label: 'pnpm', value: 'pnpm'},
+ {label: 'yarn', value: 'yarn'},
+ ];
+
return (
<div>
<Tabs
- defaultValue="npm"
- values={[
- {label: 'npm', value: 'npm'},
- {label: 'bun', value: 'bun'},
- {label: 'pnpm', value: 'pnpm'},
- {label: 'yarn', value: 'yarn'},
- ]}
+ defaultValue={showRemotionCli ? 'remotion-cli' : 'npm'}
+ values={tabs}
+ onChange={(value: string) => setSelectedTab(value)}
>
+ {showRemotionCli ? (
+ <TabItem value="remotion-cli">
+ <LightAndDark text={`npx remotion add ${remotionCliPackages}`} />
+ </TabItem>
+ ) : null}
<TabItem value="npm">
<LightAndDark text={`npm i --save-exact ${packages}`} />
</TabItem>
@@ -70,7 +98,7 @@ export const Installation: React.FC<{
<LightAndDark text={`yarn --exact add ${packages}`} />
</TabItem>
</Tabs>
- {isRemotionPackage ? (
+ {showVersionWarning ? (
<>
This assumes you are currently using v{VERSION} of Remotion.
<br />
diff --git a/packages/docs/docs/light-leaks/index.mdx b/packages/docs/docs/light-leaks/index.mdx
index 8a5405260e..80fa680e6a 100644
--- a/packages/docs/docs/light-leaks/index.mdx
+++ b/packages/docs/docs/light-leaks/index.mdx
@@ -7,42 +7,9 @@ title: '@remotion/light-leaks'
Light leak effects for Remotion videos.
-import Tabs from '@theme/Tabs';
-import TabItem from '@theme/TabItem';
import {TableOfContents} from './table-of-contents';
-<Tabs
-defaultValue="npm"
-values={[
-{ label: 'npm', value: 'npm', },
-{ label: 'pnpm', value: 'pnpm', },
-{ label: 'yarn', value: 'yarn', },
-]
-}>
-<TabItem value="npm">
-
-```bash
-npm i @remotion/light-leaks
-```
-
- </TabItem>
-
- <TabItem value="pnpm">
-
-```bash
-pnpm i @remotion/light-leaks
-```
-
- </TabItem>
-
- <TabItem value="yarn">
-
-```bash
-yarn add @remotion/light-leaks
-```
-
- </TabItem>
-</Tabs>
+<Installation pkg="@remotion/light-leaks" />
## Components