UI 方案原型
UI Prototype
Section titled “UI Prototype”在同一条路由上生成多个差异很大的 UI 方案,并通过底部浮动栏切换。用户在浏览器中切换方案,选出一个(或从每个方案中取一些设计),然后丢弃其余方案。
如果问题在于逻辑或状态,而不是界面外观,就不该用这个 skill。请使用 LOGIC.md。
- “这个页面应该是什么样子?”
- “我想在确定之前,先看看这个仪表盘的几个方案。”
- “给设置页面试试不同的布局。”
- 用户原本可能要花一天时间,在脑海里比较三个模糊的设计稿时,都适合用这个 skill。
两种子类型:优先选择子类型 A
Section titled “两种子类型:优先选择子类型 A”如果 UI prototype 与应用的其他部分衔接,就更容易评估:真实的页眉、侧边栏、数据和信息密度。单独的临时路由就像真空环境:每个方案单独看都不错。只要有合适的现有页面可以承载这些方案,默认选择子类型 A。只有 prototype 确实没有合适的位置时,才考虑子类型 B。
子类型 A:调整现有页面(优先)
Section titled “子类型 A:调整现有页面(优先)”路由已经存在。各个方案在同一条路由上渲染,由 ?variant= URL 搜索参数控制。保留现有的数据获取、参数和身份验证逻辑,只切换渲染结果。这是默认选择,除非有明确理由,否则就选它。
如果 prototype 针对的功能还没有页面,但自然适合放在某个页面里(例如仪表盘的新板块、设置页面的新卡片、现有流程的新步骤),仍然属于子类型 A。把各个方案放进承载它们的页面。
子类型 B:新建页面(最后选择)
Section titled “子类型 B:新建页面(最后选择)”只有当 prototype 的内容确实没有现成页面可承载时才使用(例如全新的顶层界面,或无法合理嵌入其他位置的流程)。
按照项目现有的路由约定创建一个临时路由。不要另创顶层结构。给它起个一看就知道是 prototype 的名字(例如在路径或文件名中加入 prototype)。同样使用 ?variant= 模式。
采用子类型 B 前,先确认:真的没有现有页面可以承载它吗?空路由会隐藏那些在有实际内容的页面上才会显现的设计问题。
两种子类型使用的底部浮动栏完全相同。
1. 说明问题并确定方案数量 N
Section titled “1. 说明问题并确定方案数量 N”默认生成 3 个方案。超过 5 个就很难保持明显差异,只会增加干扰,因此最多生成 5 个。
用一行写下计划,放在 prototype 所在位置或文件顶部的注释中:
“设置页面的三个方案,可通过
?variant=切换,位于现有的/settings路由上。”
无论用户是否准备提出异议,这样写都适用。
2. 生成差异明显的方案
Section titled “2. 生成差异明显的方案”起草每个方案,并确保符合以下要求:
- 页面用途及其可访问的数据。
- 项目的组件库和样式系统(TailwindCSS、shadcn、MUI、纯 CSS 等)。
- 清晰的导出组件名,例如
VariantA、VariantB、VariantC。
各方案在结构上必须不同:布局不同、信息层级不同、主要操作方式不同,而不只是颜色不同。三个略有调整的卡片网格不算 UI prototype,只是换了张皮。如果两个草案太相似,就重做其中一个,并明确要求“不要使用卡片网格”。
3. 把方案连接起来
Section titled “3. 把方案连接起来”在路由上创建一个统一的切换组件:
// pseudo-code, adapt to the project's frameworkconst variant = searchParams.get('variant') ?? 'A';return ( <> {variant === 'A' && <VariantA {...data} />} {variant === 'B' && <VariantB {...data} />} {variant === 'C' && <VariantC {...data} />} <PrototypeSwitcher variants={['A','B','C']} current={variant} /> </>);对于子类型 A(现有页面):在切换组件上方保留所有现有的数据获取逻辑;只根据方案切换渲染的子树。
对于子类型 B(新页面):在 /prototype/<name> 下的临时路由中挂载同一个切换组件。
4. 构建浮动切换栏
Section titled “4. 构建浮动切换栏”在屏幕底部居中放置一个小型固定栏,包含三部分:
- 左箭头:切换到上一个方案(循环切换)。
- 方案标签:显示当前方案键;如果方案导出了名称,也同时显示名称。例如
B (Sidebar layout)。 - 右箭头:切换到下一个方案(循环切换)。
交互行为:
- 点击箭头时更新 URL 搜索参数(使用框架的路由功能,例如 Next 中的
router.replace、React Router 中的navigate等),让方案链接可分享,重新加载后也能保持当前方案。 - 键盘:使用
←和→方向键切换。焦点在<input>、<textarea>或[contenteditable]上时,不要拦截方向键。 - 视觉上要与页面区分开(例如使用高对比度胶囊样式和轻微阴影),让人一眼看出它不属于正在评估的设计。
- 在生产构建中隐藏:使用
process.env.NODE_ENV !== 'production'或等效检查,避免意外合并 prototype 后把切换栏发布给用户。
把切换栏放在一个共享组件中,供两种子类型复用。将它放在项目的共享 UI 目录中。
提供 URL 和 ?variant= 参数值。用户可以随时切换查看。用户有意思的反馈通常是“我想要 B 的页眉和 C 的侧边栏”,这才是他们真正想要的设计。
6. 记录选择并清理
Section titled “6. 记录选择并清理”选出方案后,记录最终选择(选了哪个方案以及原因),然后按照 SKILL 中的说明记录 prototype。把胜出方案合并到正式代码中,其余方案移到临时分支,不要放进 main:
- 子类型 A:把胜出方案合并到现有页面;从 main 中移除落选方案和切换栏。
- 子类型 B:把胜出方案提升为正式路由;从 main 中移除临时路由和切换栏。
完整的方案集是主要来源,所以应放在临时分支上,而不是直接丢弃。留在 main 分支中的方案组件和切换栏很快就会过时,也会让后来的读者困惑。
- 方案之间只有颜色或文案不同。 这只是微调,不算 prototype。真正的方案在结构上各不相同。
- 方案之间共享太多代码。 共用一个
<Header>没问题;共用一个<Layout>就失去了意义。每个方案都应该能自由舍弃原有布局。 - 让方案触发真实的数据修改。 只读 prototype 没问题。如果某个方案需要修改数据,就让它调用 stub:要回答的问题是“界面应该是什么样子?”,不是“后端能不能正常工作”。
- 直接把 prototype 推入生产环境。 方案代码是在 prototype 的约束下编写的(没有测试,错误处理也很少)。合并时应按正式代码的要求重写。
原文链接和 commit
Section titled “原文链接和 commit”英文 UI.md
# UI Prototype
Generate **several radically different UI variations** on a single route, switchable from a floating bottom bar. The user flips between variants in the browser, picks one (or steals bits from each), then throws the rest away.
If the question is about logic/state rather than what something looks like, this is the wrong branch. Use [LOGIC.md](LOGIC.md).
## When this is the right shape
- "What should this page look like?"- "I want to see a few options for this dashboard before committing."- "Try a different layout for the settings screen."- Any time the user would otherwise spend a day picking between three vague mockups in their head.
## Two sub-shapes: strongly prefer sub-shape A
A UI prototype is much easier to judge when it's **butting up against the rest of the app**: real header, real sidebar, real data, real density. A throwaway route on its own is a vacuum: every variant looks fine in isolation. Default to sub-shape A whenever there's a plausible existing page to host the variants. Only reach for sub-shape B if the prototype genuinely has no nearby home.
### Sub-shape A: adjustment to an existing page (preferred)
The route already exists. Variants are rendered **on the same route**, gated by a `?variant=` URL search param. The existing data fetching, params, and auth all stay. Only the rendering swaps. This is the default; pick it unless there's a specific reason not to.
If the prototype is for something that doesn't yet have a page but *would naturally live inside one* (a new section of the dashboard, a new card on the settings screen, a new step in an existing flow), it's still sub-shape A. Mount the variants inside the host page.
### Sub-shape B: a new page (last resort)
Only use this when the thing being prototyped genuinely has no existing page to live inside (e.g. an entirely new top-level surface, or a flow that can't be embedded anywhere sensible).
Create a **throwaway route** following whatever routing convention the project already uses. Don't invent a new top-level structure. Name it so it's obviously a prototype (e.g. include the word `prototype` in the path or filename). Same `?variant=` pattern.
Before committing to sub-shape B, sanity-check: is there really no existing page this could be embedded in? An empty route hides design problems that a populated one would expose.
In both sub-shapes the floating bottom bar is identical.
## Process
### 1. State the question and pick N
Default to **3 variants**. More than 5 stops being radically different and starts being noise, so cap there.
Write down the plan in one line, in the prototype's location or a top-of-file comment:
> "Three variants of the settings page, switchable via `?variant=`, on the existing `/settings` route."
This works whether the user is here to push back or not.
### 2. Generate radically different variants
Draft each variant. Hold each one to:
- The page's purpose and the data it has access to.- The project's component library / styling system (TailwindCSS, shadcn, MUI, plain CSS, whatever).- A clear exported component name, e.g. `VariantA`, `VariantB`, `VariantC`.
Variants must be **structurally different**: different layout, different information hierarchy, different primary affordance, not just different colours. Three slightly-tweaked card grids isn't a UI prototype, it's wallpaper. If two drafts come out too similar, redo one with explicit "do not use a card grid" guidance.
### 3. Wire them together
Create a single switcher component on the route:
```tsx// pseudo-code, adapt to the project's frameworkconst variant = searchParams.get('variant') ?? 'A';return ( <> {variant === 'A' && <VariantA {...data} />} {variant === 'B' && <VariantB {...data} />} {variant === 'C' && <VariantC {...data} />} <PrototypeSwitcher variants={['A','B','C']} current={variant} /> </>);```
For sub-shape A (existing page): keep all the existing data fetching above the switcher; only the rendered subtree changes per variant.
For sub-shape B (new page): the throwaway route under `/prototype/<name>` mounts the same switcher.
### 4. Build the floating switcher
A small fixed-position bar at the bottom-centre of the screen with three pieces:
- **Left arrow**: cycles to the previous variant (wraps around).- **Variant label**: shows the current variant key and, if the variant exports a name, that name too. e.g. `B (Sidebar layout)`.- **Right arrow**: cycles forward (wraps around).
Behaviour:
- Clicking an arrow updates the URL search param (use the framework's router, e.g. `router.replace` on Next, `navigate` on React Router, etc) so the variant is shareable and reload-stable.- Keyboard: `←` and `→` arrow keys also cycle. Don't intercept arrow keys when an `<input>`, `<textarea>`, or `[contenteditable]` is focused.- Visually distinct from the page (e.g. high-contrast pill, subtle shadow) so it's obviously not part of the design being evaluated.- Hidden in production builds: gate on `process.env.NODE_ENV !== 'production'` or an equivalent check, so a stray prototype merge can't ship the bar to users.
Put the switcher in a single shared component so both sub-shapes can reuse it. Locate it wherever shared UI lives in the project.
### 5. Hand it over
Surface the URL (and the `?variant=` keys). The user will flip through whenever they get to it. The interesting feedback is usually **"I want the header from B with the sidebar from C"**, which is the actual design they want.
### 6. Capture the answer and clean up
Once a variant has won, capture the answer (which variant and why), then capture the prototype the way the [SKILL](SKILL.md) describes. Fold the winner into the real code and move the rest onto the throwaway branch, not into main:
- **Sub-shape A**: fold the winner into the existing page; drop the losing variants and the switcher from main.- **Sub-shape B**: promote the winning variant to a real route; drop the throwaway route and the switcher from main.
The full set of variants is the primary source, so it lands on the throwaway branch, not the bin, since variant components and the switcher left in the main branch rot fast and confuse the next reader.
## Anti-patterns
- **Variants that differ only in colour or copy.** That's a tweak, not a prototype. Real variants disagree about structure.- **Sharing too much code between variants.** A shared `<Header>` is fine; a shared `<Layout>` defeats the point. Each variant should be free to throw out the layout.- **Wiring variants to real mutations.** Read-only prototypes are fine. If a variant needs to mutate, point it at a stub: the question is "what should this look like", not "does the backend work".- **Promoting the prototype directly to production.** The variant code was written under prototype constraints (no tests, minimal error handling). Rewrite it properly when you fold it in.非官方学习站,与 Matt Pocock 和 AI Hero 没有隶属关系。本站不提供可安装的中文技能包。
技能原文采用 MIT 许可。Copyright (c) 2026 Matt Pocock