docs-demo
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAdding an Interactive Demo to Docs
为文档添加交互式演示
Interactive demos render a Remotion composition inline in documentation pages using . They live in .
@remotion/playerpackages/docs/components/demos/交互式演示通过在文档页面中内联渲染Remotion合成内容。这些演示文件存放在目录下。
@remotion/playerpackages/docs/components/demos/Steps
步骤
-
Create a component in(e.g.
packages/docs/components/demos/). It should be a standard React component using Remotion hooks likeMyDemo.tsxanduseCurrentFrame().useVideoConfig() -
Register the demo in:
packages/docs/components/demos/types.ts- Import the component
- Export a object with these fields:
DemoType- : unique string used in
id<Demo type="..." /> - : the React component
comp - /
compWidth: canvas dimensions (e.g. 1280x720)compHeight - : frame rate (typically 30)
fps - : animation length
durationInFrames - : whether it plays automatically
autoPlay - : array of interactive controls (can be empty
options)[]
-
Add to the demos array in:
packages/docs/components/demos/index.tsx- Import the demo constant from
./types - Add it to the array
demos
- Import the demo constant from
-
Use in MDX with
<Demo type="your-id" />
-
创建组件:在目录下创建组件(例如
packages/docs/components/demos/)。它应该是一个标准的React组件,使用MyDemo.tsx和useCurrentFrame()等Remotion钩子。useVideoConfig() -
注册演示:在中注册演示:
packages/docs/components/demos/types.ts- 导入该组件
- 导出一个对象,包含以下字段:
DemoType- :在
id中使用的唯一字符串<Demo type="..." /> - :对应的React组件
comp - /
compWidth:画布尺寸(例如1280x720)compHeight - :帧率(通常为30)
fps - :动画时长(以帧为单位)
durationInFrames - :是否自动播放
autoPlay - :交互式控件数组(可以为空数组
options)[]
-
添加到演示数组:在中:
packages/docs/components/demos/index.tsx- 从导入演示常量
./types - 将其添加到数组中
demos
- 从
-
在MDX中使用:通过标签使用
<Demo type="your-id" />
Options
选项
Options add interactive controls below the player. Each option needs and (, , or ).
nameoptional'no''default-enabled''default-disabled'Supported types:
- — slider with
type: 'numeric',min,max,stepdefault - — checkbox with
type: 'boolean'default - — dropdown with
type: 'enum'array andvaluesdefault - — text input with
type: 'string'default
Option values are passed to the component as . Access them as regular React props.
inputProps选项会在播放器下方添加交互式控件。每个选项需要包含和字段(可选值为、或)。
nameoptional'no''default-enabled''default-disabled'支持的类型:
- — 带有
type: 'numeric'、min、max、step参数的滑块控件default - — 带有
type: 'boolean'参数的复选框控件default - — 带有
type: 'enum'数组和values参数的下拉菜单控件default - — 带有
type: 'string'参数的文本输入框控件default
选项值会以的形式传递给组件,可以作为常规React props访问。
inputPropsExample registration
注册示例
ts
export const myDemo: DemoType = {
comp: MyDemoComp,
compHeight: 720,
compWidth: 1280,
durationInFrames: 150,
fps: 30,
id: 'my-demo',
autoPlay: true,
options: [],
};ts
export const myDemo: DemoType = {
comp: MyDemoComp,
compHeight: 720,
compWidth: 1280,
durationInFrames: 150,
fps: 30,
id: 'my-demo',
autoPlay: true,
options: [],
};