Skip to content

🎥 Make videos programmatically with React

padding

Jonny Burger160cef87761f
diff --git a/packages/docs/components/demos/Triangle.tsx b/packages/docs/components/demos/Triangle.tsx
index 541e09b57e..933d76c59d 100644
--- a/packages/docs/components/demos/Triangle.tsx
+++ b/packages/docs/components/demos/Triangle.tsx
@@ -1,3 +1,4 @@
+import type { TriangleProps } from "@remotion/shapes";
import { Triangle } from "@remotion/shapes";
import React from "react";
import { AbsoluteFill } from "remotion";
@@ -6,7 +7,8 @@ export const TriangleDemo: React.FC<{
length: number;
edgeRoundness: number;
darkMode: boolean;
-}> = ({ length, edgeRoundness, darkMode }) => {
+ direction: TriangleProps["direction"];
+}> = ({ length, edgeRoundness, direction, darkMode }) => {
return (
<AbsoluteFill
style={{
@@ -17,7 +19,7 @@ export const TriangleDemo: React.FC<{
<Triangle
fill={darkMode ? "white" : "#222"}
edgeRoundness={edgeRoundness}
- direction="up"
+ direction={direction}
length={length}
/>
</AbsoluteFill>
diff --git a/packages/docs/components/demos/control.tsx b/packages/docs/components/demos/control.tsx
index 0a13a17805..6f02456e62 100644
--- a/packages/docs/components/demos/control.tsx
+++ b/packages/docs/components/demos/control.tsx
@@ -3,7 +3,6 @@ import styles from "./styles.module.css";
import type { Option } from "./types";
const left: React.CSSProperties = {
- width: 100,
fontFamily: "GTPlanar",
flex: 1,
flexDirection: "row",
@@ -12,11 +11,11 @@ const left: React.CSSProperties = {
};
const check: React.CSSProperties = {
- marginRight: 5,
+ marginRight: 4,
};
const right: React.CSSProperties = {
- width: 40,
+ width: 45,
textAlign: "right",
fontVariantNumeric: "tabular-nums",
};
@@ -27,8 +26,8 @@ export const Control = ({
setValue,
}: {
option: Option;
- value: number;
- setValue: (value: number) => void;
+ value: number | string;
+ setValue: (value: number | string) => void;
}) => {
const enabled = value !== null;
@@ -44,12 +43,12 @@ export const Control = ({
const inputStyle = useMemo<React.CSSProperties>(
() => ({
width: 80,
- marginRight: 8,
+ marginRight: 2,
}),
[]
);
- if (option.type !== "numeric") {
+ if (option.type !== "numeric" && option.type !== "enum") {
throw new Error("numeric");
}
@@ -73,19 +72,40 @@ export const Control = ({
)}
{`${option.name}`}
</div>
- <input
- type="range"
- min={option.min}
- max={option.max}
- step={option.step}
- value={value as number}
- style={inputStyle}
- disabled={!enabled}
- onChange={(e) => setValue(Number(e.target.value))}
- />
- <div style={right}>
- <code>{value}</code>
- </div>
+ {option.type === "numeric" ? (
+ <input
+ type="range"
+ min={option.min}
+ max={option.max}
+ step={option.step}
+ value={value as number}
+ style={inputStyle}
+ disabled={!enabled}
+ onChange={(e) => setValue(Number(e.target.value))}
+ />
+ ) : null}
+ {option.type === "numeric" ? (
+ <div style={right}>
+ <code>{value}</code>
+ </div>
+ ) : (
+ <div>
+ <select
+ onChange={(e) => {
+ console.log(e.target.value);
+ setValue(e.target.value);
+ }}
+ >
+ {option.values.map((v) => {
+ return (
+ <option key={v} selected={value === v}>
+ {v}
+ </option>
+ );
+ })}
+ </select>
+ </div>
+ )}
</label>
);
};
diff --git a/packages/docs/components/demos/styles.module.css b/packages/docs/components/demos/styles.module.css
index c642c29dd9..d9dd6159a6 100644
--- a/packages/docs/components/demos/styles.module.css
+++ b/packages/docs/components/demos/styles.module.css
@@ -5,7 +5,10 @@
.item {
grid-gap: 15px;
- padding: 10px;
+ padding-left: 6px;
+ padding-right: 6px;
+ padding-top: 10px;
+ padding-bottom: 10px;
}
.item:not(:last-child) {
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.ts
index 6e494d92b5..cda2b5efb6 100644
--- a/packages/docs/components/demos/types.ts
+++ b/packages/docs/components/demos/types.ts
@@ -1,21 +1,27 @@
import { NoiseComp } from "./NoiseDemo";
import { TriangleDemo } from "./Triangle";
-export type Option = { name: string } & (
+export type Option = {
+ name: string;
+ optional: "no" | "default-enabled" | "default-disabled";
+} & (
| {
type: "numeric";
min: number;
default: number;
max: number;
step: number;
- optional: "no" | "default-enabled" | "default-disabled";
}
| {
type: "boolean";
default: boolean;
max: number;
step: number;
- optional: boolean;
+ }
+ | {
+ type: "enum";
+ default: string;
+ values: string[];
}
);
@@ -57,6 +63,13 @@ export const triangleDemo: DemoType = {
type: "numeric",
optional: "default-disabled",
},
+ {
+ name: "direction",
+ type: "enum",
+ default: "up",
+ values: ["up", "down", "left", "right"],
+ optional: "no",
+ },
],
};