@progress/kendo-react-conversational-ui
Version:
React Chat component allows the user to participate in chat sessions with users or chat bots. KendoReact Conversational UI components
89 lines (88 loc) • 2.86 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
import * as e from "react";
import { classNames as G } from "@progress/kendo-react-common";
import { Avatar as L } from "@progress/kendo-react-layout";
import R from "./Attachment.mjs";
import { isAuthor as k } from "../utils.mjs";
import { useLocalization as b } from "@progress/kendo-react-intl";
import { avatarAlt as M, messages as z } from "../../messages/index.mjs";
const B = (x) => {
const {
group: a,
user: s,
itemTemplate: n,
attachmentTemplate: m,
onRequestSelection: l,
selectedItemIndex: c,
isLastGroup: i,
message: u,
allowMessageCollapse: g,
messageToolbarActions: p,
messageContextMenuActions: d,
messageWidthMode: h = "standard"
} = x, E = b(), r = a.messages.length > 0 && k(s, a.messages[0]), o = !r, I = e.useMemo(
() => G("k-message-group", {
"k-message-group-sender k-no-avatar": r,
"k-message-group-receiver": o,
"k-message-group-full-width": h === "full"
}),
[r, o, h]
), S = () => {
if (!(!o || !f))
return /* @__PURE__ */ e.createElement(L, { type: "image" }, /* @__PURE__ */ e.createElement("img", { src: f, alt: T }));
}, N = e.useMemo(() => {
const w = a.messages.length - 1;
return a.messages.map((t, y) => {
const A = [
/* @__PURE__ */ e.createElement(
u,
{
item: t,
template: n,
selected: t.selectionIndex === c,
onRequestSelection: l,
tabIndex: y === w && i ? 0 : -1,
key: t.id,
allowMessageCollapse: g,
messageToolbarActions: p,
messageContextMenuActions: d,
isSender: k(s, t)
}
)
];
return t.attachments && t.attachments.length === 1 && A.push(
/* @__PURE__ */ e.createElement(
R,
{
item: t.attachments[0],
template: m,
selected: !1,
key: `att-${t.attachments[0].content}`
}
)
), A;
});
}, [
a.messages,
u,
n,
c,
l,
i,
g,
p,
d,
s,
m
]), { avatarUrl: f, avatarAltText: v, name: C } = a.author, T = v !== void 0 ? v : E.toLanguageString(M, z[M]);
return /* @__PURE__ */ e.createElement("div", { className: I }, S(), /* @__PURE__ */ e.createElement("div", { className: "k-message-group-content" }, /* @__PURE__ */ e.createElement("span", { className: "k-message-author" }, C), N));
};
export {
B as default
};