@copilotkit/react-ui
Version:
<img src="https://github.com/user-attachments/assets/0a6b64d9-e193-4940-a3f6-60334ac34084" alt="banner" style="border-radius: 12px; border: 2px solid #d6d4fa;" />
84 lines (83 loc) • 2.7 kB
JavaScript
;
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,
onCompositionStart,
onCompositionEnd,
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,
onCompositionStart,
onCompositionEnd,
placeholder,
style: {
overflow: "auto",
resize: "none",
maxHeight: `${maxHeight}px`
},
rows: 1
}
);
}
);
var Textarea_default = AutoResizingTextarea;
//# sourceMappingURL=Textarea.js.map