Skip to content

🎥 Make videos programmatically with React

finish transforms doc

Jonny Burgerdbf22cc6988b
diff --git a/packages/docs/components/DocsDark.tsx b/packages/docs/components/DocsDark.tsx
index c34df72a44..722f19b62e 100644
--- a/packages/docs/components/DocsDark.tsx
+++ b/packages/docs/components/DocsDark.tsx
@@ -24,7 +24,7 @@ export const SingleVideoDemo: React.FC<{
border:
"1px solid " +
(colorMode === "dark"
- ? "transparent"
+ ? "var(--ifm-color-emphasis-200)"
: "var(--ifm-color-emphasis-300)"),
flex: 1,
display: "block",
diff --git a/packages/docs/components/demos/Translate.tsx b/packages/docs/components/demos/Translate.tsx
new file mode 100644
index 0000000000..6679a2b3cd
--- /dev/null
+++ b/packages/docs/components/demos/Translate.tsx
@@ -0,0 +1,107 @@
+import React from "react";
+import { AbsoluteFill } from "remotion";
+
+const Base: React.FC<{
+ transform?: string;
+ opacity?: number;
+ showChip: boolean;
+}> = ({ transform, opacity, showChip }) => {
+ return (
+ <AbsoluteFill
+ style={{
+ padding: 20,
+ fontSize: 20,
+ fontFamily: "GTPlanar",
+ }}
+ >
+ {transform ? (
+ <div>&quot;transform&quot;: &quot;{transform}&quot;</div>
+ ) : null}
+ {opacity === undefined ? null : <div>&quot;opacity&quot;: {opacity}</div>}
+ <AbsoluteFill
+ style={{
+ opacity,
+ transform,
+ }}
+ >
+ <AbsoluteFill
+ style={{
+ justifyContent: "center",
+ alignItems: "center",
+ }}
+ >
+ <div
+ style={{
+ height: 100,
+ width: 100,
+ backgroundColor: "var(--ifm-color-primary)",
+ borderRadius: 10,
+ }}
+ />
+ </AbsoluteFill>
+ {showChip ? (
+ <AbsoluteFill
+ style={{
+ justifyContent: "center",
+ alignItems: "center",
+ }}
+ >
+ <div
+ style={{
+ backgroundColor: "white",
+ fontSize: 14,
+ width: 24,
+ height: 24,
+ display: "flex",
+ justifyContent: "center",
+ alignItems: "center",
+ borderRadius: 12,
+ marginLeft: -50,
+ marginTop: -50,
+ fontWeight: "bold",
+ }}
+ >
+ A
+ </div>
+ </AbsoluteFill>
+ ) : null}
+ </AbsoluteFill>{" "}
+ </AbsoluteFill>
+ );
+};
+
+export const TranslateDemo: React.FC<{
+ translateX: number;
+ translateY: number;
+}> = ({ translateX: x, translateY: y }) => {
+ return (
+ <Base
+ showChip={false}
+ transform={`translateX(${x}px) translateY(${y}px)`}
+ />
+ );
+};
+
+export const RotateDemo: React.FC<{
+ rotateZ: number;
+}> = ({ rotateZ }) => {
+ return <Base showChip transform={`rotateZ(${rotateZ}deg)`} />;
+};
+
+export const SkewDemo: React.FC<{
+ skew: number;
+}> = ({ skew }) => {
+ return <Base showChip={false} transform={`skew(${skew}deg)`} />;
+};
+
+export const ScaleDemo: React.FC<{
+ scale: number;
+}> = ({ scale }) => {
+ return <Base showChip transform={`scale(${scale})`} />;
+};
+
+export const OpacityDemo: React.FC<{
+ opacity: number;
+}> = ({ opacity }) => {
+ return <Base showChip={false} opacity={opacity} />;
+};
diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsx
index 5193c42be4..4c621b9a5f 100644
--- a/packages/docs/components/demos/index.tsx
+++ b/packages/docs/components/demos/index.tsx
@@ -9,9 +9,14 @@ import {
circleDemo,
ellipseDemo,
noiseDemo,
+ opacityDemo,
pieDemo,
rectDemo,
+ rotateDemo,
+ scaleDemo,
+ skewDemo,
starDemo,
+ translateDemo,
triangleDemo,
} from "./types";
@@ -31,6 +36,11 @@ const demos: DemoType[] = [
ellipseDemo,
starDemo,
pieDemo,
+ translateDemo,
+ skewDemo,
+ rotateDemo,
+ scaleDemo,
+ opacityDemo,
];
export const Demo: React.FC<{
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.ts
index 2a8e8ede56..456df72fc4 100644
--- a/packages/docs/components/demos/types.ts
+++ b/packages/docs/components/demos/types.ts
@@ -4,6 +4,13 @@ import { NoiseComp } from "./NoiseDemo";
import { PieDemo } from "./Pie";
import { RectDemo } from "./Rect";
import { StarDemo } from "./Star";
+import {
+ OpacityDemo,
+ RotateDemo,
+ ScaleDemo,
+ SkewDemo,
+ TranslateDemo,
+} from "./Translate";
import { TriangleDemo } from "./Triangle";
export type Option = {
@@ -166,6 +173,120 @@ export const circleDemo: DemoType = {
],
};
+export const translateDemo: DemoType = {
+ comp: TranslateDemo,
+ autoPlay: false,
+ compHeight: 400,
+ compWidth: 1280,
+ durationInFrames: 150,
+ fps: 30,
+ id: "translate",
+ options: [
+ {
+ default: 0,
+ max: 800,
+ step: 5,
+ min: -800,
+ type: "numeric",
+ name: "translateX",
+ optional: "no",
+ },
+ {
+ default: 0,
+ max: 800,
+ step: 5,
+ min: -800,
+ type: "numeric",
+ name: "translateY",
+ optional: "no",
+ },
+ ],
+};
+
+export const skewDemo: DemoType = {
+ comp: SkewDemo,
+ autoPlay: false,
+ compHeight: 400,
+ compWidth: 1280,
+ durationInFrames: 150,
+ fps: 30,
+ id: "skew",
+ options: [
+ {
+ default: 0,
+ max: 180,
+ step: 1,
+ min: -180,
+ type: "numeric",
+ name: "skew",
+ optional: "no",
+ },
+ ],
+};
+
+export const scaleDemo: DemoType = {
+ comp: ScaleDemo,
+ autoPlay: false,
+ compHeight: 400,
+ compWidth: 1280,
+ durationInFrames: 150,
+ fps: 30,
+ id: "scale",
+ options: [
+ {
+ default: 1,
+ max: 4,
+ step: 0.01,
+ min: -4,
+ type: "numeric",
+ name: "scale",
+ optional: "no",
+ },
+ ],
+};
+
+export const opacityDemo: DemoType = {
+ comp: OpacityDemo,
+ autoPlay: false,
+ compHeight: 400,
+ compWidth: 1280,
+ durationInFrames: 150,
+ fps: 30,
+ id: "opacity",
+ options: [
+ {
+ default: 1,
+ max: 1,
+ step: 0.01,
+ min: 0,
+ type: "numeric",
+ name: "opacity",
+ optional: "no",
+ },
+ ],
+};
+
+export const rotateDemo: DemoType = {
+ comp: RotateDemo,
+ autoPlay: false,
+ compHeight: 400,
+ compWidth: 1280,
+ durationInFrames: 150,
+ fps: 30,
+ id: "rotate",
+ options: [
+ {
+ default: 0,
+ max: 180,
+ step: 1,
+ min: -180,
+ type: "numeric",
+ name: "rotateZ",
+ optional: "no",
+ },
+ ],
+};
+
export const pieDemo: DemoType = {
comp: PieDemo,
compHeight: 720,
diff --git a/packages/docs/docs/transforms.md b/packages/docs/docs/transforms.md
index 77a4e375f2..31b1e4a0cc 100644
--- a/packages/docs/docs/transforms.md
+++ b/packages/docs/docs/transforms.md
@@ -7,13 +7,12 @@ import {Transforms} from '../components/DocsDark'
import {MuxVideo} from '../src/components/MuxVideo';
import {TransformsTutorial} from '../src/components/tutorials';
+<TransformsTutorial />
Animations occur by transforming the properties of an element over time.
Let's take a look at five common transforms that we can apply to any element.
If you are already familiar with how to apply CSS transforms in React, you can [skip this page](/docs/animating-properties).
-<TransformsTutorial />
-
## The 5 basic transformations
<Transforms />
@@ -41,6 +40,8 @@ You can set the opacity of an element using the `opacity` property.
/>
```
+<Demo type="opacity" />
+
Values below `0` and above `1` are accepted, but have no further effect.
### Scale
@@ -61,16 +62,18 @@ You can set the scale of an element using the `transform` property.
/>
```
+<Demo type="scale" />
+
The difference to changing the size of the element using `height` and `width` is that using `scale()` will not change the layout of the other elements.
### Skew
Skewing an element will lead to a distorted appearance as if the the element has been stretched on two corners of the element. Skew takes an angle that can be specified using `rad` (radians) and `deg` (degrees).
-See the explorer below to see how skewing affects an element.
-
You can set the skew of an element using the `transform` property.
+See the explorer below to see how skewing affects an element.
+
```tsx twoslash {6} title="MyComponent.tsx"
<div
style={{
@@ -82,6 +85,8 @@ You can set the skew of an element using the `transform` property.
/>
```
+<Demo type="skew" />
+
### Translate
Translating an element means moving it. A translation can be done on the X, Y or even Z axis. The transformation can be specified in `px`.
@@ -99,6 +104,8 @@ You can set the translation of an element using the `transform` property.
/>
```
+<Demo type="translate" />
+
As opposed to changing the position of an element using `margin-top` and `margin-left`, using `translate()` will not change the position of the other elements.
### Rotate
@@ -118,6 +125,8 @@ You can set the translation of an element using the `transform` property.
/>
```
+<Demo type="rotate" />
+
If you want to rotate an element around the X or Y axis, you should apply the [`perspective`](https://developer.mozilla.org/en-US/docs/Web/CSS/perspective) property to the parent element.
If you don't want to rotate around the center, you can use the [`transform-origin`](https://developer.mozilla.org/en-US/docs/Web/CSS/transform-origin) property to change the origin of the rotation.
diff --git a/packages/docs/src/components/AlsoAvailableAsVideo.tsx b/packages/docs/src/components/AlsoAvailableAsVideo.tsx
index e40018d45f..cad0b69365 100644
--- a/packages/docs/src/components/AlsoAvailableAsVideo.tsx
+++ b/packages/docs/src/components/AlsoAvailableAsVideo.tsx
@@ -7,22 +7,17 @@ const link: React.CSSProperties = {
all: "unset",
display: "block",
cursor: "pointer",
+ width: "100%",
};
const container: React.CSSProperties = {
- border: "1px solid #888",
+ background: "var(--ifm-color-emphasis-100)",
borderRadius: 10,
overflow: "hidden",
marginBottom: 30,
display: "flex",
flexDirection: "row",
-};
-
-const thumbnail: React.CSSProperties = {
- height: 100,
- display: "inline",
- marginBottom: 0,
- borderRight: "1px solid #888",
+ alignItems: "center",
};
const right: React.CSSProperties = {
@@ -34,6 +29,11 @@ const right: React.CSSProperties = {
justifyContent: "center",
};
+const icon: React.CSSProperties = {
+ height: 40,
+ marginLeft: 20,
+};
+
const wouldYouRather: React.CSSProperties = {
fontSize: ".9em",
};
@@ -74,7 +74,13 @@ export const AlsoAvailableAsVideo: React.FC<{
return (
<button type="button" style={link} onClick={onClick}>
<div style={container}>
- <img style={thumbnail} src={thumb} />
+ <svg
+ style={icon}
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 512 512"
+ >
+ <path d="M512 256c0 141.4-114.6 256-256 256S0 397.4 0 256S114.6 0 256 0S512 114.6 512 256zM188.3 147.1c-7.6 4.2-12.3 12.3-12.3 20.9V344c0 8.7 4.7 16.7 12.3 20.9s16.8 4.1 24.3-.5l144-88c7.1-4.4 11.5-12.1 11.5-20.5s-4.4-16.1-11.5-20.5l-144-88c-7.4-4.5-16.7-4.7-24.3-.5z" />
+ </svg>
<div style={right}>
<div style={wouldYouRather}>
Also available as a {minutes}min video