/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ import React, { useState } from "react"; import { EuiFlexGroup, EuiFlexItem, EuiHorizontalRule, EuiPanel, EuiTitle, EuiText, EuiAccordion, htmlIdGenerator, EuiTextColor, } from "@elastic/eui"; export interface ContentPanelProps { title?: string | JSX.Element; titleSize?: "xxxs" | "xxs" | "xs" | "s" | "m" | "l"; subTitleText?: string | JSX.Element; bodyStyles?: object; panelStyles?: object; horizontalRuleClassName?: string; actions?: React.ReactNode | React.ReactNode[]; children: React.ReactNode | React.ReactNode[]; itemCount?: number; color?: "ghost"; noExtraPadding?: boolean; accordion?: boolean; } const renderSubTitleText = (subTitleText: string | JSX.Element): JSX.Element | null => { if (typeof subTitleText === "string") { if (!subTitleText) return null; return ( {subTitleText} ); } return subTitleText; }; const ContentPanel: React.SFC = ({ title = "", titleSize = "l", subTitleText = "", bodyStyles = {}, panelStyles = {}, horizontalRuleClassName = "", actions, children, itemCount = 0, color, noExtraPadding, accordion, }) => { const [isAccordionOpen, setIsAccordionOpen] = useState<"open" | "closed">("closed"); const toggleAccordion = (isOpen: boolean) => { setIsAccordionOpen(isOpen ? "open" : "closed"); }; const isGhost = color === "ghost"; const titleContent = ( {typeof title === "string" ? (

{title} {itemCount > 0 ? `(${itemCount})` : null}

) : ( title )} {renderSubTitleText(subTitleText)}
{actions ? ( {Array.isArray(actions) ? ( (actions as React.ReactNode[]).map( (action: React.ReactNode, idx: number): React.ReactNode => {action} ) ) : ( {actions} )} ) : null}
); const content = ( <> {accordion ? ( <> ) : ( titleContent )} {isGhost ? null : } {children ? (
{children}
) : null} ); if (isGhost) { return content; } return ( {content} ); }; export default ContentPanel;