// ============================================================================ // Deep Thinking // ============================================================================ import { Card, CardBody, CardBodyProps, CardProps, ExpandableSection, ExpandableSectionProps } from '@patternfly/react-core'; import { useState, type FunctionComponent } from 'react'; import MarkdownContent from '../MarkdownContent'; import type { MarkdownContentProps } from '../MarkdownContent'; export interface DeepThinkingProps { /** Toggle content shown for expandable section */ toggleContent: React.ReactNode; /** Flag indicating whether the expandable content is expanded by default. */ isDefaultExpanded?: boolean; /** Additional props passed to expandable section */ expandableSectionProps?: Omit; /** Subheading rendered inside expandable section */ subheading?: string; /** Body text rendered inside expandable section */ body?: React.ReactNode | string; /** Additional props passed to main card */ cardProps?: CardProps; /** Additional props passed to main card body */ cardBodyProps?: CardBodyProps; /** Whether to enable markdown rendering for toggleContent. When true and toggleContent is a string, it will be parsed as markdown. */ isToggleContentMarkdown?: boolean; /** Whether to enable markdown rendering for subheading. When true, subheading will be parsed as markdown. */ isSubheadingMarkdown?: boolean; /** Whether to enable markdown rendering for body. When true and body is a string, it will be parsed as markdown. */ isBodyMarkdown?: boolean; /** Props passed to MarkdownContent component when markdown is enabled */ markdownContentProps?: Omit; /** Whether to retain styles in the MarkdownContent component. Defaults to false. */ shouldRetainStyles?: boolean; } export const DeepThinking: FunctionComponent = ({ body, cardProps, expandableSectionProps, subheading, toggleContent, isDefaultExpanded = true, cardBodyProps, isToggleContentMarkdown, isSubheadingMarkdown, isBodyMarkdown, markdownContentProps, shouldRetainStyles = false }: DeepThinkingProps) => { const [isExpanded, setIsExpanded] = useState(isDefaultExpanded); const onToggle = (_event: React.MouseEvent, isExpanded: boolean) => { setIsExpanded(isExpanded); }; const renderToggleContent = () => { if (isToggleContentMarkdown && typeof toggleContent === 'string') { return ( ); } return toggleContent; }; const renderSubheading = () => { if (!subheading) { return null; } if (isSubheadingMarkdown) { return ; } return subheading; }; const renderBody = () => { if (!body) { return null; } if (isBodyMarkdown && typeof body === 'string') { return ; } return body; }; return (
{subheading && (
{renderSubheading()}
)} {body &&
{renderBody()}
}
); }; export default DeepThinking;