UNPKG

@eccenca/gui-elements

Version:

GUI elements based on other libraries, usable in React application, written in Typescript.

59 lines 3.73 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; 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; }; import React from "react"; import { CLASSPREFIX as eccgui } from "../../configuration/constants.js"; import { FlexibleLayoutContainer, FlexibleLayoutItem } from "./../FlexibleLayout/index.js"; import { Spacing } from "./../Separation/Spacing.js"; /** * Component to display a full chat, containing chat content bubbles and text input. */ export var ChatArea = function (_a) { var children = _a.children, className = _a.className, chatField = _a.chatField, _b = _a.chatFieldPosition, chatFieldPosition = _b === void 0 ? "bottom" : _b, _c = _a.contentWidth, contentWidth = _c === void 0 ? "medium" : _c, autoSpacingSize = _a.autoSpacingSize, _d = _a.gapSize, gapSize = _d === void 0 ? "medium" : _d, autoScrollTo = _a.autoScrollTo, otherFlexibleLayoutContainerProps = __rest(_a, ["children", "className", "chatField", "chatFieldPosition", "contentWidth", "autoSpacingSize", "gapSize", "autoScrollTo"]); var chatcontents = React.useRef(null); React.useEffect(function () { if (chatcontents.current && children && autoScrollTo) { var chatitems = chatcontents.current.getElementsByClassName("".concat(eccgui, "-chat__content")); if (chatitems.length > 0) { chatitems[autoScrollTo === "first" ? 0 : chatitems.length - 1].scrollIntoView({ behavior: "instant", block: autoScrollTo === "first" ? "start" : "end", }); } } }, [chatcontents, children, autoScrollTo]); return (React.createElement(FlexibleLayoutContainer, __assign({ className: "".concat(eccgui, "-chat__area") + " ".concat(eccgui, "-chat__area--").concat(contentWidth) + (className ? " ".concat(className) : ""), vertical: true, noEqualItemSpace: true, gapSize: gapSize }, otherFlexibleLayoutContainerProps), chatField && (React.createElement(FlexibleLayoutItem, { growFactor: 0, shrinkFactor: 0, style: chatFieldPosition === "bottom" ? { order: 1 } : undefined }, React.createElement("div", { className: "".concat(eccgui, "-chat__area-contentwidth") }, chatField))), React.createElement(FlexibleLayoutItem, { style: otherFlexibleLayoutContainerProps.useAbsoluteSpace ? { overflow: "auto", minHeight: 0, padding: "2px 0", } : undefined }, React.createElement("div", { className: "".concat(eccgui, "-chat__area-contentwidth"), ref: chatcontents }, autoSpacingSize && children ? (React.createElement("ul", null, React.Children.toArray(children).map(function (child, index) { return (React.createElement("li", { key: index }, child, React.createElement(Spacing, { size: autoSpacingSize }))); }))) : (children))))); }; export default ChatArea; //# sourceMappingURL=ChatArea.js.map