ui-analyzer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUI Analyzer
UI分析器
This skill provides a systematic approach to analyzing UI design screenshots and translating them into production-ready React components using TypeScript and Tailwind CSS.
本技能提供了一套系统化的方法,用于分析UI设计截图,并将其转换为基于TypeScript和Tailwind CSS的可用于生产环境的React组件。
Purpose
用途
Transform UI design screenshots into well-structured, accessible, and maintainable React components. The skill guides through analyzing layouts, extracting design tokens, identifying components, and generating clean code that matches the design while following best practices.
将UI设计截图转换为结构清晰、可访问且易于维护的React组件。该技能会引导你完成布局分析、设计令牌提取、组件识别,并生成符合设计要求且遵循最佳实践的简洁代码。
When to Use This Skill
适用场景
Use this skill when:
- The user provides a UI design screenshot, mockup, or Figma export
- The user requests "implement this design" or "build this UI"
- The user asks to "analyze this screenshot"
- The user wants to convert a design to code
- The user needs help understanding a UI's structure
- The user requests matching an existing design
在以下场景中使用本技能:
- 用户提供UI设计截图、原型或Figma导出文件
- 用户要求"实现这个设计"或"构建这个UI"
- 用户请求"分析这个截图"
- 用户希望将设计转换为代码
- 用户需要帮助理解UI的结构
- 用户要求匹配现有设计
Analysis Workflow
分析工作流
Follow these steps systematically when analyzing a UI screenshot:
分析UI截图时,请系统遵循以下步骤:
Step 1: Initial Observation and Screenshot Reading
步骤1:初步观察与截图读取
Read the provided screenshot first using the Read tool if a file path is provided, or if the user has shared an image in the conversation.
After viewing the screenshot:
- Describe what you see in the UI
- Identify the screen/page type (login, dashboard, form, etc.)
- Determine the target device (desktop, mobile, responsive)
- Note the overall aesthetic (modern, minimal, colorful, etc.)
- Confirm understanding with the user before proceeding
首先读取提供的截图,如果提供了文件路径,使用读取工具;如果用户在对话中分享了图片,直接查看。
查看截图后:
- 描述你在UI中看到的内容
- 识别屏幕/页面类型(登录页、仪表盘、表单等)
- 确定目标设备(桌面端、移动端、响应式)
- 记录整体风格(现代、极简、多彩等)
- 在继续之前,与用户确认你的理解是否正确
Step 2: Layout Analysis
步骤2:布局分析
Identify the high-level layout structure:
-
Main layout type - Consultto identify:
references/layout-patterns.md- Single column
- Sidebar layout
- Header + content
- Grid layout
- Split screen
- Dashboard
- Master-detail
- Other patterns
-
Layout hierarchy - Break down into sections:
- Header/navigation
- Main content area
- Sidebar (if present)
- Footer (if present)
- Nested structures
-
Responsive considerations:
- How should layout adapt to mobile?
- Which elements stack or hide?
- Breakpoint strategy
Reference for Tailwind implementation patterns.
references/layout-patterns.md识别高层级的布局结构:
-
主要布局类型 - 参考来识别:
references/layout-patterns.md- 单列布局
- 侧边栏布局
- 头部+内容布局
- 网格布局
- 分屏布局
- 仪表盘布局
- 主从布局
- 其他模式
-
布局层级 - 拆分为多个部分:
- 头部/导航栏
- 主内容区域
- 侧边栏(如果存在)
- 页脚(如果存在)
- 嵌套结构
-
响应式考量:
- 布局应如何适配移动端?
- 哪些元素会堆叠或隐藏?
- 断点策略
参考获取Tailwind实现模式。
references/layout-patterns.mdStep 3: Component Identification
步骤3:组件识别
Systematically identify all UI components using :
references/ui-analysis-checklist.mdNavigation Components:
- Top nav, sidebar nav, breadcrumbs, tabs, etc.
Data Display Components:
- Cards, tables, lists, stats, badges, avatars, icons, etc.
Input Components:
- Text inputs, selects, checkboxes, radios, switches, date pickers, etc.
Action Components:
- Buttons (primary, secondary, etc.), icon buttons, links, etc.
Feedback Components:
- Alerts, toasts, progress bars, loading states, etc.
Overlay Components:
- Modals, drawers, tooltips, popovers, dropdowns, etc.
List all identified components with:
- Component type and purpose
- Location in the layout
- Approximate size and styling
- Interactive states (if visible)
使用系统识别所有UI组件:
references/ui-analysis-checklist.md导航组件:
- 顶部导航、侧边栏导航、面包屑、标签页等
数据展示组件:
- 卡片、表格、列表、统计数据、徽章、头像、图标等
输入组件:
- 文本输入框、选择器、复选框、单选框、开关、日期选择器等
操作组件:
- 按钮(主要、次要等)、图标按钮、链接等
反馈组件:
- 提示框、消息提示、进度条、加载状态等
覆盖层组件:
- 模态框、抽屉、工具提示、弹出框、下拉菜单等
列出所有识别出的组件,包含:
- 组件类型与用途
- 在布局中的位置
- 大致尺寸与样式
- 交互状态(如果可见)
Step 4: Design Token Extraction
步骤4:设计令牌提取
Extract design system values using :
references/design-tokens.mdColor Palette:
- Identify all unique colors in the design
- Categorize by usage:
- Primary brand color
- Secondary/accent colors
- Background colors (main, secondary)
- Text colors (primary, secondary, muted)
- Border colors
- State colors (success, warning, error, info)
- Map each color to nearest Tailwind color or note custom color needed
- Create a color reference table
Typography:
- Identify font family (serif, sans-serif, monospace)
- List all text sizes observed
- Map to Tailwind typography scale (to
text-xs)text-6xl - Note font weights used (normal, medium, semibold, bold)
- Identify heading hierarchy (H1-H6)
Spacing:
- Observe padding patterns (card padding, button padding, etc.)
- Observe margin/gap patterns (between sections, between items)
- Map to Tailwind spacing scale (p-4, m-6, gap-8, etc.)
- Note the spacing unit (usually 4px or 8px base)
Other Tokens:
- Border radius (rounded-none to rounded-full)
- Shadows (shadow-sm to shadow-2xl)
- Border widths
- Icon sizes
Reference for complete mapping tables.
references/design-tokens.md使用提取设计系统值:
references/design-tokens.md调色板:
- 识别设计中所有独特的颜色
- 按用途分类:
- 主品牌色
- 次要/强调色
- 背景色(主、次要)
- 文本颜色(主、次要、弱化)
- 边框颜色
- 状态颜色(成功、警告、错误、信息)
- 将每种颜色映射到最接近的Tailwind颜色,或记录需要自定义的颜色
- 创建颜色参考表
排版:
- 识别字体族(衬线、无衬线、等宽)
- 列出所有观察到的文本尺寸
- 映射到Tailwind排版刻度(到
text-xs)text-6xl - 记录使用的字重(常规、中等、半粗体、粗体)
- 识别标题层级(H1-H6)
间距:
- 观察内边距模式(卡片内边距、按钮内边距等)
- 观察外边距/间隙模式(区块之间、元素之间)
- 映射到Tailwind间距刻度(p-4、m-6、gap-8等)
- 记录间距单位(通常为4px或8px基准)
其他令牌:
- 边框圆角(rounded-none 到 rounded-full)
- 阴影(shadow-sm 到 shadow-2xl)
- 边框宽度
- 图标尺寸
参考获取完整映射表。
references/design-tokens.mdStep 5: Detailed Component Analysis
步骤5:详细组件分析
For each major component identified:
- Component boundaries - Where does it start/end?
- Props/data - What data does it receive?
- Internal structure - Sub-components and elements
- Styling details:
- Background color
- Text color and size
- Padding and margins
- Border and radius
- Shadow
- Interactive states (if visible or inferable):
- Hover
- Active/pressed
- Focused
- Disabled
- Loading
- Error
- Accessibility needs:
- ARIA labels
- Semantic HTML
- Keyboard navigation
针对每个识别出的主要组件:
- 组件边界 - 组件的起止位置在哪里?
- 属性/数据 - 它接收哪些数据?
- 内部结构 - 子组件与元素
- 样式细节:
- 背景色
- 文本颜色与尺寸
- 内边距与外边距
- 边框与圆角
- 阴影
- 交互状态(如果可见或可推断):
- 悬停
- 激活/按下
- 聚焦
- 禁用
- 加载
- 错误
- 无障碍需求:
- ARIA标签
- 语义化HTML
- 键盘导航
Step 6: Implementation Strategy
步骤6:实现策略
Plan the implementation approach:
- Component hierarchy - Which components to build first?
- Reusability - Which patterns repeat? Extract to reusable components
- State management - Does any component need Zustand or just local state?
- Integration with react-component-generator - Can existing templates be used?
- File structure - Where should components live?
If the react-component-generator skill is available:
- Reference its templates for common components (forms, cards, buttons, modals, etc.)
- Use its best practices for component structure
- Follow its naming conventions
规划实现方案:
- 组件层级 - 先构建哪些组件?
- 可复用性 - 哪些模式重复出现?提取为可复用组件
- 状态管理 - 组件是否需要Zustand还是仅需本地状态?
- 与react-component-generator集成 - 是否可以使用现有模板?
- 文件结构 - 组件应存放在哪里?
如果react-component-generator技能可用:
- 参考其通用组件模板(表单、卡片、按钮、模态框等)
- 遵循其组件结构的最佳实践
- 遵循其命名规范
Step 7: Code Generation
步骤7:代码生成
Generate React components following these principles:
Structure:
- Start with TypeScript interfaces for props
- Use functional components with React.FC
- Include JSDoc comments
- Export both named and default exports
Styling:
- Use Tailwind CSS exclusively for styling
- Apply extracted design tokens
- Organize classes logically (layout → spacing → colors → effects → states)
- Use responsive classes where needed (sm:, md:, lg:, xl:)
Best Practices:
- Use semantic HTML elements
- Include ARIA attributes for accessibility
- Handle loading and error states
- Support keyboard navigation
- Use proper TypeScript types (no )
any - Keep components focused and composable
Example Component Template:
tsx
import React from 'react';
interface ComponentNameProps {
// Props based on analysis
title: string;
description?: string;
onClick?: () => void;
className?: string;
}
/**
* ComponentName - Brief description based on UI purpose
*
* @param props - Component props
* @returns JSX.Element
*/
export const ComponentName: React.FC<ComponentNameProps> = ({
title,
description,
onClick,
className = ''
}) => {
return (
<div className={`/* Tailwind classes from design */ ${className}`}>
{/* Implementation based on screenshot */}
</div>
);
};
export default ComponentName;遵循以下原则生成React组件:
结构:
- 从TypeScript属性接口开始
- 使用带React.FC的函数式组件
- 包含JSDoc注释
- 导出命名导出与默认导出
样式:
- 仅使用Tailwind CSS进行样式设置
- 应用提取的设计令牌
- 逻辑组织类名(布局 → 间距 → 颜色 → 效果 → 状态)
- 必要时使用响应式类(sm:、md:、lg:、xl:)
最佳实践:
- 使用语义化HTML元素
- 包含用于无障碍的ARIA属性
- 处理加载与错误状态
- 支持键盘导航
- 使用正确的TypeScript类型(避免使用)
any - 保持组件聚焦且可组合
组件模板示例:
tsx
import React from 'react';
interface ComponentNameProps {
// Props based on analysis
title: string;
description?: string;
onClick?: () => void;
className?: string;
}
/**
* ComponentName - Brief description based on UI purpose
*
* @param props - Component props
* @returns JSX.Element
*/
export const ComponentName: React.FC<ComponentNameProps> = ({
title,
description,
onClick,
className = ''
}) => {
return (
<div className={`/* Tailwind classes from design */ ${className}`}>
{/* Implementation based on screenshot */}
</div>
);
};
export default ComponentName;Step 8: Verification and Refinement
步骤8:验证与优化
After generating code:
- Review against screenshot - Does it match the design?
- Check responsiveness - Will it work on different screen sizes?
- Verify accessibility - Are ARIA labels and semantic HTML present?
- Validate design tokens - Are colors, spacing, typography correct?
- Consider edge cases - Long text, empty states, loading states
- Note assumptions - Clearly state what was assumed vs confirmed
生成代码后:
- 与截图对比 - 是否匹配设计?
- 检查响应式 - 是否能在不同屏幕尺寸下正常工作?
- 验证无障碍性 - 是否包含ARIA标签与语义化HTML?
- 验证设计令牌 - 颜色、间距、排版是否正确?
- 考虑边缘情况 - 长文本、空状态、加载状态
- 记录假设 - 明确标记哪些是假设,哪些是已确认的细节
Step 9: Deliverables
步骤9:交付物
Provide the user with:
-
Analysis Summary:
- Layout description
- Component breakdown
- Design tokens extracted
-
Generated Code:
- Complete React component(s)
- TypeScript interfaces
- Tailwind classes applied
-
Implementation Notes:
- Installation requirements (if any packages needed)
- Usage examples
- Customization suggestions
- Responsive behavior notes
-
Next Steps:
- Suggest improvements or variations
- Note areas that might need refinement
- Offer to generate additional related components
向用户提供以下内容:
-
分析摘要:
- 布局描述
- 组件拆分
- 提取的设计令牌
-
生成的代码:
- 完整的React组件
- TypeScript接口
- 已应用的Tailwind类
-
实现说明:
- 安装要求(如果需要任何包)
- 使用示例
- 自定义建议
- 响应式行为说明
-
后续步骤:
- 建议改进或变体
- 记录可能需要优化的区域
- 提供生成其他相关组件的服务
Common Scenarios
常见场景
Scenario 1: Simple Form Screenshot
场景1:简单表单截图
User: "Implement this login form design [screenshot]"
Approach:
- Read screenshot
- Identify: Centered card layout with form inputs and button
- Extract: Colors, input styling, button styling, spacing
- Reference → "Centered Modal/Card" pattern
layout-patterns.md - Reference → FormComponent template
react-component-generator - Generate: LoginForm.tsx with proper validation structure
- Apply Tailwind classes matching the design
用户:“实现这个登录表单设计 [截图]”
方案:
- 读取截图
- 识别:带表单输入框和按钮的居中卡片布局
- 提取:颜色、输入框样式、按钮样式、间距
- 参考→ “居中模态框/卡片”模式
layout-patterns.md - 参考→ FormComponent模板
react-component-generator - 生成:带有正确验证结构的LoginForm.tsx
- 应用与设计匹配的Tailwind类
Scenario 2: Dashboard Screenshot
场景2:仪表盘截图
User: "Build this dashboard UI [screenshot]"
Approach:
- Read screenshot
- Identify: Header + sidebar layout with grid of stat cards
- Break down into components:
- Header component
- Sidebar navigation
- StatCard component (repeated)
- Main dashboard layout
- Extract design tokens for consistency
- Reference → "Dashboard Layout" pattern
layout-patterns.md - Generate components starting with reusable StatCard
- Compose into main Dashboard component
用户:“构建这个仪表盘UI [截图]”
方案:
- 读取截图
- 识别:头部+侧边栏布局,搭配统计卡片网格
- 拆分为组件:
- 头部组件
- 侧边栏导航
- StatCard组件(重复使用)
- 主仪表盘布局
- 提取设计令牌以保持一致性
- 参考→ “仪表盘布局”模式
layout-patterns.md - 从可复用的StatCard开始生成组件
- 组合成主Dashboard组件
Scenario 3: Complex Page with Multiple Sections
场景3:包含多个区块的复杂页面
User: "Implement this landing page [screenshot]"
Approach:
- Read screenshot
- Identify sections: Hero, features grid, testimonials, CTA
- Analyze each section separately using checklist
- Extract shared design tokens
- Generate section components one by one
- Show how sections compose into the full page
- Provide responsive behavior notes
用户:“实现这个落地页 [截图]”
方案:
- 读取截图
- 识别区块:Hero区、功能网格、客户评价、CTA区
- 使用检查表分别分析每个区块
- 提取共享的设计令牌
- 逐个生成区块组件
- 展示如何将区块组合成完整页面
- 提供响应式行为说明
Scenario 4: Component Library Screenshot
场景4:组件库截图
User: "Create components from this design system screenshot [screenshot]"
Approach:
- Read screenshot
- Identify: Multiple variations of buttons, inputs, cards shown
- Extract design tokens for the system
- Generate each component variant
- Document the prop variations
- Create a usage guide
- Suggest how to organize in the project
用户:“从这个设计系统截图创建组件 [截图]”
方案:
- 读取截图
- 识别:展示的多种按钮、输入框、卡片变体
- 提取系统的设计令牌
- 生成每个组件的变体
- 记录属性变体
- 创建使用指南
- 建议如何在项目中组织这些组件
Reference Files Usage
参考文件使用说明
references/ui-analysis-checklist.md
references/ui-analysis-checklist.md
- When to use: During Step 3 (Component Identification) and as a comprehensive analysis guide
- Purpose: Ensures no components or details are missed
- How: Work through checklist sections systematically
- 使用时机:步骤3(组件识别)期间,以及作为全面分析指南
- 用途:确保不会遗漏任何组件或细节
- 使用方法:系统地完成检查表的各个部分
references/layout-patterns.md
references/layout-patterns.md
- When to use: During Step 2 (Layout Analysis) and Step 7 (Code Generation)
- Purpose: Quickly identify common patterns and get implementation code
- How: Match observed layout to pattern, adapt provided code
- 使用时机:步骤2(布局分析)和步骤7(代码生成)期间
- 用途:快速识别常见模式并获取实现代码
- 使用方法:将观察到的布局与模式匹配,调整提供的代码
references/design-tokens.md
references/design-tokens.md
- When to use: During Step 4 (Design Token Extraction) and Step 7 (Code Generation)
- Purpose: Map visual elements to Tailwind classes accurately
- How: Use color tables, spacing scale, and component size guides
- 使用时机:步骤4(设计令牌提取)和步骤7(代码生成)期间
- 用途:准确地将视觉元素映射到Tailwind类
- 使用方法:使用颜色表、间距刻度和组件尺寸指南
Tips for Accurate Analysis
准确分析的技巧
- Be systematic - Follow the workflow steps in order, don't skip ahead
- Take measurements - Estimate sizes and spacing carefully
- Look for patterns - Repeated elements indicate design system consistency
- Note uncertainties - Clearly mark assumptions vs confirmed details
- Think responsive - Always consider mobile behavior
- Prioritize accessibility - Include ARIA labels and semantic HTML from the start
- Stay DRY - Extract reusable components when patterns repeat
- Consult references - Use the reference files liberally for accuracy
- Verify with user - Confirm understanding before extensive code generation
- Iterate - Expect refinement based on user feedback
- 系统化 - 按顺序遵循工作流步骤,不要跳过
- 测量 - 仔细估算尺寸和间距
- 寻找模式 - 重复出现的元素表明设计系统的一致性
- 记录不确定性 - 明确标记假设与已确认的细节
- 考虑响应式 - 始终考虑移动端行为
- 优先无障碍性 - 从一开始就包含ARIA标签和语义化HTML
- 保持DRY原则 - 当模式重复时提取可复用组件
- 参考文档 - 大量使用参考文件以确保准确性
- 与用户验证 - 在进行大量代码生成之前确认理解正确
- 迭代 - 根据用户反馈进行优化
Integration with Other Skills
与其他技能的集成
With react-component-generator skill
与react-component-generator技能集成
When both skills are available:
- Use ui-analyzer to understand the design and extract requirements
- Reference react-component-generator templates for similar components
- Apply ui-analyzer's extracted design tokens to the templates
- Follow react-component-generator's naming and structure conventions
This creates a powerful workflow: analyze → identify template → customize → implement.
当两个技能都可用时:
- 使用ui-analyzer理解设计并提取需求
- 参考react-component-generator的类似组件模板
- 将ui-analyzer提取的设计令牌应用到模板中
- 遵循react-component-generator的命名和结构规范
这形成了一套强大的工作流:分析 → 识别模板 → 自定义 → 实现。
Example Full Workflow
完整工作流示例
User provides login page screenshot
- ✅ Read screenshot and describe the UI
- ✅ Identify: Centered card layout, split-screen with image
- ✅ Extract design tokens:
- Primary blue: #3B82F6 →
bg-blue-500 - Text: #1F2937 →
text-gray-800 - Background: #F9FAFB →
bg-gray-50 - Card padding: ~32px →
p-8 - Input height: ~40px →
h-10 - Button: blue background, white text, rounded-md
- Primary blue: #3B82F6 →
- ✅ Identify components:
- Logo/brand element
- Heading and subheading
- Email input (with label)
- Password input (with label, show/hide icon)
- "Remember me" checkbox
- "Forgot password?" link
- Submit button
- Sign up link at bottom
- ✅ Reference layout-patterns.md → Split Screen + Centered Card patterns
- ✅ Generate LoginForm.tsx:
- TypeScript interfaces for props
- Form validation structure
- Tailwind classes matching design
- Accessibility attributes
- Responsive behavior (stacked on mobile)
- ✅ Provide usage example and notes
- ✅ Offer to generate the accompanying image section or adjust styling
用户提供登录页截图
- ✅ 读取截图并描述UI
- ✅ 识别:居中卡片布局,带图片的分屏
- ✅ 提取设计令牌:
- 主蓝色:#3B82F6 →
bg-blue-500 - 文本:#1F2937 →
text-gray-800 - 背景:#F9FAFB →
bg-gray-50 - 卡片内边距:约32px →
p-8 - 输入框高度:约40px →
h-10 - 按钮:蓝色背景、白色文本、圆角md
- 主蓝色:#3B82F6 →
- ✅ 识别组件:
- Logo/品牌元素
- 标题与副标题
- 邮箱输入框(带标签)
- 密码输入框(带标签、显示/隐藏图标)
- “记住我”复选框
- “忘记密码?”链接
- 提交按钮
- 底部的注册链接
- ✅ 参考layout-patterns.md → 分屏+居中卡片模式
- ✅ 生成LoginForm.tsx:
- TypeScript属性接口
- 表单验证结构
- 与设计匹配的Tailwind类
- 无障碍属性
- 响应式行为(移动端堆叠)
- ✅ 提供使用示例与说明
- ✅ 提供生成配套图片区域或调整样式的服务
Notes
注意事项
- Always read the screenshot first before any analysis
- Prioritize user confirmation of understanding before extensive code generation
- When in doubt about colors or spacing, choose the closest Tailwind default
- Document all assumptions clearly
- Provide complete, runnable code, not pseudocode
- Consider suggesting improvements while matching the design
- Be prepared to iterate based on user feedback
- 进行任何分析之前,务必先读取截图
- 在进行大量代码生成之前,优先与用户确认理解正确
- 如果对颜色或间距有疑问,选择最接近的Tailwind默认值
- 清晰记录所有假设
- 提供完整、可运行的代码,而非伪代码
- 在匹配设计的同时,可建议改进方案
- 准备好根据用户反馈进行迭代