import React from "react"; import { TestableComponent } from "../../components/interfaces"; import { CLASSPREFIX as eccgui } from "../../configuration/constants"; import { Markdown, MarkdownProps } from "./../../cmem/markdown/Markdown"; import { ContextMenuProps } from "./../ContextOverlay/ContextMenu"; import { DepictionProps } from "./../Depiction/Depiction"; import { FlexibleLayoutContainer, FlexibleLayoutItem } from "./../FlexibleLayout"; import { IconButtonProps } from "./../Icon/IconButton"; import { Spacing } from "./../Separation/Spacing"; import { HtmlContentBlock, OverflowTextProps } from "./../Typography"; export interface ChatContentProps extends React.HTMLAttributes, TestableComponent { /** * Should be a line of text, e.g. username, timestamp, ... */ statusLine?: React.ReactElement; /** * How the chat content box is displayed. */ displayType?: "free" | "simple" | "bubble"; /** * A depiction used as avatar next to the content box. */ avatar?: React.ReactElement; /** * If indented then the content box has some white space on the opposite side to the alignment */ indentationSize?: "small" | "medium" | "large"; /** * How the content box and avatar is aligned. * If `left` is set then the avatar is on the left side, and the indentation on the right side. */ alignment?: "left" | "right"; /** * If set then the chat bubble only grows to a height of 50% of the viewport. * In case you need to set other maximum heights then use the `style` property directly. */ limitHeight?: boolean; /** * If given then the content is automatically parsed and displayed by our `` component. * `children` need to a `string` then, otherwise it cannot be parsed. */ markdownProps?: Omit; /** * Could be used to add some type of toggle button or to include a context menu. */ actionButton?: React.ReactElement | React.ReactElement; } /** * Component to display single chat contents, including avatar and status line. */ export const ChatContent = ({ className, children, statusLine, avatar, displayType = "bubble", indentationSize, alignment = "left", limitHeight, markdownProps, actionButton, ...otherDivProps }: ChatContentProps) => { const content = markdownProps && typeof children === "string" ? {children} : children; const chatitem = (
{statusLine && ( {statusLine} )} {content}
); const indentationSizes = { small: "8%", medium: "21%", large: "34%", }; return (
{avatar && ( {React.cloneElement(avatar, { size: "small", ratio: "1:1", rounded: true, resizing: "cover" })} )} {chatitem} {actionButton && ( {actionButton} )}
); }; export default ChatContent;