generative-ui by himself65/finance-skills
npx skills add https://github.com/himself65/finance-skills --skill generative-ui此技能包含 Claude 内置 show_widget 工具的完整设计系统——该生成式 UI 功能可在 claude.ai 对话中内联渲染交互式 HTML/SVG 小组件。以下指南是实际的 Anthropic "Imagine — Visual Creation Suite" 设计规则,提取出来以便您无需 read_me 设置调用即可直接生成高质量小组件。
工作原理:在 claude.ai 上,Claude 可以访问 show_widget 工具,该工具可在对话中内联渲染原始 HTML/SVG 片段。此技能提供了良好的设计系统、模板和模式来使用它。
根据动词而非名词进行路由。同一主题,根据所问内容采用不同的视觉呈现:
| 用户说 | 类型 | 格式 |
|---|---|---|
| "X 如何工作" | 说明性图表 | SVG |
| "X 架构" | 结构图 | SVG |
| "步骤是什么" | 流程图 | SVG |
| "解释复利" |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 交互式解释器 |
| HTML |
| "比较这些选项" | 对比网格 | HTML |
| "显示收入图表" | Chart.js 图表 | HTML |
| "创建联系人卡片" | 数据记录 | HTML |
| "画一个日落" | 艺术/插图 | SVG |
<style> → HTML 内容 → <script>
输出是逐令牌流式传输的。样式必须在它们所针对的元素之前存在,脚本必须在 DOM 准备就绪后运行。
<!-- 注释 --> 或 /* 注释 */(浪费令牌,破坏流式传输)代码样式 而非加粗<!DOCTYPE>、<html>、<head> 或 <body>——仅内容片段position: fixed——使用正常流布局display: none 部分border-radius: var(--border-radius-lg),元素使用 var(--border-radius-md)Math.round()、.toFixed(n) 或 Intl.NumberFormat外部资源仅允许从以下地址加载:
cdnjs.cloudflare.comcdn.jsdelivr.netunpkg.comesm.sh所有其他来源均被阻止——请求将静默失败。
背景:--color-background-primary(白色),-secondary(表面),-tertiary(页面背景),-info,-danger,-success,-warning 文本:--color-text-primary(黑色),-secondary(柔和),-tertiary(提示),-info,-danger,-success,-warning 边框:--color-border-tertiary(0.15α,默认),-secondary(0.3α,悬停),-primary(0.4α),语义 -info/-danger/-success/-warning 排版:--font-sans,--font-serif,--font-mono 布局:--border-radius-md(8px),--border-radius-lg(12px),--border-radius-xl(16px)
所有变量自动适应浅色/深色模式。
深色模式是必需的——每种颜色必须在两种模式下都有效:
color: #333c-blue,c-teal 等)——它们会自动处理浅色/深色模式sendPrompt(text)一个全局函数,用于向聊天发送消息,就像用户输入的一样。当用户的下一步操作受益于 Claude 的思考时使用它。在 JS 中处理过滤、排序、切换和计算。
show_widget 渲染show_widget 工具内置于 claude.ai 中——无需激活。直接传递您的小组件代码:
{
"title": "snake_case_widget_name",
"widget_code": "<style>...</style>\n<div>...</div>\n<script>...</script>"
}
| 参数 | 类型 | 必需 | 描述 |
|---|---|---|---|
title | 字符串 | 是 | 小组件的蛇形命名标识符 |
widget_code | 字符串 | 是 | HTML 或 SVG 代码。对于 SVG:以 <svg> 开头。对于 HTML:内容片段 |
对于 SVG 输出:以 <svg 开头 widget_code——它将自动检测并适当包装。
对于图表,使用 onload 回调模式来处理脚本加载顺序:
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px;">
<div style="background: var(--color-background-secondary); border-radius: var(--border-radius-md); padding: 1rem;">
<div style="font-size: 13px; color: var(--color-text-secondary);">标签</div>
<div style="font-size: 24px; font-weight: 500;" id="stat1">—</div>
</div>
</div>
<div style="position: relative; width: 100%; height: 300px; margin-top: 1rem;">
<canvas id="myChart"></canvas>
</div>
<div style="display: flex; align-items: center; gap: 12px; margin-top: 1rem;">
<label style="font-size: 14px; color: var(--color-text-secondary);">参数</label>
<input type="range" min="0" max="100" value="50" id="param" step="1" style="flex: 1;" />
<span style="font-size: 14px; font-weight: 500; min-width: 32px;" id="param-out">50</span>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js" onload="initChart()"></script>
<script>
function initChart() {
const slider = document.getElementById('param');
const out = document.getElementById('param-out');
let chart = null;
function update() {
const val = parseFloat(slider.value);
out.textContent = val;
document.getElementById('stat1').textContent = val.toFixed(1);
const labels = [], data = [];
for (let x = 0; x <= 100; x++) {
labels.push(x);
data.push(x * val / 100);
}
if (chart) chart.destroy();
chart = new Chart(document.getElementById('myChart'), {
type: 'line',
data: { labels, datasets: [{ data, borderColor: '#7F77DD', borderWidth: 2, pointRadius: 0, fill: false }] },
options: {
responsive: true,
maintainAspectRatio: false,
plugins: { legend: { display: false } },
scales: { x: { grid: { display: false } } }
}
});
}
slider.addEventListener('input', update);
update();
}
if (window.Chart) initChart();
</script>
Chart.js 规则:
responsive: true, maintainAspectRatio: false-$5M 而非 $-5M(负号在货币符号之前)onload="initChart()" + if (window.Chart) initChart(); 作为后备对于流程图和图表,使用带有预构建类的 SVG:
<svg width="100%" viewBox="0 0 680 H">
<defs>
<marker id="arrow" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
<path d="M2 1L8 5L2 9" fill="none" stroke="context-stroke" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</marker>
</defs>
<!-- 单行节点(44px 高) -->
<g class="node c-blue" onclick="sendPrompt('告诉我更多关于这个的信息')">
<rect x="250" y="40" width="180" height="44" rx="8" stroke-width="0.5"/>
<text class="th" x="340" y="62" text-anchor="middle" dominant-baseline="central">步骤一</text>
</g>
<!-- 连接箭头 -->
<line x1="340" y1="84" x2="340" y2="120" class="arr" marker-end="url(#arrow)"/>
<!-- 两行节点(56px 高) -->
<g class="node c-teal" onclick="sendPrompt('解释此步骤')">
<rect x="230" y="120" width="220" height="56" rx="8" stroke-width="0.5"/>
<text class="th" x="340" y="140" text-anchor="middle" dominant-baseline="central">步骤二</text>
<text class="ts" x="340" y="158" text-anchor="middle" dominant-baseline="central">处理输入</text>
</g>
</svg>
SVG 规则:
viewBox="0 0 680 H")。设置 H 以适应内容 + 40px 内边距t(14px),ts(12px 次要),th(14px 中等 500),box,node,arr,c-{color}<text> 元素必须携带一个类(t,ts 或 th)dominant-baseline="central"fill="none"(SVG 默认为 fill: black)onclick="sendPrompt('...')"对于交互式解释器(滑块、实时计算、内联 SVG):
<div style="display: flex; align-items: center; gap: 12px; margin: 0 0 1.5rem;">
<label style="font-size: 14px; color: var(--color-text-secondary);">年数</label>
<input type="range" min="1" max="40" value="20" id="years" style="flex: 1;" />
<span style="font-size: 14px; font-weight: 500; min-width: 24px;" id="years-out">20</span>
</div>
<div style="display: flex; align-items: baseline; gap: 8px; margin: 0 0 1.5rem;">
<span style="font-size: 14px; color: var(--color-text-secondary);">$1,000 →</span>
<span style="font-size: 24px; font-weight: 500;" id="result">$3,870</span>
</div>
<div style="margin: 2rem 0; position: relative; height: 240px;">
<canvas id="chart"></canvas>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js" onload="initChart()"></script>
<script>
function initChart() {
// 滑块逻辑,图表渲染,sendPrompt() 用于后续问题
}
if (window.Chart) initChart();
</script>
使用 sendPrompt() 让用户提出后续问题:sendPrompt('如果我将利率提高到 10% 会怎样?')
渲染小组件后,简要解释:
保持简洁——小组件本身会说话。
references/design_system.md —— 完整的调色板(9 个渐变 × 7 个色阶)、CSS 变量、UI 组件模式、指标卡片、布局规则references/svg_and_diagrams.md —— SVG viewBox 设置、字体校准、预构建类、带有示例的流程图/结构图/说明性图表模式references/chart_js.md —— Chart.js 配置、脚本加载顺序、canvas 尺寸、图例模式、仪表板布局当您需要特定的设计令牌、SVG 坐标计算或 Chart.js 配置详细信息时,请阅读相关的参考文件。
每周安装次数
101
代码仓库
GitHub 星标数
489
首次出现
11 天前
安全审计
安装于
codex91
gemini-cli89
opencode89
cursor89
github-copilot88
kimi-cli88
This skill contains the complete design system for Claude's built-in show_widget tool — the generative UI feature that renders interactive HTML/SVG widgets inline in claude.ai conversations. The guidelines below are the actual Anthropic "Imagine — Visual Creation Suite" design rules, extracted so you can produce high-quality widgets directly without needing the read_me setup call.
How it works : On claude.ai, Claude has access to the show_widget tool which renders raw HTML/SVG fragments inline in the conversation. This skill provides the design system, templates, and patterns to use it well.
Route on the verb , not the noun. Same subject, different visual depending on what was asked:
| User says | Type | Format |
|---|---|---|
| "how does X work" | Illustrative diagram | SVG |
| "X architecture" | Structural diagram | SVG |
| "what are the steps" | Flowchart | SVG |
| "explain compound interest" | Interactive explainer | HTML |
| "compare these options" | Comparison grid | HTML |
| "show revenue chart" | Chart.js chart | HTML |
| "create a contact card" | Data record | HTML |
| "draw a sunset" | Art/illustration | SVG |
<style> → HTML content → <script>
Output streams token-by-token. Styles must exist before the elements they target, and scripts must run after the DOM is ready.
<!-- comments --> or /* comments */ (waste tokens, break streaming)code style not bold<!DOCTYPE>, <html>, <head>, or <body> — just content fragmentsposition: fixed — use normal-flow layoutsExternal resources may ONLY load from:
cdnjs.cloudflare.comcdn.jsdelivr.netunpkg.comesm.shAll other origins are blocked — the request silently fails.
Backgrounds : --color-background-primary (white), -secondary (surfaces), -tertiary (page bg), -info, -danger, -success, -warning Text : --color-text-primary (black), -secondary (muted), -tertiary (hints), -info, , , : (0.15α, default), (0.3α, hover), (0.4α), semantic : , , : (8px), (12px), (16px)
All auto-adapt to light/dark mode.
Dark mode is mandatory — every color must work in both modes:
color: #333c-blue, c-teal, etc.) — they handle light/dark automaticallysendPrompt(text)A global function that sends a message to chat as if the user typed it. Use it when the user's next step benefits from Claude thinking. Handle filtering, sorting, toggling, and calculations in JS instead.
show_widgetThe show_widget tool is built into claude.ai — no activation needed. Pass your widget code directly:
{
"title": "snake_case_widget_name",
"widget_code": "<style>...</style>\n<div>...</div>\n<script>...</script>"
}
| Parameter | Type | Required | Description |
|---|---|---|---|
title | string | Yes | Snake_case identifier for the widget |
widget_code | string | Yes | HTML or SVG code. For SVG: start with <svg>. For HTML: content fragment |
For SVG output: start widget_code with <svg — it will be auto-detected and wrapped appropriately.
For charts, use onload callback pattern to handle script load ordering:
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px;">
<div style="background: var(--color-background-secondary); border-radius: var(--border-radius-md); padding: 1rem;">
<div style="font-size: 13px; color: var(--color-text-secondary);">Label</div>
<div style="font-size: 24px; font-weight: 500;" id="stat1">—</div>
</div>
</div>
<div style="position: relative; width: 100%; height: 300px; margin-top: 1rem;">
<canvas id="myChart"></canvas>
</div>
<div style="display: flex; align-items: center; gap: 12px; margin-top: 1rem;">
<label style="font-size: 14px; color: var(--color-text-secondary);">Parameter</label>
<input type="range" min="0" max="100" value="50" id="param" step="1" style="flex: 1;" />
<span style="font-size: 14px; font-weight: 500; min-width: 32px;" id="param-out">50</span>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js" onload="initChart()"></script>
<script>
function initChart() {
const slider = document.getElementById('param');
const out = document.getElementById('param-out');
let chart = null;
function update() {
const val = parseFloat(slider.value);
out.textContent = val;
document.getElementById('stat1').textContent = val.toFixed(1);
const labels = [], data = [];
for (let x = 0; x <= 100; x++) {
labels.push(x);
data.push(x * val / 100);
}
if (chart) chart.destroy();
chart = new Chart(document.getElementById('myChart'), {
type: 'line',
data: { labels, datasets: [{ data, borderColor: '#7F77DD', borderWidth: 2, pointRadius: 0, fill: false }] },
options: {
responsive: true,
maintainAspectRatio: false,
plugins: { legend: { display: false } },
scales: { x: { grid: { display: false } } }
}
});
}
slider.addEventListener('input', update);
update();
}
if (window.Chart) initChart();
</script>
Chart.js rules:
responsive: true, maintainAspectRatio: false-$5M not $-5M (negative sign before currency symbol)onload="initChart()" on CDN script tag + if (window.Chart) initChart(); as fallbackFor flowcharts and diagrams, use SVG with pre-built classes:
<svg width="100%" viewBox="0 0 680 H">
<defs>
<marker id="arrow" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
<path d="M2 1L8 5L2 9" fill="none" stroke="context-stroke" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</marker>
</defs>
<!-- Single-line node (44px tall) -->
<g class="node c-blue" onclick="sendPrompt('Tell me more about this')">
<rect x="250" y="40" width="180" height="44" rx="8" stroke-width="0.5"/>
<text class="th" x="340" y="62" text-anchor="middle" dominant-baseline="central">Step one</text>
</g>
<!-- Connector arrow -->
<line x1="340" y1="84" x2="340" y2="120" class="arr" marker-end="url(#arrow)"/>
<!-- Two-line node (56px tall) -->
<g class="node c-teal" onclick="sendPrompt('Explain this step')">
<rect x="230" y="120" width="220" height="56" rx="8" stroke-width="0.5"/>
<text class="th" x="340" y="140" text-anchor="middle" dominant-baseline="central">Step two</text>
<text class="ts" x="340" y="158" text-anchor="middle" dominant-baseline="central">Processes the input</text>
</g>
</svg>
SVG rules:
viewBox="0 0 680 H"). Set H to fit content + 40px paddingt (14px), ts (12px secondary), th (14px medium 500), box, node, arr, c-{color}<text> element must carry a class (t, ts, or )For interactive explainers (sliders, live calculations, inline SVG):
<div style="display: flex; align-items: center; gap: 12px; margin: 0 0 1.5rem;">
<label style="font-size: 14px; color: var(--color-text-secondary);">Years</label>
<input type="range" min="1" max="40" value="20" id="years" style="flex: 1;" />
<span style="font-size: 14px; font-weight: 500; min-width: 24px;" id="years-out">20</span>
</div>
<div style="display: flex; align-items: baseline; gap: 8px; margin: 0 0 1.5rem;">
<span style="font-size: 14px; color: var(--color-text-secondary);">$1,000 →</span>
<span style="font-size: 24px; font-weight: 500;" id="result">$3,870</span>
</div>
<div style="margin: 2rem 0; position: relative; height: 240px;">
<canvas id="chart"></canvas>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js" onload="initChart()"></script>
<script>
function initChart() {
// slider logic, chart rendering, sendPrompt() for follow-ups
}
if (window.Chart) initChart();
</script>
Use sendPrompt() to let users ask follow-ups: sendPrompt('What if I increase the rate to 10%?')
After rendering the widget, briefly explain:
Keep it concise — the widget speaks for itself.
references/design_system.md — Complete color palette (9 ramps × 7 stops), CSS variables, UI component patterns, metric cards, layout rulesreferences/svg_and_diagrams.md — SVG viewBox setup, font calibration, pre-built classes, flowchart/structural/illustrative diagram patterns with examplesreferences/chart_js.md — Chart.js configuration, script load ordering, canvas sizing, legend patterns, dashboard layoutRead the relevant reference file when you need specific design tokens, SVG coordinate math, or Chart.js configuration details.
Weekly Installs
101
Repository
GitHub Stars
489
First Seen
11 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
codex91
gemini-cli89
opencode89
cursor89
github-copilot88
kimi-cli88
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
116,600 周安装
display: none sections during streamingborder-radius: var(--border-radius-lg) for cards, var(--border-radius-md) for elementsMath.round(), .toFixed(n), or Intl.NumberFormat-danger-success-warning--color-border-tertiary-secondary-primary-info/-danger/-success/-warning--font-sans--font-serif--font-mono--border-radius-md--border-radius-lg--border-radius-xlthdominant-baseline="central" for vertical text centering in boxesfill="none" (SVG defaults to fill: black)onclick="sendPrompt('...')"