generative-ui

安装量: 120
排名: #10473

安装

npx skills add https://github.com/himself65/finance-skills --skill generative-ui
Generative UI Skill
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. Step 1: Pick the Right Visual Type 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 Step 2: Build the Widget Structure (strict order)
<style> → HTML content → " } 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 . For HTML: content fragment For SVG output: start widget_code with < div style = " background : var ( --color-background-secondary ) ; border-radius : var ( --border-radius-md ) ; padding : 1 rem ; " > < div style = " font-size : 13 px ; color : var ( --color-text-secondary ) ; " > Label < div style = " font-size : 24 px ; font-weight : 500 ; " id = " stat1 " > — < div style = " position : relative ; width : 100 % ; height : 300 px ; margin-top : 1 rem ; " > < canvas id = " myChart " > < div style = " display : flex ; align-items : center ; gap : 12 px ; margin-top : 1 rem ; " > < label style = " font-size : 14 px ; color : var ( --color-text-secondary ) ; " > Parameter < input type = " range " min = " 0 " max = " 100 " value = " 50 " id = " param " step = " 1 " style = " flex : 1 ; " /> < span style = " font-size : 14 px ; font-weight : 500 ; min-width : 32 px ; " id = " param-out " > 50 < script src = " https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js " onload = " initChart ( ) " > < 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 ( ) ; Chart.js rules: Canvas cannot resolve CSS variables — use hardcoded hex Set height ONLY on the wrapper div, never on canvas itself Always responsive: true, maintainAspectRatio: false Always disable default legend, build custom HTML legends Number formatting: -$5M not $-5M (negative sign before currency symbol) Use onload="initChart()" on CDN script tag + if (window.Chart) initChart(); as fallback Step 5: SVG Diagram Template For 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 " /> < 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 < line x1 = " 340 " y1 = " 84 " x2 = " 340 " y2 = " 120 " class = " arr " marker-end = " url(#arrow) " /> < 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 class = " ts " x = " 340 " y = " 158 " text-anchor = " middle " dominant-baseline = " central " > Processes the input SVG rules: ViewBox always 680px wide ( viewBox="0 0 680 H" ). Set H to fit content + 40px padding Safe area: x=40 to x=640, y=40 to y=(H-40) Pre-built classes: t (14px), ts (12px secondary), th (14px medium 500), box , node , arr , c-{color} Every element must carry a class ( t , ts , or th ) Use dominant-baseline="central" for vertical text centering in boxes Connector paths need fill="none" (SVG defaults to fill: black ) Stroke width: 0.5px for borders and edges Make all nodes clickable: onclick="sendPrompt('...')" Step 6: Interactive Explainer Template For interactive explainers (sliders, live calculations, inline SVG): < div style = " display : flex ; align-items : center ; gap : 12 px ; margin : 0 0 1.5 rem ; " > < label style = " font-size : 14 px ; color : var ( --color-text-secondary ) ; " > Years < input type = " range " min = " 1 " max = " 40 " value = " 20 " id = " years " style = " flex : 1 ; " /> < span style = " font-size : 14 px ; font-weight : 500 ; min-width : 24 px ; " id = " years-out " > 20 < div style = " display : flex ; align-items : baseline ; gap : 8 px ; margin : 0 0 1.5 rem ; " > < span style = " font-size : 14 px ; color : var ( --color-text-secondary ) ; " > $1,000 → < span style = " font-size : 24 px ; font-weight : 500 ; " id = " result " > $3,870 < div style = " margin : 2 rem 0 ; position : relative ; height : 240 px ; " > < canvas id = " chart " > < script src = " https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js " onload = " initChart ( ) " > < script > function initChart ( ) { // slider logic, chart rendering, sendPrompt() for follow-ups } if ( window . Chart ) initChart ( ) ; Use sendPrompt() to let users ask follow-ups: sendPrompt('What if I increase the rate to 10%?') Step 7: Respond to the User After rendering the widget, briefly explain: What the widget shows How to interact with it (which controls do what) One key insight from the data Keep it concise — the widget speaks for itself. Reference Files references/design_system.md — Complete color palette (9 ramps × 7 stops), CSS variables, UI component patterns, metric cards, layout rules references/svg_and_diagrams.md — SVG viewBox setup, font calibration, pre-built classes, flowchart/structural/illustrative diagram patterns with examples references/chart_js.md — Chart.js configuration, script load ordering, canvas sizing, legend patterns, dashboard layout Read the relevant reference file when you need specific design tokens, SVG coordinate math, or Chart.js configuration details.
返回排行榜