@banbox/chat 1.0.13 → 1.0.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@banbox/chat",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Banbox Chat UI components — reusable across all Banbox React/Next.js projects",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -49,6 +49,16 @@ function toRef(m: Message): MessageRef {
49
49
  };
50
50
  }
51
51
 
52
+ /** Maps the first letter of a name to a deterministic background colour. */
53
+ const avatarBgByInitial: Record<string, string> = {
54
+ a: "#FFE4E4", b: "#E4F0FF", c: "#E4FFE9", d: "#FFF4E4", e: "#F4E4FF",
55
+ f: "#FFE4F4", g: "#E4FFFF", h: "#FFFFE4", i: "#E4E4FF", j: "#FFE9E4",
56
+ k: "#E4FFE4", l: "#FFE4EA", m: "#E8E4FF", n: "#E4F8FF", o: "#FFF0E4",
57
+ p: "#F0FFE4", q: "#FFE4F8", r: "#E4FFEC", s: "#FFEEE4", t: "#E4EAFF",
58
+ u: "#F8FFE4", v: "#FFE4EE", w: "#E4FFFA", x: "#FFF8E4", y: "#EAE4FF",
59
+ z: "#E4FFF0",
60
+ };
61
+
52
62
 
53
63
 
54
64
  export type SinglePopupProps = {
@@ -95,12 +105,26 @@ const SinglePopup: React.FC<SinglePopupProps> = ({ adapter, uiCallbacks, theme,
95
105
  title?: string;
96
106
  online?: boolean;
97
107
  subtitle?: string;
108
+ avatarSrc?: string;
98
109
  };
99
110
 
100
- const initialSrc = activeThread?.avatarSrc ?? "/shop/ban-box.png";
111
+ // ── Avatar resolution (priority: meta > thread) ──────────────────────
112
+ // If there is no src, fall through to the initial-letter avatar instead
113
+ // of rendering a broken image (never hardcode a host-app-specific path).
114
+ const avatarSrc: string | undefined =
115
+ meta.avatarSrc ?? activeThread?.avatarSrc;
116
+
117
+ const initial = (
118
+ meta.initial ??
119
+ activeThread?.avatarText ??
120
+ (activeThread?.title ?? meta.title ?? "?").charAt(0).toUpperCase()
121
+ );
122
+ const avatarBg =
123
+ avatarBgByInitial[initial.toLowerCase()] ?? "#E4F0FF";
124
+
101
125
  const title = meta.title ?? activeThread?.title ?? "Unknown";
102
- const online = meta.online ?? activeThread?.online ?? true;
103
- const subtitle = meta.subtitle ?? "Customer";
126
+ const online = meta.online ?? activeThread?.online ?? false;
127
+ const subtitle = meta.subtitle ?? activeThread?.subTitle ?? "Customer";
104
128
 
105
129
  const [messages, setMessages] = React.useState<Message[]>(() =>
106
130
  activeId ? adapter.messages.list(activeId) : [],
@@ -175,15 +199,28 @@ const SinglePopup: React.FC<SinglePopupProps> = ({ adapter, uiCallbacks, theme,
175
199
  <div className="h-[64px] shrink-0">
176
200
  <ChatHeader
177
201
  left={
178
- <ChatIdentity
179
- variant="avatar"
180
- src={initialSrc}
181
- online={online}
182
- title={title}
183
- subtitle={subtitle}
184
- verified={isVerified}
185
- subtitleVariant="muted"
186
- />
202
+ avatarSrc ? (
203
+ <ChatIdentity
204
+ variant="avatar"
205
+ src={avatarSrc}
206
+ online={online}
207
+ title={title}
208
+ subtitle={subtitle}
209
+ verified={isVerified}
210
+ subtitleVariant="muted"
211
+ />
212
+ ) : (
213
+ <ChatIdentity
214
+ variant="initial"
215
+ initial={initial}
216
+ bg={avatarBg}
217
+ online={online}
218
+ title={title}
219
+ subtitle={subtitle}
220
+ verified={isVerified}
221
+ subtitleVariant="muted"
222
+ />
223
+ )
187
224
  }
188
225
  right={
189
226
  <div className="flex items-center gap-1">