@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
92 lines (91 loc) • 2.62 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 t from "react";
import { classNames as m } from "@progress/kendo-react-common";
import { ScrollButtonsWrapper as R } from "./ScrollButtonsWrapper.mjs";
import { useScrollWithButtons as E } from "../hooks/useScrollWithButtons.mjs";
const w = (b) => {
const {
suggestions: r,
onSuggestionClick: l,
suggestionsView: o,
suggestionTemplate: s,
suggestionsLayout: a,
dir: n
} = b, i = t.useRef(null), { canScrollLeft: u, canScrollRight: f, scrollLeft: k, scrollRight: y } = E(i, {
enabled: a === "scrollbuttons",
dir: n,
itemsDependency: r
}), d = t.useCallback(
(e, c) => {
(e.key === "Enter" || e.key === " ") && (e.preventDefault(), l == null || l(c));
},
[l]
), p = t.useCallback(
() => r.map(
(e) => s ? /* @__PURE__ */ t.createElement(
s,
{
key: e.id,
suggestion: e,
onClick: () => {
l == null || l(e);
}
}
) : /* @__PURE__ */ t.createElement(
"span",
{
role: "button",
tabIndex: e.disabled ? -1 : 0,
"aria-label": e.description,
"aria-disabled": e.disabled,
onClick: () => !e.disabled && (l == null ? void 0 : l(e)),
onKeyDown: (c) => !e.disabled && d(c, e),
key: e.id,
title: e.description,
className: m(o === "classic" ? "k-prompt-suggestion" : "k-suggestion", {
"k-disabled": e.disabled
})
},
e.text
)
),
[r, s, l, o, d]
);
if (!r || r.length === 0)
return null;
if (o === "classic")
return p();
const h = /* @__PURE__ */ t.createElement(
"div",
{
role: "group",
className: m("k-suggestion-group", {
// Apply scrollable class when layout is 'scroll' (default for Chat component)
"k-suggestion-group-scrollable": a === "scroll"
}),
ref: a === "scrollbuttons" ? i : void 0
},
p()
);
return /* @__PURE__ */ t.createElement(
R,
{
visible: a === "scrollbuttons",
dir: n,
canScrollLeft: u,
canScrollRight: f,
onScrollLeft: k,
onScrollRight: y
},
h
);
};
export {
w as SuggestionGroup
};