@unif/react-native-ui 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 +20 -0
- package/README.md +103 -0
- package/lib/module/README.md +99 -0
- package/lib/module/action-sheet/index.js +63 -0
- package/lib/module/action-sheet/index.js.map +1 -0
- package/lib/module/action-sheet/index.md +69 -0
- package/lib/module/action-sheet/style/index.js +38 -0
- package/lib/module/action-sheet/style/index.js.map +1 -0
- package/lib/module/avatar/index.js +42 -0
- package/lib/module/avatar/index.js.map +1 -0
- package/lib/module/avatar/index.md +51 -0
- package/lib/module/avatar/style/index.js +17 -0
- package/lib/module/avatar/style/index.js.map +1 -0
- package/lib/module/button/index.js +52 -0
- package/lib/module/button/index.js.map +1 -0
- package/lib/module/button/index.md +90 -0
- package/lib/module/button/style/index.js +94 -0
- package/lib/module/button/style/index.js.map +1 -0
- package/lib/module/center/index.js +21 -0
- package/lib/module/center/index.js.map +1 -0
- package/lib/module/center/index.md +28 -0
- package/lib/module/center/style/index.js +10 -0
- package/lib/module/center/style/index.js.map +1 -0
- package/lib/module/chip/index.js +59 -0
- package/lib/module/chip/index.js.map +1 -0
- package/lib/module/chip/index.md +60 -0
- package/lib/module/chip/style/index.js +40 -0
- package/lib/module/chip/style/index.js.map +1 -0
- package/lib/module/column/index.js +30 -0
- package/lib/module/column/index.js.map +1 -0
- package/lib/module/column/index.md +34 -0
- package/lib/module/column/style/index.js +9 -0
- package/lib/module/column/style/index.js.map +1 -0
- package/lib/module/divider/index.js +21 -0
- package/lib/module/divider/index.js.map +1 -0
- package/lib/module/divider/index.md +44 -0
- package/lib/module/divider/style/index.js +17 -0
- package/lib/module/divider/style/index.js.map +1 -0
- package/lib/module/hooks/index.js +4 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/hooks/index.md +71 -0
- package/lib/module/hooks/useMergeStyles.js +27 -0
- package/lib/module/hooks/useMergeStyles.js.map +1 -0
- package/lib/module/index.js +29 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/input/index.js +69 -0
- package/lib/module/input/index.js.map +1 -0
- package/lib/module/input/index.md +73 -0
- package/lib/module/input/style/index.js +27 -0
- package/lib/module/input/style/index.js.map +1 -0
- package/lib/module/list-item/index.js +69 -0
- package/lib/module/list-item/index.js.map +1 -0
- package/lib/module/list-item/index.md +101 -0
- package/lib/module/list-item/style/index.js +39 -0
- package/lib/module/list-item/style/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/popover/index.js +60 -0
- package/lib/module/popover/index.js.map +1 -0
- package/lib/module/popover/index.md +57 -0
- package/lib/module/popover/style/index.js +22 -0
- package/lib/module/popover/style/index.js.map +1 -0
- package/lib/module/row/index.js +31 -0
- package/lib/module/row/index.js.map +1 -0
- package/lib/module/row/index.md +46 -0
- package/lib/module/row/style/index.js +15 -0
- package/lib/module/row/style/index.js.map +1 -0
- package/lib/module/space/index.js +20 -0
- package/lib/module/space/index.js.map +1 -0
- package/lib/module/space/index.md +31 -0
- package/lib/module/space/style/index.js +9 -0
- package/lib/module/space/style/index.js.map +1 -0
- package/lib/module/text/index.js +30 -0
- package/lib/module/text/index.js.map +1 -0
- package/lib/module/text/index.md +63 -0
- package/lib/module/text/style/index.js +51 -0
- package/lib/module/text/style/index.js.map +1 -0
- package/lib/module/theme/config.js +27 -0
- package/lib/module/theme/config.js.map +1 -0
- package/lib/module/theme/tokens.js +67 -0
- package/lib/module/theme/tokens.js.map +1 -0
- package/lib/module/touchable/index.js +35 -0
- package/lib/module/touchable/index.js.map +1 -0
- package/lib/module/touchable/index.md +42 -0
- package/lib/module/touchable/style/index.js +9 -0
- package/lib/module/touchable/style/index.js.map +1 -0
- package/lib/module/wave-animation/index.js +67 -0
- package/lib/module/wave-animation/index.js.map +1 -0
- package/lib/module/wave-animation/index.md +50 -0
- package/lib/typescript/jest.setup.d.ts +1 -0
- package/lib/typescript/jest.setup.d.ts.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/action-sheet/index.d.ts +22 -0
- package/lib/typescript/src/action-sheet/index.d.ts.map +1 -0
- package/lib/typescript/src/action-sheet/style/index.d.ts +16 -0
- package/lib/typescript/src/action-sheet/style/index.d.ts.map +1 -0
- package/lib/typescript/src/avatar/index.d.ts +19 -0
- package/lib/typescript/src/avatar/index.d.ts.map +1 -0
- package/lib/typescript/src/avatar/style/index.d.ts +7 -0
- package/lib/typescript/src/avatar/style/index.d.ts.map +1 -0
- package/lib/typescript/src/button/index.d.ts +24 -0
- package/lib/typescript/src/button/index.d.ts.map +1 -0
- package/lib/typescript/src/button/style/index.d.ts +16 -0
- package/lib/typescript/src/button/style/index.d.ts.map +1 -0
- package/lib/typescript/src/center/index.d.ts +11 -0
- package/lib/typescript/src/center/index.d.ts.map +1 -0
- package/lib/typescript/src/center/style/index.d.ts +5 -0
- package/lib/typescript/src/center/style/index.d.ts.map +1 -0
- package/lib/typescript/src/chip/index.d.ts +22 -0
- package/lib/typescript/src/chip/index.d.ts.map +1 -0
- package/lib/typescript/src/chip/style/index.d.ts +10 -0
- package/lib/typescript/src/chip/style/index.d.ts.map +1 -0
- package/lib/typescript/src/column/index.d.ts +20 -0
- package/lib/typescript/src/column/index.d.ts.map +1 -0
- package/lib/typescript/src/column/style/index.d.ts +4 -0
- package/lib/typescript/src/column/style/index.d.ts.map +1 -0
- package/lib/typescript/src/divider/index.d.ts +13 -0
- package/lib/typescript/src/divider/index.d.ts.map +1 -0
- package/lib/typescript/src/divider/style/index.d.ts +9 -0
- package/lib/typescript/src/divider/style/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +2 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useMergeStyles.d.ts +13 -0
- package/lib/typescript/src/hooks/useMergeStyles.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +39 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/input/index.d.ts +29 -0
- package/lib/typescript/src/input/index.d.ts.map +1 -0
- package/lib/typescript/src/input/style/index.d.ts +8 -0
- package/lib/typescript/src/input/style/index.d.ts.map +1 -0
- package/lib/typescript/src/list-item/index.d.ts +25 -0
- package/lib/typescript/src/list-item/index.d.ts.map +1 -0
- package/lib/typescript/src/list-item/style/index.d.ts +17 -0
- package/lib/typescript/src/list-item/style/index.d.ts.map +1 -0
- package/lib/typescript/src/popover/index.d.ts +27 -0
- package/lib/typescript/src/popover/index.d.ts.map +1 -0
- package/lib/typescript/src/popover/style/index.d.ts +7 -0
- package/lib/typescript/src/popover/style/index.d.ts.map +1 -0
- package/lib/typescript/src/row/index.d.ts +22 -0
- package/lib/typescript/src/row/index.d.ts.map +1 -0
- package/lib/typescript/src/row/style/index.d.ts +8 -0
- package/lib/typescript/src/row/style/index.d.ts.map +1 -0
- package/lib/typescript/src/space/index.d.ts +15 -0
- package/lib/typescript/src/space/index.d.ts.map +1 -0
- package/lib/typescript/src/space/style/index.d.ts +7 -0
- package/lib/typescript/src/space/style/index.d.ts.map +1 -0
- package/lib/typescript/src/text/index.d.ts +18 -0
- package/lib/typescript/src/text/index.d.ts.map +1 -0
- package/lib/typescript/src/text/style/index.d.ts +35 -0
- package/lib/typescript/src/text/style/index.d.ts.map +1 -0
- package/lib/typescript/src/theme/config.d.ts +18 -0
- package/lib/typescript/src/theme/config.d.ts.map +1 -0
- package/lib/typescript/src/theme/tokens.d.ts +61 -0
- package/lib/typescript/src/theme/tokens.d.ts.map +1 -0
- package/lib/typescript/src/touchable/index.d.ts +19 -0
- package/lib/typescript/src/touchable/index.d.ts.map +1 -0
- package/lib/typescript/src/touchable/style/index.d.ts +4 -0
- package/lib/typescript/src/touchable/style/index.d.ts.map +1 -0
- package/lib/typescript/src/wave-animation/index.d.ts +20 -0
- package/lib/typescript/src/wave-animation/index.d.ts.map +1 -0
- package/lib/typescript/tests/component/component.coverage.test.d.ts +2 -0
- package/lib/typescript/tests/component/component.coverage.test.d.ts.map +1 -0
- package/lib/typescript/tests/component/component.interaction.test.d.ts +2 -0
- package/lib/typescript/tests/component/component.interaction.test.d.ts.map +1 -0
- package/lib/typescript/tests/component/component.snapshot.test.d.ts +2 -0
- package/lib/typescript/tests/component/component.snapshot.test.d.ts.map +1 -0
- package/lib/typescript/tests/e2e/app.e2e.test.d.ts +2 -0
- package/lib/typescript/tests/e2e/app.e2e.test.d.ts.map +1 -0
- package/lib/typescript/tests/integration/ui.integration.test.d.ts +2 -0
- package/lib/typescript/tests/integration/ui.integration.test.d.ts.map +1 -0
- package/lib/typescript/tests/unit/mergeStyles.unit.test.d.ts +2 -0
- package/lib/typescript/tests/unit/mergeStyles.unit.test.d.ts.map +1 -0
- package/lib/typescript/tests/unit/public-api.unit.test.d.ts +2 -0
- package/lib/typescript/tests/unit/public-api.unit.test.d.ts.map +1 -0
- package/lib/typescript/tests/unit/theme-config.unit.test.d.ts +2 -0
- package/lib/typescript/tests/unit/theme-config.unit.test.d.ts.map +1 -0
- package/package.json +134 -0
- package/src/README.md +99 -0
- package/src/action-sheet/index.md +69 -0
- package/src/action-sheet/index.tsx +85 -0
- package/src/action-sheet/style/index.tsx +52 -0
- package/src/avatar/index.md +51 -0
- package/src/avatar/index.tsx +56 -0
- package/src/avatar/style/index.tsx +21 -0
- package/src/button/index.md +90 -0
- package/src/button/index.tsx +86 -0
- package/src/button/style/index.tsx +67 -0
- package/src/center/index.md +28 -0
- package/src/center/index.tsx +18 -0
- package/src/center/style/index.tsx +8 -0
- package/src/chip/index.md +60 -0
- package/src/chip/index.tsx +80 -0
- package/src/chip/style/index.tsx +47 -0
- package/src/column/index.md +34 -0
- package/src/column/index.tsx +43 -0
- package/src/column/style/index.tsx +7 -0
- package/src/divider/index.md +44 -0
- package/src/divider/index.tsx +30 -0
- package/src/divider/style/index.tsx +13 -0
- package/src/hooks/index.md +71 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useMergeStyles.ts +27 -0
- package/src/index.tsx +49 -0
- package/src/input/index.md +73 -0
- package/src/input/index.tsx +95 -0
- package/src/input/style/index.tsx +32 -0
- package/src/list-item/index.md +101 -0
- package/src/list-item/index.tsx +91 -0
- package/src/list-item/style/index.tsx +41 -0
- package/src/popover/index.md +57 -0
- package/src/popover/index.tsx +80 -0
- package/src/popover/style/index.tsx +23 -0
- package/src/row/index.md +46 -0
- package/src/row/index.tsx +47 -0
- package/src/row/style/index.tsx +14 -0
- package/src/space/index.md +31 -0
- package/src/space/index.tsx +28 -0
- package/src/space/style/index.tsx +3 -0
- package/src/text/index.md +63 -0
- package/src/text/index.tsx +45 -0
- package/src/text/style/index.tsx +32 -0
- package/src/theme/config.ts +26 -0
- package/src/theme/tokens.ts +66 -0
- package/src/touchable/index.md +42 -0
- package/src/touchable/index.tsx +45 -0
- package/src/touchable/style/index.tsx +5 -0
- package/src/wave-animation/index.md +50 -0
- package/src/wave-animation/index.tsx +93 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dream-god1
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# @unif/react-native-ui
|
|
2
|
+
|
|
3
|
+
UNIF React Native 基础 UI 组件库 — 提供原子、基础、复合三层组件体系。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @unif/react-native-ui
|
|
9
|
+
# 或
|
|
10
|
+
yarn add @unif/react-native-ui
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 使用
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { Button, Input, Avatar, ListItem, tokens } from '@unif/react-native-ui';
|
|
17
|
+
|
|
18
|
+
<Button title="提交" onPress={handleSubmit} />
|
|
19
|
+
<Input placeholder="请输入..." onChangeText={setText} />
|
|
20
|
+
<Avatar name="张三" size={40} />
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 组件列表
|
|
24
|
+
|
|
25
|
+
### 布局
|
|
26
|
+
|
|
27
|
+
| 组件 | 说明 |
|
|
28
|
+
|------|------|
|
|
29
|
+
| Row | 水平布局容器 |
|
|
30
|
+
| Column | 垂直布局容器 |
|
|
31
|
+
| Center | 居中布局容器 |
|
|
32
|
+
| Space | 间距组件 |
|
|
33
|
+
|
|
34
|
+
### 原子 (Atom)
|
|
35
|
+
|
|
36
|
+
| 组件 | 说明 |
|
|
37
|
+
|------|------|
|
|
38
|
+
| Text | 文本组件 |
|
|
39
|
+
| Touchable | 触摸反馈容器 |
|
|
40
|
+
| Divider | 分割线 |
|
|
41
|
+
| Avatar | 头像 |
|
|
42
|
+
| WaveAnimation | 波形动画 |
|
|
43
|
+
|
|
44
|
+
### 基础 (Base)
|
|
45
|
+
|
|
46
|
+
| 组件 | 说明 |
|
|
47
|
+
|------|------|
|
|
48
|
+
| Button | 按钮 |
|
|
49
|
+
| Input | 输入框(含 toolbar 插槽) |
|
|
50
|
+
| Chip | 标签/筹码 |
|
|
51
|
+
| Popover | 气泡弹出层 |
|
|
52
|
+
| ActionSheet | 操作面板 |
|
|
53
|
+
|
|
54
|
+
### 复合 (Composite)
|
|
55
|
+
|
|
56
|
+
| 组件 | 说明 |
|
|
57
|
+
|------|------|
|
|
58
|
+
| ListItem | 列表项(thumb + title + extra 布局) |
|
|
59
|
+
|
|
60
|
+
## 主题
|
|
61
|
+
|
|
62
|
+
通过 `configure()` 自定义 token,通过 `tokens` 访问当前主题值:
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import { configure, tokens } from '@unif/react-native-ui';
|
|
66
|
+
|
|
67
|
+
configure({ colorPrimary: '#1890FF' });
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 语义样式
|
|
71
|
+
|
|
72
|
+
每个组件支持 `styles` prop 进行语义化样式覆盖:
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
<Button
|
|
76
|
+
title="确定"
|
|
77
|
+
styles={{ root: { borderRadius: 20 }, title: { fontSize: 16 } }}
|
|
78
|
+
/>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## 兼容性
|
|
82
|
+
|
|
83
|
+
| @unif/react-native-ui | React Native | React | 状态 |
|
|
84
|
+
|------------------------|-------------|-------|------|
|
|
85
|
+
| 0.1.x | >= 0.71 | >= 18 | ✅ |
|
|
86
|
+
| 0.1.x | 0.74.x | 18.x | ✅ 已验证(PECPortal) |
|
|
87
|
+
| 0.1.x | 0.81.x | 19.x | ✅ 已验证(example app) |
|
|
88
|
+
|
|
89
|
+
### API 兼容说明
|
|
90
|
+
|
|
91
|
+
- `Pressable`: RN >= 0.63 ✅
|
|
92
|
+
- `StyleSheet.compose`: RN >= 0.66 ✅
|
|
93
|
+
|
|
94
|
+
## Contributing
|
|
95
|
+
|
|
96
|
+
- [Development workflow](CONTRIBUTING.md#development-workflow)
|
|
97
|
+
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
|
|
98
|
+
- [Code of conduct](CODE_OF_CONDUCT.md)
|
|
99
|
+
- [Testing strategy](TESTING.md)
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
MIT
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# @unif/react-native-ui 基础组件
|
|
2
|
+
|
|
3
|
+
借鉴 antd v6 语义化设计 + ant-design-mobile-rn 实践,提供基础 UI 组件。
|
|
4
|
+
|
|
5
|
+
## 组件总览
|
|
6
|
+
|
|
7
|
+
### 布局
|
|
8
|
+
|
|
9
|
+
| 组件 | 说明 | 文档 |
|
|
10
|
+
|------|------|------|
|
|
11
|
+
| Row | 水平布局 | [row/index.md](./row/index.md) |
|
|
12
|
+
| Column | 垂直布局 | [column/index.md](./column/index.md) |
|
|
13
|
+
| Center | 居中布局 | [center/index.md](./center/index.md) |
|
|
14
|
+
| Space | 间距占位 | [space/index.md](./space/index.md) |
|
|
15
|
+
|
|
16
|
+
### 通用
|
|
17
|
+
|
|
18
|
+
| 组件 | 说明 | 文档 |
|
|
19
|
+
|------|------|------|
|
|
20
|
+
| Text | 语义化文字 | [text/index.md](./text/index.md) |
|
|
21
|
+
| Button | 语义化按钮 | [button/index.md](./button/index.md) |
|
|
22
|
+
| Touchable | 统一触摸反馈 | [touchable/index.md](./touchable/index.md) |
|
|
23
|
+
| Divider | 分割线 | [divider/index.md](./divider/index.md) |
|
|
24
|
+
| ListItem | 列表行 | [list-item/index.md](./list-item/index.md) |
|
|
25
|
+
| mergeStyles | 样式合并工具 | [hooks/index.md](./hooks/index.md) |
|
|
26
|
+
|
|
27
|
+
## 引入方式
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { Row, Column, Center, Space, Text, Button, Touchable, Divider, ListItem } from '@unif/react-native-ui';
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 目录结构
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
src/
|
|
37
|
+
├── index.tsx # 统一导出
|
|
38
|
+
├── README.md # 总览(本文件)
|
|
39
|
+
├── theme/
|
|
40
|
+
│ ├── config.ts # 主题配置(configure API)
|
|
41
|
+
│ └── tokens.ts # Design Tokens
|
|
42
|
+
├── hooks/
|
|
43
|
+
│ ├── index.ts
|
|
44
|
+
│ ├── index.md # mergeStyles 文档
|
|
45
|
+
│ └── useMergeStyles.ts
|
|
46
|
+
├── row/
|
|
47
|
+
│ ├── index.tsx # Row 组件
|
|
48
|
+
│ ├── index.md
|
|
49
|
+
│ └── style/
|
|
50
|
+
│ └── index.tsx
|
|
51
|
+
├── column/
|
|
52
|
+
│ ├── index.tsx # Column 组件
|
|
53
|
+
│ ├── index.md
|
|
54
|
+
│ └── style/
|
|
55
|
+
│ └── index.tsx
|
|
56
|
+
├── center/
|
|
57
|
+
│ ├── index.tsx # Center 组件
|
|
58
|
+
│ ├── index.md
|
|
59
|
+
│ └── style/
|
|
60
|
+
│ └── index.tsx
|
|
61
|
+
├── space/
|
|
62
|
+
│ ├── index.tsx # Space 组件
|
|
63
|
+
│ ├── index.md
|
|
64
|
+
│ └── style/
|
|
65
|
+
│ └── index.tsx
|
|
66
|
+
├── text/
|
|
67
|
+
│ ├── index.tsx # Text 组件
|
|
68
|
+
│ ├── index.md
|
|
69
|
+
│ └── style/
|
|
70
|
+
│ └── index.tsx
|
|
71
|
+
├── button/
|
|
72
|
+
│ ├── index.tsx # Button 组件
|
|
73
|
+
│ ├── index.md
|
|
74
|
+
│ └── style/
|
|
75
|
+
│ └── index.tsx
|
|
76
|
+
├── touchable/
|
|
77
|
+
│ ├── index.tsx # Touchable 组件
|
|
78
|
+
│ ├── index.md
|
|
79
|
+
│ └── style/
|
|
80
|
+
│ └── index.tsx
|
|
81
|
+
├── divider/
|
|
82
|
+
│ ├── index.tsx # Divider 组件
|
|
83
|
+
│ ├── index.md
|
|
84
|
+
│ └── style/
|
|
85
|
+
│ └── index.tsx
|
|
86
|
+
└── list-item/
|
|
87
|
+
├── index.tsx # ListItem 组件
|
|
88
|
+
├── index.md
|
|
89
|
+
└── style/
|
|
90
|
+
└── index.tsx
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## 设计原则
|
|
94
|
+
|
|
95
|
+
1. **语义化** — `variant="caption"` 而非 `fontSize={13}`,意图清晰
|
|
96
|
+
2. **Semantic Styles** — 消费方通过 `styles={{content: {...}}}` 精确覆盖内部 slot,不侵入组件结构
|
|
97
|
+
3. **Token 驱动** — 所有颜色、间距来自 `tokens`,主题可控
|
|
98
|
+
4. **样式数组组合** — `[baseStyle, variantStyle, stateStyle, userStyle]` 优先级叠加
|
|
99
|
+
5. **性能安全** — 样式常量预定义在模块顶层,`mergeStyles` 配合 `useMemo` 使用
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ActionSheet 基础组件
|
|
5
|
+
*
|
|
6
|
+
* 轻量底部选项面板,Modal + 网格布局。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import React, { useMemo } from 'react';
|
|
10
|
+
import { View, Text, TouchableOpacity, TouchableWithoutFeedback, Modal } from 'react-native';
|
|
11
|
+
import { mergeStyles } from "../hooks/index.js";
|
|
12
|
+
import { DEFAULT_STYLES } from "./style/index.js";
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
const ActionSheet = ({
|
|
15
|
+
visible,
|
|
16
|
+
onClose,
|
|
17
|
+
options,
|
|
18
|
+
onSelect,
|
|
19
|
+
columns = 3,
|
|
20
|
+
style,
|
|
21
|
+
styles: semanticStyles,
|
|
22
|
+
testID
|
|
23
|
+
}) => {
|
|
24
|
+
const s = useMemo(() => mergeStyles(DEFAULT_STYLES, semanticStyles), [semanticStyles]);
|
|
25
|
+
if (!visible) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return /*#__PURE__*/_jsxs(Modal, {
|
|
29
|
+
visible: visible,
|
|
30
|
+
transparent: true,
|
|
31
|
+
animationType: "slide",
|
|
32
|
+
onRequestClose: onClose,
|
|
33
|
+
children: [/*#__PURE__*/_jsx(TouchableWithoutFeedback, {
|
|
34
|
+
onPress: onClose,
|
|
35
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
36
|
+
style: s.overlay
|
|
37
|
+
})
|
|
38
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
39
|
+
style: [s.panel, style],
|
|
40
|
+
testID: testID,
|
|
41
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
42
|
+
style: s.grid,
|
|
43
|
+
children: options.map(item => /*#__PURE__*/_jsxs(TouchableOpacity, {
|
|
44
|
+
style: [s.option, {
|
|
45
|
+
width: `${Math.floor(100 / columns)}%`
|
|
46
|
+
}],
|
|
47
|
+
onPress: () => onSelect(item.key),
|
|
48
|
+
activeOpacity: 0.7,
|
|
49
|
+
testID: testID ? `${testID}-${item.key}` : undefined,
|
|
50
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
51
|
+
style: s.optionIcon,
|
|
52
|
+
children: item.icon
|
|
53
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
54
|
+
style: s.optionLabel,
|
|
55
|
+
children: item.label
|
|
56
|
+
})]
|
|
57
|
+
}, item.key))
|
|
58
|
+
})
|
|
59
|
+
})]
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
export default ActionSheet;
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useMemo","View","Text","TouchableOpacity","TouchableWithoutFeedback","Modal","mergeStyles","DEFAULT_STYLES","jsx","_jsx","jsxs","_jsxs","ActionSheet","visible","onClose","options","onSelect","columns","style","styles","semanticStyles","testID","s","transparent","animationType","onRequestClose","children","onPress","overlay","panel","grid","map","item","option","width","Math","floor","key","activeOpacity","undefined","optionIcon","icon","optionLabel","label"],"sourceRoot":"../../../src","sources":["action-sheet/index.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO;AACtC,SACEC,IAAI,EACJC,IAAI,EACJC,gBAAgB,EAChBC,wBAAwB,EACxBC,KAAK,QACA,cAAc;AAErB,SAASC,WAAW,QAAQ,mBAAU;AAEtC,SAASC,cAAc,QAAQ,kBAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAczC,MAAMC,WAAuC,GAAGA,CAAC;EAC/CC,OAAO;EACPC,OAAO;EACPC,OAAO;EACPC,QAAQ;EACRC,OAAO,GAAG,CAAC;EACXC,KAAK;EACLC,MAAM,EAAEC,cAAc;EACtBC;AACF,CAAC,KAAK;EACJ,MAAMC,CAAC,GAAGtB,OAAO,CACf,MAAMM,WAAW,CAA4BC,cAAc,EAAEa,cAAc,CAAC,EAC5E,CAACA,cAAc,CACjB,CAAC;EAED,IAAI,CAACP,OAAO,EAAE;IACZ,OAAO,IAAI;EACb;EAEA,oBACEF,KAAA,CAACN,KAAK;IACJQ,OAAO,EAAEA,OAAQ;IACjBU,WAAW;IACXC,aAAa,EAAC,OAAO;IACrBC,cAAc,EAAEX,OAAQ;IAAAY,QAAA,gBAExBjB,IAAA,CAACL,wBAAwB;MAACuB,OAAO,EAAEb,OAAQ;MAAAY,QAAA,eACzCjB,IAAA,CAACR,IAAI;QAACiB,KAAK,EAAEI,CAAC,CAACM;MAAQ,CAAE;IAAC,CACF,CAAC,eAE3BnB,IAAA,CAACR,IAAI;MAACiB,KAAK,EAAE,CAACI,CAAC,CAACO,KAAK,EAAEX,KAAK,CAAE;MAACG,MAAM,EAAEA,MAAO;MAAAK,QAAA,eAC5CjB,IAAA,CAACR,IAAI;QAACiB,KAAK,EAAEI,CAAC,CAACQ,IAAK;QAAAJ,QAAA,EACjBX,OAAO,CAACgB,GAAG,CAAEC,IAAI,iBAChBrB,KAAA,CAACR,gBAAgB;UAEfe,KAAK,EAAE,CACLI,CAAC,CAACW,MAAM,EACR;YAAEC,KAAK,EAAE,GAAGC,IAAI,CAACC,KAAK,CAAC,GAAG,GAAGnB,OAAO,CAAC;UAAW,CAAC,CACjD;UACFU,OAAO,EAAEA,CAAA,KAAMX,QAAQ,CAACgB,IAAI,CAACK,GAAG,CAAE;UAClCC,aAAa,EAAE,GAAI;UACnBjB,MAAM,EAAEA,MAAM,GAAG,GAAGA,MAAM,IAAIW,IAAI,CAACK,GAAG,EAAE,GAAGE,SAAU;UAAAb,QAAA,gBAErDjB,IAAA,CAACR,IAAI;YAACiB,KAAK,EAAEI,CAAC,CAACkB,UAAW;YAAAd,QAAA,EAAEM,IAAI,CAACS;UAAI,CAAO,CAAC,eAC7ChC,IAAA,CAACP,IAAI;YAACgB,KAAK,EAAEI,CAAC,CAACoB,WAAY;YAAAhB,QAAA,EAAEM,IAAI,CAACW;UAAK,CAAO,CAAC;QAAA,GAV1CX,IAAI,CAACK,GAWM,CACnB;MAAC,CACE;IAAC,CACH,CAAC;EAAA,CACF,CAAC;AAEZ,CAAC;AAED,eAAezB,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: ActionSheet
|
|
3
|
+
nav:
|
|
4
|
+
title: 组件
|
|
5
|
+
order: 1
|
|
6
|
+
group:
|
|
7
|
+
title: 基础
|
|
8
|
+
order: 2
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# ActionSheet 底部操作面板
|
|
12
|
+
|
|
13
|
+
从底部弹出的选项网格面板。
|
|
14
|
+
|
|
15
|
+
## 何时使用
|
|
16
|
+
|
|
17
|
+
- 需要展示操作选项时(如拍照、选照片等)
|
|
18
|
+
- 底部弹出式面板
|
|
19
|
+
|
|
20
|
+
## 代码演示
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { ActionSheet, Icon } from '@unif/react-native-ui';
|
|
24
|
+
|
|
25
|
+
const options = [
|
|
26
|
+
{ key: 'camera', label: '拍照', icon: <Icon name="camera-outline" size={28} /> },
|
|
27
|
+
{ key: 'photo', label: '照片', icon: <Icon name="image-outline" size={28} /> },
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
<ActionSheet
|
|
31
|
+
visible={visible}
|
|
32
|
+
onClose={() => setVisible(false)}
|
|
33
|
+
options={options}
|
|
34
|
+
onSelect={(key) => console.log(key)}
|
|
35
|
+
/>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## API
|
|
39
|
+
|
|
40
|
+
| 属性 | 说明 | 类型 | 默认值 |
|
|
41
|
+
| -------- | -------------- | ----------------------------------- | ------ |
|
|
42
|
+
| visible | 是否可见 | `boolean` | - |
|
|
43
|
+
| onClose | 关闭回调 | `() => void` | - |
|
|
44
|
+
| title | 标题 | `string` | - |
|
|
45
|
+
| options | 选项列表 | `ActionSheetOption[]` | - |
|
|
46
|
+
| onSelect | 选择回调 | `(key: string) => void` | - |
|
|
47
|
+
| columns | 每行列数 | `number` | `3` |
|
|
48
|
+
| style | 面板样式 | `ViewStyle` | - |
|
|
49
|
+
| styles | 语义样式 | `ActionSheetSemanticStyles` | - |
|
|
50
|
+
| testID | 测试标识 | `string` | - |
|
|
51
|
+
|
|
52
|
+
## ActionSheetOption
|
|
53
|
+
|
|
54
|
+
| 属性 | 说明 | 类型 |
|
|
55
|
+
| ----- | ------ | ----------- |
|
|
56
|
+
| key | 唯一标识 | `string` |
|
|
57
|
+
| label | 显示文本 | `string` |
|
|
58
|
+
| icon | 图标 | `ReactNode` |
|
|
59
|
+
|
|
60
|
+
## Semantic Styles
|
|
61
|
+
|
|
62
|
+
| Slot | 说明 |
|
|
63
|
+
| ----------- | -------------- |
|
|
64
|
+
| overlay | 遮罩层 |
|
|
65
|
+
| panel | 底部面板 |
|
|
66
|
+
| grid | 网格容器 |
|
|
67
|
+
| option | 单个选项 |
|
|
68
|
+
| optionIcon | 选项图标容器 |
|
|
69
|
+
| optionLabel | 选项标签文本 |
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { tokens } from "../../theme/tokens.js";
|
|
4
|
+
export const DEFAULT_STYLES = {
|
|
5
|
+
overlay: {
|
|
6
|
+
flex: 1,
|
|
7
|
+
backgroundColor: 'rgba(0,0,0,0.3)'
|
|
8
|
+
},
|
|
9
|
+
panel: {
|
|
10
|
+
backgroundColor: tokens.colorBgElevated,
|
|
11
|
+
borderTopLeftRadius: 12,
|
|
12
|
+
borderTopRightRadius: 12,
|
|
13
|
+
paddingTop: 20,
|
|
14
|
+
paddingBottom: 24,
|
|
15
|
+
paddingHorizontal: tokens.spaceMd
|
|
16
|
+
},
|
|
17
|
+
grid: {
|
|
18
|
+
flexDirection: 'row',
|
|
19
|
+
justifyContent: 'space-around'
|
|
20
|
+
},
|
|
21
|
+
option: {
|
|
22
|
+
alignItems: 'center'
|
|
23
|
+
},
|
|
24
|
+
optionIcon: {
|
|
25
|
+
width: 56,
|
|
26
|
+
height: 56,
|
|
27
|
+
borderRadius: 12,
|
|
28
|
+
backgroundColor: tokens.colorBgPage,
|
|
29
|
+
justifyContent: 'center',
|
|
30
|
+
alignItems: 'center',
|
|
31
|
+
marginBottom: tokens.spaceSm
|
|
32
|
+
},
|
|
33
|
+
optionLabel: {
|
|
34
|
+
fontSize: 12,
|
|
35
|
+
color: tokens.colorTextSecondary
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["tokens","DEFAULT_STYLES","overlay","flex","backgroundColor","panel","colorBgElevated","borderTopLeftRadius","borderTopRightRadius","paddingTop","paddingBottom","paddingHorizontal","spaceMd","grid","flexDirection","justifyContent","option","alignItems","optionIcon","width","height","borderRadius","colorBgPage","marginBottom","spaceSm","optionLabel","fontSize","color","colorTextSecondary"],"sourceRoot":"../../../../src","sources":["action-sheet/style/index.tsx"],"mappings":";;AACA,SAASA,MAAM,QAAQ,uBAAoB;AAiB3C,OAAO,MAAMC,cAAyC,GAAG;EACvDC,OAAO,EAAE;IACPC,IAAI,EAAE,CAAC;IACPC,eAAe,EAAE;EACnB,CAAC;EACDC,KAAK,EAAE;IACLD,eAAe,EAAEJ,MAAM,CAACM,eAAe;IACvCC,mBAAmB,EAAE,EAAE;IACvBC,oBAAoB,EAAE,EAAE;IACxBC,UAAU,EAAE,EAAE;IACdC,aAAa,EAAE,EAAE;IACjBC,iBAAiB,EAAEX,MAAM,CAACY;EAC5B,CAAC;EACDC,IAAI,EAAE;IACJC,aAAa,EAAE,KAAK;IACpBC,cAAc,EAAE;EAClB,CAAC;EACDC,MAAM,EAAE;IACNC,UAAU,EAAE;EACd,CAAC;EACDC,UAAU,EAAE;IACVC,KAAK,EAAE,EAAE;IACTC,MAAM,EAAE,EAAE;IACVC,YAAY,EAAE,EAAE;IAChBjB,eAAe,EAAEJ,MAAM,CAACsB,WAAW;IACnCP,cAAc,EAAE,QAAQ;IACxBE,UAAU,EAAE,QAAQ;IACpBM,YAAY,EAAEvB,MAAM,CAACwB;EACvB,CAAC;EACDC,WAAW,EAAE;IACXC,QAAQ,EAAE,EAAE;IACZC,KAAK,EAAE3B,MAAM,CAAC4B;EAChB;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Avatar 原子组件
|
|
5
|
+
*
|
|
6
|
+
* 圆形图像/图标容器,支持图片、图标、占位三种模式。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import React, { useMemo } from 'react';
|
|
10
|
+
import { View, Image } from 'react-native';
|
|
11
|
+
import { mergeStyles } from "../hooks/index.js";
|
|
12
|
+
import { DEFAULT_STYLES } from "./style/index.js";
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
const Avatar = ({
|
|
15
|
+
size = 40,
|
|
16
|
+
source,
|
|
17
|
+
icon,
|
|
18
|
+
style,
|
|
19
|
+
styles: semanticStyles,
|
|
20
|
+
testID
|
|
21
|
+
}) => {
|
|
22
|
+
const s = useMemo(() => mergeStyles(DEFAULT_STYLES, semanticStyles), [semanticStyles]);
|
|
23
|
+
const sizeStyle = {
|
|
24
|
+
width: size,
|
|
25
|
+
height: size,
|
|
26
|
+
borderRadius: size / 2
|
|
27
|
+
};
|
|
28
|
+
return /*#__PURE__*/_jsx(View, {
|
|
29
|
+
style: [s.root, sizeStyle, style],
|
|
30
|
+
testID: testID,
|
|
31
|
+
children: source ? /*#__PURE__*/_jsx(Image, {
|
|
32
|
+
source: source,
|
|
33
|
+
style: [s.image, {
|
|
34
|
+
width: size,
|
|
35
|
+
height: size,
|
|
36
|
+
borderRadius: size / 2
|
|
37
|
+
}]
|
|
38
|
+
}) : icon ? icon : null
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
export default Avatar;
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useMemo","View","Image","mergeStyles","DEFAULT_STYLES","jsx","_jsx","Avatar","size","source","icon","style","styles","semanticStyles","testID","s","sizeStyle","width","height","borderRadius","root","children","image"],"sourceRoot":"../../../src","sources":["avatar/index.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO;AACtC,SAASC,IAAI,EAAEC,KAAK,QAAQ,cAAc;AAE1C,SAASC,WAAW,QAAQ,mBAAU;AAEtC,SAASC,cAAc,QAAQ,kBAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAWzC,MAAMC,MAA6B,GAAGA,CAAC;EACrCC,IAAI,GAAG,EAAE;EACTC,MAAM;EACNC,IAAI;EACJC,KAAK;EACLC,MAAM,EAAEC,cAAc;EACtBC;AACF,CAAC,KAAK;EACJ,MAAMC,CAAC,GAAGf,OAAO,CACf,MAAMG,WAAW,CAAuBC,cAAc,EAAES,cAAc,CAAC,EACvE,CAACA,cAAc,CACjB,CAAC;EAED,MAAMG,SAAoB,GAAG;IAC3BC,KAAK,EAAET,IAAI;IACXU,MAAM,EAAEV,IAAI;IACZW,YAAY,EAAEX,IAAI,GAAG;EACvB,CAAC;EAED,oBACEF,IAAA,CAACL,IAAI;IAACU,KAAK,EAAE,CAACI,CAAC,CAACK,IAAI,EAAEJ,SAAS,EAAEL,KAAK,CAAE;IAACG,MAAM,EAAEA,MAAO;IAAAO,QAAA,EACrDZ,MAAM,gBACLH,IAAA,CAACJ,KAAK;MACJO,MAAM,EAAEA,MAAO;MACfE,KAAK,EAAE,CAACI,CAAC,CAACO,KAAK,EAAE;QAAEL,KAAK,EAAET,IAAI;QAAEU,MAAM,EAAEV,IAAI;QAAEW,YAAY,EAAEX,IAAI,GAAG;MAAE,CAAC;IAAE,CACzE,CAAC,GACAE,IAAI,GACNA,IAAI,GACF;EAAI,CACJ,CAAC;AAEX,CAAC;AAED,eAAeH,MAAM","ignoreList":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Avatar
|
|
3
|
+
nav:
|
|
4
|
+
title: 组件
|
|
5
|
+
order: 1
|
|
6
|
+
group:
|
|
7
|
+
title: 原子
|
|
8
|
+
order: 1
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Avatar 头像
|
|
12
|
+
|
|
13
|
+
圆形图像/图标容器,支持图片、图标、占位三种模式。
|
|
14
|
+
|
|
15
|
+
## 何时使用
|
|
16
|
+
|
|
17
|
+
- 展示用户头像
|
|
18
|
+
- 展示 AI 助手图标头像
|
|
19
|
+
|
|
20
|
+
## 代码演示
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { Avatar, Icon } from '@unif/react-native-ui';
|
|
24
|
+
|
|
25
|
+
// 图片头像
|
|
26
|
+
<Avatar size={40} source={{ uri: 'https://example.com/avatar.png' }} />
|
|
27
|
+
|
|
28
|
+
// 图标头像
|
|
29
|
+
<Avatar size={28} icon={<Icon name="sparkles" size={18} color="#EB6E00" />} />
|
|
30
|
+
|
|
31
|
+
// 默认占位
|
|
32
|
+
<Avatar size={40} />
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## API
|
|
36
|
+
|
|
37
|
+
| 属性 | 说明 | 类型 | 默认值 |
|
|
38
|
+
| ------- | ---------------- | ---------------------- | ------ |
|
|
39
|
+
| size | 头像尺寸 | `number` | `40` |
|
|
40
|
+
| source | 图片来源 | `ImageSourcePropType` | - |
|
|
41
|
+
| icon | 替代图片的图标 | `ReactNode` | - |
|
|
42
|
+
| style | 容器样式 | `ViewStyle` | - |
|
|
43
|
+
| styles | 语义样式 | `AvatarSemanticStyles` | - |
|
|
44
|
+
| testID | 测试标识 | `string` | - |
|
|
45
|
+
|
|
46
|
+
## Semantic Styles
|
|
47
|
+
|
|
48
|
+
| Slot | 说明 |
|
|
49
|
+
| ----- | ---------- |
|
|
50
|
+
| root | 外层容器 |
|
|
51
|
+
| image | 图片元素 |
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { tokens } from "../../theme/tokens.js";
|
|
4
|
+
export const DEFAULT_STYLES = {
|
|
5
|
+
root: {
|
|
6
|
+
justifyContent: 'center',
|
|
7
|
+
alignItems: 'center',
|
|
8
|
+
backgroundColor: tokens.colorBgElevated,
|
|
9
|
+
overflow: 'hidden',
|
|
10
|
+
...tokens.shadowSm
|
|
11
|
+
},
|
|
12
|
+
image: {
|
|
13
|
+
width: '100%',
|
|
14
|
+
height: '100%'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["tokens","DEFAULT_STYLES","root","justifyContent","alignItems","backgroundColor","colorBgElevated","overflow","shadowSm","image","width","height"],"sourceRoot":"../../../../src","sources":["avatar/style/index.tsx"],"mappings":";;AACA,SAASA,MAAM,QAAQ,uBAAoB;AAO3C,OAAO,MAAMC,cAAoC,GAAG;EAClDC,IAAI,EAAE;IACJC,cAAc,EAAE,QAAQ;IACxBC,UAAU,EAAE,QAAQ;IACpBC,eAAe,EAAEL,MAAM,CAACM,eAAe;IACvCC,QAAQ,EAAE,QAAQ;IAClB,GAAGP,MAAM,CAACQ;EACZ,CAAC;EACDC,KAAK,EAAE;IACLC,KAAK,EAAE,MAAa;IACpBC,MAAM,EAAE;EACV;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 按钮组件
|
|
5
|
+
*
|
|
6
|
+
* type + size + semantic styles。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import React, { useMemo } from 'react';
|
|
10
|
+
import { Pressable, Text, View, ActivityIndicator } from 'react-native';
|
|
11
|
+
import { mergeStyles } from "../hooks/index.js";
|
|
12
|
+
import { DEFAULT_STYLES, SIZE_STYLES, TYPE_STYLES, DISABLED_STYLES, BLOCK_STYLES, PRESSED_STYLE, loadingStyle } from "./style/index.js";
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
const Button = ({
|
|
15
|
+
type = 'primary',
|
|
16
|
+
size = 'default',
|
|
17
|
+
icon,
|
|
18
|
+
disabled,
|
|
19
|
+
block,
|
|
20
|
+
loading,
|
|
21
|
+
onPress,
|
|
22
|
+
style,
|
|
23
|
+
styles: semanticStyles,
|
|
24
|
+
testID,
|
|
25
|
+
children
|
|
26
|
+
}) => {
|
|
27
|
+
const s = useMemo(() => mergeStyles(DEFAULT_STYLES, SIZE_STYLES[size], TYPE_STYLES[type], disabled ? DISABLED_STYLES : undefined, block ? BLOCK_STYLES : undefined, semanticStyles), [type, size, disabled, block, semanticStyles]);
|
|
28
|
+
return /*#__PURE__*/_jsxs(Pressable, {
|
|
29
|
+
style: ({
|
|
30
|
+
pressed
|
|
31
|
+
}) => [s.root, pressed && PRESSED_STYLE, style],
|
|
32
|
+
onPress: onPress,
|
|
33
|
+
disabled: disabled || loading,
|
|
34
|
+
testID: testID,
|
|
35
|
+
children: [icon && /*#__PURE__*/_jsx(View, {
|
|
36
|
+
style: s.icon,
|
|
37
|
+
children: icon
|
|
38
|
+
}), loading && /*#__PURE__*/_jsx(ActivityIndicator, {
|
|
39
|
+
color: s.content?.color,
|
|
40
|
+
size: "small",
|
|
41
|
+
style: loadingStyle
|
|
42
|
+
}), typeof children === 'string' ? /*#__PURE__*/_jsx(Text, {
|
|
43
|
+
style: s.content,
|
|
44
|
+
children: children
|
|
45
|
+
}) : /*#__PURE__*/_jsx(View, {
|
|
46
|
+
style: s.content,
|
|
47
|
+
children: children
|
|
48
|
+
})]
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
export default Button;
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useMemo","Pressable","Text","View","ActivityIndicator","mergeStyles","DEFAULT_STYLES","SIZE_STYLES","TYPE_STYLES","DISABLED_STYLES","BLOCK_STYLES","PRESSED_STYLE","loadingStyle","jsx","_jsx","jsxs","_jsxs","Button","type","size","icon","disabled","block","loading","onPress","style","styles","semanticStyles","testID","children","s","undefined","pressed","root","color","content"],"sourceRoot":"../../../src","sources":["button/index.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO;AACtC,SAASC,SAAS,EAAEC,IAAI,EAAEC,IAAI,EAAEC,iBAAiB,QAAQ,cAAc;AAEvE,SAASC,WAAW,QAAQ,mBAAU;AAEtC,SACEC,cAAc,EACdC,WAAW,EACXC,WAAW,EACXC,eAAe,EACfC,YAAY,EACZC,aAAa,EACbC,YAAY,QACP,kBAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAgBjB,MAAMC,MAA6B,GAAGA,CAAC;EACrCC,IAAI,GAAG,SAAS;EAChBC,IAAI,GAAG,SAAS;EAChBC,IAAI;EACJC,QAAQ;EACRC,KAAK;EACLC,OAAO;EACPC,OAAO;EACPC,KAAK;EACLC,MAAM,EAAEC,cAAc;EACtBC,MAAM;EACNC;AACW,CAAC,KAAK;EACjB,MAAMC,CAAC,GAAG9B,OAAO,CACf,MACEK,WAAW,CACTC,cAAc,EACdC,WAAW,CAACY,IAAI,CAAC,EACjBX,WAAW,CAACU,IAAI,CAAC,EACjBG,QAAQ,GAAGZ,eAAe,GAAGsB,SAAS,EACtCT,KAAK,GAAGZ,YAAY,GAAGqB,SAAS,EAChCJ,cACF,CAAC,EACH,CAACT,IAAI,EAAEC,IAAI,EAAEE,QAAQ,EAAEC,KAAK,EAAEK,cAAc,CAC9C,CAAC;EAED,oBACEX,KAAA,CAACf,SAAS;IACRwB,KAAK,EAAEA,CAAC;MAAEO;IAAQ,CAAC,KAAK,CAACF,CAAC,CAACG,IAAI,EAAED,OAAO,IAAIrB,aAAa,EAAEc,KAAK,CAAE;IAClED,OAAO,EAAEA,OAAQ;IACjBH,QAAQ,EAAEA,QAAQ,IAAIE,OAAQ;IAC9BK,MAAM,EAAEA,MAAO;IAAAC,QAAA,GAEdT,IAAI,iBAAIN,IAAA,CAACX,IAAI;MAACsB,KAAK,EAAEK,CAAC,CAACV,IAAK;MAAAS,QAAA,EAAET;IAAI,CAAO,CAAC,EAC1CG,OAAO,iBACNT,IAAA,CAACV,iBAAiB;MAChB8B,KAAK,EAAEJ,CAAC,CAACK,OAAO,EAAED,KAAgB;MAClCf,IAAI,EAAC,OAAO;MACZM,KAAK,EAAEb;IAAa,CACrB,CACF,EACA,OAAOiB,QAAQ,KAAK,QAAQ,gBAC3Bf,IAAA,CAACZ,IAAI;MAACuB,KAAK,EAAEK,CAAC,CAACK,OAAQ;MAAAN,QAAA,EAAEA;IAAQ,CAAO,CAAC,gBAEzCf,IAAA,CAACX,IAAI;MAACsB,KAAK,EAAEK,CAAC,CAACK,OAAqB;MAAAN,QAAA,EAAEA;IAAQ,CAAO,CACtD;EAAA,CACQ,CAAC;AAEhB,CAAC;AAED,eAAeZ,MAAM","ignoreList":[]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Button 语义化按钮
|
|
2
|
+
|
|
3
|
+
支持 `type` / `size` 变体和 `styles` 语义插槽覆盖。使用 `Pressable` 实现按下态反馈。
|
|
4
|
+
|
|
5
|
+
## 何时使用
|
|
6
|
+
|
|
7
|
+
- 替代 `<TouchableOpacity>` + 手写按钮样式的组合
|
|
8
|
+
- 需要统一按钮风格(主按钮、描边按钮、幽灵按钮)时
|
|
9
|
+
|
|
10
|
+
## 代码演示
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
// 主按钮
|
|
14
|
+
<Button onPress={handleConfirm}>确认下单</Button>
|
|
15
|
+
|
|
16
|
+
// 描边按钮
|
|
17
|
+
<Button type="outline" onPress={handleModify}>修改</Button>
|
|
18
|
+
|
|
19
|
+
// 幽灵按钮
|
|
20
|
+
<Button type="ghost" onPress={handlePush}>推送经销商</Button>
|
|
21
|
+
|
|
22
|
+
// 并排等宽
|
|
23
|
+
<View style={{flexDirection: 'row', gap: 10}}>
|
|
24
|
+
<Button type="outline" block onPress={handleModify}>修改</Button>
|
|
25
|
+
<Button block onPress={handleConfirm}>确认</Button>
|
|
26
|
+
</View>
|
|
27
|
+
|
|
28
|
+
// 带图标
|
|
29
|
+
<Button icon={<Icon name="add" size={16} color="#FFF" />} onPress={handleAdd}>
|
|
30
|
+
添加
|
|
31
|
+
</Button>
|
|
32
|
+
|
|
33
|
+
// 语义插槽覆盖
|
|
34
|
+
<Button
|
|
35
|
+
type="outline"
|
|
36
|
+
onPress={handleAction}
|
|
37
|
+
styles={{root: {borderColor: 'red'}, content: {color: 'red'}}}>
|
|
38
|
+
危险操作
|
|
39
|
+
</Button>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## API
|
|
43
|
+
|
|
44
|
+
| 属性 | 说明 | 类型 | 默认值 |
|
|
45
|
+
|------|------|------|--------|
|
|
46
|
+
| type | 按钮类型 | `'primary'` \| `'outline'` \| `'ghost'` \| `'danger'` | `'primary'` |
|
|
47
|
+
| size | 按钮大小 | `'default'` \| `'small'` | `'default'` |
|
|
48
|
+
| icon | 左侧图标 | `ReactNode` | - |
|
|
49
|
+
| disabled | 禁用状态 | `boolean` | `false` |
|
|
50
|
+
| block | 撑满父容器(flex: 1) | `boolean` | `false` |
|
|
51
|
+
| loading | 加载状态 | `boolean` | `false` |
|
|
52
|
+
| onPress | 点击回调 | `() => void` | **必填** |
|
|
53
|
+
| style | 外层容器样式 | `ViewStyle` | - |
|
|
54
|
+
| styles | 语义插槽样式 | `Partial<ButtonSemanticStyles>` | - |
|
|
55
|
+
| testID | 测试标识 | `string` | - |
|
|
56
|
+
| children | 按钮内容 | `ReactNode` | **必填** |
|
|
57
|
+
|
|
58
|
+
## Semantic Styles
|
|
59
|
+
|
|
60
|
+
通过 `styles` prop 精确覆盖组件内部各 slot 的样式,不侵入组件结构。
|
|
61
|
+
|
|
62
|
+
| 插槽 | 类型 | 说明 |
|
|
63
|
+
|------|------|------|
|
|
64
|
+
| root | `ViewStyle` | 按钮容器(背景、边框、圆角等) |
|
|
65
|
+
| icon | `ViewStyle` | 图标区域(间距等) |
|
|
66
|
+
| content | `TextStyle` | 文字区域(字号、颜色、字重等) |
|
|
67
|
+
|
|
68
|
+
## Type 规格
|
|
69
|
+
|
|
70
|
+
| type | 背景 | 文字色 | 边框 |
|
|
71
|
+
|------|------|--------|------|
|
|
72
|
+
| primary | colorPrimary | #FFF | 无 |
|
|
73
|
+
| outline | 透明 | colorTextSecondary | colorBorder |
|
|
74
|
+
| ghost | 透明 | colorPrimary | colorPrimary |
|
|
75
|
+
| danger | colorError | #FFF | 无 |
|
|
76
|
+
|
|
77
|
+
## Size 规格
|
|
78
|
+
|
|
79
|
+
| size | paddingVertical | borderRadius | fontSize |
|
|
80
|
+
|------|----------------|--------------|----------|
|
|
81
|
+
| default | 10 | 8 | 14 |
|
|
82
|
+
| small | 6 | 6 | 12 |
|
|
83
|
+
|
|
84
|
+
## 样式合并顺序
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
DEFAULT_STYLES → SIZE_STYLES → TYPE_STYLES → DISABLED_STYLES → BLOCK_STYLES → semanticStyles
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
内部使用 `mergeStyles` + `useMemo` 按 slot 维度合并,仅在 props 变化时重算。
|