import React, { Children, useId } from 'react'; import ActionLink from '../../common/ActionLink'; import ConditionalWrapper from '../../common/ConditionalWrapper'; import WrapperTag from "../../common/WrapperTag"; import { SummaryCardProps } from './types'; import { ActionLinkProps } from '../../common/ActionLink/types'; import clsx from 'clsx'; const SummaryCard = ({ children, className, headingLevel = 'h3', title, ...props }: SummaryCardProps) => { const actions: React.ReactElement[] = []; const remainingChildren: React.ReactElement[] = []; const describedById = useId(); Children.forEach(children, (child: React.ReactNode) => { const thisChild = child as React.ReactElement; if (thisChild && thisChild.type === ActionLink) { actions.push(React.cloneElement(thisChild, { describedby: describedById })); } else { remainingChildren.push(thisChild); } }); return (
{title} {!!actions.length && 1} wrapper={(children: React.JSX.Element) =>
    {children}
} > {actions && actions.map((action, index: number) => ( 1} wrapper={(children: React.JSX.Element) =>
  • {children}
  • } key={'action' + index} > {action}
    ))}
    }
    {remainingChildren}
    ); }; SummaryCard.displayName = 'SummaryCard'; SummaryCard.Action = ActionLink; SummaryCard.Action.displayName = 'SummaryCard.Action'; export default SummaryCard;