advanced-chat-kai 0.4.2 → 1.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 CHANGED
@@ -1,8 +1,7 @@
1
1
  # advanced-chat-kai
2
2
 
3
- ![light](https://github.com/user-attachments/assets/bbdadeda-b26f-4af5-9bb6-2c40ace765c7)
4
- ![dark](https://github.com/user-attachments/assets/34a4ce47-b7ba-43a6-a87c-c914c65e6523)
5
- ![custom](https://github.com/user-attachments/assets/7a9690b4-ce7c-4775-b937-82525e161f55)
3
+ <img alt="light" src="https://github.com/user-attachments/assets/2683a3ae-0419-4a35-ba3c-b5344750d5b6" />
4
+ <img alt="dark" src="https://github.com/user-attachments/assets/36d2fc3e-6f93-44ea-a3d2-f6137b9d0bd6" />
6
5
 
7
6
  ![npm version](https://img.shields.io/npm/v/advanced-chat-kai) ![npm downloads](https://img.shields.io/npm/dm/advanced-chat-kai) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/advanced-chat-kai) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) [![codecov](https://codecov.io/gh/spider-hand/advanced-chat-kai/graph/badge.svg?token=ETHZJ2CTPF)](https://codecov.io/gh/spider-hand/advanced-chat-kai)
8
7
 
@@ -25,7 +24,11 @@ A highly customizable Web Component for building chat interfaces
25
24
  | ------------------- | ---------------------- | -------------------------------- | ----------------------- | ------------------ |
26
25
  | `advanced-chat-kai` | 112.9kB | 23.2kB | 465ms | 27ms |
27
26
  | `vue-advanced-chat` | 493.4kB | 149.8kB | 3s | 171ms |
28
- | | 📦 **77% smaller** | 📦 **84% smaller** | ⚡️ **85% faster** | ⚡️ **84% faster** |
27
+ | | 📦 **77% smaller** | 📦 **84% smaller** | ⚡️ **85% faster** | ⚡️ **84% faster** |
28
+
29
+ ## Demo
30
+
31
+ Try it out [here](https://advanced-chat-kai-demo.pages.dev/).
29
32
 
30
33
  ## Table of contents
31
34
 
@@ -80,6 +83,7 @@ npm install advanced-chat-kai
80
83
  | `showTheirAvatar` | boolean | false | `true` | Whether the other user's avatar on the message should be rendered or not |
81
84
  | `alignMyMessagesLeft` | boolean | false | `false` | Whether my messages should be aligned to the left or not |
82
85
  | `enterToSend` | boolean | false | `false` | Whether the enter key should send the message or not |
86
+ | `timestampFormatter` | ((date: Date) => string) \| null | false | `null` | Custom function to format Date timestamps. If null, uses default Intl format |
83
87
  | `dialog` | [Dialog](#dialog) \| null | false | `null` | The dialog to be rendered |
84
88
  | `height` | string | false | `"60em"` | The height of the chat component |
85
89
  | `width` | string | false | `"80em"` | The width of the chat component |
@@ -120,6 +124,7 @@ rooms = [
120
124
  Notes:
121
125
 
122
126
  - `type` must be either `divider` or `message`.
127
+ - `timestamp` can be a string (displayed as-is) or a Date object (formatted using `timestampFormatter` or default Intl format).
123
128
  - `reactions` represents the emoji reactions and the list of user IDs who reacted with each emoji.
124
129
  - `isSelected` can be used to indicate that an action (such as editing) is currently active on the message.
125
130
 
@@ -141,11 +146,11 @@ messages = [
141
146
  senderName: "User 1",
142
147
  senderAvatar: "/avatar.png",
143
148
  content: "Hello, world",
144
- timestamp: "12:34 PM",
145
- reactions: new Map<string, Set<string>>([
146
- ["👍", new Set(["2", "3"])],
147
- ["🎉", new Set(["1", "4", "5"])],
148
- ]),
149
+ timestamp: "12:34 PM", // or new Date()
150
+ reactions: {
151
+ "👍": ["2", "3"],
152
+ "🎉": ["1", "4", "5"],
153
+ },
149
154
  attachments: [
150
155
  {
151
156
  name: "file1.txt",
@@ -207,20 +212,20 @@ chatMessageReply = {
207
212
  senderAvatar: "/avatar.png",
208
213
  content: "Hello, world",
209
214
  timestamp: "12:34 PM",
210
- reactions: new Map<string, Set<string>>([
211
- ["👍", new Set(["2", "3"])],
212
- ["🎉", new Set(["1", "4", "5"])],
213
- ]),
215
+ reactions: {
216
+ "👍": ["2", "3"],
217
+ "🎉": ["1", "4", "5"],
218
+ },
214
219
  attachments: [
215
220
  {
216
221
  name: "file1.txt",
217
222
  meta: "20 KB",
218
223
  id: "0",
219
- }
224
+ },
220
225
  ],
221
226
  isDeleted: false,
222
227
  isSelected: false,
223
- }
228
+ };
224
229
  ```
225
230
 
226
231
  ##### ChatAction
@@ -290,89 +295,119 @@ this.messages.push(newMessage);
290
295
 
291
296
  ## Events
292
297
 
293
- | Name | Detail / Payload | Fires when a user |
294
- | ----------------------- | ------------------------------------- | -------------------------------------------------- |
295
- | `add-room` | - | Clicked the add button on the sidebar |
296
- | `search-room` | `{ value }` | Changed the input on the searchbox |
297
- | `select-room-action` | `{ label, value, roomId }` | Selected an action on the room |
298
- | `load-more-rooms` | - | Reached the bottom of the room list |
299
- | `select-room` | `{ room }` | Selected a room in the list |
300
- | `load-more-messages` | - | Reached the top of the message list |
301
- | `select-message-action` | `{ label, value, messageId }` | Selected an action on the message |
302
- | `select-suggestion` | `{ suggestion }` | Selected a suggestion in the list |
303
- | `select-emoji` | `{ messageId, currentUserId, emoji }` | Selected an emoji reaction in picker for a message |
304
- | `reply-to-message` | `{ replyTo }` | Clicked the reply button on a message |
305
- | `click-reaction` | `{ messageId, reaction }` | Clicked an existing emoji reaction on a message |
306
- | `download-attachment` | `{ attachment }` | Clicked the download button on an attachment |
307
- | `remove-attachment` | `{ attachment }` | Clicked the close button on an attachment |
308
- | `cancel-reply` | - | Clicked the close button on the reply message |
309
- | `select-file` | `{ file }` | Selected a file |
310
- | `send-message` | `{ roomId, senderId, content }` | Clicked the send button on the footer |
311
- | `click-dialog-button` | `{ event, side }` | Clicked a button on a dialog |
298
+ | Name | Detail / Payload | Fires when a user |
299
+ | ----------------------- | ---------------------------------------- | ----------------------------------------------------------------------------- |
300
+ | `add-room` | - | Clicked the add button on the sidebar |
301
+ | `search-room` | `{ value }` | Changed the input on the searchbox |
302
+ | `select-room-action` | `{ label, value, roomId }` | Selected an action on the room |
303
+ | `load-more-rooms` | - | Reached the bottom of the room list |
304
+ | `select-room` | `{ room }` | Selected a room in the list |
305
+ | `load-more-messages` | - | Reached the top of the message list |
306
+ | `select-message-action` | `{ label, value, messageId }` | Selected an action on the message |
307
+ | `select-suggestion` | `{ suggestion }` | Selected a suggestion in the list |
308
+ | `select-emoji` | `{ messageId, currentUserId, emoji }` | Selected an emoji reaction in picker for a message |
309
+ | `reply-to-message` | `{ replyTo }` | Clicked the reply button on a message |
310
+ | `click-reaction` | `{ messageId, reaction }` | Clicked an existing emoji reaction on a message |
311
+ | `download-attachment` | `{ attachment }` | Clicked the download button on an attachment |
312
+ | `remove-attachment` | `{ attachment }` | Clicked the close button on an attachment |
313
+ | `cancel-reply` | - | Clicked the close button on the reply message, or sent a message with a reply |
314
+ | `select-file` | `{ file }` | Selected a file |
315
+ | `send-message` | `{ roomId, senderId, content, replyTo }` | Clicked the send button on the footer |
316
+ | `click-dialog-button` | `{ event, side }` | Clicked a button on a dialog |
312
317
 
313
318
  ## Styling
314
319
 
315
- The `--chat-surface-50` to `--chat-surface-950` variables define the primary surface color scale, used across light and dark themes for backgrounds and component surfaces.
316
-
317
- | Variable | Description |
318
- | -------------------------------------- | --------------------------------------------------- |
319
- | `--chat-base-font-size` | The base font size of the chat component |
320
- | `--chat-white` | |
321
- | `--chat-black` | |
322
- | `--chat-success` | |
323
- | `--chat-danger` | |
324
- | `--chat-warning` | |
325
- | `--chat-info` | |
326
- | `--chat-surface-50` | |
327
- | `--chat-surface-100` | |
328
- | `--chat-surface-200` | |
329
- | `--chat-surface-300` | |
330
- | `--chat-surface-400` | |
331
- | `--chat-surface-500` | |
332
- | `--chat-surface-600` | |
333
- | `--chat-surface-700` | |
334
- | `--chat-surface-800` | |
335
- | `--chat-surface-900` | |
336
- | `--chat-surface-950` | |
337
- | `--chat-text` | The default text color |
338
- | `--chat-subtext` | The default subtext color |
339
- | `--chat-border` | The default border color |
340
- | `--chat-floating-item-border` | The default border color for floating items |
341
- | `--chat-floating-item-box-shadow` | The default box shadow for floating items |
342
- | `--chat-placeholder` | The default placeholder color |
343
- | `--chat-deleted` | The default background color for deleted messages |
344
- | `--chat-overlay` | The default background color for overlay |
345
- | `--chat-notification-badge-background` | The default background color for notification badge |
346
- | `--chat-notification-badge-text` | The default text color for notification badge |
347
-
348
- Also, a minimal set of CSS variables is exposed specifically for applying brand colors to the key UI elements:
349
-
350
- | Variable | Description |
351
- | -------------------------------------- | ------------------------------------------------------------------- |
352
- | `--chat-send-button-bg` | The background color of the send button |
353
- | `--chat-send-button-bg-hover` | The background color of the send button on hover |
354
- | `--chat-my-message-bg` | The background color of my messages |
355
- | `--chat-my-message-bg-selected` | The background color of my messages when selected |
356
- | `--chat-my-reaction-list-bg` | The background color of the reaction list on my messages |
357
- | `--chat-my-reaction-button-bg` | The background color of the reaction button on my messages |
358
- | `--chat-my-reaction-button-bg-hover` | The background color of the reaction button on my messages on hover |
359
- | `--chat-suggestion-list-item-bg` | The background color of the suggestion list item |
360
- | `--chat-suggestion-list-item-bg-hover` | The background color of the suggestion list item on hover |
361
- | `--chat-my-message-menu-bg` | The background color of the message menu on my messages |
362
- | `--chat-my-message-button-bg-hover` | The background color of the message button on my messages on hover |
363
- | `--chat-my-attachment-bg` | The background color of the attachment on my messages |
364
- | `--chat-my-attachment-bg-hover` | The background color of the attachment on my messages on hover |
365
- | `--chat-text-on-brand` | The text color on brand colors |
366
- | `--chat-subtext-on-brand` | The subtext color on brand colors |
320
+ CSS variable names are based on the [shadcn](https://ui.shadcn.com/docs/theming) design system and [Tailwind CSS](https://tailwindcss.com/docs/customizing-spacing) spacing/typography scale, prefixed with `--chat-`. You can override these variables to customize the appearance of the chat component.
321
+
322
+ ### Color Variables
323
+
324
+ | Variable |
325
+ | ------------------------------- |
326
+ | `--chat-background` |
327
+ | `--chat-foreground` |
328
+ | `--chat-card` |
329
+ | `--chat-card-foreground` |
330
+ | `--chat-popover` |
331
+ | `--chat-popover-foreground` |
332
+ | `--chat-primary` |
333
+ | `--chat-primary-foreground` |
334
+ | `--chat-secondary` |
335
+ | `--chat-secondary-foreground` |
336
+ | `--chat-muted` |
337
+ | `--chat-muted-foreground` |
338
+ | `--chat-accent` |
339
+ | `--chat-accent-foreground` |
340
+ | `--chat-destructive` |
341
+ | `--chat-destructive-foreground` |
342
+ | `--chat-border` |
343
+ | `--chat-input` |
344
+ | `--chat-ring` |
345
+
346
+ ### Font Size Variables
347
+
348
+ | Variable | Default |
349
+ | ------------------ | ----------- |
350
+ | `--chat-text-xs` | `0.75rem` |
351
+ | `--chat-text-sm` | `0.875rem` |
352
+ | `--chat-text-base` | `1rem` |
353
+ | `--chat-text-lg` | `1.125rem` |
354
+ | `--chat-text-xl` | `1.25rem` |
355
+
356
+ ### Border Radius Variables
357
+
358
+ | Variable | Default |
359
+ | -------------------- | --------- |
360
+ | `--chat-radius-sm` | `0.125rem` |
361
+ | `--chat-radius` | `0.25rem` |
362
+ | `--chat-radius-md` | `0.375rem` |
363
+ | `--chat-radius-lg` | `0.5rem` |
364
+ | `--chat-radius-xl` | `0.75rem` |
365
+ | `--chat-radius-2xl` | `1rem` |
366
+ | `--chat-radius-3xl` | `1.5rem` |
367
+ | `--chat-radius-full` | `9999px` |
368
+
369
+ ### Spacing Variables
370
+
371
+ | Variable | Default |
372
+ | -------------------- | ---------- |
373
+ | `--chat-spacing-0` | `0` |
374
+ | `--chat-spacing-0-5` | `0.125rem` |
375
+ | `--chat-spacing-1` | `0.25rem` |
376
+ | `--chat-spacing-1-5` | `0.375rem` |
377
+ | `--chat-spacing-2` | `0.5rem` |
378
+ | `--chat-spacing-2-5` | `0.625rem` |
379
+ | `--chat-spacing-3` | `0.75rem` |
380
+ | `--chat-spacing-4` | `1rem` |
381
+ | `--chat-spacing-5` | `1.25rem` |
382
+ | `--chat-spacing-6` | `1.5rem` |
383
+ | `--chat-spacing-8` | `2rem` |
384
+
385
+ ### Custom Variables
386
+
387
+ | Variable | Description |
388
+ | -------------------------------- | ---------------------------------------- |
389
+ | `--chat-base-font-size` | The base font size of the chat component |
390
+ | `--chat-message-mine` | The background color of my messages |
391
+ | `--chat-message-mine-foreground` | The text/icon color on my messages |
392
+ | `--chat-success` | The background color of success badge |
393
+ | `--chat-success-foreground` | The text color on success badge |
394
+ | `--chat-danger` | The background color of danger badge |
395
+ | `--chat-danger-foreground` | The text color on danger badge |
396
+ | `--chat-warning` | The background color of warning badge |
397
+ | `--chat-warning-foreground` | The text color on warning badge |
398
+ | `--chat-info` | The background color of info badge |
399
+ | `--chat-info-foreground` | The text color on info badge |
400
+
401
+ ### Usage
367
402
 
368
403
  You can override the component's style using CSS custom properties (variables). These are applied directly to `advanced-chat-kai` element:
369
404
 
370
405
  ```css
371
406
  advanced-chat-kai {
372
- --chat-success: green;
373
- --chat-danger: red;
374
- --chat-warning: yellow;
375
- --chat-info: blue;
407
+ --chat-primary: oklch(0.65 0.24 15);
408
+ --chat-primary-foreground: oklch(1 0 0);
409
+ --chat-message-mine: oklch(0.65 0.24 15);
410
+ --chat-message-mine-foreground: oklch(1 0 0);
376
411
  }
377
412
  ```
378
413