# shadcn Component Visual Adapter
## 🎯 Objective
Refactor the existing `${component_name}` component located at `${component_file_path}` to match the **visual design, structure, and behavior** of the reference component available at:
> ${install_command:bunx --bun shadcn@latest add accordion}
${reference_url:} ← optional; leave blank if no docs page exists
Do NOT replace business logic, existing props interface, or data-fetching patterns. Preserve them.
Adapt only the **visual layer**: markup structure, class names, animations, and accessibility attributes.
---
## 📋 Step 1 — Analyze the Existing Component
Before writing any code:
1. Read the full source of `${component_file_path}`.
2. Map out:
- All **props and their types** (TypeScript interfaces or PropTypes).
- Internal **state variables** (`useState`, `useReducer`, Zustand slices, etc.).
- **Context providers or custom hooks** consumed.
- **Child components** rendered and where they live.
- **Event handlers** and callbacks exposed to the parent.
3. List every **import** — flag any that will conflict with or can be replaced by the shadcn primitive.
Output a brief audit table before touching any code:
| Item | Current value | Action |
|------|--------------|--------|
| Props | ... | keep / rename / remove |
| State | ... | keep / migrate |
| Context/Hooks | ... | keep / replace |
| Sub-components | ... | keep / replace |
| Dependencies | ... | keep / install / remove |
---
## 📦 Step 2 — Dependency Resolution
Run the install command directly:
${install_command}
After the command completes, the generated files will appear in
${components_dir:components/ui}/. Proceed to Step 3 using those files.
---
## 🔬 Step 3 — Review Reference Component
IF ${reference_url} is provided → fetch it and extract the visual spec as before.
IF ${reference_url} is blank → read the files downloaded by the CLI command
in Step 2 and extract the same information from the source code directly:
- cva variant schema
- data-state / data-disabled attributes
- animation/transition classes
- ARIA roles and props
- cn() usage patterns
---
## 🛠 Step 4 — Refactor the Component
Apply the visual structure from Step 3 to the existing component from Step 1.
### Rules:
- ✅ Keep all **existing prop names and types** unless a direct shadcn equivalent exists.
- ✅ Keep all **data-fetching, business logic, and callbacks**.
- ✅ Wrap Radix primitives using **`forwardRef`** and spread `...props` to preserve flexibility.
- ✅ Use `cn()` for all className merging — never string concatenation.
- ✅ Export named compound sub-components if the reference component uses them (e.g., `Accordion`, `AccordionItem`, `AccordionTrigger`, `AccordionContent`).
- ❌ Do NOT import the generated shadcn file and re-export it — build the primitive inline in the refactored file to keep the logic co-located.
- ❌ Do NOT add Tailwind classes not present in the reference component without explicit instruction.
### Responsive behavior (`${responsive_breakpoints:sm md lg}`):
Apply mobile-first responsive classes. Confirm current breakpoints in `tailwind.config.ts` match the project's convention. If the reference uses container queries, install `@tailwindcss/container-queries`.
---
## 🧩 Step 5 — Context Providers and Hooks
If the reference component requires a context provider (e.g., `ToastProvider`, `TooltipProvider`):
1. Check if it is already mounted in `${provider_file:app/layout.tsx}` or `${provider_file:app/providers.tsx}`.
2. If not, add it to the appropriate layout file. Provide the exact diff.
3. If a custom hook is required (e.g., `useToast`, `useDialog`), place it in `${hooks_dir:hooks/}` and import it from there.
---
## ❓ Step 6 — Clarifying Questions (ask before generating if unknown)
If any of the following are not determinable from the existing code, **ask before writing**:
1. **Data/props**: What shape of data will be passed? (Provide a sample object if helpful.)
2. **State management**: Is component state local, or managed externally (Zustand, Redux, React Query)?
3. **Assets**: Are there required images, logos, or custom icons not covered by lucide-react?
4. **Responsive**: What is the expected layout at `${responsive_breakpoints:sm md lg}` breakpoints?
5. **Placement**: Where in the app routing/layout tree will this component live? (Important for context provider placement.)
---
## 📐 Step 7 — Output Format
Provide the result as:
1. **`${component_file_path}`** — full refactored component file.
2. **`${components_dir:components/ui}/${shadcn_component_slug}.tsx`** — shadcn primitive (only if needed and not generated by CLI).
3. **`lib/utils.ts`** — only if it needs to be created or updated.
4. **Layout/provider diff** — only if a provider needs to be added.
5. A short **migration notes** section listing:
- Removed dependencies
- Renamed props (if any)
- Any manual steps required (e.g., adding CSS variables to `globals.css`)
---
## 🎨 Tailwind CSS Variables (shadcn design tokens)
Confirm that `globals.css` contains the required CSS custom properties. If the reference component uses tokens like `--radius`, `--background`, `--foreground`, `--primary`, `--ring`, append the missing variables. Use the shadcn default token set for `${color_theme:zinc}` unless the project already defines a custom theme.
---
## 🚫 Constraints
- Framework: **${framework:Next.js 14+ App Router}**
- Styling: **Tailwind CSS ${tailwind_version:3}** only — no inline styles, no CSS modules, no styled-components.
- TypeScript: **strict mode**. All new code must be fully typed.
- Do not upgrade or downgrade any existing dependency version unless there is a direct peer conflict.# shadcn 组件视觉适配器
## 🎯 目标
重构位于 `${component_file_path}` 的现有 `${component_name}` 组件,使其在 **视觉设计、结构和行为** 上与以下参考组件保持一致:
> ${install_command:bunx --bun shadcn@latest add accordion}
${reference_url:} ← 可选项;如果没有文档页面则留空
不要替换业务逻辑、现有的 props 接口或数据获取模式,请保留这些内容。
只调整 **视觉层**:标记结构、类名、动画以及无障碍属性。
---
## 📋 步骤 1 — 分析现有组件
在编写任何代码之前:
1. 完整阅读 `${component_file_path}` 的源码。
2. 梳理以下内容:
- 所有 **props 及其类型**(TypeScript 接口或 PropTypes)。
- 内部 **状态变量**(`useState`、`useReducer`、Zustand slice 等)。
- 所使用的 **Context Provider 或自定义 hooks**。
- 渲染的 **子组件** 及其所在位置。
- 向父组件暴露的 **事件处理器** 和回调。
3. 列出每一个 **import** —— 标记可能与 shadcn primitive 冲突或可被其替换的项。
在修改任何代码之前,先输出一份简明的审查表:
| 项目 | 当前值 | 处理方式 |
|------|--------|----------|
| Props | ... | 保留 / 重命名 / 移除 |
| State | ... | 保留 / 迁移 |
| Context/Hooks | ... | 保留 / 替换 |
| 子组件 | ... | 保留 / 替换 |
| 依赖 | ... | 保留 / 安装 / 移除 |
---
## 步骤 2 — 依赖解析
直接运行安装命令:
${install_command}
命令执行完成后,生成的文件会出现在
${components_dir:components/ui}/ 目录下。请使用这些文件继续步骤 3。
---
## 🔬 步骤 3 — 检查参考组件
如果提供了 ${reference_url} → 获取该页面并按之前的方式提取视觉规范。
如果 ${reference_url} 为空 → 读取步骤 2 中由 CLI 命令下载的文件,直接从源码中提取同样的信息:
- cva 变体 schema
- data-state / data-disabled 属性
- 动画 / 过渡类名
- ARIA 角色和属性
- cn() 的使用模式
---
## 🛠 步骤 4 — 重构组件
将步骤 3 中的视觉结构应用到步骤 1 中的现有组件上。
### 规则:
- ✅ 保留所有 **现有 prop 的名称和类型**,除非存在直接对应的 shadcn 等价物。
- ✅ 保留所有 **数据获取、业务逻辑和回调**。
- ✅ 使用 **`forwardRef`** 包裹 Radix primitive,并展开 `...props` 以保留灵活性。
- ✅ 使用 `cn()` 进行所有 className 合并 —— 禁止字符串拼接。
- ✅ 如果参考组件使用了具名复合子组件(例如 `Accordion`、`AccordionItem`、`AccordionTrigger`、`AccordionContent`),请导出相应的具名子组件。
- ❌ 不要导入生成的 shadcn 文件再重新导出 —— 应在重构文件中内联构建 primitive,以保持逻辑内聚。
- ❌ 除非明确指示,否则不要添加参考组件中未出现的 Tailwind 类名。
### 响应式行为(`${responsive_breakpoints:sm md lg}`):
应用移动优先的响应式类名。请确认 `tailwind.config.ts` 中当前的断点与项目约定一致。如果参考组件使用了容器查询,请安装 `@tailwindcss/container-queries`。
---
## 🧩 步骤 5 — Context Provider 与 Hooks
如果参考组件需要 Context Provider(例如 `ToastProvider`、`TooltipProvider`):
1. 检查它是否已经挂载在 `${provider_file:app/layout.tsx}` 或 `${provider_file:app/providers.tsx}` 中。
2. 如果没有,请将其添加到合适的 layout 文件中,并给出精确的 diff。
3. 如果需要自定义 hook(例如 `useToast`、`useDialog`),请将其放在 `${hooks_dir:hooks/}` 下,并从该处导入。
---
## ❓ 步骤 6 — 澄清问题(若无法确定,请在生成前询问)
如果以下内容无法从现有代码中确定,请在编写前 **先行询问**:
1. **数据 / props**:将传入的数据结构是什么?(如有需要请提供示例对象。)
2. **状态管理**:组件状态是本地维护,还是由外部管理(Zustand、Redux、React Query)?
3. **资源**:是否存在 lucide-react 未覆盖的必需图片、Logo 或自定义图标?
4. **响应式**:在 `${responsive_breakpoints:sm md lg}` 断点处的预期布局是怎样的?
5. **位置**:此组件将放置在应用的路由 / layout 树的哪个位置?(这对 Context Provider 的放置很重要。)
---
## 步骤 7 — 输出格式
请按以下形式给出结果:
1. **`${component_file_path}`** —— 完整的重构后组件文件。
2. **`${components_dir:components/ui}/${shadcn_component_slug}.tsx`** —— shadcn primitive(仅在需要且未由 CLI 生成时提供)。
3. **`lib/utils.ts`** —— 仅在需要新建或更新时提供。
4. **Layout / Provider diff** —— 仅在需要新增 Provider 时提供。
5. 一段简短的 **迁移说明**,列出:
- 已移除的依赖
- 重命名的 props(如有)
- 所需的任何手动操作(例如向 `globals.css` 添加 CSS 变量)
---
## 🎨 Tailwind CSS 变量(shadcn 设计令牌)
请确认 `globals.css` 中包含所需的 CSS 自定义属性。如果参考组件使用了 `--radius`、`--background`、`--foreground`、`--primary`、`--ring` 等令牌,请补全缺失的变量。除非项目已经定义了自定义主题,否则请使用 `${color_theme:zinc}` 的 shadcn 默认令牌集。
---
## 约束
- 框架:**${framework:Next.js 14+ App Router}**
- 样式:**Tailwind CSS ${tailwind_version:3}** —— 不使用内联样式、CSS Modules 或 styled-components。
- TypeScript:**strict 模式**。所有新代码必须具有完整类型。
- 除非存在直接的 peer 依赖冲突,否则不要升级或降级任何现有依赖的版本。相关资源
按类型、任务、场景与标签加权推荐
Mastra Factory
AI代理 · 工作流 · 开源框架 · TypeScript · LLM编排
Mastra 由 Gatsby 团队开发,是一个用于构建 AI 应用和代理的框架,它支持工作流、内存管理、流式处理、评估、追踪以及 Studio(一个用于开发和测试的交互式 UI)。
BrionetAI
AI代理 · 企业自动化 · 多模型编排 · 私有化部署 · 工作流引擎
将问题转化为互动式学习体验。你可以获取动画讲解、多语言语音旁白、AI 生成的模拟考试、自动生成的闪卡,以及个性化的分步学习路径。
Tuanjie AI
AI编程 · 代码生成 · 开发者工具 · 智能问答
AI赋能代码生成、调试、重构,智能代码索引与深度分析,支持VS Code/Visual Studio/JetBrains/Unity Tools,让游戏开发效率翻倍
Harden
AI代理 · 安全加固 · 完整性 · 开发工具 · 代码审查
Harden AIF 是一款免费的本地 AI 编码代理安全工具。它采用后训练模型,利用您的请求和会话上下文,在工具调用运行前对其进行检查。在关键的代理安全基准测试中,它超越了前沿模型,同时将您的代码库和工具输出保留在您的本地计算机上。
Web Search Agents by Nimble
web · search · real-time · data · AI · agent · scraping · structured
网络搜索代理是针对您特定领域(例如公司信息丰富、法规研究等)的专业网络爬虫和研究代理。它们会自主学习您的使用场景,深入挖掘对您最重要的资源,从而为您的 AI 提供更深入、更相关的网络上下文
Jolo — Your agents. One workspace.
AI代理 · 工作台 · 自动化 · 多智能体 · 协作
Jolo 是一款开源桌面应用程序和命令行界面 (CLI),用于与编码代理协作。它将 Claude Code、Codex、Devin、Gemini 和其他代理整合到一个工作区中,并包含聊天记录、文件、终端和浏览器