@ihoomanai/react-chat 2.0.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/README.md ADDED
@@ -0,0 +1,220 @@
1
+ # @ihooman/react-chat
2
+
3
+ React components and hooks for the Ihooman Chat Widget. Provides native React integration with proper lifecycle management and SSR compatibility.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @ihooman/react-chat
9
+ # or
10
+ yarn add @ihooman/react-chat
11
+ # or
12
+ pnpm add @ihooman/react-chat
13
+ ```
14
+
15
+ ## Requirements
16
+
17
+ - React 17.0.0 or higher
18
+ - A valid Widget ID from your [Ihooman Dashboard](https://ihooman.ai)
19
+
20
+ ## Quick Start
21
+
22
+ ### Basic Usage
23
+
24
+ ```tsx
25
+ import { ChatWidget } from '@ihooman/react-chat';
26
+
27
+ function App() {
28
+ return (
29
+ <ChatWidget
30
+ widgetId="wgt_abc123def456"
31
+ position="bottom-right"
32
+ onReady={() => console.log('Widget ready!')}
33
+ />
34
+ );
35
+ }
36
+ ```
37
+
38
+ ### With Provider and Hook
39
+
40
+ For programmatic control over the widget from any component:
41
+
42
+ ```tsx
43
+ import { ChatWidgetProvider, ChatWidget, useChatWidget } from '@ihooman/react-chat';
44
+
45
+ function SupportButton() {
46
+ const { open, isReady } = useChatWidget();
47
+
48
+ return (
49
+ <button onClick={open} disabled={!isReady}>
50
+ Need Help?
51
+ </button>
52
+ );
53
+ }
54
+
55
+ function App() {
56
+ return (
57
+ <ChatWidgetProvider>
58
+ <ChatWidget widgetId="wgt_abc123def456" />
59
+ <SupportButton />
60
+ </ChatWidgetProvider>
61
+ );
62
+ }
63
+ ```
64
+
65
+ ## Components
66
+
67
+ ### `<ChatWidget />`
68
+
69
+ The main component that renders the chat widget.
70
+
71
+ #### Props
72
+
73
+ | Prop | Type | Required | Description |
74
+ |------|------|----------|-------------|
75
+ | `widgetId` | `string` | Yes | Your Widget ID from the Ihooman dashboard |
76
+ | `serverUrl` | `string` | No | Custom server URL (defaults to production) |
77
+ | `theme` | `'light' \| 'dark'` | No | Color theme |
78
+ | `position` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | No | Widget position |
79
+ | `startOpen` | `boolean` | No | Start with widget open |
80
+ | `user` | `{ name?: string; email?: string; metadata?: Record<string, string> }` | No | User information |
81
+ | `onReady` | `() => void` | No | Called when widget is ready |
82
+ | `onOpen` | `() => void` | No | Called when widget opens |
83
+ | `onClose` | `() => void` | No | Called when widget closes |
84
+ | `onMessage` | `(message: Message) => void` | No | Called on new messages |
85
+ | `onError` | `(error: Error) => void` | No | Called on errors |
86
+
87
+ See the [full props documentation](#chatwidget-props) for all available options.
88
+
89
+ ### `<ChatWidgetProvider />`
90
+
91
+ Context provider for global widget access. Wrap your app with this to use the `useChatWidget` hook.
92
+
93
+ ```tsx
94
+ <ChatWidgetProvider>
95
+ {/* Your app components */}
96
+ </ChatWidgetProvider>
97
+ ```
98
+
99
+ ## Hooks
100
+
101
+ ### `useChatWidget()`
102
+
103
+ Hook for controlling the widget from any component within the provider.
104
+
105
+ ```tsx
106
+ const {
107
+ isOpen, // boolean - Whether widget is open
108
+ isReady, // boolean - Whether widget is initialized
109
+ isConnected, // boolean - Whether connected to server
110
+ open, // () => void - Open the widget
111
+ close, // () => void - Close the widget
112
+ toggle, // () => void - Toggle open/closed
113
+ sendMessage, // (content: string) => void - Send a message
114
+ setUser, // (user: UserInfo) => void - Set user info
115
+ clearHistory,// () => void - Clear chat history
116
+ messages, // Message[] - Current messages
117
+ unreadCount, // number - Unread message count
118
+ } = useChatWidget();
119
+ ```
120
+
121
+ ## Examples
122
+
123
+ ### With User Information
124
+
125
+ ```tsx
126
+ <ChatWidget
127
+ widgetId="wgt_abc123def456"
128
+ user={{
129
+ name: 'John Doe',
130
+ email: 'john@example.com',
131
+ metadata: {
132
+ plan: 'premium',
133
+ customerId: 'cust_123'
134
+ }
135
+ }}
136
+ />
137
+ ```
138
+
139
+ ### Custom Styling
140
+
141
+ ```tsx
142
+ <ChatWidget
143
+ widgetId="wgt_abc123def456"
144
+ primaryColor="#6366f1"
145
+ gradientFrom="#6366f1"
146
+ gradientTo="#8b5cf6"
147
+ borderRadius={16}
148
+ fontFamily="Inter, sans-serif"
149
+ />
150
+ ```
151
+
152
+ ### Programmatic Messages
153
+
154
+ ```tsx
155
+ function QuickActions() {
156
+ const { sendMessage, isReady } = useChatWidget();
157
+
158
+ return (
159
+ <div>
160
+ <button
161
+ onClick={() => sendMessage('I need help with my order')}
162
+ disabled={!isReady}
163
+ >
164
+ Order Help
165
+ </button>
166
+ <button
167
+ onClick={() => sendMessage('How do I reset my password?')}
168
+ disabled={!isReady}
169
+ >
170
+ Password Help
171
+ </button>
172
+ </div>
173
+ );
174
+ }
175
+ ```
176
+
177
+ ### Next.js / SSR
178
+
179
+ The component is SSR-compatible and defers initialization to the client:
180
+
181
+ ```tsx
182
+ // pages/_app.tsx or app/layout.tsx
183
+ import { ChatWidgetProvider, ChatWidget } from '@ihooman/react-chat';
184
+
185
+ export default function App({ Component, pageProps }) {
186
+ return (
187
+ <ChatWidgetProvider>
188
+ <Component {...pageProps} />
189
+ <ChatWidget widgetId="wgt_abc123def456" />
190
+ </ChatWidgetProvider>
191
+ );
192
+ }
193
+ ```
194
+
195
+ ## TypeScript
196
+
197
+ Full TypeScript support is included. Import types as needed:
198
+
199
+ ```tsx
200
+ import type {
201
+ ChatWidgetProps,
202
+ UseChatWidgetReturn,
203
+ Message,
204
+ UserInfo
205
+ } from '@ihooman/react-chat';
206
+ ```
207
+
208
+ ## Framework Compatibility
209
+
210
+ - ✅ React 17+
211
+ - ✅ React 18+
212
+ - ✅ Next.js (Pages & App Router)
213
+ - ✅ Gatsby
214
+ - ✅ Remix
215
+ - ✅ Vite
216
+ - ✅ Create React App
217
+
218
+ ## License
219
+
220
+ MIT © [Ihooman AI](https://ihooman.ai)
@@ -0,0 +1,42 @@
1
+ /**
2
+ * ChatWidget React Component
3
+ *
4
+ * A React wrapper for the Ihooman Chat Widget that handles
5
+ * initialization, lifecycle management, and SSR compatibility.
6
+ *
7
+ * @module @ihooman/react-chat
8
+ */
9
+ import React from 'react';
10
+ import type { ChatWidgetProps } from './types';
11
+ /**
12
+ * ChatWidget Component
13
+ *
14
+ * Renders the Ihooman Chat Widget with React lifecycle management.
15
+ * Supports SSR by deferring initialization to useEffect.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * import { ChatWidget } from '@ihooman/react-chat';
20
+ *
21
+ * function App() {
22
+ * return (
23
+ * <ChatWidget
24
+ * widgetId="wgt_abc123def456"
25
+ * position="bottom-right"
26
+ * onReady={() => console.log('Widget ready!')}
27
+ * />
28
+ * );
29
+ * }
30
+ * ```
31
+ *
32
+ * @example With user information
33
+ * ```tsx
34
+ * <ChatWidget
35
+ * widgetId="wgt_abc123def456"
36
+ * user={{ name: 'John Doe', email: 'john@example.com' }}
37
+ * />
38
+ * ```
39
+ */
40
+ export declare function ChatWidget({ widgetId, serverUrl, theme, position, startOpen, user, title, subtitle, welcomeMessage, placeholder, primaryColor, gradientFrom, gradientTo, showTimestamps, showTypingIndicator, enableSounds, enableFileUpload, persistSession, zIndex, width, height, buttonSize, borderRadius, fontFamily, avatarUrl, poweredBy, onReady, onOpen, onClose, onMessage, onError, }: ChatWidgetProps): React.ReactElement | null;
41
+ export default ChatWidget;
42
+ //# sourceMappingURL=ChatWidget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatWidget.d.ts","sourceRoot":"","sources":["../src/ChatWidget.tsx"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAyC,MAAM,OAAO,CAAC;AAG9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,UAAU,CAAC,EACzB,QAAQ,EACR,SAAS,EACT,KAAK,EACL,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,cAAc,EACd,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,MAAM,EACN,KAAK,EACL,MAAM,EACN,UAAU,EACV,YAAY,EACZ,UAAU,EACV,SAAS,EACT,SAAS,EACT,OAAO,EACP,MAAM,EACN,OAAO,EACP,SAAS,EACT,OAAO,GACR,EAAE,eAAe,GAAG,KAAK,CAAC,YAAY,GAAG,IAAI,CA0J7C;AAED,eAAe,UAAU,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * ChatWidgetProvider Component
3
+ *
4
+ * Provides global widget state and controls to all child components.
5
+ * Wrap your app with this provider to use the useChatWidget hook.
6
+ */
7
+ import React from 'react';
8
+ import type { ChatWidgetProviderProps } from './types';
9
+ /**
10
+ * Provider component for the Chat Widget context
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * import { ChatWidgetProvider, ChatWidget } from '@ihooman/react-chat';
15
+ *
16
+ * function App() {
17
+ * return (
18
+ * <ChatWidgetProvider>
19
+ * <ChatWidget widgetId="wgt_abc123def456" />
20
+ * <YourApp />
21
+ * </ChatWidgetProvider>
22
+ * );
23
+ * }
24
+ * ```
25
+ */
26
+ export declare function ChatWidgetProvider({ children }: ChatWidgetProviderProps): React.ReactElement;
27
+ export default ChatWidgetProvider;
28
+ //# sourceMappingURL=ChatWidgetProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatWidgetProvider.d.ts","sourceRoot":"","sources":["../src/ChatWidgetProvider.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAyC,MAAM,OAAO,CAAC;AAG9D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAEvD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,QAAQ,EAAE,EAAE,uBAAuB,GAAG,KAAK,CAAC,YAAY,CAmC5F;AAED,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * React Context for Ihooman Chat Widget
3
+ *
4
+ * Provides global access to widget state and controls
5
+ * throughout the React component tree.
6
+ */
7
+ import type { IhoomanChatAPI, Message } from '@ihooman/chat-widget';
8
+ /**
9
+ * Internal context value type
10
+ */
11
+ export interface ChatWidgetContextValue {
12
+ /** Reference to the widget API instance */
13
+ widgetRef: IhoomanChatAPI | null;
14
+ /** Set the widget API reference */
15
+ setWidgetRef: (widget: IhoomanChatAPI | null) => void;
16
+ /** Whether the widget is initialized and ready */
17
+ isReady: boolean;
18
+ /** Set the ready state */
19
+ setIsReady: (ready: boolean) => void;
20
+ /** Whether the widget window is open */
21
+ isOpen: boolean;
22
+ /** Set the open state */
23
+ setIsOpen: (open: boolean) => void;
24
+ /** Whether connected to the server */
25
+ isConnected: boolean;
26
+ /** Set the connected state */
27
+ setIsConnected: (connected: boolean) => void;
28
+ /** Current chat messages */
29
+ messages: Message[];
30
+ /** Set the messages */
31
+ setMessages: (messages: Message[]) => void;
32
+ /** Number of unread messages */
33
+ unreadCount: number;
34
+ /** Set the unread count */
35
+ setUnreadCount: (count: number) => void;
36
+ }
37
+ /**
38
+ * React Context for the Chat Widget
39
+ */
40
+ export declare const ChatWidgetContext: import("react").Context<ChatWidgetContextValue>;
41
+ /**
42
+ * Hook to access the ChatWidget context
43
+ * @internal
44
+ */
45
+ export declare function useChatWidgetContext(): ChatWidgetContextValue;
46
+ /**
47
+ * Type guard to check if widget is available
48
+ */
49
+ export declare function isWidgetAvailable(widget: IhoomanChatAPI | null): widget is IhoomanChatAPI;
50
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAY,MAAM,sBAAsB,CAAC;AAE9E;;GA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