chat.tsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. import { useDebouncedCallback } from "use-debounce";
  2. import { memo, useState, useRef, useEffect, useLayoutEffect } from "react";
  3. import SendWhiteIcon from "../icons/send-white.svg";
  4. import BrainIcon from "../icons/brain.svg";
  5. import RenameIcon from "../icons/rename.svg";
  6. import ExportIcon from "../icons/share.svg";
  7. import ReturnIcon from "../icons/return.svg";
  8. import CopyIcon from "../icons/copy.svg";
  9. import DownloadIcon from "../icons/download.svg";
  10. import LoadingIcon from "../icons/three-dots.svg";
  11. import AddIcon from "../icons/add.svg";
  12. import DeleteIcon from "../icons/delete.svg";
  13. import MaxIcon from "../icons/max.svg";
  14. import MinIcon from "../icons/min.svg";
  15. import LightIcon from "../icons/light.svg";
  16. import DarkIcon from "../icons/dark.svg";
  17. import AutoIcon from "../icons/auto.svg";
  18. import BottomIcon from "../icons/bottom.svg";
  19. import StopIcon from "../icons/pause.svg";
  20. import {
  21. Message,
  22. SubmitKey,
  23. useChatStore,
  24. BOT_HELLO,
  25. ROLES,
  26. createMessage,
  27. useAccessStore,
  28. Theme,
  29. useAppConfig,
  30. ModelConfig,
  31. DEFAULT_TOPIC,
  32. } from "../store";
  33. import {
  34. copyToClipboard,
  35. downloadAs,
  36. selectOrCopy,
  37. autoGrowTextArea,
  38. useMobileScreen,
  39. } from "../utils";
  40. import dynamic from "next/dynamic";
  41. import { ControllerPool } from "../requests";
  42. import { Prompt, usePromptStore } from "../store/prompt";
  43. import Locale from "../locales";
  44. import { IconButton } from "./button";
  45. import styles from "./home.module.scss";
  46. import chatStyle from "./chat.module.scss";
  47. import { Input, List, ListItem, Modal, Popover, showModal } from "./ui-lib";
  48. import { useNavigate } from "react-router-dom";
  49. import { Path } from "../constant";
  50. import { ModelConfigList } from "./model-config";
  51. import { Avatar, AvatarPicker } from "./emoji";
  52. import { MaskConfig } from "./mask";
  53. import { DEFAULT_MASK_ID } from "../store/mask";
  54. const Markdown = dynamic(
  55. async () => memo((await import("./markdown")).Markdown),
  56. {
  57. loading: () => <LoadingIcon />,
  58. },
  59. );
  60. function exportMessages(messages: Message[], topic: string) {
  61. const mdText =
  62. `# ${topic}\n\n` +
  63. messages
  64. .map((m) => {
  65. return m.role === "user"
  66. ? `## ${Locale.Export.MessageFromYou}:\n${m.content}`
  67. : `## ${Locale.Export.MessageFromChatGPT}:\n${m.content.trim()}`;
  68. })
  69. .join("\n\n");
  70. const filename = `${topic}.md`;
  71. showModal({
  72. title: Locale.Export.Title,
  73. children: (
  74. <div className="markdown-body">
  75. <pre className={styles["export-content"]}>{mdText}</pre>
  76. </div>
  77. ),
  78. actions: [
  79. <IconButton
  80. key="copy"
  81. icon={<CopyIcon />}
  82. bordered
  83. text={Locale.Export.Copy}
  84. onClick={() => copyToClipboard(mdText)}
  85. />,
  86. <IconButton
  87. key="download"
  88. icon={<DownloadIcon />}
  89. bordered
  90. text={Locale.Export.Download}
  91. onClick={() => downloadAs(mdText, filename)}
  92. />,
  93. ],
  94. });
  95. }
  96. export function SessionConfigModel(props: { onClose: () => void }) {
  97. const chatStore = useChatStore();
  98. const session = chatStore.currentSession();
  99. return (
  100. <div className="modal-mask">
  101. <Modal
  102. title={Locale.Context.Edit}
  103. onClose={() => props.onClose()}
  104. actions={[
  105. <IconButton
  106. key="reset"
  107. icon={<CopyIcon />}
  108. bordered
  109. text="重置"
  110. onClick={() =>
  111. confirm(Locale.Memory.ResetConfirm) && chatStore.resetSession()
  112. }
  113. />,
  114. <IconButton
  115. key="copy"
  116. icon={<CopyIcon />}
  117. bordered
  118. text="保存为面具"
  119. onClick={() => copyToClipboard(session.memoryPrompt)}
  120. />,
  121. ]}
  122. >
  123. <MaskConfig
  124. mask={session.mask}
  125. updateMask={(updater) => {
  126. const mask = { ...session.mask };
  127. updater(mask);
  128. chatStore.updateCurrentSession((session) => (session.mask = mask));
  129. }}
  130. extraListItems={
  131. session.mask.modelConfig.sendMemory ? (
  132. <ListItem
  133. title={`${Locale.Memory.Title} (${session.lastSummarizeIndex} of ${session.messages.length})`}
  134. subTitle={session.memoryPrompt || Locale.Memory.EmptyContent}
  135. ></ListItem>
  136. ) : (
  137. <></>
  138. )
  139. }
  140. ></MaskConfig>
  141. </Modal>
  142. </div>
  143. );
  144. }
  145. function PromptToast(props: {
  146. showToast?: boolean;
  147. showModal?: boolean;
  148. setShowModal: (_: boolean) => void;
  149. }) {
  150. const chatStore = useChatStore();
  151. const session = chatStore.currentSession();
  152. const context = session.mask.context;
  153. return (
  154. <div className={chatStyle["prompt-toast"]} key="prompt-toast">
  155. {props.showToast && (
  156. <div
  157. className={chatStyle["prompt-toast-inner"] + " clickable"}
  158. role="button"
  159. onClick={() => props.setShowModal(true)}
  160. >
  161. <BrainIcon />
  162. <span className={chatStyle["prompt-toast-content"]}>
  163. {Locale.Context.Toast(context.length)}
  164. </span>
  165. </div>
  166. )}
  167. {props.showModal && (
  168. <SessionConfigModel onClose={() => props.setShowModal(false)} />
  169. )}
  170. </div>
  171. );
  172. }
  173. function useSubmitHandler() {
  174. const config = useAppConfig();
  175. const submitKey = config.submitKey;
  176. const shouldSubmit = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
  177. if (e.key !== "Enter") return false;
  178. if (e.key === "Enter" && e.nativeEvent.isComposing) return false;
  179. return (
  180. (config.submitKey === SubmitKey.AltEnter && e.altKey) ||
  181. (config.submitKey === SubmitKey.CtrlEnter && e.ctrlKey) ||
  182. (config.submitKey === SubmitKey.ShiftEnter && e.shiftKey) ||
  183. (config.submitKey === SubmitKey.MetaEnter && e.metaKey) ||
  184. (config.submitKey === SubmitKey.Enter &&
  185. !e.altKey &&
  186. !e.ctrlKey &&
  187. !e.shiftKey &&
  188. !e.metaKey)
  189. );
  190. };
  191. return {
  192. submitKey,
  193. shouldSubmit,
  194. };
  195. }
  196. export function PromptHints(props: {
  197. prompts: Prompt[];
  198. onPromptSelect: (prompt: Prompt) => void;
  199. }) {
  200. if (props.prompts.length === 0) return null;
  201. return (
  202. <div className={styles["prompt-hints"]}>
  203. {props.prompts.map((prompt, i) => (
  204. <div
  205. className={styles["prompt-hint"]}
  206. key={prompt.title + i.toString()}
  207. onClick={() => props.onPromptSelect(prompt)}
  208. >
  209. <div className={styles["hint-title"]}>{prompt.title}</div>
  210. <div className={styles["hint-content"]}>{prompt.content}</div>
  211. </div>
  212. ))}
  213. </div>
  214. );
  215. }
  216. function useScrollToBottom() {
  217. // for auto-scroll
  218. const scrollRef = useRef<HTMLDivElement>(null);
  219. const [autoScroll, setAutoScroll] = useState(true);
  220. const scrollToBottom = () => {
  221. const dom = scrollRef.current;
  222. if (dom) {
  223. setTimeout(() => (dom.scrollTop = dom.scrollHeight), 1);
  224. }
  225. };
  226. // auto scroll
  227. useLayoutEffect(() => {
  228. autoScroll && scrollToBottom();
  229. });
  230. return {
  231. scrollRef,
  232. autoScroll,
  233. setAutoScroll,
  234. scrollToBottom,
  235. };
  236. }
  237. export function ChatActions(props: {
  238. showPromptModal: () => void;
  239. scrollToBottom: () => void;
  240. hitBottom: boolean;
  241. }) {
  242. const config = useAppConfig();
  243. // switch themes
  244. const theme = config.theme;
  245. function nextTheme() {
  246. const themes = [Theme.Auto, Theme.Light, Theme.Dark];
  247. const themeIndex = themes.indexOf(theme);
  248. const nextIndex = (themeIndex + 1) % themes.length;
  249. const nextTheme = themes[nextIndex];
  250. config.update((config) => (config.theme = nextTheme));
  251. }
  252. // stop all responses
  253. const couldStop = ControllerPool.hasPending();
  254. const stopAll = () => ControllerPool.stopAll();
  255. return (
  256. <div className={chatStyle["chat-input-actions"]}>
  257. {couldStop && (
  258. <div
  259. className={`${chatStyle["chat-input-action"]} clickable`}
  260. onClick={stopAll}
  261. >
  262. <StopIcon />
  263. </div>
  264. )}
  265. {!props.hitBottom && (
  266. <div
  267. className={`${chatStyle["chat-input-action"]} clickable`}
  268. onClick={props.scrollToBottom}
  269. >
  270. <BottomIcon />
  271. </div>
  272. )}
  273. {props.hitBottom && (
  274. <div
  275. className={`${chatStyle["chat-input-action"]} clickable`}
  276. onClick={props.showPromptModal}
  277. >
  278. <BrainIcon />
  279. </div>
  280. )}
  281. <div
  282. className={`${chatStyle["chat-input-action"]} clickable`}
  283. onClick={nextTheme}
  284. >
  285. {theme === Theme.Auto ? (
  286. <AutoIcon />
  287. ) : theme === Theme.Light ? (
  288. <LightIcon />
  289. ) : theme === Theme.Dark ? (
  290. <DarkIcon />
  291. ) : null}
  292. </div>
  293. </div>
  294. );
  295. }
  296. export function Chat() {
  297. type RenderMessage = Message & { preview?: boolean };
  298. const chatStore = useChatStore();
  299. const [session, sessionIndex] = useChatStore((state) => [
  300. state.currentSession(),
  301. state.currentSessionIndex,
  302. ]);
  303. const config = useAppConfig();
  304. const fontSize = config.fontSize;
  305. const inputRef = useRef<HTMLTextAreaElement>(null);
  306. const [userInput, setUserInput] = useState("");
  307. const [beforeInput, setBeforeInput] = useState("");
  308. const [isLoading, setIsLoading] = useState(false);
  309. const { submitKey, shouldSubmit } = useSubmitHandler();
  310. const { scrollRef, setAutoScroll, scrollToBottom } = useScrollToBottom();
  311. const [hitBottom, setHitBottom] = useState(false);
  312. const isMobileScreen = useMobileScreen();
  313. const navigate = useNavigate();
  314. const onChatBodyScroll = (e: HTMLElement) => {
  315. const isTouchBottom = e.scrollTop + e.clientHeight >= e.scrollHeight - 20;
  316. setHitBottom(isTouchBottom);
  317. };
  318. // prompt hints
  319. const promptStore = usePromptStore();
  320. const [promptHints, setPromptHints] = useState<Prompt[]>([]);
  321. const onSearch = useDebouncedCallback(
  322. (text: string) => {
  323. setPromptHints(promptStore.search(text));
  324. },
  325. 100,
  326. { leading: true, trailing: true },
  327. );
  328. const onPromptSelect = (prompt: Prompt) => {
  329. setUserInput(prompt.content);
  330. setPromptHints([]);
  331. inputRef.current?.focus();
  332. };
  333. // auto grow input
  334. const [inputRows, setInputRows] = useState(2);
  335. const measure = useDebouncedCallback(
  336. () => {
  337. const rows = inputRef.current ? autoGrowTextArea(inputRef.current) : 1;
  338. const inputRows = Math.min(
  339. 5,
  340. Math.max(2 + Number(!isMobileScreen), rows),
  341. );
  342. setInputRows(inputRows);
  343. },
  344. 100,
  345. {
  346. leading: true,
  347. trailing: true,
  348. },
  349. );
  350. // eslint-disable-next-line react-hooks/exhaustive-deps
  351. useEffect(measure, [userInput]);
  352. // only search prompts when user input is short
  353. const SEARCH_TEXT_LIMIT = 30;
  354. const onInput = (text: string) => {
  355. setUserInput(text);
  356. const n = text.trim().length;
  357. // clear search results
  358. if (n === 0) {
  359. setPromptHints([]);
  360. } else if (!config.disablePromptHint && n < SEARCH_TEXT_LIMIT) {
  361. // check if need to trigger auto completion
  362. if (text.startsWith("/")) {
  363. let searchText = text.slice(1);
  364. onSearch(searchText);
  365. }
  366. }
  367. };
  368. // submit user input
  369. const onUserSubmit = () => {
  370. if (userInput.length <= 0) return;
  371. setIsLoading(true);
  372. chatStore.onUserInput(userInput).then(() => setIsLoading(false));
  373. setBeforeInput(userInput);
  374. setUserInput("");
  375. setPromptHints([]);
  376. if (!isMobileScreen) inputRef.current?.focus();
  377. setAutoScroll(true);
  378. };
  379. // stop response
  380. const onUserStop = (messageId: number) => {
  381. ControllerPool.stop(sessionIndex, messageId);
  382. };
  383. // check if should send message
  384. const onInputKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
  385. // if ArrowUp and no userInput
  386. if (e.key === "ArrowUp" && userInput.length <= 0) {
  387. setUserInput(beforeInput);
  388. e.preventDefault();
  389. return;
  390. }
  391. if (shouldSubmit(e)) {
  392. onUserSubmit();
  393. e.preventDefault();
  394. }
  395. };
  396. const onRightClick = (e: any, message: Message) => {
  397. // auto fill user input
  398. if (message.role === "user") {
  399. setUserInput(message.content);
  400. }
  401. // copy to clipboard
  402. if (selectOrCopy(e.currentTarget, message.content)) {
  403. e.preventDefault();
  404. }
  405. };
  406. const findLastUesrIndex = (messageId: number) => {
  407. // find last user input message and resend
  408. let lastUserMessageIndex: number | null = null;
  409. for (let i = 0; i < session.messages.length; i += 1) {
  410. const message = session.messages[i];
  411. if (message.id === messageId) {
  412. break;
  413. }
  414. if (message.role === "user") {
  415. lastUserMessageIndex = i;
  416. }
  417. }
  418. return lastUserMessageIndex;
  419. };
  420. const deleteMessage = (userIndex: number) => {
  421. chatStore.updateCurrentSession((session) =>
  422. session.messages.splice(userIndex, 2),
  423. );
  424. };
  425. const onDelete = (botMessageId: number) => {
  426. const userIndex = findLastUesrIndex(botMessageId);
  427. if (userIndex === null) return;
  428. deleteMessage(userIndex);
  429. };
  430. const onResend = (botMessageId: number) => {
  431. // find last user input message and resend
  432. const userIndex = findLastUesrIndex(botMessageId);
  433. if (userIndex === null) return;
  434. setIsLoading(true);
  435. const content = session.messages[userIndex].content;
  436. deleteMessage(userIndex);
  437. chatStore.onUserInput(content).then(() => setIsLoading(false));
  438. inputRef.current?.focus();
  439. };
  440. const context: RenderMessage[] = session.mask.context.slice();
  441. const accessStore = useAccessStore();
  442. if (
  443. context.length === 0 &&
  444. session.messages.at(0)?.content !== BOT_HELLO.content
  445. ) {
  446. const copiedHello = Object.assign({}, BOT_HELLO);
  447. if (!accessStore.isAuthorized()) {
  448. copiedHello.content = Locale.Error.Unauthorized;
  449. }
  450. context.push(copiedHello);
  451. }
  452. // preview messages
  453. const messages = context
  454. .concat(session.messages as RenderMessage[])
  455. .concat(
  456. isLoading
  457. ? [
  458. {
  459. ...createMessage({
  460. role: "assistant",
  461. content: "……",
  462. }),
  463. preview: true,
  464. },
  465. ]
  466. : [],
  467. )
  468. .concat(
  469. userInput.length > 0 && config.sendPreviewBubble
  470. ? [
  471. {
  472. ...createMessage({
  473. role: "user",
  474. content: userInput,
  475. }),
  476. preview: true,
  477. },
  478. ]
  479. : [],
  480. );
  481. const [showPromptModal, setShowPromptModal] = useState(false);
  482. const renameSession = () => {
  483. const newTopic = prompt(Locale.Chat.Rename, session.topic);
  484. if (newTopic && newTopic !== session.topic) {
  485. chatStore.updateCurrentSession((session) => (session.topic = newTopic!));
  486. }
  487. };
  488. // Auto focus
  489. useEffect(() => {
  490. if (isMobileScreen) return;
  491. inputRef.current?.focus();
  492. // eslint-disable-next-line react-hooks/exhaustive-deps
  493. }, []);
  494. return (
  495. <div className={styles.chat} key={session.id}>
  496. <div className="window-header">
  497. <div className="window-header-title">
  498. <div
  499. className={`window-header-main-title " ${styles["chat-body-title"]}`}
  500. onClickCapture={renameSession}
  501. >
  502. {!session.topic ? DEFAULT_TOPIC : session.topic}
  503. </div>
  504. <div className="window-header-sub-title">
  505. {Locale.Chat.SubTitle(session.messages.length)}
  506. </div>
  507. </div>
  508. <div className="window-actions">
  509. <div className={"window-action-button" + " " + styles.mobile}>
  510. <IconButton
  511. icon={<ReturnIcon />}
  512. bordered
  513. title={Locale.Chat.Actions.ChatList}
  514. onClick={() => navigate(Path.Home)}
  515. />
  516. </div>
  517. <div className="window-action-button">
  518. <IconButton
  519. icon={<RenameIcon />}
  520. bordered
  521. onClick={renameSession}
  522. />
  523. </div>
  524. <div className="window-action-button">
  525. <IconButton
  526. icon={<ExportIcon />}
  527. bordered
  528. title={Locale.Chat.Actions.Export}
  529. onClick={() => {
  530. exportMessages(
  531. session.messages.filter((msg) => !msg.isError),
  532. session.topic,
  533. );
  534. }}
  535. />
  536. </div>
  537. {!isMobileScreen && (
  538. <div className="window-action-button">
  539. <IconButton
  540. icon={config.tightBorder ? <MinIcon /> : <MaxIcon />}
  541. bordered
  542. onClick={() => {
  543. config.update(
  544. (config) => (config.tightBorder = !config.tightBorder),
  545. );
  546. }}
  547. />
  548. </div>
  549. )}
  550. </div>
  551. <PromptToast
  552. showToast={!hitBottom}
  553. showModal={showPromptModal}
  554. setShowModal={setShowPromptModal}
  555. />
  556. </div>
  557. <div
  558. className={styles["chat-body"]}
  559. ref={scrollRef}
  560. onScroll={(e) => onChatBodyScroll(e.currentTarget)}
  561. onMouseDown={() => inputRef.current?.blur()}
  562. onWheel={(e) => setAutoScroll(hitBottom && e.deltaY > 0)}
  563. onTouchStart={() => {
  564. inputRef.current?.blur();
  565. setAutoScroll(false);
  566. }}
  567. >
  568. {messages.map((message, i) => {
  569. const isUser = message.role === "user";
  570. const showActions =
  571. !isUser &&
  572. i > 0 &&
  573. !(message.preview || message.content.length === 0);
  574. const showTyping = message.preview || message.streaming;
  575. return (
  576. <div
  577. key={i}
  578. className={
  579. isUser ? styles["chat-message-user"] : styles["chat-message"]
  580. }
  581. >
  582. <div className={styles["chat-message-container"]}>
  583. <div className={styles["chat-message-avatar"]}>
  584. {message.role === "user" ? (
  585. <Avatar avatar={config.avatar} />
  586. ) : session.mask.id === DEFAULT_MASK_ID ? (
  587. <Avatar model={message.model ?? "gpt-3.5-turbo"} />
  588. ) : (
  589. <Avatar avatar={session.mask.avatar} />
  590. )}
  591. </div>
  592. {showTyping && (
  593. <div className={styles["chat-message-status"]}>
  594. {Locale.Chat.Typing}
  595. </div>
  596. )}
  597. <div className={styles["chat-message-item"]}>
  598. {showActions && (
  599. <div className={styles["chat-message-top-actions"]}>
  600. {message.streaming ? (
  601. <div
  602. className={styles["chat-message-top-action"]}
  603. onClick={() => onUserStop(message.id ?? i)}
  604. >
  605. {Locale.Chat.Actions.Stop}
  606. </div>
  607. ) : (
  608. <>
  609. <div
  610. className={styles["chat-message-top-action"]}
  611. onClick={() => onDelete(message.id ?? i)}
  612. >
  613. {Locale.Chat.Actions.Delete}
  614. </div>
  615. <div
  616. className={styles["chat-message-top-action"]}
  617. onClick={() => onResend(message.id ?? i)}
  618. >
  619. {Locale.Chat.Actions.Retry}
  620. </div>
  621. </>
  622. )}
  623. <div
  624. className={styles["chat-message-top-action"]}
  625. onClick={() => copyToClipboard(message.content)}
  626. >
  627. {Locale.Chat.Actions.Copy}
  628. </div>
  629. </div>
  630. )}
  631. <Markdown
  632. content={message.content}
  633. loading={
  634. (message.preview || message.content.length === 0) &&
  635. !isUser
  636. }
  637. onContextMenu={(e) => onRightClick(e, message)}
  638. onDoubleClickCapture={() => {
  639. if (!isMobileScreen) return;
  640. setUserInput(message.content);
  641. }}
  642. fontSize={fontSize}
  643. parentRef={scrollRef}
  644. />
  645. </div>
  646. {!isUser && !message.preview && (
  647. <div className={styles["chat-message-actions"]}>
  648. <div className={styles["chat-message-action-date"]}>
  649. {message.date.toLocaleString()}
  650. </div>
  651. </div>
  652. )}
  653. </div>
  654. </div>
  655. );
  656. })}
  657. </div>
  658. <div className={styles["chat-input-panel"]}>
  659. <PromptHints prompts={promptHints} onPromptSelect={onPromptSelect} />
  660. <ChatActions
  661. showPromptModal={() => setShowPromptModal(true)}
  662. scrollToBottom={scrollToBottom}
  663. hitBottom={hitBottom}
  664. />
  665. <div className={styles["chat-input-panel-inner"]}>
  666. <textarea
  667. ref={inputRef}
  668. className={styles["chat-input"]}
  669. placeholder={Locale.Chat.Input(submitKey)}
  670. onInput={(e) => onInput(e.currentTarget.value)}
  671. value={userInput}
  672. onKeyDown={onInputKeyDown}
  673. onFocus={() => setAutoScroll(true)}
  674. onBlur={() => {
  675. setAutoScroll(false);
  676. setTimeout(() => setPromptHints([]), 500);
  677. }}
  678. autoFocus
  679. rows={inputRows}
  680. />
  681. <IconButton
  682. icon={<SendWhiteIcon />}
  683. text={Locale.Chat.Send}
  684. className={styles["chat-input-send"]}
  685. noDark
  686. onClick={onUserSubmit}
  687. />
  688. </div>
  689. </div>
  690. </div>
  691. );
  692. }