指导在前端项目中按团队规范创建和拆分 React 组件,包括目录结构、文件命名、样式与主题变量使用。当前端需要新增或重构组件时使用本技能。
当你需要:
请使用本技能,并同时遵守 .agents/rules/03-项目结构.md 与 .agents/rules/04-组件规范.md。
详见 .agents/rules/04-组件规范.md 中的"组件放置决策树"。
src/components/<component-name>/src/routes/<route>/components/命名约定:
kebab-case,例如 error-boundaryPascalCase,例如 ErrorBoundary通用组件示例:
src/components/shentu-button/
├─ index.tsx
└─ index.module.scss
页面级组件示例:
src/routes/home/components/header/
├─ index.tsx
└─ index.module.scss
// src/components/shentu-button/index.tsx
import React from 'react';
import classNames from 'classnames';
import styles from './index.module.scss';
interface ShentuButtonProps {
onClick: () => void;
className?: string;
}
export const ShentuButton: React.FC<ShentuButtonProps> = ({onClick, className, children}) => {
return (
<button
type="button"
className={classNames(styles.shentuButton, className)}
onClick={onClick}
>
{children}
</button>
);
};
并在 src/components/index.ts 中集中导出:
// src/components/index.ts
export * from './shentu-button';
在 index.module.scss 中:
// src/components/shentu-button/index.module.scss
.shentuButton {
padding: 8px 16px;
border-radius: 4px;
border: none;
cursor: pointer;
// 必须使用主题变量,禁止硬编码主色
background-color: var(--ant-color-primary);
color: var(--ant-color-text);
}
原则:
index.module.scssvar(--ant-color-primary)、var(--ant-color-text) 等var(--shentu-card-bg)、var(--shentu-border-radius) 等#1677ff。样式还原检查:涉及 UI 还原的组件样式开发,请参考 .agents/skills/create-proposal/SKILL.md 中的「样式还原验证检查清单」及对应页面的 docs/样式还原/<名称>-UI分析清单.md。
.tsx 文件建议不超过 400 行,超过时优先考虑拆分为子组件。components/ 下。src/components。通用交互控件应基于 Antd 进行二次封装:
import React from 'react';
import {Button, ButtonProps} from 'antd';
type ShentuButtonProps = ButtonProps & {
// 可以扩展一些自定义属性
};
export const ShentuButton: React.FC<ShentuButtonProps> = (props) => {
return <Button type="primary" {...props} />;
};
index.tsx + index.module.scss 的结构?src/components/index.ts 集中导出通用组件?Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer