安裝 belt CLI 技能:
npx skills add belt-sh/cli
元件渲染器
來自 ui.inference.sh 的 JSON 宣告式 UI。

快速開始
npx shadcn@latest add https://ui.inference.sh/r/widgets.json
基本用法
import { WidgetRenderer } from "@/registry/blocks/widgets/widget-renderer"
import type { Widget, WidgetAction } from "@/registry/blocks/widgets/types"
const widget: Widget = {
type: 'ui',
title: '我的元件',
children: [
{ type: 'text', value: 'Hello World' },
{ type: 'button', label: '點擊我', onClickAction: { type: 'click' } },
],
}
<WidgetRenderer
widget={widget}
onAction={(action, formData) => console.log(action, formData)}
/>
元件類型
佈局
{ "type": "row", "gap": 2, "children": [...] }
{ "type": "col", "gap": 2, "children": [...] }
{ "type": "box", "background": "gradient-ocean", "padding": 4, "radius": "lg", "children": [...] }
排版
{ "type": "title", "value": "標題", "size": "2xl", "weight": "bold" }
{ "type": "text", "value": "內文", "variant": "bold" }
{ "type": "caption", "value": "小字" }
{ "type": "label", "value": "欄位標籤", "fieldName": "email" }
互動
{ "type": "button", "label": "提交", "variant": "default", "onClickAction": { "type": "submit" } }
{ "type": "input", "name": "email", "placeholder": "請輸入 Email" }
{ "type": "textarea", "name": "message", "placeholder": "您的訊息" }
{ "type": "select", "name": "plan", "options": [{ "value": "pro", "label": "專業版" }] }
{ "type": "checkbox", "name": "agree", "label": "我同意", "defaultChecked": false }
顯示
{ "type": "badge", "label": "新增", "variant": "secondary" }
{ "type": "icon", "iconName": "check", "size": "lg" }
{ "type": "image", "src": "https://...", "alt": "圖片", "width": 100, "height": 100 }
{ "type": "divider" }
範例:航班卡片
const flightWidget: Widget = {
type: 'ui',
children: [
{
type: 'box', background: 'gradient-ocean', padding: 4, radius: 'lg', children: [
{
type: 'row', justify: 'between', children: [
{
type: 'col', gap: 1, children: [
{ type: 'caption', value: '出發' },
{ type: 'title', value: 'SFO', size: '2xl', weight: 'bold' },
]
},
{ type: 'icon', iconName: 'plane', size: 'lg' },
{
type: 'col', gap: 1, align: 'end', children: [
{ type: 'caption', value: '抵達' },
{ type: 'title', value: 'JFK', size: '2xl', weight: 'bold' },
]
},
]
},
]
},
],
}
範例:表單
const formWidget: Widget = {
type: 'ui',
title: '聯絡表單',
asForm: true,
children: [
{
type: 'col', gap: 3, children: [
{ type: 'input', name: 'name', placeholder: '您的姓名' },
{ type: 'input', name: 'email', placeholder: 'Email 地址' },
{ type: 'textarea', name: 'message', placeholder: '訊息' },
{ type: 'button', label: '傳送', variant: 'default', onClickAction: { type: 'submit' } },
]
},
],
}
漸層
| 名稱 | 描述 |
|---|---|
gradient-ocean | 藍色青綠漸層 |
gradient-sunset | 橘色粉紅漸層 |
gradient-purple | 紫色漸層 |
gradient-cool | 冷藍色漸層 |
gradient-midnight | 深藍色漸層 |
處理動作
const handleAction = (action: WidgetAction, formData?: WidgetFormData) => {
switch (action.type) {
case 'submit':
console.log('表單資料:', formData)
break
case 'click':
console.log('按鈕被點擊')
break
}
}
相關技能
# 完整代理元件
npx skills add inference-sh/skills@agent-ui
# 聊天 UI 區塊
npx skills add inference-sh/skills@chat-ui
# 工具 UI
npx skills add inference-sh/skills@tools-ui