prototype
MAmattpocock/skills336k5,004 new stars in the last 7 days
前端组件开发方法论,包括组件设计原则、状态管理、样式实现和性能优化
| 状态类型 | 管理方式 | 适用场景 |
|---|---|---|
| 本地状态 | useState/ref | 组件内部状态(表单输入、展开/收起) |
| 共享状态 | Context/Store | 跨组件共享(用户信息、主题) |
| 服务端状态 | Query库/SWR | API 数据缓存和同步 |
| URL 状态 | Router | 页面参数、筛选条件 |
ui-design.json > ui-spec.md > 项目现有样式 > 框架默认值
当 .boss/<feature>/ui-design.json 存在时:
读取 tokens:映射为 CSS 变量或主题对象
// 示例:从 tokens 生成 CSS 变量
const colors = uiDesign.tokens.colors;
// --color-primary: #007AFF
解析 pages 和 frames:推导页面结构和布局
pages[].frames[] 提取页面组件层级frames[].layout 获取布局约束(宽度、间距、对齐)实现 prototype.links:推导导航和交互
复用 components:提取可复用组件
components[] 识别通用组件(Button、Input、Card)实现前端 API 调用前,必须阅读:
// services/api/users.ts
export const userApi = {
async getUser(id: string): Promise<User> {
const response = await fetch(`/api/users/${id}`);
return response.json();
},
async createUser(data: CreateUserRequest): Promise<User> {
const response = await fetch('/api/users', {
method: 'POST',
body: JSON.stringify(data),
});
return response.json();
},
};
后端未就绪时,基于 architecture.md §5 创建 Mock:
// services/api/users.mock.ts
export const mockUserApi = {
async getUser(id: string): Promise<User> {
return { id, name: 'Mock User', email: '[email protected]' };
},
};
必须遵循 TDD:先写失败测试(RED)→ 最小实现(GREEN)→ 重构(REFACTOR)。详见
shared/tddskill。
| 测试类型 | 占比 | 工具示例 |
|---|---|---|
| 单元测试 | 70% | Jest + Testing Library |
| 集成测试 | 20% | Testing Library |
| E2E 测试 | 10% | Playwright/Cypress |
实现组件前:
实现组件后:
MAmattpocock/skills336k5,004 new stars in the last 7 days
AFaffaan-m/ECC314k4,125 new stars in the last 7 days
FIfirecrawl/firecrawl214k5,821 new stars in the last 7 days
ANanthropics/skills203k3,333 new stars in the last 7 days
Set visual direction and typography for UI, avoiding templated defaults.
ANanthropics/skills203k3,333 new stars in the last 7 days
Build complex HTML artifacts with React, Tailwind CSS, state management and routing.
ANanthropics/skills203k3,333 new stars in the last 7 days