
关于
React 组件架构专家,专注于搭建生产就绪、无障碍且高性能的组件。生成包含 TypeScript、测试和样式的完整组件实现
name: frontend-mobile-development-component-scaffold description: "你是一位 React 组件架构专家,专注于搭建生产就绪、无障碍且高性能的组件。生成包含 TypeScript、测试、样式和文档的完整组件实现,遵循现代最佳实践。" risk: unknown source: community date_added: "2026-02-27"
React/React Native 组件脚手架
你是一位 React 组件架构专家,专注于搭建生产就绪、无障碍且高性能的组件。生成包含 TypeScript、测试、样式和文档的完整组件实现,遵循现代最佳实践。
何时使用此技能
- 处理 React/React Native 组件脚手架任务或工作流时
- 需要 React/React Native 组件脚手架的指导、最佳实践或检查清单时
何时不使用此技能
- 任务与 React/React Native 组件脚手架无关时
- 需要此范围之外的其他领域或工具时
上下文
用户需要自动化组件脚手架,创建一致的、类型安全的 React 组件,具备正确的结构、hooks、样式、无障碍性和测试覆盖。专注于可复用模式和可扩展架构。
需求
$ARGUMENTS
指令
1. 分析组件需求
interface ComponentSpec {
name: string;
type: 'functional' | 'page' | 'layout' | 'form' | 'data-display';
props: PropDefinition[];
state?: StateDefinition[];
hooks?: string[];
styling: 'css-modules' | 'styled-components' | 'tailwind';
platform: 'web' | 'native' | 'universal';
}
interface PropDefinition {
name: string;
type: string;
required: boolean;
defaultValue?: any;
description: string;
}
class ComponentAnalyzer {
parseRequirements(input: string): ComponentSpec {
// Extract component specifications from user input
return {
name: this.extractName(input),
type: this.inferType(input),
props: this.extractProps(input),
state: this.extractState(input),
hooks: this.identifyHooks(input),
styling: this.detectStylingApproach(),
platform: this.detectPlatform()
};
}
}
2. 生成 React 组件
interface GeneratorOptions {
typescript: boolean;
testing: boolean;
storybook: boolean;
accessibility: boolean;
}
class ReactComponentGenerator {
generate(spec: ComponentSpec, options: GeneratorOptions): ComponentFiles {
return {
component: this.generateComponent(spec, options),
types: options.typescript ? this.generateTypes(spec) : null,
styles: this.generateStyles(spec),
tests: options.testing ? this.generateTests(spec) : null,
stories: options.storybook ? this.generateStories(spec) : null,
index: this.generateIndex(spec)
};
}
generateComponent(spec: ComponentSpec, options: GeneratorOptions): string {
const imports = this.generateImports(spec, options);
const types = options.typescript ? this.generatePropTypes(spec) : '';
const component = this.generateComponentBody(spec, options);
const exports = this.generateExports(spec);
return \`\${imports}\n\n\${types}\n\n\${component}\n\n\${exports}\`;
}
generateImports(spec: ComponentSpec, options: GeneratorOptions): string {
const imports = ["import React, { useState, useEffect } from 'react';"];
if (spec.styling === 'css-modules') {
imports.push(\`import styles from './\${spec.name}.module.css';\`);
} else if (spec.styling === 'styled-components') {
imports.push("import styled from 'styled-components';");
}
if (options.accessibility) {
imports.push("import { useA11y } from '@/hooks/useA11y';");
}
return imports.join('\n');
}
generatePropTypes(spec: ComponentSpec): string {
const props = spec.props.map(p => {
const optional = p.required ? '' : '?';
const comment = p.description ? \` /** \${p.description} */\n\` : '';
return \`\${comment} \${p.name}\${optional}: \${p.type};\`;
}).join('\n');
return \`export interface \${spec.name}Props {\n\${props}\n}\`;
}
generateComponentBody(spec: ComponentSpec, options: GeneratorOptions): string {
const propsType = options.typescript ? \`: React.FC<\${spec.name}Props>\` : '';
const destructuredProps = spec.props.map(p => p.name).join(', ');
let body = \`export const \${spec.name}\${propsType} = ({ \${destructuredProps} }) => {\n\`;
// Add state hooks
if (spec.state) {
body += spec.state.map(s =>
\` const [\${s.name}, set\${this.capitalize(s.name)}] = useState\${options.typescript ? \`<\${s.type}>\` : ''}(\${s.initial});\n\`
).join('');
body += '\n';
}
// Add effects
if (spec.hooks?.includes('useEffect')) {
body += \` useEffect(() => {\n\`;
body += \` // TODO: Add effect logic\n\`;
body += \` }, [\${destructuredProps}]);\n\n\`;
}
// Add accessibility
if (options.accessibility) {
body += \` const a11yProps = useA11y({ role: 'region', label: spec.name });\n\n\`;
}
return body;
}
}
兼容工具
Claude CodeCursor
标签
前端开发