关于 prompt-engineering-ui
prompt-engineering-ui 是面向 UI 生成提示词设计的技能,帮助使用者向 LLM 清晰表达界面意图。内容涵盖视觉规范、行为状态、无障碍要求及迭代改进。
主要功能
- 01组件契约与设计令牌
- 02视觉参考与状态规范
- 03约束优先的提示词模式
- 04结构化反馈与差异改进
- 05少样本示例与可复用模板
适用场景
- 01规范一致的 UI 组件
- 02描述设计令牌与视觉意图
- 03覆盖交互及无障碍状态
- 04通过定向反馈改进生成界面
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ ormus-solutions/ libreuiux-claude-code --skill prompt-engineering-ui安装后在 Claude Code 中输入/prompt-engineering-ui确认已加载。
详细介绍
UI 生成的提示词工程
掌握向大模型传达设计意图的技巧。本技能介绍专为生成一致、高质量用户界面而优化的提示词模式。
何时使用本技能
- 编写用于生成一致 UI 组件的提示词
- 向 AI 系统准确描述设计意图
- 为设计系统构建可复用的提示词模板
- 通过结构化反馈迭代生成 UI
- 为 UI 模式创建少样本示例
- 调试不一致的 UI 生成结果
UI 提示词面临的挑战
UI 生成独具挑战性,因为它需要:
- 视觉精确性 - 精确的间距、颜色和字体
- 行为规范 - 交互、状态和动画
- 上下文一致性 - 符合设计系统
- 无障碍合规性 - WCAG、ARIA、键盘导航
- 响应式适配 - 多种断点和设备
- 代码质量 - 简洁、易维护的输出
标准提示词技术往往效果不佳,因为 UI 同时涉及视觉、行为和技术层面。
核心提示词模式
模式 1:组件契约
将组件定义为契约,明确指定输入和输出。
## Component Contract: DataTable
### Purpose
Display tabular data with sorting, filtering, and pagination.
### Props (Inputs)
| Prop | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| data | T[] | Yes | - | Array of data objects |
| columns | ColumnDef[] | Yes | - | Column configuration |
| pageSize | number | No | 10 | Rows per page |
| sortable | boolean | No | true | Enable column sorting |
| filterable | boolean | No | false | Show filter inputs |
### Visual Specification
- **Container**: bg-white rounded-lg shadow-sm border border-gray-200
- **Header row**: bg-gray-50 text-gray-600 text-sm font-medium
- **Data rows**: hover:bg-gray-50 border-b border-gray-100
- **Typography**: Font-sans, body text 14px, headers 12px uppercase
- **Spacing**: Cell padding 12px horizontal, 8px vertical
### States
1. **Loading**: Skeleton rows with pulse animation
2. **Empty**: Centered message with icon
3. **Error**: Red border, error message below
4. **Selected**: bg-blue-50, left border accent
### Accessibility Requirements
- role="table" on container
- Sortable columns announce sort direction
- Focus visible on all interactive elements
- Keyboard navigation: Tab through headers, Enter to sort
### Output Format
React TypeScript component using Tailwind CSS.
Include JSDoc comments and prop types.
有效原因:
- 明确的契约消除了歧义
- 视觉规范使用实际的 CSS 值
- 状态要求可避免实现不完整
- 无障碍是不可妥协的要求
模式 2:注入设计令牌
在提示词中直接嵌入设计令牌,以保持一致性。
Generate a Card component following these design tokens:
## Tokens
```json
{
"spacing": {
"xs": "4px",
"sm": "8px",
"md": "16px",
"lg": "24px",
"xl": "32px"
},
"colors": {
"surface": {
"primary": "#FFFFFF",
"secondary": "#F9FAFB",
"elevated": "#FFFFFF"
},
"border": {
"subtle": "#E5E7EB",
"default": "#D1D5DB"
},
"shadow": {
"sm": "0 1px 2px rgba(0,0,0,0.05)",
"md": "0 4px 6px rgba(0,0,0,0.1)"
}
},
"radius": {
"sm": "4px",
"md": "8px",
"lg": "12px"
}
}
要求
- 卡片使用
surface.elevated背景 - 边框使用
border.subtle - 内边距使用
spacing.lg - 圆角使用
radius.lg - 阴影使用
shadow.md
尽可能将这些令牌映射为 Tailwind 类。
**Token Mapping Strategy**:
```typescript
// Prompt can include this mapping guide
const tokenToTailwind = {
"spacing.xs": "p-1",
"spacing.sm": "p-2",
"spacing.md": "p-4",
"spacing.lg": "p-6",
"spacing.xl": "p-8",
"colors.surface.primary": "bg-white",
"colors.surface.secondary": "bg-gray-50",
"colors.border.subtle": "border-gray-200",
"radius.lg": "rounded-xl",
"shadow.md": "shadow-md",
};
模式 3:视觉参考链
将视觉描述从抽象逐步串联到具体。
## Component: Hero Section
### Mood (Abstract)
Confident, minimal, focused. The user should feel capable and unintimidated.
### Aesthetic (Semi-Abstract)
- Clean sans-serif typography
- Generous whitespace (40% of viewport)
- Single accent color for CTAs
- Photography: abstract, not literal
### Visual Details (Concrete)
- **Layout**: Centered, max-width 1200px, py-24
- **Headline**: text-5xl font-bold tracking-tight text-gray-900
- **Subheadline**: text-xl text-gray-600 max-w-2xl mx-auto mt-6
- **CTA Group**: mt-10 flex gap-4 justify-center
- **Primary CTA**: bg-indigo-600 hover:bg-indigo-700 text-white px-8 py-4 rounded-lg
- **Secondary CTA**: border border-gray-300 text-gray-700 px-8 py-4 rounded-lg
### Content
- Headline: "Build interfaces that inspire"
- Subheadline: "The design system that empowers creators to ship beautiful products faster."
- Primary CTA: "Get Started"
- Secondary CTA: "Learn More"
链条:
Mood → Aesthetic → Visual Details → Content
↓ ↓ ↓ ↓
Emotion Style CSS Values Text
此模式有效,因为它从意图逐步推进到实现。
模式 4:状态机规范
将组件状态定义为状态机。
## Button Component States
### State Machine
idle → hover → pressed → idle ↓ ↓ ↓ focus focus focus ↓ ↓ ↓ disabled (terminal) loading (blocks all transitions)
### State Definitions
| State | Visual Treatment | Tailwind Classes |
|-------|------------------|------------------|
| idle | Default appearance | bg-blue-600 text-white |
| hover | Slightly darker | hover:bg-blue-700 |
| focus | Ring indicator | focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 |
| pressed | Darker, slight scale | active:bg-blue-800 active:scale-[0.98] |
| disabled | Muted, no pointer | disabled:bg-gray-300 disabled:cursor-not-allowed |
| loading | Spinner, no text | Spinner SVG, opacity-50, pointer-events-none |
### Transitions
- All transitions: `transition-all duration-150 ease-in-out`
- Scale transitions: spring-like (use framer-motion if available)
### Implementation Notes
- Use `<button>` element, never `<div>`
- disabled state must be set via HTML attribute
- loading should set aria-busy="true"
模式 5:约束优先提示
先列出约束,缩小解决方案的范围。
## Constraints (Non-Negotiable)
### Technical Constraints
- React 18+ with TypeScript strict mode
- Tailwind CSS only (no CSS-in-JS)
- No external component libraries
- Bundle size: component must be < 5KB gzipped
### Design Constraints
- Must pass WCAG 2.1 AA
- Must work without JavaScript (progressive enhancement)
- Must support RTL layouts
- Color contrast ratio >= 4.5:1
### Browser Support
- Chrome 90+, Firefox 88+, Safari 14+, Edge 90+
- No IE11 support required
### Performance Constraints
- First paint < 100ms
- No layout shift on load
- Images must be lazy-loaded
---
## Now, generate a Modal component that satisfies all constraints above.
约束优先的原因:
- 立即排除无效方案
- 让生成过程聚焦于可行方案
- 让审核更轻松(按清单验证)
- 避免“有创意”却违反要求的方案
迭代优化模式
反馈循环协议
组织反馈,以便有效迭代:
## Iteration 1 Feedback
### What Works
- Component structure is correct
- Props interface is well-typed
- Basic styling matches tokens
### What Needs Fixing
#### Critical (Must Fix)
1. **Missing keyboard navigation**
- Current: Only mouse interaction works
- Required: Arrow keys to navigate, Enter to select
- Reference: WAI-ARIA Listbox pattern
2. **Color contrast failure**
- Current: text-gray-400 on bg-white (ratio 2.5:1)
- Required: Minimum 4.5:1 for body text
- Fix: Use text-gray-600 (ratio 5.7:1)
#### Important (Should Fix)
3. **Animation too fast**
- Current: duration-75
- Recommended: duration-150 for better perception
#### Nice to Have
4. Consider adding subtle shadow on hover
### Revised Requirements
Regenerate the component addressing Critical and Important items.
基于差异的优化
要求进行具体更改,而不是完整重新生成:
## Current Component
```tsx
<button className="bg-blue-500 text-white px-4 py-2 rounded">
Click me
</button>
请求的更改
- 添加悬停状态:悬停时使用 bg-blue-600
- 添加焦点环:聚焦时使用 ring-2 ring-blue-500 ring-offset-2
- 添加禁用状态:添加属性和视觉处理
- 添加加载状态:添加加载指示器和 loading 属性
输出格式
仅展示修改后的代码,并使用行内注释说明每项更改。
---
### The A/B Variant Request
Request multiple options for comparison:
```markdown
Generate 3 variants of a Card component:
## Variant A: Minimal
- No shadow
- Hairline border only
- Maximum whitespace
## Variant B: Elevated
- Pronounced shadow
- No visible border
- Subtle hover lift effect
## Variant C: Outlined
- Thick left accent border
- Light background fill
- Category color coding
## Common Requirements (All Variants)
- Same prop interface
- Same content structure
- Same responsive behavior
- Same accessibility
## Output
Provide all three variants as separate components.
Include a brief rationale for when to use each.
UI 的少样本示例
示例:按钮变体
## Few-Shot Examples: Button Component
### Example 1: Primary Button
Input: Primary action button with "Submit" text
Output:
```tsx
<button className="bg-indigo-600 hover:bg-indigo-700 text-white font-medium py-2.5 px-5 rounded-lg transition-colors focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
Submit
</button>
示例 2:次要按钮
输入:带有“Cancel”文本的次要操作按钮 输出:
<button className="bg-white hover:bg-gray-50 text-gray-700 font-medium py-2.5 px-5 rounded-lg border border-gray-300 transition-colors focus:ring-2 focus:ring-gray-500 focus:ring-offset-2">
Cancel
</button>
示例 3:危险按钮
输入:带有“Delete”文本的破坏性操作按钮 输出:
<button className="bg-red-600 hover:bg-red-700 text-white font-medium py-2.5 px-5 rounded-lg transition-colors focus:ring-2 focus:ring-red-500 focus:ring-offset-2">
Delete
</button>
现在生成:带有“Learn More”文本的幽灵按钮
**Pattern Recognition**:
- Consistent class structure across examples
- Clear input-output mapping
- Similar complexity level
- Demonstrates the pattern, not just the answer
---
## Prompt Templates
### Template: Component Generation
```markdown
# Generate: {ComponentName}
## Context
Project: {ProjectDescription}
Design System: {DesignSystemName}
Framework: React + TypeScript + Tailwind
## Design Tokens
{DesignTokensJSON}
## Component Specification
Purpose: {ComponentPurpose}
Props: {PropsTable}
States: {StatesList}
Variants: {VariantsList}
## Visual Requirements
Layout: {LayoutDescription}
Typography: {TypographySpecs}
Colors: {ColorSpecs}
Spacing: {SpacingSpecs}
## Behavior
Interactions: {InteractionList}
Animations: {AnimationSpecs}
Accessibility: {A11yRequirements}
## Constraints
{ConstraintsList}
## Output
Provide production-ready React TypeScript component.
Include prop types, JSDoc comments, and usage example.
模板:设计评审
# Review: {ComponentCode}
## Review Criteria
### Design Fidelity
- Does it match the design tokens?
- Is spacing consistent?
- Are colors correct?
### Accessibility
- Keyboard navigable?
- Screen reader friendly?
- Color contrast sufficient?
### Code Quality
- Types correct?
- Props well-named?
- Logic clear?
### Performance
- Unnecessary re-renders?
- Bundle size reasonable?
- Animations performant?
## Output Format
For each criterion, provide:
- Score (1-5)
- Issues found
- Specific fixes needed
UI 提示词中的反模式
1. 模糊的审美描述
不佳:“让它看起来现代、简洁” 良好:“使用 Inter 字体、16px 基准字号、1.5 行高和 24px 垂直节奏”
2. 状态覆盖不全
不佳:“创建一个按钮” 良好:“创建一个按钮,包含空闲、悬停、聚焦、激活、禁用和加载状态”
3. 缺少设计系统上下文
不佳:「使用漂亮的蓝色」 良好:「使用设计令牌中的主色:#4F46E5」
4. 隐含的无障碍要求
不佳:「确保无障碍」 良好:「添加 ARIA 标签,按照 WAI-ARIA Listbox 模式实现键盘导航,并提供焦点指示器」
5. 期望一步到位
不佳:期望首次尝试就能获得完美结果 良好:规划 2-3 轮迭代优化,并提供结构化反馈
快速参考
| 情况 | 使用的模式 |
|---|---|
| 新组件 | 组件契约 |
| 确保一致性 | 设计令牌注入 |
| 说明视觉意图 | 视觉参考链 |
| 复杂交互 | 状态机规范 |
| 避免返工 | 约束优先提示 |
| 改进输出 | 反馈循环协议 |
| 微调 | 基于差异的优化 |
| 探索选项 | A/B 变体请求 |
与其他技能集成
此技能与以下技能搭配效果良好:
agent-orchestration/ui-agent-patterns- 用于 Agent 委派的提示词模式context-management/design-system-context- 将令牌载入提示词llm-application-dev/prompt-engineering-patterns- 通用提示词工程基础design-mastery/design-principles- 用于描述的视觉词汇
「精准的提示词体现精准的思考。意图越清晰,UI 就越明了。」