building-html-canvases
Skill này làm gì
Skill này tạo các canvas kiểu tài liệu hoặc đồ họa, như báo cáo, sơ đồ và bản vẽ, bằng mã web đơn giản. Nó dành cho người cần một trang dễ đọc hoặc một phần trực quan trong PostHog thay vì một ứng dụng đầy đủ.
Khi nào nên dùng
- ✓Khi bạn muốn một báo cáo hoặc bài viết được trình bày dưới dạng canvas.
- ✓Khi bạn muốn một sơ đồ, bản vẽ hoặc hình đồ họa được tạo ra bên trong PostHog.
- ✓Khi một canvas chủ yếu là tĩnh và không cần nhiều điều khiển tương tác.
Liên kết skill
https://github.com/PostHog/posthog/blob/master/products/canvas/skills/building-html-canvases/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Tạo một canvas trình bày các phát hiện theo quý của chúng tôi thành một báo cáo gọn gàng, dễ đọc, kèm một biểu đồ đơn giản.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
AI viết HTML có ngữ nghĩa, mã định kiểu và mã đồ họa trình duyệt, được bọc trong lớp React nhỏ mà PostHog yêu cầu. AI cũng dọn dẹp các hoạt ảnh và trình lắng nghe để canvas hoạt động tốt khi chủ đề thay đổi.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Building HTML canvases
Some canvases are documents or graphics programs, not applications: a written report, a diagram, a generative-art piece, a WebGL scene. For these, semantic HTML, CSS, and direct browser APIs are the right tools — don't force Quill components or React state onto a static page.
The wrapper the current runtime requires
Every canvas keeps src/canvas.tsx as its mounted React entry component (default export, no
props). Keep the React layer as a thin shell and write the
experience in HTML/CSS/browser APIs inside it:
- A document is JSX that is effectively semantic HTML —
<article>, headings, lists, tables, figures — with a<style>block for typography and layout. Write real, specific copy. - A drawing/WebGL program renders a
<canvas>element and drives it imperatively from auseEffectvia a ref: get the 2D/WebGL context, run the setup and render loop there. - Clean up in the effect's return: cancel
requestAnimationFrameloops, remove listeners, and release contexts, so theme switches and remounts don't leak or double-run. - Mixing tiers is fine: a mostly static page can mount one interactive island, and a data board
can hand a chart's
<canvas>to imperative code while React owns the chrome.
The import allowlist still applies (react, react-dom, @posthog/quill, recharts, lucide-react,
dayjs) — browser globals (document, CanvasRenderingContext2D, WebGLRenderingContext,
requestAnimationFrame, IntersectionObserver, Web Audio, etc.) need no import. Three.js and
other npm graphics libraries are not yet loadable; write against raw WebGL or 2D canvas until the
build pipeline's dependency admission ships.
Styling and theme without Quill
- Size the outermost JSX/HTML element to the iframe viewport with
min-h-screenormin-height: 100vh, so it fills the viewport and grows past it as content demands. Do not useh-screenorheight: 100vhthere: a fixed viewport height caps a flex column, so tall children shrink and clip instead of scrolling. Do not useh-fullorheight: 100%on that root either: a published canvas's artifact shell gives itshtml,body, and#rootelements no explicit height, so percentage height collapses to the content height. Amin-heightroot is not a definite height, so a descendant's percentage height still collapses; give an intermediate wrapper an explicit height when a child must fill a box. - Use Tailwind utilities and/or a
<style>block (keyframes and complex selectors are fine). - The host toggles a
.darkclass on the document root when the user's PostHog theme changes. Define your colors as CSS variables under:root { … }with overrides underhtml.dark { … }, or use theme token utilities (bg-background,text-foreground,border-border) — never a light-only hardcoded color. - Give your own CSS variables a prefix (
--doc-bg,--doc-muted). Never reuse a platform token name: the bundled Quill stylesheet sets--background,--border,--card,--chrome,--input,--muted,--primary, and--fill-*on every element, so a:rootorhtml.darkvalue with one of those names never reaches any element. A page that colors its text with its own--mutedthen renders unreadable (pale text on a pale page). Validation rejects such a declaration withplatform_token_redeclared. - For canvas/WebGL drawing colors, read the resolved token at runtime
(
getComputedStyle(document.documentElement).getPropertyValue("--primary")) or your own CSS variables, and re-read on theme change if the scene is long-lived.
Rules that still apply
- PostHog data comes only through the
phbridge (seequerying-canvas-data), includingph.capturefor interaction analytics. Other requests and external styles, images, fonts, media, or frames require their exact public HTTPS origins incapabilities.network.originsand work only after publishing. Remote scripts and dynamic imports remain blocked. - A document that states PostHog numbers must make each one verifiable: an insight-backed number
links its saved insight through
ph.openExternal(URL from thegenerate-app-urlMCP tool, from a click); an ad-hocph.querynumber discloses the exact query that ran in a<details>element beside the claim — see "Verifiability" inquerying-canvas-data. - External links go through
ph.openExternal(url)(posthog.com origins only), from a user interaction. - Validate and publish through the c
Câu hỏi thường gặp
Tôi có cần biết React không?
Không nhiều. Phần React chỉ là lớp bọc mỏng, phần còn lại là HTML, CSS và mã trình duyệt thông thường.
Canvas có thể hiển thị dữ liệu từ PostHog không?
Có, qua cầu nối dữ liệu của PostHog, mà canvas phải khai báo.
Khi nào cách này không phải là lựa chọn tốt nhất?
Với một ứng dụng tương tác có nhiều điều khiển, cách dùng React và Quill phù hợp hơn.
Chi tiết
Mô tả gốc của tác giả
Author a PostHog canvas with semantic HTML, CSS, and direct browser APIs — documents, articles, generative graphics, 2D canvas and WebGL experiences, and focused experiments where React components add no useful structure. Use after building-canvases has routed a canvas request to a plain-HTML/browser-API implementation. Covers the thin component wrapper the current runtime requires, styling and theming without Quill, drawing surfaces, and animation/cleanup patterns.
repo: PostHog/posthog
Độ phổ biến
- Sao GitHub
- 41k
- Vị trí xếp hạng
- #6839
- Giấy phép
- —
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
depot-ci
41kGiúp agent của bạn thiết lập và chạy quy trình Depot CI, một lựa chọn thay thế GitHub Actions, gồm chuyển các quy trình hiện có và đọc nhật ký chạy.
depot-container-builds
41kGiúp agent của bạn build image Docker trên các builder từ xa của Depot, gồm image đa nền tảng, đẩy lên registry và sửa lỗi build.
depot-github-runners
41kGiúp agent của bạn chuyển các job GitHub Actions sang runner do Depot quản lý, chọn kích thước và nhãn runner, và xử lý lỗi thiết lập runner.
editing-agents-md
41kGiúp agent của bạn quyết định một quy tắc nên nằm trong file AGENTS.md hay CLAUDE.md, và viết sao cho quy tắc được tuân thủ mà file không bị phình to.
Skill tương tự
angular-developer
280kGiúp agent của bạn viết code Angular và tư vấn cấu trúc dự án, hữu ích khi bắt đầu dự án mới hoặc cải thiện hiệu suất.
frontend-a11y
280kGiúp agent của bạn làm cho giao diện web dễ tiếp cận với mọi người. Đảm bảo website và ứng dụng hoạt động tốt với trình đọc màn hình và điều hướng bằng bàn phím.
frontend-patterns
280kGiúp agent của bạn áp dụng các mẫu hiện đại trong phát triển frontend. Tối ưu hiệu năng, quản lý trạng thái và tuân theo thực hành tốt nhất với React và Next.js.