mirror of
https://github.com/ant-design/ant-design.git
synced 2026-02-09 02:49:18 +08:00
Co-authored-by: afc163 <507615+afc163@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: afc163 <afc163@gmail.com>
4.8 KiB
4.8 KiB
Ant Design Repository Copilot Instructions
This is the Ant Design (antd) repository - a React component library with enterprise-class UI design language, widely used for building professional web applications.
Project Context
- Framework: TypeScript + React (compatible with React 16-19)
- Package: Published as npm package
antd - Purpose: Enterprise-class UI components for React applications
- Design System: Follows Ant Design specifications
- Internationalization: Full i18n support
Code Standards & Best Practices
TypeScript Requirements
- Always use TypeScript with strict type checking
- Never use
anytype - define precise types instead - Use interfaces (not type aliases) for object structures
- Export all public interface types
- Component props interfaces should be named
ComponentNameProps - Component ref types should use
React.ForwardRefRenderFunction - Prefer union types over enums, use
as constfor constants
React Component Guidelines
- Use functional components with hooks exclusively (no class components)
- Use early returns to improve readability
- Apply performance optimizations with React.memo, useMemo, useCallback appropriately
- Support server-side rendering
- Maintain backward compatibility - avoid breaking changes
- Components must support ref forwarding with this structure:
ComponentRef { nativeElement: HTMLElement; focus: VoidFunction; // other methods }
Naming Conventions
- Components: PascalCase (e.g.,
Button,DatePicker) - Props: camelCase with specific patterns:
- Default values:
default+PropName(e.g.,defaultValue) - Force rendering:
forceRender - Panel state: use
openinstead ofvisible - Display toggles:
show+PropName - Capabilities:
PropName+able - Data source:
dataSource - Disabled state:
disabled - Additional content:
extra - Icons:
icon - Triggers:
trigger - CSS classes:
className
- Default values:
- Events:
on+EventName(e.g.,onClick,onChange) - Sub-component events:
on+SubComponentName+EventName - Use complete names, never abbreviations
Styling Approach
- Use
@ant-design/cssinjsfor all styling - Place component styles in
style/directory - Generate styles with functions named
gen[ComponentName]Style - Use design tokens from the Ant Design token system
- Never hardcode colors, sizes, or spacing values
- Support both light and dark themes
- Use CSS logical properties for RTL support (e.g.,
margin-inline-startinstead ofmargin-left) - Respect
prefers-reduced-motionfor animations
Bundle & Performance
- Avoid introducing new dependencies
- Maintain strict bundle size control
- Support tree shaking
- Browser compatibility: Chrome 80+
- Optimize for minimal re-renders
Testing Requirements
- Write comprehensive tests using Jest and React Testing Library
- Target 100% test coverage
- Place tests in
__tests__directory asindex.test.tsxorcomponentName.test.tsx - Include snapshot tests for UI components
Demo & Documentation
- Keep demo code concise and copy-pasteable
- Focus each demo on a single feature
- Provide both English and Chinese documentation
- Follow import order: React → dependencies → antd components → custom components → types → styles
- Use 2-space indentation
- Prefer antd built-in components over external dependencies
API Documentation Format
When documenting component APIs, use this table structure:
- String defaults in backticks:
"default" - Boolean defaults as literal values:
trueorfalse - Number defaults as literal values:
0,100 - No default value:
- - Descriptions start with capital letter, no ending period
- Sort API properties alphabetically
Internationalization
- Locale configuration files use pattern:
locale_COUNTRY.ts(e.g.,zh_CN.ts) - Use
useLocalehook fromcomponents/locale/index.tsx - When modifying locale strings, update ALL language files
- Locale content should be plain strings with
${}placeholders for variables
File Organization
- Components in
components/[component-name]/directory - Demos in
components/[component-name]/demo/as.tsxfiles - Use kebab-case for demo filenames:
basic.tsx,custom-filter.tsx - Each component demo includes both
.mddocumentation and.tsxcode
Development Commands
npm start- Development servernpm run build- Build projectnpm test- Run testsnpm run lint- Code lintingnpm run format- Code formatting
Quality Standards
- Pass all ESLint and TypeScript checks
- Achieve 100% test coverage
- Support accessibility (WCAG 2.1 AA)
- Maintain cross-browser compatibility
- No console errors or warnings
When contributing code, ensure it follows these patterns and integrates seamlessly with the existing Ant Design ecosystem.