跳到正文
Skillpedia
网站与界面(前端)41k · #6840

building-react-quill-canvases

它能做什么

本技能使用 React 和 PostHog 自有的设计系统,构建仪表盘、数据看板和工具等交互式画布。适合希望画布具有应用式体验、并与 PostHog 外观保持一致的人。

适用场景

  • ✓当你想在 PostHog 中放置交互式仪表盘或数据看板时。
  • ✓当你需要带有按钮和输入框的表单、工具或应用式画布的时候。
  • ✓当画布必须在浅色和深色主题下都与 PostHog 外观一致的时候。

技能链接

https://github.com/PostHog/posthog/blob/master/products/canvas/skills/building-react-quill-canvases/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/PostHog/posthog/blob/master/products/canvas/skills/building-react-quill-canvases/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请构建一个交互式画布,包含一个日期选择器和三张试用用户的指标卡片。”

每周 5 个新技能,1 分钟读完。

工作原理

AI 会编写一个由 PostHog 挂载的 React 组件,使用允许的组件和导入,并单独加载每张数据卡片。它会让主题和加载状态与 PostHog 的设计保持一致。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Building React + Quill canvases

The whole application is one React/TSX file (src/canvas.tsx in the source project). It must export default a single React component that takes no props — the host mounts it. Do not import react-dom or call createRoot.

Start from the working scaffold in references/starter-scaffold.md on a first build: it already wires the date picker, theme tokens, per-query loading state (every card fills in independently as its own data lands), and correct typed-node result reading. Keep that wiring; replace the sample metrics and layout. Keep its pattern of one component per card with editable() params, and follow the "Params" section of the building-canvases skill for each card you add.

Imports

Use React, Quill, Recharts, Lucide, and Day.js for the standard application shell. The platform also admits ten optional libraries for specialized work. Read references/platform-libraries.md before choosing one.

PostHog data comes through import { ph } from "@posthog/canvas-sdk" — a platform-provided module, so it needs no dependencies entry. The same object exists as the window.ph global (how existing canvases reach it); prefer the import in new code.

Other bare imports, dynamic import(), require(), <script> tags, and remote code fail validation. Direct network requests and external images, fonts, media, or frames require an exact HTTPS origin in capabilities.network.origins. They work only in the published canvas — the edit-mode preview blocks direct network access regardless of declaration. Stylesheets from declared origins are allowed; remote scripts remain blocked, so bundle code with the canvas.

Quill component rules

A PostHog data board must be built entirely from @posthog/quill components — never a native control or a styled <div> standing in for one:

  • Dropdown/picker → Select (never a native <select>); button → Button (never <button>); text field → Input/Textarea; checkbox → Checkbox; label → Label.
  • Table → Table (TableHeader > TableRow > TableHead, then TableBody > TableRow > TableCell); panel → Card (CardHeader + CardTitle + CardContent); pill → Badge; titles → Heading; body → Text.
  • A Table inside a Card needs <Card size="sm" flush> around <Table size="sm" fullWidth>. Without flush the card's padding insets the table, so its header and rows stop meeting the card's edges. flush drops the card's section gap, bottom padding, and the CardContent inline padding, while the header keeps its own padding and divider. Matching size="sm" on both lines the table's edge columns up with the card's title.
  • The only non-Quill tags allowed are plain layout <div>s and recharts elements.
  • Quill is built on Base UI: compose compound parts (Select + SelectTrigger/SelectContent/SelectItem), use controlled value + onValueChange, and swap a part's element with the render prop (e.g. <PopoverTrigger render={<Button …/>} />) instead of wrapping it.
  • Quill components are already themed — never restyle one with Tailwind classes or inline style; use their variant/size props. Put layout utilities (flex, grid, gap-4, p-4) on your own wrapper <div>s.
  • Buttons: default to variant="outline"; variant="primary" for the one main action only.

Styling and theme

  • Give the canvas's outermost element min-h-screen (min-height: 100vh) so it fills the iframe viewport and grows past it as content demands. Do not use h-screen there: a fixed viewport height caps a flex column, so tall children shrink and clip instead of scrolling. Do not use h-full there either: a published canvas's artifact shell gives its html, body, and #root elements no explicit height, so a percentage root height collapses to content height.
  • The root needs no overflow-y-auto: once it grows past the viewport the iframe's own document scrolls.
  • A min-height root is not a definite height, so h-full on a direct child still collapses to content height. Give an intermediate wrapper an explicit height (h-[280px]) when a child must fill a box.
  • Style with Tailwind utilities and Quill components; reserve inline style for genuinely dynamic runtime values (fixed sizes use arbitrary-value utilities like h-[280px]).
  • Write specific interface copy. Never use lorem ipsum or placeholder labels in a finished
常见问题

它可以使用哪些库?

标准库,例如 React、Quill、Recharts、Lucide 和 Day.js,以及一小部分可选库。其他导入会验证失败。

画布会等待所有数据加载完才显示吗?

不会。每张卡片会在其自身数据到达时逐个填充。

它可以使用互联网上的任何包吗?

不可以。允许列表之外的导入会验证失败,因此只能使用经批准的库。

详情

作者的原始描述

Author the React + Quill implementation of a PostHog canvas: the single-component contract, the allowed imports, Quill (PostHog's design system) component and composition rules, theme-aware design tokens, loading skeletons, and the in-canvas date picker. Use after building-canvases has routed a canvas request to a React implementation — dashboards, data boards, forms, tools, or any canvas that should look native to PostHog.

repo: PostHog/posthog

热度

GitHub 星标
41k
排名
#6840
许可证
—
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能