import clsx from "clsx"; import { FC, HTMLAttributes, ReactNode, useState } from "react"; import { HtmlContent } from "../HtmlContent"; import styles from "./styles.module.css"; interface Props extends Omit, "children"> { children: ReactNode; className?: string; forceShow?: boolean; heading?: ReactNode; maxLength?: number; } /** * A component that will display a "Show More" button if the content is longer * than the maxLength prop. It will also accept a heading prop to display text * above the content. */ export const CollapsibleContent: FC = ({ forceShow, className, children, heading, maxLength = 600, ...props }) => { const [isOpen, setIsOpen] = useState(forceShow); const handleToggleClick = (): void => { setIsOpen((prev) => !prev); }; if (typeof children === "string" && children?.length <= maxLength && !heading) return ( ); return ( {heading && {heading}} {typeof children === "string" ? ( ) : ( {children} )} {!forceShow && ( {isOpen ? "Show Less" : "Show More"} )} ); };