skill/skills/frontend/component-development/SKILL.md
前端组件开发方法论,包括组件设计原则、状态管理、样式实现和性能优化
npx skillsauth add echovic/boss-skill frontend/component-developmentInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
| 状态类型 | 管理方式 | 适用场景 | |----------|----------|----------| | 本地状态 | 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]' };
},
};
| 测试类型 | 占比 | 工具示例 | |----------|------|----------| | 单元测试 | 70% | Jest + Testing Library | | 集成测试 | 20% | Testing Library | | E2E 测试 | 10% | Playwright/Cypress |
实现组件前:
实现组件后:
testing
交互规范,定义加载状态、空状态、反馈机制、动效、无障碍等交互细节
content-media
设计变体模式,产出2-3个设计方案及 tradeoff 分析,供用户选择后确定最终方案
content-media
设计系统规范,包含颜色、字体、间距、圆角、阴影、动效等基础设计token
testing
UI组件规范,定义按钮、输入框、卡片等基础组件的变体、尺寸、状态