Skip to content

🎥 Make videos programmatically with React

document slide

Jonny Burger55e7a3d940b0
diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsx
index 979b0d86e0..1f01ca736a 100644
--- a/packages/docs/components/demos/index.tsx
+++ b/packages/docs/components/demos/index.tsx
@@ -64,7 +64,7 @@ export const Demo: React.FC<{
[
o.name,
o.optional === "default-disabled" ? null : o.default,
- ] as const
+ ] as const,
)
.reduce((a, b) => {
a[b[0]] = b[1];
@@ -95,7 +95,10 @@ export const Demo: React.FC<{
style={{
width: "100%",
aspectRatio: demo.compWidth / demo.compHeight,
- borderBottom: "1px solid var(--ifm-color-emphasis-300)",
+ borderBottom:
+ demo.options.length > 0
+ ? "1px solid var(--ifm-color-emphasis-300)"
+ : 0,
}}
errorFallback={({ error }) => {
return (
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.ts
index 946b213176..2281b691c5 100644
--- a/packages/docs/components/demos/types.ts
+++ b/packages/docs/components/demos/types.ts
@@ -490,7 +490,15 @@ export const slidePresentationDemo: DemoType = {
fps: 30,
id: "slide",
autoPlay: true,
- options: [],
+ options: [
+ {
+ type: "enum",
+ name: "direction",
+ default: "from-left",
+ optional: "no",
+ values: ["from-left", "from-bottom", "from-right", "from-top"],
+ },
+ ],
};
export const wipePresentationDemo: DemoType = {
diff --git a/packages/docs/components/transitions/previews.tsx b/packages/docs/components/transitions/previews.tsx
index 14a0081e04..9371007c4d 100644
--- a/packages/docs/components/transitions/previews.tsx
+++ b/packages/docs/components/transitions/previews.tsx
@@ -3,6 +3,7 @@ import { Player } from "@remotion/player";
import type { TransitionPresentation } from "@remotion/transitions";
import { springTiming, TransitionSeries } from "@remotion/transitions";
import { fade } from "@remotion/transitions/fade";
+import type { SlideDirection } from "@remotion/transitions/slide";
import { slide } from "@remotion/transitions/slide";
import { wipe } from "@remotion/transitions/wipe";
import React, { useEffect, useRef } from "react";
@@ -118,8 +119,10 @@ export const FadeDemo: React.FC = () => {
return <SampleTransition effect={fade()} />;
};
-export const SlideDemo: React.FC = () => {
- return <SampleTransition effect={slide()} />;
+export const SlideDemo: React.FC<{
+ direction: SlideDirection;
+}> = ({ direction }) => {
+ return <SampleTransition effect={slide({ direction })} />;
};
export const WipeDemo: React.FC = () => {
diff --git a/packages/docs/docs/transitions/presentations/slide.mdx b/packages/docs/docs/transitions/presentations/slide.mdx
index fe3965a03e..47e3155164 100644
--- a/packages/docs/docs/transitions/presentations/slide.mdx
+++ b/packages/docs/docs/transitions/presentations/slide.mdx
@@ -3,7 +3,7 @@ crumb: "@remotion/transitions - Presentations"
title: "slide()"
---
-A simple slide animation.
+A presentation which where the entering slide pushes out the exiting slide.
<Demo type="slide" />
@@ -55,7 +55,17 @@ const BasicTransition = () => {
## API
-This API has no options.
+Takes an object with the following properties:
+
+### `direction`
+
+One of `from-left`, `from-right`, `from-top`, `from-bottom`. TypeScript type:
+
+```tsx twoslash
+import { SlideDirection } from "@remotion/transitions/slide";
+
+const slideDirection: SlideDirection = "from-left";
+```
## See also
diff --git a/packages/transitions/src/presentations/slide.tsx b/packages/transitions/src/presentations/slide.tsx
index 805d1d6002..15845ba5ee 100644
--- a/packages/transitions/src/presentations/slide.tsx
+++ b/packages/transitions/src/presentations/slide.tsx
@@ -1,92 +1,96 @@
-import React, {useMemo} from 'react';
-import {AbsoluteFill} from 'remotion';
+import React, { useMemo } from "react";
+import { AbsoluteFill } from "remotion";
import type {
- TransitionPresentation,
- TransitionPresentationComponentProps,
-} from '../types.js';
+ TransitionPresentation,
+ TransitionPresentationComponentProps,
+} from "../types.js";
-type WipeDirection = 'from-left' | 'from-top' | 'from-right' | 'from-bottom';
+export type SlideDirection =
+ | "from-left"
+ | "from-top"
+ | "from-right"
+ | "from-bottom";
type SlideProps = {
- direction?: WipeDirection;
+ direction?: SlideDirection;
};
const SlidePresentation: React.FC<
- TransitionPresentationComponentProps<SlideProps>
+ TransitionPresentationComponentProps<SlideProps>
> = ({
- children,
- presentationProgress,
- presentationDirection,
- passedProps: {direction = 'from-left'},
+ children,
+ presentationProgress,
+ presentationDirection,
+ passedProps: { direction = "from-left" },
}) => {
- const directionStyle = useMemo((): React.CSSProperties => {
- if (presentationDirection === 'out') {
- switch (direction) {
- case 'from-left':
- return {
- transform: `translateX(${presentationProgress * 100}%)`,
- };
- case 'from-right':
- return {
- transform: `translateX(-${presentationProgress * 100}%)`,
- };
- case 'from-top':
- return {
- transform: `translateY(${presentationProgress * 100}%)`,
- };
- case 'from-bottom':
- return {
- transform: `translateY(-${presentationProgress * 100}%)`,
- };
- default:
- throw new Error(`Invalid direction: ${direction}`);
- }
- }
+ const directionStyle = useMemo((): React.CSSProperties => {
+ if (presentationDirection === "out") {
+ switch (direction) {
+ case "from-left":
+ return {
+ transform: `translateX(${presentationProgress * 100}%)`,
+ };
+ case "from-right":
+ return {
+ transform: `translateX(-${presentationProgress * 100}%)`,
+ };
+ case "from-top":
+ return {
+ transform: `translateY(${presentationProgress * 100}%)`,
+ };
+ case "from-bottom":
+ return {
+ transform: `translateY(-${presentationProgress * 100}%)`,
+ };
+ default:
+ throw new Error(`Invalid direction: ${direction}`);
+ }
+ }
- switch (direction) {
- case 'from-left':
- return {
- transform: `translateX(${-100 + presentationProgress * 100}%)`,
- };
- case 'from-right':
- return {
- transform: `translateX(${100 - presentationProgress * 100}%)`,
- };
- case 'from-top':
- return {
- transform: `translateY(${-100 + presentationProgress * 100}%)`,
- };
- case 'from-bottom':
- return {
- transform: `translateY(${100 - presentationProgress * 100}%)`,
- };
- default:
- throw new Error(`Invalid direction: ${direction}`);
- }
- }, [presentationDirection, presentationProgress, direction]);
+ switch (direction) {
+ case "from-left":
+ return {
+ transform: `translateX(${-100 + presentationProgress * 100}%)`,
+ };
+ case "from-right":
+ return {
+ transform: `translateX(${100 - presentationProgress * 100}%)`,
+ };
+ case "from-top":
+ return {
+ transform: `translateY(${-100 + presentationProgress * 100}%)`,
+ };
+ case "from-bottom":
+ return {
+ transform: `translateY(${100 - presentationProgress * 100}%)`,
+ };
+ default:
+ throw new Error(`Invalid direction: ${direction}`);
+ }
+ }, [presentationDirection, presentationProgress, direction]);
- const style: React.CSSProperties = useMemo(() => {
- return {
- width: '100%',
- height: '100%',
- justifyContent: 'center',
- alignItems: 'center',
- ...directionStyle,
- };
- }, [directionStyle]);
+ const style: React.CSSProperties = useMemo(() => {
+ return {
+ width: "100%",
+ height: "100%",
+ justifyContent: "center",
+ alignItems: "center",
+ ...directionStyle,
+ };
+ }, [directionStyle]);
- return (
- <AbsoluteFill>
- <AbsoluteFill style={style}>{children}</AbsoluteFill>
- </AbsoluteFill>
- );
+ return (
+ <AbsoluteFill>
+ <AbsoluteFill style={style}>{children}</AbsoluteFill>
+ </AbsoluteFill>
+ );
};
export const slide = (
- props?: SlideProps
+ props?: SlideProps
): TransitionPresentation<SlideProps> => {
- return {
- component: SlidePresentation,
- props: props ?? {},
- };
+ return {
+ component: SlidePresentation,
+ props: props ?? {},
+ };
};