@guiwzh/small-design 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 guiwzh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,230 @@
1
+ # @guiwz/small-design
2
+
3
+ 一套轻量级 React 组件库,基于 React 18 + TypeScript + SCSS 构建。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @guiwz/small-design
9
+ ```
10
+
11
+ ### Peer Dependencies
12
+
13
+ 需要确保项目中已安装以下依赖:
14
+
15
+ ```bash
16
+ npm install react react-dom
17
+ ```
18
+
19
+ 部分组件需要额外依赖(可选):
20
+
21
+ ```bash
22
+ # Upload 组件需要
23
+ npm install axios
24
+
25
+ # KeepAlive 组件需要
26
+ npm install react-router-dom
27
+ ```
28
+
29
+ ## 使用
30
+
31
+ ```tsx
32
+ import { Button, Menu, AutoComplete } from '@guiwz/small-design'
33
+ import '@guiwz/small-design/dist/index.css'
34
+ ```
35
+
36
+ ## 组件列表
37
+
38
+ ### Button
39
+
40
+ 页面中最常用的按钮元素,支持 HTML 中 button 和 a 链接的所有属性。
41
+
42
+ ```tsx
43
+ <Button btnType="primary" size="lg">Primary Button</Button>
44
+ <Button btnType="link" href="https://example.com">Link</Button>
45
+ ```
46
+
47
+ | 属性 | 说明 | 类型 | 默认值 |
48
+ |------|------|------|--------|
49
+ | btnType | 按钮类型 | `'primary' \| 'default' \| 'danger' \| 'link'` | `'default'` |
50
+ | size | 按钮尺寸 | `'lg' \| 'sm'` | - |
51
+ | disabled | 是否禁用 | `boolean` | `false` |
52
+ | href | 链接地址(btnType 为 link 时生效) | `string` | - |
53
+
54
+ ### Menu
55
+
56
+ 导航菜单,支持横向与纵向两种模式,支持下拉子菜单。
57
+
58
+ ```tsx
59
+ <Menu defaultIndex="0" mode="horizontal" onSelect={(index) => {}}>
60
+ <Menu.Item>首页</Menu.Item>
61
+ <Menu.Item>文档</Menu.Item>
62
+ <Menu.SubMenu title="更多">
63
+ <Menu.Item>选项一</Menu.Item>
64
+ <Menu.Item>选项二</Menu.Item>
65
+ </Menu.SubMenu>
66
+ </Menu>
67
+ ```
68
+
69
+ | 属性 | 说明 | 类型 | 默认值 |
70
+ |------|------|------|--------|
71
+ | mode | 菜单方向 | `'horizontal' \| 'vertical'` | `'horizontal'` |
72
+ | defaultIndex | 默认激活项索引 | `string` | `'0'` |
73
+ | defaultOpenSubMenus | 默认展开的子菜单(纵向模式) | `string[]` | `[]` |
74
+ | onSelect | 选中回调 | `(index: string, e: MouseEvent) => void` | - |
75
+
76
+ ### AutoComplete
77
+
78
+ 搜索输入框,支持异步建议、防抖、缓存、键盘导航。
79
+
80
+ ```tsx
81
+ <AutoComplete
82
+ fetchSuggestions={(query) => fetch(`/api/search?q=${query}`).then(r => r.json())}
83
+ onSelect={(item) => console.log(item)}
84
+ debounceTime={300}
85
+ />
86
+ ```
87
+
88
+ | 属性 | 说明 | 类型 | 默认值 |
89
+ |------|------|------|--------|
90
+ | fetchSuggestions | 获取建议的函数 | `(str: string) => DataSourceType[] \| Promise<DataSourceType[]>` | 必填 |
91
+ | onSelect | 选中建议回调 | `(item: DataSourceType) => void` | - |
92
+ | onChange | 输入变化回调 | `(str: string) => void` | - |
93
+ | onError | 请求错误回调 | `(error: unknown) => void` | - |
94
+ | renderOption | 自定义建议项渲染 | `(item: DataSourceType) => ReactElement` | - |
95
+ | debounceTime | 防抖时间(ms) | `number` | `300` |
96
+ | expireTime | 缓存过期时间(ms) | `number` | `3600000` |
97
+
98
+ ### Upload
99
+
100
+ 文件上传组件,支持点击和拖拽上传,带进度展示和取消功能。
101
+
102
+ ```tsx
103
+ <Upload
104
+ action="https://api.example.com/upload"
105
+ onSuccess={(data, file) => {}}
106
+ onError={(err, file) => {}}
107
+ multiple
108
+ drag
109
+ >
110
+ 拖拽文件到此处上传
111
+ </Upload>
112
+ ```
113
+
114
+ | 属性 | 说明 | 类型 | 默认值 |
115
+ |------|------|------|--------|
116
+ | action | 上传地址 | `string` | 必填 |
117
+ | beforeUpload | 上传前校验 | `(file: File) => boolean \| Promise<File>` | - |
118
+ | onprogress | 上传进度回调 | `(percentage: number, file: UploadFile) => void` | - |
119
+ | onSuccess | 上传成功回调 | `(data: any, file: UploadFile) => void` | - |
120
+ | onError | 上传失败回调 | `(err: any, file: UploadFile) => void` | - |
121
+ | onExceed | 超出限制回调 | `(message: string) => void` | - |
122
+ | drag | 是否启用拖拽上传 | `boolean` | `false` |
123
+ | multiple | 是否支持多文件 | `boolean` | `false` |
124
+ | maxsize | 文件大小限制(MB) | `number` | - |
125
+ | maxnum | 文件数量限制 | `number` | - |
126
+
127
+ ### Icon
128
+
129
+ 基于 FontAwesome 的图标组件,支持主题色。
130
+
131
+ ```tsx
132
+ <Icon icon="coffee" theme="primary" size="2x" />
133
+ ```
134
+
135
+ ### Input
136
+
137
+ 增强输入框,支持前缀、后缀和图标。
138
+
139
+ ```tsx
140
+ <Input prepend="https://" append=".com" />
141
+ <Input icon="search" />
142
+ ```
143
+
144
+ ### Progress
145
+
146
+ 进度条组件。
147
+
148
+ ```tsx
149
+ <Progress percent={60} theme="success" />
150
+ ```
151
+
152
+ ### Signature
153
+
154
+ 基于 Canvas 的手写签名板,支持笔触切换、清除和保存。
155
+
156
+ ```tsx
157
+ <Signature onSave={(dataUrl) => {}} width={400} height={200} />
158
+ ```
159
+
160
+ ### VirtualList
161
+
162
+ 虚拟滚动列表,只渲染可视区域内的列表项。
163
+
164
+ ```tsx
165
+ <VirtualList containerHeight={400} itemHeight={50} itemCount={10000}>
166
+ <MyListItem />
167
+ </VirtualList>
168
+ ```
169
+
170
+ ### LazyLoad
171
+
172
+ 懒加载组件,子元素进入可视区域时才渲染。
173
+
174
+ ```tsx
175
+ <LazyLoad>
176
+ <img src="large-image.jpg" />
177
+ </LazyLoad>
178
+ ```
179
+
180
+ ### KeepAlive
181
+
182
+ 路由级组件缓存,类似 Vue 的 `<keep-alive>`。
183
+
184
+ ```tsx
185
+ <KeepAliveLayout keepPaths={['/home', /^\/detail/]}>
186
+ <Outlet />
187
+ </KeepAliveLayout>
188
+ ```
189
+
190
+ ### Transition
191
+
192
+ 动画过渡封装组件。
193
+
194
+ ```tsx
195
+ <Transition in={show} timeout={300} animation="zoom-in-top">
196
+ <div>内容</div>
197
+ </Transition>
198
+ ```
199
+
200
+ ## Hooks
201
+
202
+ ### useDebounce
203
+
204
+ ```tsx
205
+ const debouncedValue = useDebounce(inputValue, 300)
206
+ ```
207
+
208
+ ### useClickOutside
209
+
210
+ ```tsx
211
+ const ref = useRef(null)
212
+ useClickOutside(ref, () => { /* 点击外部时触发 */ })
213
+ ```
214
+
215
+ ## 开发
216
+
217
+ ```bash
218
+ # 启动开发服务器
219
+ npm start
220
+
221
+ # 构建库
222
+ npm run build
223
+
224
+ # 运行测试
225
+ npm test
226
+ ```
227
+
228
+ ## License
229
+
230
+ MIT