import React from "react"; import { Markdown } from "../../cmem/markdown/Markdown"; import { IconButton } from "../Icon/IconButton"; import { TextReducer, TextReducerProps } from "../TextReducer/TextReducer"; import { ChatContentProps } from "./ChatContent"; export interface ChatContentCollapsedProps { children: React.ReactElement; /** * Set this to `false` if the compoment should initally start in an expanded state. */ collapsed?: boolean; /** * Use this to set extra `TextReducer` properties. * This is used to create the collapsed variant of the given content. */ textReducerProps?: Omit; /** * Text for collapse button. */ textCollapse?: string; /** * Text for expand button. */ textExpand?: string; } /** * Adds an auto collapsing feature for convenience to `ChatContent`. */ export const ChatContentCollapsed = ({ children, collapsed = true, textReducerProps = {}, textCollapse = "Collapse", textExpand = "Expand", }: ChatContentCollapsedProps) => { const [displayCollapsed, setDispayCollapsed] = React.useState(collapsed); const childrenAsTextline = ( {typeof children.props.children === "string" ? ( {children.props.children} ) : ( children.props.children )} ); return React.cloneElement(children, { children: displayCollapsed ? childrenAsTextline : children.props.children, actionButton: ( setDispayCollapsed(!displayCollapsed)} /> ), }); }; export default ChatContentCollapsed;