@unif/react-native-chat 0.2.1 → 0.2.3

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.
Files changed (63) hide show
  1. package/lib/commonjs/bubble/Bubble.js +74 -72
  2. package/lib/commonjs/bubble/Bubble.js.map +1 -1
  3. package/lib/commonjs/card-wrapper/CardWrapper.js +25 -24
  4. package/lib/commonjs/card-wrapper/CardWrapper.js.map +1 -1
  5. package/lib/commonjs/conversations/Conversations.js +135 -84
  6. package/lib/commonjs/conversations/Conversations.js.map +1 -1
  7. package/lib/commonjs/index.js +0 -6
  8. package/lib/commonjs/index.js.map +1 -1
  9. package/lib/commonjs/prompts/Prompts.js +38 -37
  10. package/lib/commonjs/prompts/Prompts.js.map +1 -1
  11. package/lib/commonjs/sender/Sender.js +120 -122
  12. package/lib/commonjs/sender/Sender.js.map +1 -1
  13. package/lib/commonjs/theme/tokens.js +2 -56
  14. package/lib/commonjs/theme/tokens.js.map +1 -1
  15. package/lib/commonjs/welcome/Welcome.js +89 -90
  16. package/lib/commonjs/welcome/Welcome.js.map +1 -1
  17. package/lib/module/bubble/Bubble.js +73 -71
  18. package/lib/module/bubble/Bubble.js.map +1 -1
  19. package/lib/module/card-wrapper/CardWrapper.js +24 -23
  20. package/lib/module/card-wrapper/CardWrapper.js.map +1 -1
  21. package/lib/module/conversations/Conversations.js +137 -86
  22. package/lib/module/conversations/Conversations.js.map +1 -1
  23. package/lib/module/index.js +3 -1
  24. package/lib/module/index.js.map +1 -1
  25. package/lib/module/prompts/Prompts.js +37 -36
  26. package/lib/module/prompts/Prompts.js.map +1 -1
  27. package/lib/module/sender/Sender.js +121 -123
  28. package/lib/module/sender/Sender.js.map +1 -1
  29. package/lib/module/theme/tokens.js +2 -55
  30. package/lib/module/theme/tokens.js.map +1 -1
  31. package/lib/module/welcome/Welcome.js +88 -89
  32. package/lib/module/welcome/Welcome.js.map +1 -1
  33. package/lib/typescript/commonjs/bubble/Bubble.d.ts.map +1 -1
  34. package/lib/typescript/commonjs/card-wrapper/CardWrapper.d.ts.map +1 -1
  35. package/lib/typescript/commonjs/conversations/Conversations.d.ts +4 -2
  36. package/lib/typescript/commonjs/conversations/Conversations.d.ts.map +1 -1
  37. package/lib/typescript/commonjs/index.d.ts +2 -1
  38. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  39. package/lib/typescript/commonjs/prompts/Prompts.d.ts.map +1 -1
  40. package/lib/typescript/commonjs/sender/Sender.d.ts.map +1 -1
  41. package/lib/typescript/commonjs/theme/tokens.d.ts +1 -45
  42. package/lib/typescript/commonjs/theme/tokens.d.ts.map +1 -1
  43. package/lib/typescript/commonjs/welcome/Welcome.d.ts.map +1 -1
  44. package/lib/typescript/module/bubble/Bubble.d.ts.map +1 -1
  45. package/lib/typescript/module/card-wrapper/CardWrapper.d.ts.map +1 -1
  46. package/lib/typescript/module/conversations/Conversations.d.ts +4 -2
  47. package/lib/typescript/module/conversations/Conversations.d.ts.map +1 -1
  48. package/lib/typescript/module/index.d.ts +2 -1
  49. package/lib/typescript/module/index.d.ts.map +1 -1
  50. package/lib/typescript/module/prompts/Prompts.d.ts.map +1 -1
  51. package/lib/typescript/module/sender/Sender.d.ts.map +1 -1
  52. package/lib/typescript/module/theme/tokens.d.ts +1 -45
  53. package/lib/typescript/module/theme/tokens.d.ts.map +1 -1
  54. package/lib/typescript/module/welcome/Welcome.d.ts.map +1 -1
  55. package/package.json +2 -1
  56. package/src/bubble/Bubble.tsx +85 -80
  57. package/src/card-wrapper/CardWrapper.tsx +31 -29
  58. package/src/conversations/Conversations.tsx +170 -100
  59. package/src/index.tsx +4 -1
  60. package/src/prompts/Prompts.tsx +51 -41
  61. package/src/sender/Sender.tsx +125 -138
  62. package/src/theme/tokens.ts +1 -56
  63. package/src/welcome/Welcome.tsx +109 -108
@@ -3,7 +3,7 @@
3
3
  * 渐变背景 + 装饰性光晕 + 2x2 快捷入口卡片网格
4
4
  */
5
5
 
6
- import React from 'react';
6
+ import React, { useMemo } from 'react';
7
7
  import {
8
8
  View,
9
9
  Text,
@@ -12,7 +12,8 @@ import {
12
12
  type ViewStyle,
13
13
  type TextStyle,
14
14
  } from 'react-native';
15
- import {chatTokens} from '../theme/tokens';
15
+ import { useTokens } from '@unif/react-native-ui';
16
+ import { chatTokens } from '../theme/tokens';
16
17
 
17
18
  export interface WelcomeQuickStart {
18
19
  key: string;
@@ -52,56 +53,122 @@ const Welcome: React.FC<WelcomeProps> = ({
52
53
  subtitle = '智能助手,有什么可以帮你?',
53
54
  quickStarts = [],
54
55
  onQuickStart,
55
- gradientColors = [
56
- chatTokens.colorBgWelcomeStart,
57
- chatTokens.colorBgWelcomeMid,
58
- chatTokens.colorBgWelcomeEnd,
59
- ],
56
+ gradientColors,
60
57
  style,
61
58
  styles: semanticStyles,
62
59
  testID = 'welcome',
63
60
  renderIcon,
64
61
  renderGradient,
65
62
  }) => {
63
+ const t = useTokens();
64
+
65
+ const colors = gradientColors ?? [
66
+ chatTokens.colorBgWelcomeStart,
67
+ chatTokens.colorBgWelcomeMid,
68
+ chatTokens.colorBgWelcomeEnd,
69
+ ];
70
+
71
+ const ds = useMemo(
72
+ () =>
73
+ StyleSheet.create({
74
+ container: {
75
+ flex: 1,
76
+ },
77
+ content: {
78
+ flex: 1,
79
+ justifyContent: 'flex-start',
80
+ alignItems: 'center',
81
+ paddingHorizontal: 20,
82
+ paddingTop: 56,
83
+ },
84
+ glowTopRight: {
85
+ position: 'absolute',
86
+ top: -40,
87
+ right: -40,
88
+ width: 200,
89
+ height: 200,
90
+ borderRadius: 100,
91
+ backgroundColor: 'rgba(235,110,0,0.06)',
92
+ },
93
+ glowBottomLeft: {
94
+ position: 'absolute',
95
+ bottom: 40,
96
+ left: -40,
97
+ width: 160,
98
+ height: 160,
99
+ borderRadius: 80,
100
+ backgroundColor: 'rgba(0,122,255,0.04)',
101
+ },
102
+ title: {
103
+ marginTop: 16,
104
+ fontSize: 20,
105
+ fontWeight: '600',
106
+ color: t.colorText,
107
+ },
108
+ subtitle: {
109
+ marginTop: 6,
110
+ textAlign: 'center',
111
+ fontSize: 15,
112
+ color: t.colorTextSecondary,
113
+ },
114
+ grid: {
115
+ marginTop: 32,
116
+ width: '100%',
117
+ flexDirection: 'row',
118
+ flexWrap: 'wrap',
119
+ justifyContent: 'space-between',
120
+ gap: 12,
121
+ },
122
+ card: {
123
+ width: '47%',
124
+ backgroundColor: t.colorBgElevated,
125
+ borderRadius: 16,
126
+ padding: 16,
127
+ ...t.shadowSm,
128
+ },
129
+ cardTitle: {
130
+ marginTop: 8,
131
+ fontSize: 14,
132
+ fontWeight: '500',
133
+ color: t.colorText,
134
+ },
135
+ cardDescription: {
136
+ marginTop: 2,
137
+ fontSize: 11,
138
+ color: t.colorTextSecondary,
139
+ },
140
+ }),
141
+ [t]
142
+ );
143
+
66
144
  const content = (
67
145
  <>
68
- {/* 右上角装饰光晕 */}
69
- <View style={defaultStyles.glowTopRight} />
70
- {/* 左下角装饰光晕 */}
71
- <View style={defaultStyles.glowBottomLeft} />
146
+ <View style={ds.glowTopRight} />
147
+ <View style={ds.glowBottomLeft} />
72
148
 
73
- <View style={defaultStyles.content}>
74
- {renderIcon?.('sparkles', 48, chatTokens.colorPrimary)}
149
+ <View style={ds.content}>
150
+ {renderIcon?.('sparkles', 48, t.colorPrimary)}
75
151
 
76
- <Text style={[defaultStyles.title, semanticStyles?.title]}>
77
- {title}
78
- </Text>
79
- <Text style={[defaultStyles.subtitle, semanticStyles?.subtitle]}>
80
- {subtitle}
81
- </Text>
152
+ <Text style={[ds.title, semanticStyles?.title]}>{title}</Text>
153
+ <Text style={[ds.subtitle, semanticStyles?.subtitle]}>{subtitle}</Text>
82
154
 
83
155
  {quickStarts.length > 0 && (
84
- <View style={defaultStyles.grid}>
156
+ <View style={ds.grid}>
85
157
  {quickStarts.map((item, index) => (
86
158
  <TouchableOpacity
87
159
  key={item.key}
88
- style={[defaultStyles.card, semanticStyles?.card]}
160
+ style={[ds.card, semanticStyles?.card]}
89
161
  onPress={() => onQuickStart?.(item.key)}
90
162
  activeOpacity={0.7}
91
- testID={`${testID}-quick-${index}`}>
92
- {renderIcon?.(item.icon, 24, chatTokens.colorPrimary)}
93
- <Text
94
- style={[
95
- defaultStyles.cardTitle,
96
- semanticStyles?.cardTitle,
97
- ]}>
163
+ testID={`${testID}-quick-${index}`}
164
+ >
165
+ {renderIcon?.(item.icon, 24, t.colorPrimary)}
166
+ <Text style={[ds.cardTitle, semanticStyles?.cardTitle]}>
98
167
  {item.title}
99
168
  </Text>
100
169
  <Text
101
- style={[
102
- defaultStyles.cardDescription,
103
- semanticStyles?.cardDescription,
104
- ]}>
170
+ style={[ds.cardDescription, semanticStyles?.cardDescription]}
171
+ >
105
172
  {item.description}
106
173
  </Text>
107
174
  </TouchableOpacity>
@@ -112,97 +179,31 @@ const Welcome: React.FC<WelcomeProps> = ({
112
179
  </>
113
180
  );
114
181
 
115
- // 如果提供了 renderGradient,使用自定义渐变
116
182
  if (renderGradient) {
117
183
  return renderGradient({
118
- colors: gradientColors,
184
+ colors,
119
185
  children: content,
120
- style: { ...defaultStyles.container, ...semanticStyles?.root, ...style } as ViewStyle,
186
+ style: {
187
+ ...ds.container,
188
+ ...semanticStyles?.root,
189
+ ...style,
190
+ } as ViewStyle,
121
191
  });
122
192
  }
123
193
 
124
- // 无渐变 fallback(纯色背景)
125
194
  return (
126
195
  <View
127
196
  style={[
128
- defaultStyles.container,
129
- {backgroundColor: gradientColors[0]},
197
+ ds.container,
198
+ { backgroundColor: colors[0] },
130
199
  semanticStyles?.root,
131
200
  style,
132
201
  ]}
133
- testID={testID}>
202
+ testID={testID}
203
+ >
134
204
  {content}
135
205
  </View>
136
206
  );
137
207
  };
138
208
 
139
- const defaultStyles = StyleSheet.create({
140
- container: {
141
- flex: 1,
142
- },
143
- content: {
144
- flex: 1,
145
- justifyContent: 'flex-start',
146
- alignItems: 'center',
147
- paddingHorizontal: 20,
148
- paddingTop: 56,
149
- },
150
- glowTopRight: {
151
- position: 'absolute',
152
- top: -40,
153
- right: -40,
154
- width: 200,
155
- height: 200,
156
- borderRadius: 100,
157
- backgroundColor: 'rgba(235,110,0,0.06)',
158
- },
159
- glowBottomLeft: {
160
- position: 'absolute',
161
- bottom: 40,
162
- left: -40,
163
- width: 160,
164
- height: 160,
165
- borderRadius: 80,
166
- backgroundColor: 'rgba(0,122,255,0.04)',
167
- },
168
- title: {
169
- marginTop: 16,
170
- fontSize: 20,
171
- fontWeight: '600',
172
- color: chatTokens.colorText,
173
- },
174
- subtitle: {
175
- marginTop: 6,
176
- textAlign: 'center',
177
- fontSize: 15,
178
- color: chatTokens.colorTextSecondary,
179
- },
180
- grid: {
181
- marginTop: 32,
182
- width: '100%',
183
- flexDirection: 'row',
184
- flexWrap: 'wrap',
185
- justifyContent: 'space-between',
186
- gap: 12,
187
- },
188
- card: {
189
- width: '47%',
190
- backgroundColor: chatTokens.colorBgElevated,
191
- borderRadius: 16,
192
- padding: 16,
193
- ...chatTokens.shadowSm,
194
- },
195
- cardTitle: {
196
- marginTop: 8,
197
- fontSize: 14,
198
- fontWeight: '500',
199
- color: chatTokens.colorText,
200
- },
201
- cardDescription: {
202
- marginTop: 2,
203
- fontSize: 11,
204
- color: chatTokens.colorTextSecondary,
205
- },
206
- });
207
-
208
209
  export default React.memo(Welcome);