UNPKG

@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

10 lines (9 loc) 2.26 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),P=require("@progress/kendo-react-buttons"),r=require("@progress/kendo-react-inputs"),c=require("@progress/kendo-svg-icons"),u=require("@progress/kendo-react-common"),G=({placeholder:S="Ask or generate content with AI...",promptValue:v,onMenuClick:B,promptInput:h=r.TextArea,generateButton:A,enableSpeechToText:s=!1,streaming:e=!1,commands:i,onPromptRequest:m,onPromptCancel:E})=>{const[o,p]=t.useState(v||""),[y,d]=u.useCustomComponent(A),[x,f]=u.useCustomComponent(h),b={svgIcon:e?c.stopSmIcon:c.paperPlaneIcon,active:(!!e).toString(),title:"Send Button","aria-label":"Send Button",disabled:!o.trim()&&!e,"aria-disabled":!o.trim()&&!e},w={placeholder:S,className:"!k-flex-row",autoSize:!0,rows:1},I=i&&i.length>0,R=Object.keys(d).length>0?d:b,N=Object.keys(f).length>0?f:w,k=n=>{const{isFinal:l,alternatives:C}=n;if(l&&C.length>0){const q=C[0].transcript,M=(()=>{const a=o,V=a&&!a.endsWith(" ")&&!a.endsWith(` `);return a+(V?" ":"")+q})();p(M)}},j=n=>{const l=n.target.value;p(l)},g=()=>{o.trim()&&m&&m(o.trim())};return t.createElement(x,{value:o,onChange:j,onKeyDown:n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),g())},prefix:I||s?t.createElement(t.Fragment,null,t.createElement(r.InputPrefix,{className:"!k-align-items-start"},I&&t.createElement(P.Button,{"aria-label":"Commands Button",title:"Commands Button",fillMode:"flat",svgIcon:c.menuIcon,onClick:B}),s&&t.createElement(P.SpeechToTextButton,{fillMode:"flat",...typeof s=="object"?{...s,onResult:s.onResult||k}:{onResult:k}})),t.createElement(r.InputSeparator,null)):void 0,suffix:t.createElement(r.InputSuffix,{className:"!k-align-items-start"},t.createElement(y,{className:u.classNames("k-prompt-send",{"k-generating":e,"k-active":e}),fillMode:"flat",onClick:e?E:g,...R})),...N})};exports.InlineAIPromptInput=G;