跳到正文
Skillpedia
网站与界面(前端)10k · #11895

state-machine

它能做什么

这个技能列出组件可能处于的状态,例如加载中、空白或出错,并在临时页面上逐一展示。适合希望调整每种状态外观的开发者和设计师。

适用场景

  • ✓当你想查看表格或面板在加载中、空白和出错状态下的样子的时候。
  • ✓当你需要为每个方案、角色或功能开关调整屏幕外观的时候。
  • ✓当你想要一个带模拟数据的页面,并可以用按键在各状态之间切换的时候。

技能链接

https://github.com/jakubkrehel/skills/blob/main/skills/state-machine/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/jakubkrehel/skills/blob/main/skills/state-machine/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请在测试页面上展示我们审计日志表格的每一种状态,方便我逐一调整。”

每周 5 个新技能,1 分钟读完。

工作原理

该技能会读取组件的代码,找出它已经处理的每个状态。然后它会为每个状态构建一个带模拟数据的临时页面,并提供可以在它们之间切换的切换器。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

State machine

This skill takes one component and renders it on a throwaway page in every state it can be in. Mock data feeds each state, a switcher flips between them and the page is deleted in one step when you are done.

It is a workbench, not a review. The page stays up while the user works on the visuals, one state on screen and every other a keypress away. Stacking hostile scenarios on one page for a single look is break, exploring alternative designs is variant and reviewing finished work is interface-review.

1. Scope one component

One component per run: the audit log table, the network panel, the billing card. "The settings page" spans several, so list them and ask which one.

Restate it in one sentence: what the component shows, where it renders in production and where its data comes from.

2. Find the states in the code

The states are the branches the component already has. Read it and its data hooks for every one:

Kind States
Data Loading, empty, error, one item, a typical set, a set long enough to scroll or paginate, some requests resolved and others pending, stale data refetching
Account Plan tier, role and permission checks, an owner versus a member
Feature Flags, trials, limits reached, a disabled or locked feature

A state the code cannot reach is not a state. Do not add a branch to render one. Where the design shows a state the code lacks, list it as missing and leave it out.

Write the set down before building, one line each, named the way the product talks about it: empty, enterprise, member-no-access. Group them under headings in the product's words, by what changes. Use Data and Account or narrower ones such as Connection or Access. The switcher shows these groups. Say which kinds you dropped and why in one line. Combine kinds only where the code branches on the combination, such as member-empty, never as a cross product.

3. Build the throwaway page

A scratch route inside the app holds the real component, imported from the project and untouched. The route inherits the app's layout, fonts, global styles and providers for free.

Where the framework splits server from client components, the page is client code, "use client" in Next. Otherwise fixture data can silently vanish crossing that boundary, and the page renders empty.

Render one instance in a container as wide as the component is in production. The container, the fixtures and the switcher are everything the page adds, with no fonts, styles or themes of its own. Keep the page, its fixtures and its switcher in one folder, such as /states/audit-log, so removal is one delete.

4. Feed each state at the data boundary

Supply the data where the component receives it, from the page, without editing the component. In order of preference:

  1. Props, where the component takes its data as props.
  2. The app's own data seam: a seeded query cache, a mock provider or the project's request mocks.

A fixture threaded through props five levels down tests a path production never takes. Where the only way in is editing the component, say so and ask before adding a seam.

Make the data look like the product. Real-shaped names, timestamps, amounts and the item counts users actually have. Three rows of "Test item" make every state look fine.

Loading and pending states hold still. Keep them pending until the switcher moves, rather than resolving after a timeout.

5. Add the switcher

A grouped list beside the component flips the __state search param, so every state is a link. Where there is no room beside the component, it moves above it as a select with the same groups. The double underscore keeps it clear of any param the app's layout reads. switcher.md holds the spec.

6. Confirm every state renders, then hand over

Load the page once in a browser already at hand and flip through every state. The component shows the mock data, not the real data and not a blank region. Mock data that never appears is the common failure here. Live sync, a cache that refetches over the seed or a server boundary dropping the fixture all cause it. Fix the plumbing before handing over.

With no browser at hand, say so and hand the URL over for the user to check.

Then hand over the URL, the state list and the switcher keys. Stop there. Changing how a state looks is the user's next request, not part of this one.

Re-check every state after each change

After a visual change,

常见问题

它会添加代码无法到达的状态吗?

不会。它只展示组件代码已经处理的状态。

它会改动真实页面吗?

不会。它只在使用模拟数据的临时页面上工作,真实页面不受影响。

完成后会保留测试页面吗?

不会。该页面设计为完成后可一步删除。

详情

作者的原始描述

Renders every state of a component you choose on a throwaway page, with mock data and a switcher, so you can work on each state.

repo: jakubkrehel/skills

热度

GitHub 星标
10k
排名
#11895
许可证
MIT
更新时间
2026/11/1

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能