@eccenca/gui-elements
Version:
GUI elements based on other libraries, usable in React application, written in Typescript.
53 lines • 2.58 kB
JavaScript
;
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatField = void 0;
const react_1 = __importDefault(require("react"));
const constants_1 = require("../../configuration/constants");
const IconButton_1 = require("../Icon/IconButton");
const TextArea_1 = require("../TextField/TextArea");
/**
* Component to input chat text.
* Based on `TextArea` component.
*/
const ChatField = (_a) => {
var _b;
var { className, onTextSubmit, onChange, onKeyDown, rightElement } = _a, otherTextAreaProps = __rest(_a, ["className", "onTextSubmit", "onChange", "onKeyDown", "rightElement"]);
const chatvalue = react_1.default.useRef((_b = otherTextAreaProps.children) !== null && _b !== void 0 ? _b : "");
const onContentChange = (value) => {
chatvalue.current = value;
};
const onEnter = (e) => {
if (onKeyDown)
onKeyDown(e);
if (e.keyCode === 13 && e.shiftKey === false && onTextSubmit) {
e.preventDefault();
onTextSubmit(chatvalue.current);
}
};
return (react_1.default.createElement(TextArea_1.TextArea, Object.assign({ fill: true, autoResize: true, className: `${constants_1.CLASSPREFIX}-chat__inputfield` + (className ? ` ${className}` : ""), onChange: onTextSubmit
? (e) => {
onContentChange(e.target.value);
if (onChange)
onChange(e);
}
: onChange, onKeyDown: onTextSubmit ? onEnter : onKeyDown, rightElement: (onTextSubmit || rightElement) && (react_1.default.createElement(react_1.default.Fragment, null,
onTextSubmit && (react_1.default.createElement(IconButton_1.IconButton, { name: "operation-send", onClick: () => onTextSubmit(chatvalue.current) })),
rightElement)) }, otherTextAreaProps)));
};
exports.ChatField = ChatField;
exports.default = exports.ChatField;
//# sourceMappingURL=ChatField.js.map