@channlize/react 0.1.0 → 0.3.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/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode } from 'react';
3
- import { ChannlizeConfig, ChannlizeClient, CreateContactResponse, ChannlizeError, ContactFormData, ChatMessage, ChatSession } from '@channlize/core';
4
- export { AuthenticationError, ChannlizeConfig, ChannlizeError, ChatMessage, ChatSession, ContactFormData, CreateChatSessionResponse, CreateContactResponse, FileAttachment, RateLimitError, SendMessageResponse, ValidationError } from '@channlize/core';
1
+ import * as react from 'react';
2
+ import { ReactNode, CSSProperties } from 'react';
3
+ import { ChannlizeConfig, ChannlizeClient, CreateContactResponse, ChannlizeError, ContactFormData, ChatMessage, ChatSession, TrackEventOptions } from '@channlize/core';
4
+ export { AuthenticationError, ChannlizeConfig, ChannlizeError, ChatMessage, ChatSession, ContactFormData, CreateChatSessionResponse, CreateContactResponse, EventSeverity, FileAttachment, RateLimitError, SendMessageResponse, TrackEventOptions, ValidationError } from '@channlize/core';
5
5
 
6
6
  interface ChannlizeContextValue {
7
7
  client: ChannlizeClient;
@@ -14,7 +14,7 @@ interface ChannlizeProviderProps {
14
14
  /**
15
15
  * Provider component that makes Channlize client available to all child components
16
16
  */
17
- declare function ChannlizeProvider({ config, children }: ChannlizeProviderProps): react_jsx_runtime.JSX.Element;
17
+ declare function ChannlizeProvider({ config, children, }: ChannlizeProviderProps): react.JSX.Element;
18
18
  /**
19
19
  * Hook to access the Channlize client and configuration
20
20
  */
@@ -54,54 +54,210 @@ interface UseChatSessionReturn {
54
54
  sendMessage: (content: string, attachments?: File[]) => Promise<void>;
55
55
  startSession: () => Promise<void>;
56
56
  endSession: () => Promise<void>;
57
+ /**
58
+ * Reopen the real-time stream for the current session after it failed
59
+ * (`error.code === 'SSE_ERROR'`). Routine reconnects are automatic.
60
+ */
61
+ reconnect: () => void;
57
62
  }
58
63
  /**
59
64
  * Hook for managing chat sessions with real-time messaging
60
65
  */
61
66
  declare function useChatSession(options?: UseChatSessionOptions): UseChatSessionReturn;
62
67
 
63
- interface FormProps {
64
- /** Custom fields to include in the form */
65
- customFields?: Array<{
66
- name: string;
67
- label: string;
68
- type: 'text' | 'email' | 'textarea' | 'select';
69
- required?: boolean;
70
- options?: string[];
68
+ /**
69
+ * Returns a stable `track` function bound to the provider client for log
70
+ * tracking (browser / widget key; shown under Log tracking in the
71
+ * dashboard). To post a Slack message when something happens, use Events
72
+ * (`notify` from `@channlize/core`) on your server instead.
73
+ */
74
+ declare function useChannlizeAnalytics(): {
75
+ track: (name: string, options?: TrackEventOptions) => Promise<{
76
+ success: boolean;
77
+ id: string;
71
78
  }>;
79
+ };
80
+
81
+ /** `auto` and `system` both follow `prefers-color-scheme`. */
82
+ type ContactFormTheme = 'auto' | 'system' | 'light' | 'dark';
83
+ /** Whether a built-in field is shown, and whether it must be filled in. */
84
+ type ContactFieldMode = 'required' | 'optional' | 'hidden';
85
+ interface ContactFormTopic {
86
+ /** Identifies the option, e.g. for `defaultValues.topic` from a URL */
87
+ value: string;
88
+ /**
89
+ * Shown in the select, sent as `customFields.topic`, and used as the
90
+ * subject when that is blank. Defaults to `value`.
91
+ */
92
+ label?: string;
93
+ }
94
+ /** The built-in fields' values (also what `defaultValues` takes). */
95
+ interface ContactFormValues {
96
+ name: string;
97
+ email: string;
98
+ company: string;
99
+ subject: string;
100
+ topic: string;
101
+ message: string;
102
+ }
103
+ interface ContactFormCustomField {
104
+ name: string;
105
+ label: string;
106
+ type: 'text' | 'email' | 'textarea' | 'select';
107
+ required?: boolean;
108
+ options?: string[];
109
+ placeholder?: string;
110
+ }
111
+ /** Every user-facing string in the form, for copy changes or translation. */
112
+ interface ContactFormLabels {
113
+ name: string;
114
+ email: string;
115
+ company: string;
116
+ subject: string;
117
+ topic: string;
118
+ message: string;
119
+ namePlaceholder: string;
120
+ emailPlaceholder: string;
121
+ companyPlaceholder: string;
122
+ subjectPlaceholder: string;
123
+ topicPlaceholder: string;
124
+ messagePlaceholder: string;
125
+ optional: string;
126
+ submit: string;
127
+ submitting: string;
128
+ successTitle: string;
129
+ successMessage: string;
130
+ sendAnother: string;
131
+ /** Shown under a required field left empty */
132
+ errorRequired: string;
133
+ /** Shown under a required select left on the placeholder */
134
+ errorSelect: string;
135
+ errorEmail: string;
136
+ /** `{min}` is replaced with the minimum length */
137
+ errorTooShort: string;
138
+ /** `{max}` is replaced with the maximum length */
139
+ errorTooLong: string;
140
+ /** Announced when a submit is blocked by invalid fields */
141
+ errorSummary: string;
142
+ /** Shown when sending fails */
143
+ errorGeneric: string;
144
+ /** Shown when the API rate limit is hit */
145
+ errorRateLimit: string;
146
+ /** Small print under the submit button; '' hides it */
147
+ footnote: string;
148
+ }
149
+ declare const defaultContactFormLabels: ContactFormLabels;
150
+ interface FormProps {
151
+ /** Custom fields to include in the form (sent as `customFields`) */
152
+ customFields?: ContactFormCustomField[];
72
153
  /** Callback when form is successfully submitted */
73
- onSuccess?: () => void;
154
+ onSuccess?: (response: CreateContactResponse) => void;
74
155
  /** Callback when form submission fails */
75
156
  onError?: (error: Error) => void;
76
157
  /** Custom CSS classes */
77
158
  className?: string;
78
- /** Custom styles for form elements */
159
+ /** Custom styles for form elements (applied inline, so they win over the theme) */
79
160
  styles?: {
80
- form?: React.CSSProperties;
81
- field?: React.CSSProperties;
82
- label?: React.CSSProperties;
83
- input?: React.CSSProperties;
84
- textarea?: React.CSSProperties;
85
- button?: React.CSSProperties;
86
- error?: React.CSSProperties;
87
- success?: React.CSSProperties;
161
+ form?: CSSProperties;
162
+ field?: CSSProperties;
163
+ label?: CSSProperties;
164
+ input?: CSSProperties;
165
+ textarea?: CSSProperties;
166
+ button?: CSSProperties;
167
+ error?: CSSProperties;
168
+ success?: CSSProperties;
88
169
  };
89
- /** Button text */
170
+ /** Button text (same as `labels.submit`) */
90
171
  submitText?: string;
91
- /** Success message */
172
+ /** Success message (same as `labels.successMessage`) */
92
173
  successMessage?: string;
174
+ /** Colour scheme (default `light`). `auto` / `system` follow `prefers-color-scheme`. */
175
+ theme?: ContactFormTheme;
176
+ /** Accent colour (button, focus ring). Hex recommended. */
177
+ primaryColor?: string;
178
+ /** Text colour on the accent colour. Defaults to white or near-black, whichever is readable. */
179
+ primaryTextColor?: string;
180
+ /** `card` (default) draws a themed surface with padding; `plain` inherits the host's. */
181
+ variant?: 'card' | 'plain';
182
+ /** Skip the built-in stylesheet entirely (class names stay for your own CSS) */
183
+ unstyled?: boolean;
184
+ /**
185
+ * Built-in fields. Email and message are always required.
186
+ * Defaults: name `required`, subject `optional`, company `hidden`,
187
+ * topic `optional` when `topics` is set.
188
+ */
189
+ fields?: {
190
+ name?: ContactFieldMode;
191
+ company?: ContactFieldMode;
192
+ subject?: ContactFieldMode;
193
+ topic?: ContactFieldMode;
194
+ };
195
+ /** Options of the topic select; it is shown only when this is set */
196
+ topics?: Array<string | ContactFormTopic>;
197
+ /**
198
+ * Initial values, e.g. a topic from the URL (`?topic=sales`). A topic
199
+ * matches an option's value or label, case-insensitively.
200
+ */
201
+ defaultValues?: Partial<ContactFormValues>;
202
+ /** Override any user-facing string */
203
+ labels?: Partial<ContactFormLabels>;
204
+ /** Minimum message length (default `10`, what the Channlize API accepts) */
205
+ minMessageLength?: number;
206
+ /** Maximum message length (default `5000`) */
207
+ maxMessageLength?: number;
208
+ /** Add a hidden honeypot field; bots that fill it get a fake success (default `true`) */
209
+ honeypot?: boolean;
210
+ /** Show the built-in success state after sending (default `true`) */
211
+ showSuccessState?: boolean;
212
+ /** Prefix of the fields' ids (default `channlize`, e.g. `channlize-email`) */
213
+ idPrefix?: string;
93
214
  }
94
215
 
95
216
  /**
96
- * ContactForm component - Alias for Form component
97
- * Provides a form for collecting contact information and messages
217
+ * ContactForm component
218
+ *
219
+ * A themed, accessible contact form that posts to Channlize (and from there
220
+ * to your Slack). Inline validation, loading / success / error states, an
221
+ * optional topic select and company field, and a honeypot spam guard.
222
+ * Must be rendered inside `<ChannlizeProvider>`.
98
223
  */
99
- declare function ContactForm(props: FormProps): react_jsx_runtime.JSX.Element;
224
+ declare function ContactForm(props: FormProps): react.JSX.Element;
225
+ type ContactFormProps = FormProps;
100
226
 
227
+ type ChatTheme = 'auto' | 'light' | 'dark';
228
+ /** Every user-facing string in the chat, for copy changes or translation. */
229
+ interface SupportChatLabels {
230
+ online: string;
231
+ connecting: string;
232
+ reconnecting: string;
233
+ offline: string;
234
+ connectionLost: string;
235
+ startFailed: string;
236
+ retry: string;
237
+ today: string;
238
+ yesterday: string;
239
+ you: string;
240
+ sending: string;
241
+ failed: string;
242
+ remove: string;
243
+ moreOptions: string;
244
+ minimize: string;
245
+ endChat: string;
246
+ endChatTitle: string;
247
+ endChatDescription: string;
248
+ endChatConfirm: string;
249
+ cancel: string;
250
+ attach: string;
251
+ removeAttachment: string;
252
+ messages: string;
253
+ conversationEnded: string;
254
+ charactersLeft: string;
255
+ }
256
+ declare const defaultSupportChatLabels: SupportChatLabels;
101
257
  interface SupportChatProps extends UseChatSessionOptions {
102
258
  /** Custom CSS classes */
103
259
  className?: string;
104
- /** Custom styles for chat elements */
260
+ /** Custom styles for chat elements (applied inline, so they win over the theme) */
105
261
  styles?: {
106
262
  container?: React.CSSProperties;
107
263
  header?: React.CSSProperties;
@@ -117,20 +273,48 @@ interface SupportChatProps extends UseChatSessionOptions {
117
273
  };
118
274
  /** Placeholder text for message input */
119
275
  placeholder?: string;
120
- /** Header title */
276
+ /** Header title: your team or brand name */
121
277
  title?: string;
122
- /** Button text */
278
+ /** Accessible label (and tooltip) of the send button */
123
279
  sendButtonText?: string;
124
280
  /** Show timestamps on messages */
125
281
  showTimestamps?: boolean;
126
282
  /** Allow file attachments */
127
283
  allowAttachments?: boolean;
284
+ /** Logo or team avatar URL, shown in the header and on the welcome screen */
285
+ avatarUrl?: string;
286
+ /** Custom avatar element (overrides `avatarUrl`) */
287
+ avatar?: ReactNode;
288
+ /** Text after "Online" in the header, e.g. "Replies in a few minutes". Set to '' to hide. */
289
+ statusText?: string;
290
+ /** Welcome heading shown before the first message */
291
+ greeting?: string;
292
+ /** Welcome text shown under the greeting */
293
+ welcomeMessage?: string;
294
+ /** Quick replies shown on the welcome screen; clicking one sends it */
295
+ suggestions?: string[];
296
+ /** Colour scheme. `auto` follows `prefers-color-scheme`. */
297
+ theme?: ChatTheme;
298
+ /** Accent colour (header, customer bubbles, send button). Hex recommended. */
299
+ primaryColor?: string;
300
+ /** Text colour on the accent colour. Defaults to white or near-black, whichever is readable. */
301
+ primaryTextColor?: string;
302
+ /** Locale for dates and times (defaults to the browser locale) */
303
+ locale?: string;
304
+ /** Maximum message length */
305
+ maxLength?: number;
306
+ /** Show "End conversation" in the header menu */
307
+ allowEndChat?: boolean;
308
+ /** When set, a minimize button is shown in the header and Esc calls it */
309
+ onMinimize?: () => void;
310
+ /** Override any user-facing string */
311
+ labels?: Partial<SupportChatLabels>;
128
312
  }
129
313
  /**
130
314
  * SupportChat component - Real-time chat interface
131
315
  * Provides a complete chat UI with message history and real-time updates
132
316
  */
133
- declare function SupportChat({ autoConnect, metadata, onMessage, onError, sessionId, persistSession, storageKey, className, styles, placeholder, title, sendButtonText, showTimestamps, allowAttachments, }: SupportChatProps): react_jsx_runtime.JSX.Element;
317
+ declare function SupportChat({ autoConnect, metadata, onMessage, onError, sessionId, persistSession, storageKey, className, styles, placeholder, title, sendButtonText, showTimestamps, allowAttachments, avatarUrl, avatar, statusText, greeting, welcomeMessage, suggestions, theme, primaryColor, primaryTextColor, locale, maxLength, allowEndChat, onMinimize, labels: labelOverrides, }: SupportChatProps): react.JSX.Element;
134
318
 
135
319
  interface ChannlizeChatProps {
136
320
  /** Channlize configuration */
@@ -148,29 +332,36 @@ interface ChannlizeChatProps {
148
332
  buttonIcon?: ReactNode;
149
333
  /** Button size in pixels */
150
334
  buttonSize?: number;
151
- /** Button colors */
335
+ /** Launcher colours. Default to `primaryColor`. */
152
336
  buttonColors?: {
153
337
  background?: string;
154
338
  hover?: string;
155
339
  text?: string;
156
340
  };
157
341
  /** Chat window props (passed to SupportChat) */
158
- chatProps?: Omit<SupportChatProps, 'autoConnect'>;
342
+ chatProps?: Omit<SupportChatProps, 'autoConnect' | 'onMinimize'>;
343
+ /** Accent colour for the launcher and chat window (hex recommended) */
344
+ primaryColor?: string;
345
+ /** Colour scheme. `auto` (default) follows `prefers-color-scheme`. */
346
+ theme?: ChatTheme;
159
347
  /** Whether to start closed or open */
160
348
  defaultOpen?: boolean;
161
- /** Whether to show badge with unread count */
349
+ /**
350
+ * Show `unreadCount` on the launcher instead of the built-in count. Without
351
+ * it, the launcher counts agent replies received while the chat is closed.
352
+ */
162
353
  showBadge?: boolean;
163
- /** Unread count (for badge) */
354
+ /** Unread count (for badge, used with `showBadge`) */
164
355
  unreadCount?: number;
165
356
  /** Custom z-index */
166
357
  zIndex?: number;
167
- /** Whether to show on mobile */
358
+ /** Whether to show the launcher on small screens (< 640px) */
168
359
  showOnMobile?: boolean;
169
360
  /** Callback when chat opens */
170
361
  onOpen?: () => void;
171
362
  /** Callback when chat closes */
172
363
  onClose?: () => void;
173
- /** Whether to enable animations */
364
+ /** Whether to enable animations (always reduced with `prefers-reduced-motion`) */
174
365
  enableAnimations?: boolean;
175
366
  /** Custom class for button container */
176
367
  buttonClassName?: string;
@@ -191,13 +382,16 @@ interface ChannlizeChatProps {
191
382
  * projectId: "your-project-id",
192
383
  * }}
193
384
  * position="bottom-right"
385
+ * primaryColor="#2563eb"
194
386
  * chatProps={{
195
- * title: "Customer Support",
196
- * placeholder: "How can we help?"
387
+ * title: "Acme Support",
388
+ * greeting: "Hi there!",
389
+ * welcomeMessage: "Ask us anything.",
197
390
  * }}
198
391
  * />
199
392
  * ```
200
393
  */
201
- declare function ChannlizeChat({ config, position, offset, buttonElement, buttonIcon, buttonSize, buttonColors, chatProps, defaultOpen, showBadge, unreadCount, zIndex, showOnMobile, onOpen, onClose, enableAnimations, buttonClassName, chatClassName, }: ChannlizeChatProps): react_jsx_runtime.JSX.Element | null;
394
+ declare function ChannlizeChat({ config, position, offset, buttonElement, buttonIcon, buttonSize, buttonColors, chatProps, primaryColor, theme, defaultOpen, showBadge, unreadCount, zIndex, showOnMobile, onOpen, onClose, enableAnimations, buttonClassName, chatClassName, }: ChannlizeChatProps): react.JSX.Element | null;
202
395
 
203
- export { ChannlizeChat, ChannlizeProvider, ContactForm, SupportChat, useChannlize, useChatSession, useContactForm };
396
+ export { ChannlizeChat, ChannlizeProvider, ContactForm, SupportChat, defaultContactFormLabels, defaultSupportChatLabels, useChannlize, useChannlizeAnalytics, useChatSession, useContactForm };
397
+ export type { ChannlizeChatProps, ChatTheme, ContactFieldMode, ContactFormCustomField, ContactFormLabels, ContactFormProps, ContactFormTheme, ContactFormTopic, ContactFormValues, SupportChatLabels, SupportChatProps, UseChatSessionOptions, UseChatSessionReturn };