npx skills add https://github.com/tldraw/tldraw --skill write-example示例项目 (apps/examples) 包含了如何使用 tldraw SDK 的最小化演示。示例被嵌入到文档网站并部署到 examples.tldraw.com。
apps/examples/src/examples 中的示例标准。
每个示例都位于其自己的文件夹中:
apps/examples/src/examples/
└── my-example/
├── README.md # 必需的元数据
├── MyExampleExample.tsx # 主示例文件
└── my-example.css # 可选的样式文件
custom-canvas, button-demo, magical-wand广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
必需的前置元数据格式:
---
title: 示例标题
component: ./ExampleFile.tsx
category: category-id
priority: 1
keywords: [keyword1, keyword2]
---
关于此示例演示内容的一行摘要。
---
示例的详细说明。如果有助于解释示例代码本身不明显的内容,请在此处包含代码片段。
| 字段 | 描述 |
|---|---|
| title | 句子首字母大写,与文件夹名称对应 |
| component | 指向示例文件的相对路径 |
| category | 有效的类别 ID 之一(见下文) |
| priority | 在类别内的显示顺序(数字越小,优先级越高) |
| keywords | 搜索关键词(避免使用像"tldraw"这样明显的词) |
getting-started, configuration, editor-api, ui, layout, events, shapes/tools, collaboration, data/assets, use-cases
CustomCanvasExample.tsx, ButtonExample.tsximport { Tldraw } from 'tldraw'
import 'tldraw/tldraw.css'
export default function MyExampleExample() {
return (
<div className="tldraw__editor">
<Tldraw />
</div>
)
}
要求:
tldraw__editor 类tldraw/tldraw.css 以获取样式<div className="tldraw__editor"> 包裹my-example.cssimport './my-example.css'style 属性使用大量内联样式对于需要按钮或控件的示例,使用 TopPanel 组件插槽和 TldrawUiButton:
import { Tldraw, TldrawUiButton, useEditor } from 'tldraw'
import 'tldraw/tldraw.css'
import './my-example.css'
function MyControls() {
const editor = useEditor()
return (
<div className="tlui-menu my-controls">
<TldrawUiButton type="normal" onClick={() => editor.zoomIn()}>
放大
</TldrawUiButton>
<TldrawUiButton type="normal" onClick={() => editor.zoomOut()}>
缩小
</TldrawUiButton>
</div>
)
}
export default function MyExampleExample() {
return (
<div className="tldraw__editor">
<Tldraw components={{ TopPanel: MyControls }} />
</div>
)
}
控制面板的 CSS:
.my-controls {
display: flex;
flex-wrap: wrap;
margin: 8px;
}
使用带数字引用的脚注格式:
import { Tldraw, type TLComponents } from 'tldraw'
import 'tldraw/tldraw.css'
// [1]
const components: TLComponents = {
PageMenu: null,
}
export default function CustomComponentsExample() {
return (
<div className="tldraw__editor">
{/* [2] */}
<Tldraw components={components} />
</div>
)
}
/*
[1]
在 React 组件外部定义组件覆盖,使其保持静态。
如果在内部定义,请使用 useMemo 以防止在每次渲染时重新创建。
[2]
通过 components 属性传递组件覆盖。
*/
use-casesInput.tsx 中的复杂输入组件每周安装量
157
代码仓库
GitHub 星标
46.0K
首次出现
2026年1月22日
安全审计
安装于
gemini-cli133
opencode127
antigravity122
codex122
github-copilot117
cursor113
The examples project (apps/examples) contains minimal demonstrations of how to use the tldraw SDK. Examples are embedded on the docs site and deployed to examples.tldraw.com.
Standards for examples in apps/examples/src/examples.
Each example lives in its own folder:
apps/examples/src/examples/
└── my-example/
├── README.md # Required metadata
├── MyExampleExample.tsx # Main example file
└── my-example.css # Optional styles
custom-canvas, button-demo, magical-wandRequired frontmatter format:
---
title: Example title
component: ./ExampleFile.tsx
category: category-id
priority: 1
keywords: [keyword1, keyword2]
---
One-line summary of what this example demonstrates.
---
Detailed explanation of the example. Include code snippets here if they help explain concepts not obvious from the example code itself.
| Field | Description |
|---|---|
| title | Sentence case, corresponds to folder name |
| component | Relative path to example file |
| category | One of the valid category IDs (see below) |
| priority | Display order within category (lower = higher) |
| keywords | Search terms (avoid obvious terms like "tldraw") |
getting-started, configuration, editor-api, ui, layout, events, shapes/tools, collaboration, data/assets, use-cases
CustomCanvasExample.tsx, ButtonExample.tsximport { Tldraw } from 'tldraw'
import 'tldraw/tldraw.css'
export default function MyExampleExample() {
return (
<div className="tldraw__editor">
<Tldraw />
</div>
)
}
Requirements:
tldraw__editor class for full-page examplestldraw/tldraw.css for styles<div className="tldraw__editor">my-example.cssimport './my-example.css'style propFor examples that need buttons or controls, use the TopPanel component slot with TldrawUiButton:
import { Tldraw, TldrawUiButton, useEditor } from 'tldraw'
import 'tldraw/tldraw.css'
import './my-example.css'
function MyControls() {
const editor = useEditor()
return (
<div className="tlui-menu my-controls">
<TldrawUiButton type="normal" onClick={() => editor.zoomIn()}>
Zoom in
</TldrawUiButton>
<TldrawUiButton type="normal" onClick={() => editor.zoomOut()}>
Zoom out
</TldrawUiButton>
</div>
)
}
export default function MyExampleExample() {
return (
<div className="tldraw__editor">
<Tldraw components={{ TopPanel: MyControls }} />
</div>
)
}
CSS for control panels:
.my-controls {
display: flex;
flex-wrap: wrap;
margin: 8px;
}
Use footnote format with numbered references:
import { Tldraw, type TLComponents } from 'tldraw'
import 'tldraw/tldraw.css'
// [1]
const components: TLComponents = {
PageMenu: null,
}
export default function CustomComponentsExample() {
return (
<div className="tldraw__editor">
{/* [2] */}
<Tldraw components={components} />
</div>
)
}
/*
[1]
Define component overrides outside the React component so they're static.
If defined inside, use useMemo to prevent recreation on every render.
[2]
Pass component overrides via the components prop.
*/
use-casesInput.tsxWeekly Installs
157
Repository
GitHub Stars
46.0K
First Seen
Jan 22, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
gemini-cli133
opencode127
antigravity122
codex122
github-copilot117
cursor113
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
116,600 周安装
AI会议纪要生成技能:快速创建结构化内部会议记录,自动提取决策与行动项
8,100 周安装
Dataverse Python 生产级代码生成器 | 含错误处理、重试逻辑、OData优化
8,100 周安装
Pinia - Vue官方状态管理库:类型安全、支持Options/Composition API、TypeScript
8,200 周安装
高自主性前端开发技能 - 设计工程与AI指令驱动的React/Next.js最佳实践
8,500 周安装
Java文档最佳实践指南:Javadoc注释规范与代码文档化技巧
8,200 周安装
pnpm 10.x 包管理器教程 - 快速节省磁盘空间,严格依赖管理,工作区配置指南
8,200 周安装