Widgets Ui

作者 inference-sh0aabdc6f47f7無授權條款763 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫2 天前更新

Declarative UI widgets from JSON for React/Next.js from ui.inference.sh. Render rich interactive UIs from structured agent responses. Capabilities: forms, buttons, cards, layouts, inputs, selects, checkboxes. Use for: agent-generated UIs, dynamic forms, data display, interactive cards. Triggers: widgets, declarative ui, json ui, widget renderer, agent widgets, dynamic ui, form widgets, card widgets, shadcn widgets, structured output ui

AI 產生的概覽

將宣告式 JSON 元件樹渲染為 React/Next.js 互動式介面,例如表單、卡片與版面配置。

功能
此技能說明了一個 WidgetRenderer 元件,可將結構化 JSON 元件定義轉換為 React/Next.js 互動式介面。內容涵蓋版面配置、排版、互動與展示類元件,包括列、欄、方塊、按鈕、輸入框、下拉選單、核取方塊、徽章、圖示與圖片。也說明如何處理送出與點擊等元件動作,並列出可用的漸層背景。產出為用於代理程式生成介面的前端程式碼與 JSON 結構。
適用情境
當代理程式需要把結構化輸出渲染成豐富的互動式介面,而非純文字時使用。適合 React 或 Next.js 專案中的動態表單、資料展示卡片及其他代理程式生成的介面。也適用於將元件動作接回應用程式處理邏輯的情境。
執行需求
需要 React 或 Next.js 專案,並可透過 shadcn 命令列安裝元件登錄檔中的元件。文件引用了外部登錄檔與文件網站,取得時需要網路連線。此技能不附帶指令碼,僅包含說明與程式碼範例。

Install the belt CLI skill: npx skills add belt-sh/cli

Widget Renderer

Declarative UI from JSON via ui.inference.sh.

[Widget Renderer]

Quick Start

bash
npx shadcn@latest add https://ui.inference.sh/r/widgets.json

Basic Usage

tsx
import { WidgetRenderer } from "@/registry/blocks/widgets/widget-renderer"import type { Widget, WidgetAction } from "@/registry/blocks/widgets/types"
const widget: Widget = {  type: 'ui',  title: 'My Widget',  children: [    { type: 'text', value: 'Hello World' },    { type: 'button', label: 'Click me', onClickAction: { type: 'click' } },  ],}
<WidgetRenderer  widget={widget}  onAction={(action, formData) => console.log(action, formData)}/>

Widget Types

Layout

json
{ "type": "row", "gap": 2, "children": [...] }{ "type": "col", "gap": 2, "children": [...] }{ "type": "box", "background": "gradient-ocean", "padding": 4, "radius": "lg", "children": [...] }

Typography

json
{ "type": "title", "value": "Heading", "size": "2xl", "weight": "bold" }{ "type": "text", "value": "Body text", "variant": "bold" }{ "type": "caption", "value": "Small text" }{ "type": "label", "value": "Field label", "fieldName": "email" }

Interactive

json
{ "type": "button", "label": "Submit", "variant": "default", "onClickAction": { "type": "submit" } }{ "type": "input", "name": "email", "placeholder": "Enter email" }{ "type": "textarea", "name": "message", "placeholder": "Your message" }{ "type": "select", "name": "plan", "options": [{ "value": "pro", "label": "Pro" }] }{ "type": "checkbox", "name": "agree", "label": "I agree", "defaultChecked": false }

Display

json
{ "type": "badge", "label": "New", "variant": "secondary" }{ "type": "icon", "iconName": "check", "size": "lg" }{ "type": "image", "src": "https://...", "alt": "Image", "width": 100, "height": 100 }{ "type": "divider" }

Example: Flight Card

tsx
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: 'departure' },                { type: 'title', value: 'SFO', size: '2xl', weight: 'bold' },              ]            },            { type: 'icon', iconName: 'plane', size: 'lg' },            {              type: 'col', gap: 1, align: 'end', children: [                { type: 'caption', value: 'arrival' },                { type: 'title', value: 'JFK', size: '2xl', weight: 'bold' },              ]            },          ]        },      ]    },  ],}

Example: Form

tsx
const formWidget: Widget = {  type: 'ui',  title: 'Contact Form',  asForm: true,  children: [    {      type: 'col', gap: 3, children: [        { type: 'input', name: 'name', placeholder: 'Your name' },        { type: 'input', name: 'email', placeholder: 'Email address' },        { type: 'textarea', name: 'message', placeholder: 'Message' },        { type: 'button', label: 'Send', variant: 'default', onClickAction: { type: 'submit' } },      ]    },  ],}

Gradients

NameDescription
gradient-oceanBlue teal gradient
gradient-sunsetOrange pink gradient
gradient-purplePurple gradient
gradient-coolCool blue gradient
gradient-midnightDark blue gradient

Handling Actions

tsx
const handleAction = (action: WidgetAction, formData?: WidgetFormData) => {  switch (action.type) {    case 'submit':      console.log('Form data:', formData)      break    case 'click':      console.log('Button clicked')      break  }}

Related Skills

bash
# Full agent componentnpx skills add inference-sh/skills@agent-ui
# Chat UI blocksnpx skills add inference-sh/skills@chat-ui
# Tool UInpx skills add inference-sh/skills@tools-ui

Documentation

Component docs: ui.inference.sh/blocks/widgets

來源與署名

來源:inference-sh/skills位於ui/widgets-ui提交0aabdc6

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架