UNPKG

@eccenca/gui-elements

Version:

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

55 lines 3.57 kB
"use strict"; 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.ChatArea = void 0; const react_1 = __importDefault(require("react")); const constants_1 = require("../../configuration/constants"); const FlexibleLayout_1 = require("./../FlexibleLayout"); const Spacing_1 = require("./../Separation/Spacing"); /** * Component to display a full chat, containing chat content bubbles and text input. */ const ChatArea = (_a) => { var { children, className, chatField, chatFieldPosition = "bottom", contentWidth = "medium", autoSpacingSize, gapSize = "medium", autoScrollTo } = _a, otherFlexibleLayoutContainerProps = __rest(_a, ["children", "className", "chatField", "chatFieldPosition", "contentWidth", "autoSpacingSize", "gapSize", "autoScrollTo"]); const chatcontents = react_1.default.useRef(null); react_1.default.useEffect(() => { if (chatcontents.current && children && autoScrollTo) { const chatitems = chatcontents.current.getElementsByClassName(`${constants_1.CLASSPREFIX}-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_1.default.createElement(FlexibleLayout_1.FlexibleLayoutContainer, Object.assign({ className: `${constants_1.CLASSPREFIX}-chat__area` + ` ${constants_1.CLASSPREFIX}-chat__area--${contentWidth}` + (className ? ` ${className}` : ""), vertical: true, noEqualItemSpace: true, gapSize: gapSize }, otherFlexibleLayoutContainerProps), chatField && (react_1.default.createElement(FlexibleLayout_1.FlexibleLayoutItem, { growFactor: 0, shrinkFactor: 0, style: chatFieldPosition === "bottom" ? { order: 1 } : undefined }, react_1.default.createElement("div", { className: `${constants_1.CLASSPREFIX}-chat__area-contentwidth` }, chatField))), react_1.default.createElement(FlexibleLayout_1.FlexibleLayoutItem, { style: otherFlexibleLayoutContainerProps.useAbsoluteSpace ? { overflow: "auto", minHeight: 0, padding: "2px 0", } : undefined }, react_1.default.createElement("div", { className: `${constants_1.CLASSPREFIX}-chat__area-contentwidth`, ref: chatcontents }, autoSpacingSize && children ? (react_1.default.createElement("ul", null, react_1.default.Children.toArray(children).map((child, index) => (react_1.default.createElement("li", { key: index }, child, react_1.default.createElement(Spacing_1.Spacing, { size: autoSpacingSize })))))) : (children))))); }; exports.ChatArea = ChatArea; exports.default = exports.ChatArea; //# sourceMappingURL=ChatArea.js.map