UNPKG

@copilotkit/react-ui

Version:

<div align="center"> <a href="https://copilotkit.ai" target="_blank"> <img src="https://github.com/copilotkit/copilotkit/raw/main/assets/banner.png" alt="CopilotKit Logo"> </a>

73 lines (72 loc) 2.57 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/components/chat/Textarea.tsx var Textarea_exports = {}; __export(Textarea_exports, { default: () => Textarea_default }); module.exports = __toCommonJS(Textarea_exports); var import_react = require("react"); var import_jsx_runtime = require("react/jsx-runtime"); var AutoResizingTextarea = (0, import_react.forwardRef)( ({ maxRows = 1, placeholder, value, onChange, onKeyDown, autoFocus }, ref) => { const internalTextareaRef = (0, import_react.useRef)(null); const [maxHeight, setMaxHeight] = (0, import_react.useState)(0); (0, import_react.useImperativeHandle)(ref, () => internalTextareaRef.current); (0, import_react.useEffect)(() => { const calculateMaxHeight = () => { const textarea = internalTextareaRef.current; if (textarea) { textarea.style.height = "auto"; const singleRowHeight = textarea.scrollHeight; setMaxHeight(singleRowHeight * maxRows); if (autoFocus) { textarea.focus(); } } }; calculateMaxHeight(); }, [maxRows]); (0, import_react.useEffect)(() => { const textarea = internalTextareaRef.current; if (textarea) { textarea.style.height = "auto"; textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`; } }, [value, maxHeight]); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "textarea", { ref: internalTextareaRef, value, onChange, onKeyDown, placeholder, style: { overflow: "auto", resize: "none", maxHeight: `${maxHeight}px` }, rows: 1 } ); } ); var Textarea_default = AutoResizingTextarea; //# sourceMappingURL=Textarea.js.map