react-native-srschat 0.1.1 → 0.1.2

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.
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Chat = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _reactNative = require("react-native");
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ const defaultTheme = {
11
+ primaryColor: '#007AFF',
12
+ backgroundColor: '#FFFFFF',
13
+ textColor: '#000000'
14
+ };
15
+ const Chat = ({
16
+ onSendMessage,
17
+ theme = defaultTheme
18
+ }) => {
19
+ const [message, setMessage] = _react.default.useState('');
20
+ const [messages, setMessages] = _react.default.useState([]);
21
+ const handleSend = async () => {
22
+ if (!message.trim()) {
23
+ return;
24
+ }
25
+ setMessages(prev => [...prev, {
26
+ text: message,
27
+ fromUser: true
28
+ }]);
29
+ setMessage('');
30
+ const response = await onSendMessage(message);
31
+ setMessages(prev => [...prev, {
32
+ text: response,
33
+ fromUser: false
34
+ }]);
35
+ };
36
+ const containerStyle = [styles.container, {
37
+ backgroundColor: theme.backgroundColor
38
+ }];
39
+ const getMessageStyle = fromUser => [styles.messageBubble, fromUser ? styles.userMessage : styles.botMessage, {
40
+ backgroundColor: fromUser ? theme.primaryColor : '#E8E8E8'
41
+ }];
42
+ const getTextStyle = fromUser => [styles.messageText, {
43
+ color: fromUser ? '#fff' : theme.textColor
44
+ }];
45
+ return /*#__PURE__*/_react.default.createElement(_reactNative.SafeAreaView, {
46
+ style: containerStyle,
47
+ testID: "chat-container"
48
+ }, /*#__PURE__*/_react.default.createElement(_reactNative.KeyboardAvoidingView, {
49
+ behavior: _reactNative.Platform.OS === 'ios' ? 'padding' : 'height',
50
+ style: styles.content
51
+ }, /*#__PURE__*/_react.default.createElement(_reactNative.ScrollView, {
52
+ style: styles.messagesContainer
53
+ }, messages.map((msg, i) => /*#__PURE__*/_react.default.createElement(_reactNative.View, {
54
+ key: i,
55
+ style: getMessageStyle(msg.fromUser)
56
+ }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
57
+ style: getTextStyle(msg.fromUser)
58
+ }, msg.text)))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
59
+ style: styles.inputContainer
60
+ }, /*#__PURE__*/_react.default.createElement(_reactNative.TextInput, {
61
+ style: [styles.input, {
62
+ color: theme.textColor
63
+ }],
64
+ value: message,
65
+ onChangeText: setMessage,
66
+ placeholder: "Type a message...",
67
+ placeholderTextColor: "#999"
68
+ }), /*#__PURE__*/_react.default.createElement(_reactNative.Button, {
69
+ title: "Send",
70
+ onPress: handleSend,
71
+ color: theme.primaryColor
72
+ }))));
73
+ };
74
+ exports.Chat = Chat;
75
+ const styles = _reactNative.StyleSheet.create({
76
+ container: {
77
+ flex: 1,
78
+ backgroundColor: '#FFFFFF'
79
+ },
80
+ content: {
81
+ flex: 1,
82
+ backgroundColor: '#F8F9FA'
83
+ },
84
+ messagesContainer: {
85
+ flex: 1,
86
+ padding: 20,
87
+ paddingTop: 30
88
+ },
89
+ messageBubble: {
90
+ maxWidth: '85%',
91
+ padding: 16,
92
+ borderRadius: 20,
93
+ marginBottom: 16,
94
+ backgroundColor: '#FFFFFF',
95
+ shadowColor: '#000',
96
+ shadowOffset: {
97
+ width: 0,
98
+ height: 2
99
+ },
100
+ shadowOpacity: 0.05,
101
+ shadowRadius: 8,
102
+ elevation: 3
103
+ },
104
+ userMessage: {
105
+ alignSelf: 'flex-end',
106
+ backgroundColor: '#FFFFFF',
107
+ borderWidth: 1,
108
+ borderColor: 'rgba(0, 0, 0, 0.04)'
109
+ },
110
+ botMessage: {
111
+ alignSelf: 'flex-start',
112
+ backgroundColor: '#FFFFFF',
113
+ borderWidth: 1,
114
+ borderColor: 'rgba(0, 0, 0, 0.04)'
115
+ },
116
+ messageText: {
117
+ fontSize: 15,
118
+ lineHeight: 22,
119
+ fontWeight: '400',
120
+ color: '#2C2C2E',
121
+ letterSpacing: 0.2
122
+ },
123
+ inputContainer: {
124
+ flexDirection: 'row',
125
+ alignItems: 'center',
126
+ paddingHorizontal: 16,
127
+ paddingVertical: 12,
128
+ backgroundColor: '#FFFFFF',
129
+ borderTopWidth: 1,
130
+ borderTopColor: 'rgba(0, 0, 0, 0.06)',
131
+ shadowColor: '#000',
132
+ shadowOffset: {
133
+ width: 0,
134
+ height: -8
135
+ },
136
+ shadowOpacity: 0.04,
137
+ shadowRadius: 12,
138
+ elevation: 8,
139
+ marginTop: 'auto'
140
+ },
141
+ input: {
142
+ flex: 1,
143
+ backgroundColor: '#F8F9FA',
144
+ borderRadius: 16,
145
+ borderWidth: 1,
146
+ borderColor: 'rgba(0, 0, 0, 0.06)',
147
+ paddingHorizontal: 20,
148
+ paddingVertical: 12,
149
+ marginRight: 12,
150
+ fontSize: 15,
151
+ maxHeight: 120,
152
+ color: '#2C2C2E',
153
+ shadowColor: '#000',
154
+ shadowOffset: {
155
+ width: 0,
156
+ height: 1
157
+ },
158
+ shadowOpacity: 0.04,
159
+ shadowRadius: 4,
160
+ elevation: 2
161
+ }
162
+ });
163
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","e","__esModule","default","defaultTheme","primaryColor","backgroundColor","textColor","Chat","onSendMessage","theme","message","setMessage","React","useState","messages","setMessages","handleSend","trim","prev","text","fromUser","response","containerStyle","styles","container","getMessageStyle","messageBubble","userMessage","botMessage","getTextStyle","messageText","color","createElement","SafeAreaView","style","testID","KeyboardAvoidingView","behavior","Platform","OS","content","ScrollView","messagesContainer","map","msg","i","View","key","Text","inputContainer","TextInput","input","value","onChangeText","placeholder","placeholderTextColor","Button","title","onPress","exports","StyleSheet","create","flex","padding","paddingTop","maxWidth","borderRadius","marginBottom","shadowColor","shadowOffset","width","height","shadowOpacity","shadowRadius","elevation","alignSelf","borderWidth","borderColor","fontSize","lineHeight","fontWeight","letterSpacing","flexDirection","alignItems","paddingHorizontal","paddingVertical","borderTopWidth","borderTopColor","marginTop","marginRight","maxHeight"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAUsB,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAYtB,MAAMG,YAAY,GAAG;EACnBC,YAAY,EAAE,SAAS;EACvBC,eAAe,EAAE,SAAS;EAC1BC,SAAS,EAAE;AACb,CAAC;AAEM,MAAMC,IAAyB,GAAGA,CAAC;EACxCC,aAAa;EACbC,KAAK,GAAGN;AACV,CAAC,KAAK;EACJ,MAAM,CAACO,OAAO,EAAEC,UAAU,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,EAAE,CAAC;EAChD,MAAM,CAACC,QAAQ,EAAEC,WAAW,CAAC,GAAGH,cAAK,CAACC,QAAQ,CAA2C,EAAE,CAAC;EAE5F,MAAMG,UAAU,GAAG,MAAAA,CAAA,KAAY;IAC7B,IAAI,CAACN,OAAO,CAACO,IAAI,CAAC,CAAC,EAAE;MACnB;IACF;IAEAF,WAAW,CAAEG,IAAI,IAAK,CAAC,GAAGA,IAAI,EAAE;MAAEC,IAAI,EAAET,OAAO;MAAEU,QAAQ,EAAE;IAAK,CAAC,CAAC,CAAC;IACnET,UAAU,CAAC,EAAE,CAAC;IAEd,MAAMU,QAAQ,GAAG,MAAMb,aAAa,CAACE,OAAO,CAAC;IAC7CK,WAAW,CAAEG,IAAI,IAAK,CAAC,GAAGA,IAAI,EAAE;MAAEC,IAAI,EAAEE,QAAQ;MAAED,QAAQ,EAAE;IAAM,CAAC,CAAC,CAAC;EACvE,CAAC;EAED,MAAME,cAAc,GAAG,CACrBC,MAAM,CAACC,SAAS,EAChB;IACEnB,eAAe,EAAEI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AC;MACRC,MAAM,EAAE;IACV,CAAC;IACDC,aAAa,EAAE,IAAI;IACnBC,YAAY,EAAE,CAAC;IACfC,SAAS,EAAE;EACb;AACF,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,155 @@
1
+ import React from 'react';
2
+ import { SafeAreaView, Text, StyleSheet, View, TextInput, ScrollView, KeyboardAvoidingView, Platform, Button } from 'react-native';
3
+ const defaultTheme = {
4
+ primaryColor: '#007AFF',
5
+ backgroundColor: '#FFFFFF',
6
+ textColor: '#000000'
7
+ };
8
+ export const Chat = ({
9
+ onSendMessage,
10
+ theme = defaultTheme
11
+ }) => {
12
+ const [message, setMessage] = React.useState('');
13
+ const [messages, setMessages] = React.useState([]);
14
+ const handleSend = async () => {
15
+ if (!message.trim()) {
16
+ return;
17
+ }
18
+ setMessages(prev => [...prev, {
19
+ text: message,
20
+ fromUser: true
21
+ }]);
22
+ setMessage('');
23
+ const response = await onSendMessage(message);
24
+ setMessages(prev => [...prev, {
25
+ text: response,
26
+ fromUser: false
27
+ }]);
28
+ };
29
+ const containerStyle = [styles.container, {
30
+ backgroundColor: theme.backgroundColor
31
+ }];
32
+ const getMessageStyle = fromUser => [styles.messageBubble, fromUser ? styles.userMessage : styles.botMessage, {
33
+ backgroundColor: fromUser ? theme.primaryColor : '#E8E8E8'
34
+ }];
35
+ const getTextStyle = fromUser => [styles.messageText, {
36
+ color: fromUser ? '#fff' : theme.textColor
37
+ }];
38
+ return /*#__PURE__*/React.createElement(SafeAreaView, {
39
+ style: containerStyle,
40
+ testID: "chat-container"
41
+ }, /*#__PURE__*/React.createElement(KeyboardAvoidingView, {
42
+ behavior: Platform.OS === 'ios' ? 'padding' : 'height',
43
+ style: styles.content
44
+ }, /*#__PURE__*/React.createElement(ScrollView, {
45
+ style: styles.messagesContainer
46
+ }, messages.map((msg, i) => /*#__PURE__*/React.createElement(View, {
47
+ key: i,
48
+ style: getMessageStyle(msg.fromUser)
49
+ }, /*#__PURE__*/React.createElement(Text, {
50
+ style: getTextStyle(msg.fromUser)
51
+ }, msg.text)))), /*#__PURE__*/React.createElement(View, {
52
+ style: styles.inputContainer
53
+ }, /*#__PURE__*/React.createElement(TextInput, {
54
+ style: [styles.input, {
55
+ color: theme.textColor
56
+ }],
57
+ value: message,
58
+ onChangeText: setMessage,
59
+ placeholder: "Type a message...",
60
+ placeholderTextColor: "#999"
61
+ }), /*#__PURE__*/React.createElement(Button, {
62
+ title: "Send",
63
+ onPress: handleSend,
64
+ color: theme.primaryColor
65
+ }))));
66
+ };
67
+ const styles = StyleSheet.create({
68
+ container: {
69
+ flex: 1,
70
+ backgroundColor: '#FFFFFF'
71
+ },
72
+ content: {
73
+ flex: 1,
74
+ backgroundColor: '#F8F9FA'
75
+ },
76
+ messagesContainer: {
77
+ flex: 1,
78
+ padding: 20,
79
+ paddingTop: 30
80
+ },
81
+ messageBubble: {
82
+ maxWidth: '85%',
83
+ padding: 16,
84
+ borderRadius: 20,
85
+ marginBottom: 16,
86
+ backgroundColor: '#FFFFFF',
87
+ shadowColor: '#000',
88
+ shadowOffset: {
89
+ width: 0,
90
+ height: 2
91
+ },
92
+ shadowOpacity: 0.05,
93
+ shadowRadius: 8,
94
+ elevation: 3
95
+ },
96
+ userMessage: {
97
+ alignSelf: 'flex-end',
98
+ backgroundColor: '#FFFFFF',
99
+ borderWidth: 1,
100
+ borderColor: 'rgba(0, 0, 0, 0.04)'
101
+ },
102
+ botMessage: {
103
+ alignSelf: 'flex-start',
104
+ backgroundColor: '#FFFFFF',
105
+ borderWidth: 1,
106
+ borderColor: 'rgba(0, 0, 0, 0.04)'
107
+ },
108
+ messageText: {
109
+ fontSize: 15,
110
+ lineHeight: 22,
111
+ fontWeight: '400',
112
+ color: '#2C2C2E',
113
+ letterSpacing: 0.2
114
+ },
115
+ inputContainer: {
116
+ flexDirection: 'row',
117
+ alignItems: 'center',
118
+ paddingHorizontal: 16,
119
+ paddingVertical: 12,
120
+ backgroundColor: '#FFFFFF',
121
+ borderTopWidth: 1,
122
+ borderTopColor: 'rgba(0, 0, 0, 0.06)',
123
+ shadowColor: '#000',
124
+ shadowOffset: {
125
+ width: 0,
126
+ height: -8
127
+ },
128
+ shadowOpacity: 0.04,
129
+ shadowRadius: 12,
130
+ elevation: 8,
131
+ marginTop: 'auto'
132
+ },
133
+ input: {
134
+ flex: 1,
135
+ backgroundColor: '#F8F9FA',
136
+ borderRadius: 16,
137
+ borderWidth: 1,
138
+ borderColor: 'rgba(0, 0, 0, 0.06)',
139
+ paddingHorizontal: 20,
140
+ paddingVertical: 12,
141
+ marginRight: 12,
142
+ fontSize: 15,
143
+ maxHeight: 120,
144
+ color: '#2C2C2E',
145
+ shadowColor: '#000',
146
+ shadowOffset: {
147
+ width: 0,
148
+ height: 1
149
+ },
150
+ shadowOpacity: 0.04,
151
+ shadowRadius: 4,
152
+ elevation: 2
153
+ }
154
+ });
155
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","SafeAreaView","Text","StyleSheet","View","TextInput","ScrollView","KeyboardAvoidingView","Platform","Button","defaultTheme","primaryColor","backgroundColor","textColor","Chat","onSendMessage","theme","message","setMessage","useState","messages","setMessages","handleSend","trim","prev","text","fromUser","response","containerStyle","styles","container","getMessageStyle","messageBubble","userMessage","botMessage","getTextStyle","messageText","color","createElement","style","testID","behavior","OS","content","messagesContainer","map","msg","i","key","inputContainer","input","value","onChangeText","placeholder","placeholderTextColor","title","onPress","create","flex","padding","paddingTop","maxWidth","borderRadius","marginBottom","shadowColor","shadowOffset","width","height","shadowOpacity","shadowRadius","elevation","alignSelf","borderWidth","borderColor","fontSize","lineHeight","fontWeight","letterSpacing","flexDirection","alignItems","paddingHorizontal","paddingVertical","borderTopWidth","borderTopColor","marginTop","marginRight","maxHeight"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SACEC,YAAY,EACZC,IAAI,EACJC,UAAU,EACVC,IAAI,EACJC,SAAS,EACTC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IACpBC,iBAAiB,EAAE,EAAE;IACrBC,eAAe,EAAE,EAAE;IACnBrE,eAAe,EAAE,SAAS;IAC1BsE,cAAc,EAAE,CAAC;IACjBC,cAAc,EAAE,qBAAqB;IACrCnB,WAAW,EAAE,MAAM;IACnBC,YAAY,EAAE;MACZC,KAAK,EAAE,CAAC;MACRC,MAAM,EAAE,CAAC;IACX,CAAC;IACDC,aAAa,EAAE,IAAI;IACnBC,YAAY,EAAE,EAAE;IAChBC,SAAS,EAAE,CAAC;IACZc,SAAS,EAAE;EACb,CAAC;EACDlC,KAAK,EAAE;IACLQ,IAAI,EAAE,CAAC;IACP9C,eAAe,EAAE,SAAS;IAC1BkD,YAAY,EAAE,EAAE;IAChBU,WAAW,EAAE,CAAC;IACdC,WAAW,EAAE,qBAAqB;IAClCO,iBAAiB,EAAE,EAAE;IACrBC,eAAe,EAAE,EAAE;IACnBI,WAAW,EAAE,EAAE;IACfX,QAAQ,EAAE,EAAE;IACZY,SAAS,EAAE,GAAG;IACdjD,KAAK,EAAE,SAAS;IAChB2B,WAAW,EAAE,MAAM;IACnBC,YAAY,EAAE;MACZC,KAAK,EAAE,CAAC;MACRC,MAAM,EAAE;IACV,CAAC;IACDC,aAAa,EAAE,IAAI;IACnBC,YAAY,EAAE,CAAC;IACfC,SAAS,EAAE;EACb;AACF,CAAC,CAAC","ignoreList":[]}
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  interface ChatProps {
3
- onSendMessage?: (message: string) => Promise<string>;
3
+ onSendMessage: (message: string) => Promise<string>;
4
4
  placeholder?: string;
5
5
  theme?: {
6
6
  primaryColor?: string;
@@ -9,4 +9,5 @@ interface ChatProps {
9
9
  };
10
10
  }
11
11
  export declare const Chat: React.FC<ChatProps>;
12
- export default Chat;
12
+ export {};
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAa1B,UAAU,SAAS;IACjB,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE;QACN,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAQD,eAAO,MAAM,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CAwEpC,CAAC"}
package/package.json CHANGED
@@ -1,17 +1,23 @@
1
1
  {
2
2
  "name": "react-native-srschat",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "A modern, sophisticated chat interface for React Native",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "module": "dist/index.js",
8
+ "source": "src/index.tsx",
9
+ "react-native": "src/index.tsx",
7
10
  "scripts": {
8
- "build": "tsc",
9
- "prepare": "npm run build",
10
- "lint": "eslint .",
11
- "prepublishOnly": "npm run lint && npm run build"
11
+ "build": "bob build",
12
+ "prepare": "bob build",
13
+ "lint": "eslint \"src/**/*.{ts,tsx}\" \"example/src/**/*.{ts,tsx}\" --fix",
14
+ "prepublishOnly": "yarn lint && yarn build",
15
+ "test": "jest --config jest.config.js",
16
+ "example": "yarn workspace react-native-srschat-example start"
12
17
  },
13
18
  "files": [
14
19
  "dist",
20
+ "src",
15
21
  "README.md",
16
22
  "LICENSE"
17
23
  ],
@@ -29,9 +35,15 @@
29
35
  "react-native": ">=0.60.0"
30
36
  },
31
37
  "devDependencies": {
38
+ "@babel/core": "^7.20.0",
39
+ "@babel/plugin-transform-runtime": "^7.22.15",
40
+ "@babel/preset-env": "^7.20.0",
41
+ "@babel/preset-react": "^7.20.0",
42
+ "@babel/preset-typescript": "^7.20.0",
32
43
  "@react-native/eslint-config": "^0.72.2",
33
- "@types/react": "^18.0.0",
34
- "@types/react-native": "^0.70.0",
44
+ "@types/jest": "^29.0.0",
45
+ "@types/react": "~18.2.45",
46
+ "@types/react-native": "~0.72.8",
35
47
  "@typescript-eslint/eslint-plugin": "^5.0.0",
36
48
  "@typescript-eslint/parser": "^5.0.0",
37
49
  "eslint": "^8.0.0",
@@ -39,9 +51,15 @@
39
51
  "eslint-plugin-prettier": "^5.2.3",
40
52
  "eslint-plugin-react": "^7.0.0",
41
53
  "eslint-plugin-react-native": "^4.0.0",
54
+ "jest": "^29.0.0",
55
+ "jest-expo": "~50.0.0",
56
+ "metro-react-native-babel-preset": "^0.77.0",
42
57
  "prettier": "^3.4.2",
43
- "react": "^18.2.0",
44
- "typescript": "^4.9.0"
58
+ "react": "18.2.0",
59
+ "react-native": "0.73.6",
60
+ "react-native-builder-bob": "^0.20.0",
61
+ "ts-jest": "^29.0.0",
62
+ "typescript": "^5.1.3"
45
63
  },
46
64
  "repository": {
47
65
  "type": "git",
@@ -50,5 +68,26 @@
50
68
  "bugs": {
51
69
  "url": "https://github.com/alxkai/react-native-srschat/issues"
52
70
  },
53
- "homepage": "https://github.com/alxkai/react-native-srschat#readme"
71
+ "homepage": "https://github.com/alxkai/react-native-srschat#readme",
72
+ "workspaces": [
73
+ "example"
74
+ ],
75
+ "dependencies": {
76
+ "@babel/runtime": "^7.20.0"
77
+ },
78
+ "react-native-builder-bob": {
79
+ "source": "src",
80
+ "output": "dist",
81
+ "targets": [
82
+ "commonjs",
83
+ "module",
84
+ [
85
+ "typescript",
86
+ {
87
+ "project": "tsconfig.build.json"
88
+ }
89
+ ]
90
+ ]
91
+ },
92
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
54
93
  }
package/src/index.tsx ADDED
@@ -0,0 +1,191 @@
1
+ import React from 'react';
2
+ import {
3
+ SafeAreaView,
4
+ Text,
5
+ StyleSheet,
6
+ View,
7
+ TextInput,
8
+ ScrollView,
9
+ KeyboardAvoidingView,
10
+ Platform,
11
+ Button,
12
+ } from 'react-native';
13
+
14
+ interface ChatProps {
15
+ onSendMessage: (message: string) => Promise<string>;
16
+ placeholder?: string;
17
+ theme?: {
18
+ primaryColor?: string;
19
+ backgroundColor?: string;
20
+ textColor?: string;
21
+ };
22
+ }
23
+
24
+ const defaultTheme = {
25
+ primaryColor: '#007AFF',
26
+ backgroundColor: '#FFFFFF',
27
+ textColor: '#000000',
28
+ };
29
+
30
+ export const Chat: React.FC<ChatProps> = ({
31
+ onSendMessage,
32
+ theme = defaultTheme,
33
+ }) => {
34
+ const [message, setMessage] = React.useState('');
35
+ const [messages, setMessages] = React.useState<Array<{text: string; fromUser: boolean}>>([]);
36
+
37
+ const handleSend = async () => {
38
+ if (!message.trim()) {
39
+ return;
40
+ }
41
+
42
+ setMessages((prev) => [...prev, { text: message, fromUser: true }]);
43
+ setMessage('');
44
+
45
+ const response = await onSendMessage(message);
46
+ setMessages((prev) => [...prev, { text: response, fromUser: false }]);
47
+ };
48
+
49
+ const containerStyle = [
50
+ styles.container,
51
+ {
52
+ backgroundColor: theme.backgroundColor,
53
+ },
54
+ ];
55
+
56
+ const getMessageStyle = (fromUser: boolean) => [
57
+ styles.messageBubble,
58
+ fromUser ? styles.userMessage : styles.botMessage,
59
+ { backgroundColor: fromUser ? theme.primaryColor : '#E8E8E8' },
60
+ ];
61
+
62
+ const getTextStyle = (fromUser: boolean) => [
63
+ styles.messageText,
64
+ { color: fromUser ? '#fff' : theme.textColor },
65
+ ];
66
+
67
+ return (
68
+ <SafeAreaView style={containerStyle} testID="chat-container">
69
+ <KeyboardAvoidingView
70
+ behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
71
+ style={styles.content}
72
+ >
73
+ <ScrollView style={styles.messagesContainer}>
74
+ {messages.map((msg, i) => (
75
+ <View
76
+ key={i}
77
+ style={getMessageStyle(msg.fromUser)}
78
+ >
79
+ <Text style={getTextStyle(msg.fromUser)}>
80
+ {msg.text}
81
+ </Text>
82
+ </View>
83
+ ))}
84
+ </ScrollView>
85
+ <View style={styles.inputContainer}>
86
+ <TextInput
87
+ style={[styles.input, { color: theme.textColor }]}
88
+ value={message}
89
+ onChangeText={setMessage}
90
+ placeholder="Type a message..."
91
+ placeholderTextColor="#999"
92
+ />
93
+ <Button
94
+ title="Send"
95
+ onPress={handleSend}
96
+ color={theme.primaryColor}
97
+ />
98
+ </View>
99
+ </KeyboardAvoidingView>
100
+ </SafeAreaView>
101
+ );
102
+ };
103
+
104
+ const styles = StyleSheet.create({
105
+ container: {
106
+ flex: 1,
107
+ backgroundColor: '#FFFFFF',
108
+ },
109
+ content: {
110
+ flex: 1,
111
+ backgroundColor: '#F8F9FA',
112
+ },
113
+ messagesContainer: {
114
+ flex: 1,
115
+ padding: 20,
116
+ paddingTop: 30,
117
+ },
118
+ messageBubble: {
119
+ maxWidth: '85%',
120
+ padding: 16,
121
+ borderRadius: 20,
122
+ marginBottom: 16,
123
+ backgroundColor: '#FFFFFF',
124
+ shadowColor: '#000',
125
+ shadowOffset: {
126
+ width: 0,
127
+ height: 2,
128
+ },
129
+ shadowOpacity: 0.05,
130
+ shadowRadius: 8,
131
+ elevation: 3,
132
+ },
133
+ userMessage: {
134
+ alignSelf: 'flex-end',
135
+ backgroundColor: '#FFFFFF',
136
+ borderWidth: 1,
137
+ borderColor: 'rgba(0, 0, 0, 0.04)',
138
+ },
139
+ botMessage: {
140
+ alignSelf: 'flex-start',
141
+ backgroundColor: '#FFFFFF',
142
+ borderWidth: 1,
143
+ borderColor: 'rgba(0, 0, 0, 0.04)',
144
+ },
145
+ messageText: {
146
+ fontSize: 15,
147
+ lineHeight: 22,
148
+ fontWeight: '400',
149
+ color: '#2C2C2E',
150
+ letterSpacing: 0.2,
151
+ },
152
+ inputContainer: {
153
+ flexDirection: 'row',
154
+ alignItems: 'center',
155
+ paddingHorizontal: 16,
156
+ paddingVertical: 12,
157
+ backgroundColor: '#FFFFFF',
158
+ borderTopWidth: 1,
159
+ borderTopColor: 'rgba(0, 0, 0, 0.06)',
160
+ shadowColor: '#000',
161
+ shadowOffset: {
162
+ width: 0,
163
+ height: -8,
164
+ },
165
+ shadowOpacity: 0.04,
166
+ shadowRadius: 12,
167
+ elevation: 8,
168
+ marginTop: 'auto',
169
+ },
170
+ input: {
171
+ flex: 1,
172
+ backgroundColor: '#F8F9FA',
173
+ borderRadius: 16,
174
+ borderWidth: 1,
175
+ borderColor: 'rgba(0, 0, 0, 0.06)',
176
+ paddingHorizontal: 20,
177
+ paddingVertical: 12,
178
+ marginRight: 12,
179
+ fontSize: 15,
180
+ maxHeight: 120,
181
+ color: '#2C2C2E',
182
+ shadowColor: '#000',
183
+ shadowOffset: {
184
+ width: 0,
185
+ height: 1,
186
+ },
187
+ shadowOpacity: 0.04,
188
+ shadowRadius: 4,
189
+ elevation: 2,
190
+ },
191
+ });
package/dist/index.js DELETED
@@ -1,243 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
- if (ar || !(i in from)) {
41
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
- ar[i] = from[i];
43
- }
44
- }
45
- return to.concat(ar || Array.prototype.slice.call(from));
46
- };
47
- var __importDefault = (this && this.__importDefault) || function (mod) {
48
- return (mod && mod.__esModule) ? mod : { "default": mod };
49
- };
50
- Object.defineProperty(exports, "__esModule", { value: true });
51
- exports.Chat = void 0;
52
- var react_1 = __importDefault(require("react"));
53
- var react_native_1 = require("react-native");
54
- var defaultTheme = {
55
- primaryColor: '#FF4500',
56
- backgroundColor: '#FFFFFF',
57
- textColor: '#000000',
58
- secondaryBackgroundColor: 'rgba(0, 0, 0, 0.03)',
59
- };
60
- var getMessageTextColor = function (sender, theme) {
61
- if (theme === void 0) { theme = defaultTheme; }
62
- return (sender === 'user' ? '#fff' : theme.textColor);
63
- };
64
- var Chat = function (_a) {
65
- var onSendMessage = _a.onSendMessage, _b = _a.theme, theme = _b === void 0 ? defaultTheme : _b;
66
- var _c = react_1.default.useState([]), messages = _c[0], setMessages = _c[1];
67
- var _d = react_1.default.useState(''), inputText = _d[0], setInputText = _d[1];
68
- var handleSend = function () { return __awaiter(void 0, void 0, void 0, function () {
69
- var userMessage_1, response, botMessage_1, error_1;
70
- return __generator(this, function (_a) {
71
- switch (_a.label) {
72
- case 0:
73
- if (!inputText.trim()) return [3 /*break*/, 4];
74
- userMessage_1 = {
75
- id: Date.now().toString(),
76
- text: inputText.trim(),
77
- sender: 'user',
78
- };
79
- setInputText('');
80
- setMessages(function (prev) { return __spreadArray(__spreadArray([], prev, true), [userMessage_1], false); });
81
- if (!onSendMessage) return [3 /*break*/, 4];
82
- _a.label = 1;
83
- case 1:
84
- _a.trys.push([1, 3, , 4]);
85
- return [4 /*yield*/, onSendMessage(userMessage_1.text)];
86
- case 2:
87
- response = _a.sent();
88
- botMessage_1 = {
89
- id: (Date.now() + 1).toString(),
90
- text: response,
91
- sender: 'bot',
92
- };
93
- setMessages(function (prev) { return __spreadArray(__spreadArray([], prev, true), [botMessage_1], false); });
94
- return [3 /*break*/, 4];
95
- case 3:
96
- error_1 = _a.sent();
97
- console.error('Error sending message:', error_1);
98
- return [3 /*break*/, 4];
99
- case 4: return [2 /*return*/];
100
- }
101
- });
102
- }); };
103
- var containerStyle = [
104
- styles.container,
105
- {
106
- backgroundColor: theme.backgroundColor,
107
- },
108
- ];
109
- return (react_1.default.createElement(react_native_1.SafeAreaView, { style: containerStyle },
110
- react_1.default.createElement(react_native_1.KeyboardAvoidingView, { behavior: react_native_1.Platform.OS === 'ios' ? 'padding' : 'height', style: styles.content },
111
- react_1.default.createElement(react_native_1.ScrollView, { style: styles.messagesContainer }, messages.map(function (message) { return (react_1.default.createElement(react_native_1.View, { key: message.id, style: [
112
- styles.messageBubble,
113
- message.sender === 'user'
114
- ? [
115
- styles.userMessage,
116
- {
117
- backgroundColor: theme.primaryColor,
118
- },
119
- ]
120
- : styles.botMessage,
121
- ] },
122
- react_1.default.createElement(react_native_1.Text, { style: [
123
- styles.messageText,
124
- {
125
- color: getMessageTextColor(message.sender, theme),
126
- },
127
- ] }, message.text))); })),
128
- react_1.default.createElement(react_native_1.View, { style: styles.inputContainer },
129
- react_1.default.createElement(react_native_1.TextInput, { style: [styles.input], value: inputText, onChangeText: setInputText, placeholder: "Message...", placeholderTextColor: "rgba(0, 0, 0, 0.35)", multiline: true }),
130
- react_1.default.createElement(react_native_1.TouchableOpacity, { style: styles.sendButton, onPress: handleSend },
131
- react_1.default.createElement(react_native_1.Text, { style: styles.sendButtonText }, "\u2192"))))));
132
- };
133
- exports.Chat = Chat;
134
- var styles = react_native_1.StyleSheet.create({
135
- container: {
136
- flex: 1,
137
- backgroundColor: '#FFFFFF',
138
- },
139
- content: {
140
- flex: 1,
141
- backgroundColor: '#F8F9FA',
142
- },
143
- messagesContainer: {
144
- flex: 1,
145
- padding: 20,
146
- paddingTop: 30,
147
- },
148
- messageBubble: {
149
- maxWidth: '85%',
150
- padding: 16,
151
- borderRadius: 20,
152
- marginBottom: 16,
153
- backgroundColor: '#FFFFFF',
154
- shadowColor: '#000',
155
- shadowOffset: {
156
- width: 0,
157
- height: 2,
158
- },
159
- shadowOpacity: 0.05,
160
- shadowRadius: 8,
161
- elevation: 3,
162
- },
163
- userMessage: {
164
- alignSelf: 'flex-end',
165
- backgroundColor: '#FFFFFF',
166
- borderWidth: 1,
167
- borderColor: 'rgba(0, 0, 0, 0.04)',
168
- },
169
- botMessage: {
170
- alignSelf: 'flex-start',
171
- backgroundColor: '#FFFFFF',
172
- borderWidth: 1,
173
- borderColor: 'rgba(0, 0, 0, 0.04)',
174
- },
175
- messageText: {
176
- fontSize: 15,
177
- lineHeight: 22,
178
- fontWeight: '400',
179
- color: '#2C2C2E',
180
- letterSpacing: 0.2,
181
- },
182
- inputContainer: {
183
- flexDirection: 'row',
184
- alignItems: 'center',
185
- paddingHorizontal: 16,
186
- paddingVertical: 12,
187
- backgroundColor: '#FFFFFF',
188
- borderTopWidth: 1,
189
- borderTopColor: 'rgba(0, 0, 0, 0.06)',
190
- shadowColor: '#000',
191
- shadowOffset: {
192
- width: 0,
193
- height: -8,
194
- },
195
- shadowOpacity: 0.04,
196
- shadowRadius: 12,
197
- elevation: 8,
198
- marginTop: 'auto',
199
- },
200
- input: {
201
- flex: 1,
202
- backgroundColor: '#F8F9FA',
203
- borderRadius: 16,
204
- borderWidth: 1,
205
- borderColor: 'rgba(0, 0, 0, 0.06)',
206
- paddingHorizontal: 20,
207
- paddingVertical: 12,
208
- marginRight: 12,
209
- fontSize: 15,
210
- maxHeight: 120,
211
- color: '#2C2C2E',
212
- shadowColor: '#000',
213
- shadowOffset: {
214
- width: 0,
215
- height: 1,
216
- },
217
- shadowOpacity: 0.04,
218
- shadowRadius: 4,
219
- elevation: 2,
220
- },
221
- sendButton: {
222
- width: 44,
223
- height: 44,
224
- borderRadius: 22,
225
- justifyContent: 'center',
226
- alignItems: 'center',
227
- backgroundColor: '#007AFF',
228
- shadowColor: '#000',
229
- shadowOffset: {
230
- width: 0,
231
- height: 2,
232
- },
233
- shadowOpacity: 0.1,
234
- shadowRadius: 4,
235
- elevation: 3,
236
- },
237
- sendButtonText: {
238
- color: '#FFFFFF',
239
- fontSize: 15,
240
- fontWeight: '600',
241
- },
242
- });
243
- exports.default = exports.Chat;