-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path.cursorrules
More file actions
170 lines (146 loc) · 4.43 KB
/
.cursorrules
File metadata and controls
170 lines (146 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
You are an expert React/TypeScript developer working with the Tiny Design UI library (`@tiny-design/react`).
## About Tiny Design
Tiny Design is a React component library with 80+ components. Package: `@tiny-design/react`. Docs: https://wangdicoder.github.io/tiny-design/
## Import Pattern
Always import from the package root:
```tsx
import { Button, Modal, Table, Input, Form } from '@tiny-design/react';
```
Icons are a separate package:
```tsx
import { SearchIcon, CloseIcon } from '@tiny-design/icons';
```
## Key Conventions
- **CSS prefix**: `ty-` (e.g., `.ty-btn`, `.ty-modal`), customizable via `ConfigProvider`
- **BEM naming**: `ty-component`, `ty-component__element`, `ty-component_modifier`
- **Sizes**: `'sm' | 'md' | 'lg'` — used by Button, Input, Select, Table, etc.
- **All components support**: `style`, `className`, `prefixCls`, and `ref` (via forwardRef)
## Component Quick Reference
### Buttons
```tsx
<Button btnType="primary" size="md" loading={isLoading} icon={<SearchIcon />}>
Search
</Button>
<Button btnType="danger">Delete</Button>
<Button btnType="outline" round>Rounded</Button>
```
Button types: `'default' | 'primary' | 'outline' | 'ghost' | 'link' | 'info' | 'danger' | 'warning' | 'success'`
### Forms
```tsx
<Form layout="vertical" onFinish={handleSubmit}>
<Form.Item label="Email" name="email" rules={[{ required: true, type: 'email' }]}>
<Input prefix={<MailIcon />} allowClear />
</Form.Item>
<Form.Item label="Password" name="password" rules={[{ required: true }]}>
<InputPassword />
</Form.Item>
<Form.Item>
<Button btnType="primary" htmlType="submit">Submit</Button>
</Form.Item>
</Form>
```
### Table
```tsx
<Table
columns={[
{ title: 'Name', dataIndex: 'name' },
{ title: 'Age', dataIndex: 'age', sorter: (a, b) => a.age - b.age },
{ title: 'Action', render: (_, record) => <Button btnType="link">Edit</Button> },
]}
dataSource={data}
rowKey="id"
rowSelection={{ selectedRowKeys, onChange: setSelectedRowKeys }}
pagination={{ current, pageSize: 10, total, onChange: setCurrent }}
loading={isLoading}
/>
```
### Modal
```tsx
<Modal
visible={visible}
header="Title"
centered
onConfirm={() => handleOk()}
onCancel={() => setVisible(false)}
confirmLoading={loading}
>
Content here
</Modal>
```
### Feedback (imperative)
```tsx
Message.success('Saved!');
Message.error('Something went wrong');
Notification.open({ title: 'Alert', description: 'Details here' });
```
### Select
```tsx
<Select
options={[{ label: 'Option A', value: 'a' }, { label: 'Option B', value: 'b' }]}
mode="multiple"
searchable
placeholder="Choose..."
onChange={(val) => setValue(val)}
/>
```
### Layout
```tsx
<Layout>
<Layout.Header>Header</Layout.Header>
<Layout>
<Layout.Sider>Sidebar</Layout.Sider>
<Layout.Content>Main</Layout.Content>
</Layout>
<Layout.Footer>Footer</Layout.Footer>
</Layout>
```
### Drawer
```tsx
<Drawer visible={visible} placement="right" width={400} onClose={() => setVisible(false)}>
Drawer content
</Drawer>
```
### Tabs
```tsx
<Tabs type="card" onChange={(key) => setActiveKey(key)}>
<Tabs.TabPane tab="Tab 1" key="1">Content 1</Tabs.TabPane>
<Tabs.TabPane tab="Tab 2" key="2">Content 2</Tabs.TabPane>
</Tabs>
```
### Alert
```tsx
<Alert type="warning" closable banner message="This is a warning" />
```
## Common Patterns
### ConfigProvider (theme/locale)
```tsx
<ConfigProvider prefixCls="my-app" themeMode="dark">
<App />
</ConfigProvider>
```
### Grid Layout (24 columns)
```tsx
<Grid.Row gutter={16}>
<Grid.Col span={8}>Col 1</Grid.Col>
<Grid.Col span={8}>Col 2</Grid.Col>
<Grid.Col span={8}>Col 3</Grid.Col>
</Grid.Row>
```
### Flex
```tsx
<Flex gap={12} align="center" justify="space-between">
<span>Left</span>
<Button btnType="primary">Right</Button>
</Flex>
```
## Rules When Generating Code
1. Always use `btnType` (not `type`) for Button variants
2. Modal uses `visible` (not `open`), `header` (not `title`), `onConfirm`/`onCancel`
3. Alert uses `type` for variant, not `severity`
4. Table columns use `dataIndex` to map to data fields
5. Form.Item uses `name` for field binding and `rules` for validation
6. Use `Message.success()` / `Message.error()` for toast-like feedback (imperative API)
7. Use `Notification.open()` for rich notifications (imperative API)
8. Drawer uses `visible` and `onClose`
9. All size props accept `'sm' | 'md' | 'lg'`, not `'small' | 'medium' | 'large'`
10. Import styles: `import '@tiny-design/react/es/style.css'`