@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/dist/index.cjs +47 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +47 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/chat/SinglePopup.tsx +49 -12
package/package.json
CHANGED
package/src/chat/SinglePopup.tsx
CHANGED
|
@@ -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
|
-
|
|
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 ??
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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">
|