Skip to content

Commit e293f09

Browse files
docs: add copilot-instructions file to reduce AI hallucinations (ant-design#58101)
1 parent 6a293ef commit e293f09

1 file changed

Lines changed: 63 additions & 8 deletions

File tree

.github/copilot-instructions.md

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This is the Ant Design (antd) repository - a React component library with enterprise-class UI design language, widely used for building professional web applications.
44

5+
> For deeper, project-wide conventions (demo/test import rules, documentation format, changelog rules, PR templates, etc.), see [`CLAUDE.md`](../CLAUDE.md) at the repository root. This file is a concise, suggestion-time reference designed to keep AI tools from hallucinating non-existent components or APIs.
6+
57
## Project Context
68

79
- **Framework**: TypeScript + React (compatible with React 16-19)
@@ -10,6 +12,54 @@ This is the Ant Design (antd) repository - a React component library with enterp
1012
- **Design System**: Follows Ant Design specifications
1113
- **Internationalization**: Full i18n support
1214

15+
## Authoritative Component List
16+
17+
The following are the **only** top-level exports of `antd`. Do **not** invent components outside this list (e.g. `antd` does not export `Container`, `Stack`, `Heading`, `Box`, `Sidebar`, `Navbar`, `IconButton`, etc.).
18+
19+
`Affix`, `Alert`, `Anchor`, `App`, `AutoComplete`, `Avatar`, `BackTop` (deprecated — use `FloatButton.BackTop`), `Badge`, `BorderBeam`, `Breadcrumb`, `Button`, `Calendar`, `Card`, `Carousel`, `Cascader`, `Checkbox`, `Col`, `Collapse`, `ColorPicker`, `ConfigProvider`, `DatePicker`, `Descriptions`, `Divider`, `Drawer`, `Dropdown`, `Empty`, `Flex`, `FloatButton`, `Form`, `Grid`, `Image`, `Input`, `InputNumber`, `Layout`, `List`, `Masonry`, `Mentions`, `Menu`, `Modal`, `Pagination`, `Popconfirm`, `Popover`, `Progress`, `QRCode`, `Radio`, `Rate`, `Result`, `Row`, `Segmented`, `Select`, `Skeleton`, `Slider`, `Space`, `Spin`, `Splitter`, `Statistic`, `Steps`, `Switch`, `Table`, `Tabs`, `Tag`, `TimePicker`, `Timeline`, `Tooltip`, `Tour`, `Transfer`, `Tree`, `TreeSelect`, `Typography`, `Upload`, `Watermark`.
20+
21+
Function exports (lowercase): `message`, `notification`, `theme`, `version`, `unstableSetRender`.
22+
23+
When in doubt, verify against `components/index.ts` (the source of truth for public exports). Icons live in a **separate** package: `@ant-design/icons` — never import icons from `antd`.
24+
25+
## Import Patterns
26+
27+
```tsx
28+
// Components and types
29+
import { Button, Form, Input, type FormProps } from 'antd';
30+
31+
// Locales live under antd/locale (not from the main entry)
32+
import enUS from 'antd/locale/en_US';
33+
34+
// Icons live in a separate package
35+
import { SearchOutlined } from '@ant-design/icons';
36+
37+
// DatePicker / TimePicker / Calendar require a date library wrapper.
38+
// The default uses dayjs — moment is no longer the default since v5.
39+
import dayjs from 'dayjs';
40+
```
41+
42+
## API Migration Notes (Do Not Hallucinate the Old Names)
43+
44+
The current major version uses these renames. Use the **new** API in suggestions:
45+
46+
| Component | Deprecated (do not suggest) | Use instead |
47+
| --- | --- | --- |
48+
| Modal, Drawer, Dropdown, Tooltip, Popover, Popconfirm, Cascader, Select, AutoComplete, TreeSelect, etc. | `visible`, `onVisibleChange` | `open`, `onOpenChange` |
49+
| Modal, Drawer, Tabs, etc. | `destroyOnClose` | `destroyOnHidden` |
50+
| Tabs | `<Tabs><Tabs.TabPane /></Tabs>` (children API) | `<Tabs items={[{ key, label, children }]} />` |
51+
| Menu | `<Menu><Menu.Item /></Menu>` (children API) | `<Menu items={[{ key, label }]} />` |
52+
| Breadcrumb | `routes`, `<Breadcrumb.Item />` (children API) | `items={[{ title }]}` |
53+
| Anchor | children-based `<Anchor.Link />` | `items={[{ key, href, title }]}` |
54+
| AutoComplete, Cascader, Select | `dropdownClassName`, `dropdownStyle`, `dropdownRender`, `dropdownMatchSelectWidth` | `classNames.popup.root`, `styles.popup.root`, `popupRender`, `popupMatchSelectWidth` |
55+
| AutoComplete, Cascader | `onDropdownVisibleChange` | `onOpenChange` |
56+
| Card | `bordered` | `variant` |
57+
| Avatar.Group | `maxCount`, `maxStyle`, `maxPopoverPlacement` | `max={{ count, style, popover }}` |
58+
| BackTop | top-level `BackTop` | `FloatButton.BackTop` |
59+
| Calendar | `dateCellRender`, `dateFullCellRender` | `cellRender`, `fullCellRender` |
60+
61+
Internally these are flagged via `warning.deprecated(...)` and `@deprecated` JSDoc tags; check the component's `interface.ts` / `index.tsx` if unsure.
62+
1363
## Code Standards & Best Practices
1464

1565
### TypeScript Requirements
@@ -62,8 +112,7 @@ This is the Ant Design (antd) repository - a React component library with enterp
62112
- Use `@ant-design/cssinjs` for all styling
63113
- Place component styles in `style/` directory
64114
- Generate styles with functions named `gen[ComponentName]Style`
65-
- Use design tokens from the Ant Design token system
66-
- Never hardcode colors, sizes, or spacing values
115+
- Use design tokens from the Ant Design token system (read tokens via the `theme.useToken()` hook, or `token` argument inside style functions) — never hardcode colors, sizes, or spacing values
67116
- Support both light and dark themes
68117
- Use CSS logical properties for RTL support (e.g., `margin-inline-start` instead of `margin-left`)
69118
- Respect `prefers-reduced-motion` for animations
@@ -82,16 +131,22 @@ This is the Ant Design (antd) repository - a React component library with enterp
82131
- Target 100% test coverage
83132
- Place tests in `__tests__` directory as `index.test.tsx` or `componentName.test.tsx`
84133
- Include snapshot tests for UI components
134+
- Inside `components/**/__tests__/` use **relative** paths (`../`, `../../_util/...`) — never `antd`, `antd/es/*`, or path aliases. See [`CLAUDE.md`](../CLAUDE.md) for the full rule.
85135

86136
### Demo & Documentation
87137

88138
- Keep demo code concise and copy-pasteable
89139
- Focus each demo on a single feature
90-
- Provide both English and Chinese documentation
140+
- Provide both English and Chinese documentation (`index.en-US.md` and `index.zh-CN.md`)
141+
- Inside `components/**/demo/` use **absolute** imports (`antd`, `antd/es/*`, `antd/locale/*`) — never relative paths to component internals. The semantic demos (`_semantic*.tsx`) are an exception. See [`CLAUDE.md`](../CLAUDE.md) for the full rule.
91142
- Follow import order: React → dependencies → antd components → custom components → types → styles
92143
- Use 2-space indentation
93144
- Prefer antd built-in components over external dependencies
94145

146+
### Type Checks (Utility)
147+
148+
Prefer the helpers in `components/_util/is.ts` (`isNumber`, `isString`, `isPlainObject`, `isFunction`, `isThenable`, `isPrimitive`, `isNonNullable`) over inline `typeof` / `instanceof` checks when the helper covers the case.
149+
95150
### API Documentation Format
96151

97152
When documenting component APIs, use this table structure:
@@ -101,21 +156,21 @@ When documenting component APIs, use this table structure:
101156
- Number defaults as literal values: `0`, `100`
102157
- No default value: `-`
103158
- Descriptions start with capital letter, no ending period
104-
- Sort API properties alphabetically
159+
- Sort API properties alphabetically (ignoring common props like `className`, `style`; place event callbacks last)
105160

106161
### Internationalization
107162

108163
- Locale configuration files use pattern: `locale_COUNTRY.ts` (e.g., `zh_CN.ts`)
109164
- Use `useLocale` hook from `components/locale/index.tsx`
110-
- When modifying locale strings, update ALL language files
165+
- When modifying locale strings, update ALL language files under `components/locale/`
111166
- Locale content should be plain strings with `${}` placeholders for variables
112167

113168
### File Organization
114169

115-
- Components in `components/[component-name]/` directory
116-
- Demos in `components/[component-name]/demo/` as `.tsx` files
170+
- Components in `components/[component-name]/` directory (kebab-case directory name, PascalCase implementation file)
171+
- Demos in `components/[component-name]/demo/` as `.tsx` files paired with `.md` documentation
117172
- Use kebab-case for demo filenames: `basic.tsx`, `custom-filter.tsx`
118-
- Each component demo includes both `.md` documentation and `.tsx` code
173+
- Each component exports through `components/[component-name]/index.tsx`
119174

120175
## Development Commands
121176

0 commit comments

Comments
 (0)