Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions external_plugins/design-to-components/.zcode-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "design-to-components",
"version": "0.1.0",
"description": "Turn a design or screenshot into a React component kit: keep design tokens (colours, fonts, font sizes, radii, spacing, shadows) and a component checklist in the panel, the agent writes TSX components with one example per state, and the plugin type-checks them with TypeScript (strict), renders every example next to the design, bundles them with esbuild-wasm into an interactive catalog page, and outputs tokens.css and tokens.ts. Flags hard-coded colours and missing states. Local only.",
"description_i18n": {
"en": "Turn a design or screenshot into a React component kit: keep design tokens (colours, fonts, font sizes, radii, spacing, shadows) and a component checklist in the panel, the agent writes TSX components with one example per state, and the plugin type-checks them with TypeScript (strict), renders every example next to the design, bundles them with esbuild-wasm into an interactive catalog page, and outputs tokens.css and tokens.ts. Flags hard-coded colours and missing states. Local only.",
"zh-CN": "把设计稿或截图做成 React 组件库:在面板里维护设计变量(颜色、字体、字号、圆角、间距、阴影)和组件清单,Agent 为每个组件写 TSX,每种状态一个示例;插件用 TypeScript(strict)做类型检查,把每个示例渲染出来与设计稿并排对照,用 esbuild-wasm 打包成可交互的组件目录页,并输出 tokens.css 和 tokens.ts。会提示写死的颜色和缺少的状态示例。全部在本地完成。"
},
"author": {
"name": "Penova",
"url": "https://github.com/ppppp2005-p"
},
"license": "MIT",
"keywords": [
"react",
"components",
"design system",
"design tokens",
"tsx",
"typescript",
"storybook",
"esbuild",
"组件库",
"设计稿",
"设计变量",
"前端"
],
"skills": "skills",
"mcpServers": {
"design-to-components": {
"type": "stdio",
"command": "node",
"args": [
"${ZCODE_PLUGIN_ROOT}/dist/server.mjs"
],
"cwd": "${ZCODE_PROJECT_DIR}",
"timeoutMs": 900000,
"env": {
"ZCODE_WORKSPACE_ROOT": "${ZCODE_PROJECT_DIR}"
}
}
},
"ui": {
"surfaces": [
{
"id": "editor",
"title": {
"zh-CN": "设计稿转组件库",
"en-US": "Design To Components"
},
"icon": "component",
"server": "design-to-components",
"resourceUri": "ui://design-to-components/panel.html",
"availability": "session"
}
]
}
}
21 changes: 21 additions & 0 deletions external_plugins/design-to-components/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Penova

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
48 changes: 48 additions & 0 deletions external_plugins/design-to-components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Design To Components

Turn a design or screenshot into a **React component kit**. The panel keeps the design tokens and a component checklist. The agent writes the TSX components. The plugin type-checks them, renders every state next to the design, and builds an interactive catalog page.

## Features

- **Design tokens** (`dc_tokens`): colours, fonts, font sizes, radii, spacing and shadows in `tokens.json`. They generate `tokens.css` (`--color-primary`, `--font-size-md`, `--radius-md`, `--space-4`, …) and a typed `tokens.ts`. You can edit them in the panel with colour pickers.
- **Component checklist** (`dc_plan`): each component lists the states it needs (for example Button: primary, secondary, disabled, loading). The panel shows which are written and compile (✓ / ✗ / ○).
- **Components** (`dc_write`): `src/<Name>.tsx` (+ `src/<Name>.css`). Each file exports the component and `examples`, one per state. Files live directly in `src/`; `src/components/<Name>/<Name>.tsx` is accepted and flattened.
- **Checks** on every write:
- **TypeScript strict** type-check with React 19 types.
- esbuild bundling (only `react` / `react-dom` and kit files can be imported).
- Every example is rendered (render errors are shown).
- The named export must exist, and each planned state needs an example.
- **Hard-coded colours** that should be tokens are flagged.
- **Preview**: every example rendered with the real CSS, next to the design image.
- **Catalog**: `catalog/index.html` is a self-contained interactive page (React + your components, bundled with esbuild-wasm) that works from `file://`. Plus `index.ts`, which re-exports everything.

## Usage

Ask the agent in ZCode Desktop:

- "Build React components from this design"
- "Pull the colours and type scale from the screenshot into tokens"
- "Add a loading state to the Button and check it compiles"

To use the kit in your app (React 18/19), copy `src/`, `tokens.css`, `tokens.ts` and `index.ts`, import `tokens.css` once, and let your bundler (Vite, Next, …) handle the CSS imports.

## Tools

| Tool | Purpose |
|---|---|
| `dc_new` | Create a kit (tokens files, README) and link design images |
| `dc_tokens` | Set / remove tokens; regenerates tokens.css / tokens.ts |
| `dc_plan` | Component checklist with required states |
| `dc_write` | Write / delete component files and rebuild |
| `dc_build` | Type-check, render examples and rebuild the catalog |

## Scope (v0.1)

- React + TypeScript with plain CSS files. No Vue, no Figma import, and no Tailwind or CSS-in-JS setup.
- Components can import only React and files in the kit. Third-party UI libraries are not available in the preview.
- The panel preview is static (each state is its own example). Hover, focus and typing can be tried in `catalog/index.html`.

## Privacy, network and files

- Runs locally with no network access and no API keys. esbuild (WebAssembly), TypeScript and the React types are bundled with the plugin.
- Writes only `ui-kit/<name>/` and `.design-to-components/project.json`.
48 changes: 48 additions & 0 deletions external_plugins/design-to-components/README_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 设计稿转组件库

把设计稿或截图做成 **React 组件库**。面板里维护设计变量和组件清单,Agent 编写 TSX 组件,插件负责类型检查,把每种状态渲染出来与设计稿并排对照,并生成可交互的组件目录页。

## 功能

- **设计变量**(`dc_tokens`):颜色、字体、字号、圆角、间距、阴影都存在 `tokens.json` 里。插件据此生成 `tokens.css`(`--color-primary`、`--font-size-md`、`--radius-md`、`--space-4` 等)和带类型的 `tokens.ts`。面板里可以用取色器直接修改。
- **组件清单**(`dc_plan`):列出每个组件需要的状态(例如 Button:primary、secondary、disabled、loading)。面板显示哪些已经写好、能否编译(✓ / ✗ / ○)。
- **组件**(`dc_write`):`src/<名称>.tsx`(可配 `src/<名称>.css`)。每个文件导出组件本身和 `examples`,每种状态一个示例。文件都直接放在 `src/`;写成 `src/components/<名称>/<名称>.tsx` 也可以,会自动平铺。
- **每次写入都会检查**:
- **TypeScript strict** 类型检查(使用 React 19 类型)。
- 用 esbuild 打包:只能引用 `react` / `react-dom` 和组件库里的文件。
- 渲染每个示例,渲染出错会直接显示。
- 必须有同名导出;清单里每种状态都要有对应示例。
- 提示应该改用设计变量的**写死颜色**。
- **预览**:每个示例都用真实 CSS 渲染,与设计稿并排显示。
- **组件目录页**:`catalog/index.html` 是一个自包含的交互页面(用 esbuild-wasm 把 React 和你的组件打包在一起),通过 `file://` 直接打开也能用。另外生成 `index.ts`,统一导出所有组件。

## 用法

在 ZCode Desktop 里对 Agent 说:

- “按这张设计稿做一套 React 组件”
- “把截图里的颜色和字号整理成设计变量”
- “给按钮加一个加载状态并检查能否编译”

在自己的项目(React 18/19)里使用:复制 `src/`、`tokens.css`、`tokens.ts` 和 `index.ts`,在入口处引入一次 `tokens.css`,CSS 文件交给打包工具(Vite、Next 等)处理。

## 工具

| 工具 | 作用 |
|---|---|
| `dc_new` | 新建组件库(生成设计变量文件和 README),关联设计稿 |
| `dc_tokens` | 设置或删除设计变量,重新生成 tokens.css / tokens.ts |
| `dc_plan` | 组件清单及每个组件需要的状态 |
| `dc_write` | 写入或删除组件文件,并重新构建 |
| `dc_build` | 类型检查、渲染示例、重新生成组件目录页 |

## 范围(v0.1)

- 只支持 React + TypeScript,样式用普通 CSS 文件;不支持 Vue,不接入 Figma,也不配置 Tailwind 或 CSS-in-JS。
- 组件只能引用 React 和组件库里的文件;第三方 UI 库在预览中不可用。
- 面板里的预览是静态的(每种状态单独写一个示例)。悬停、聚焦、输入等交互可以在 `catalog/index.html` 里试。

## 隐私、网络和文件

- 本地运行,不联网,不需要 API 密钥。esbuild(WebAssembly 版)、TypeScript 和 React 类型声明都随插件附带。
- 只写 `ui-kit/<名称>/` 和 `.design-to-components/project.json`。
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: design-to-components
description: 按设计稿/截图做 React 组件库:整理设计变量(tokens.css / tokens.ts)、列组件清单与状态、写 TSX 组件,插件做 TypeScript 检查、渲染每个状态与设计稿对照、生成可交互目录页。用户提到“设计稿转组件 / 组件库 / design system / 设计变量 / React 组件”时使用。
---

# 设计稿转组件库(React + TSX)

1. 看设计稿,整理出:
- 颜色(主色、主色上的文字色、背景、次级背景、文字、次要文字、边框,以及危险、成功、警告等状态色)。
- 字体、字号阶梯、圆角、间距和阴影。
2. 用 `dc_new(name, design, tokens)` 新建组件库,或用 `dc_tokens({tokens})` 补全设计变量。变量名只用小写字母、数字和短横线。
3. 用 `dc_plan({components})` 列出组件,每个组件写出需要的状态,例如 Button:primary、secondary、disabled、loading。
4. 用 `dc_write({files})` 写组件,可以一次写多个。文件都平铺在 `src/`(如 `src/Button.tsx`、`src/Button.css`);写成 `src/components/Button/Button.tsx` 也会被自动平铺到 `src/Button.tsx` 并修正导入:
- `Name.tsx`:`export function Name(props)`。props 要有类型,并按需扩展原生属性,例如 `ButtonHTMLAttributes<HTMLButtonElement>`。
- 同一个文件里写 `export const examples = [{ name: "Primary", render: () => <Name …/> }, …]`。每种计划中的状态都要有一个示例,示例名里要包含状态名。
- `Name.css`:类名加前缀(例如 `fn-button`)。颜色、字号、圆角、间距一律用 `var(--color-…)`、`var(--font-size-…)`、`var(--radius-…)`、`var(--space-…)`,不要写死颜色。
- 只能引用 `react` 和组件库里的文件(例如 `./Button`、`../tokens`)。
- 注意无障碍:`label` 关联 `input`,出错时设置 `aria-invalid`,加载中设置 `aria-busy`,按钮用 `<button>`。
5. 看 `dc_write` 返回的问题:TypeScript 错误和渲染错误必须修完,提醒(写死的颜色、缺少的状态示例)也要处理。用户在面板里对照设计稿检查。
6. 完成后告诉用户:`ui-kit/<名称>/catalog/index.html` 在浏览器里可以交互查看;要用到自己的项目里,复制 `src/`、`tokens.css`、`tokens.ts` 和 `index.ts`。
50 changes: 50 additions & 0 deletions marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,56 @@
"把上一个 Hi3D 任务生成的模型按角色拆分成部件"
]
}
},
{
"name": "design-to-components",
"componentTypes": [
"ui"
],
"source": "./external_plugins/design-to-components",
"displayName": "Design To Components",
"displayName_i18n": {
"en": "Design To Components",
"zh-CN": "设计稿转组件库"
},
"description": "Turn a design or screenshot into a React component kit: keep design tokens (colours, fonts, font sizes, radii, spacing, shadows) and a component checklist in the panel, the agent writes TSX components with one example per state, and the plugin type-checks them with TypeScript (strict), renders every example next to the design, bundles them with esbuild-wasm into an interactive catalog page, and outputs tokens.css and tokens.ts. Flags hard-coded colours and missing states. Local only.",
"description_i18n": {
"en": "Turn a design or screenshot into a React component kit: keep design tokens (colours, fonts, font sizes, radii, spacing, shadows) and a component checklist in the panel, the agent writes TSX components with one example per state, and the plugin type-checks them with TypeScript (strict), renders every example next to the design, bundles them with esbuild-wasm into an interactive catalog page, and outputs tokens.css and tokens.ts. Flags hard-coded colours and missing states. Local only.",
"zh-CN": "把设计稿或截图做成 React 组件库:在面板里维护设计变量(颜色、字体、字号、圆角、间距、阴影)和组件清单,Agent 为每个组件写 TSX,每种状态一个示例;插件用 TypeScript(strict)做类型检查,把每个示例渲染出来与设计稿并排对照,用 esbuild-wasm 打包成可交互的组件目录页,并输出 tokens.css 和 tokens.ts。会提示写死的颜色和缺少的状态示例。全部在本地完成。"
},
"version": "0.1.0",
"author": {
"name": "Penova",
"url": "https://github.com/ppppp2005-p"
},
"license": "MIT",
"category": "developer-tools",
"keywords": [
"react",
"components",
"design system",
"design tokens",
"tsx",
"typescript",
"storybook",
"esbuild",
"组件库",
"设计稿",
"设计变量",
"前端"
],
"examplePrompts": [
"Build React components from this design",
"Pull the colours and type scale from the screenshot into tokens",
"Add a loading state to the Button and check it compiles"
],
"examplePrompts_i18n": {
"zh-CN": [
"按这张设计稿做一套 React 组件",
"把截图里的颜色和字号整理成设计变量",
"给按钮加一个加载状态并检查能否编译"
]
}
}
]
}
Loading