import React, { Children, useId } from 'react'; import ActionLink from '../../common/ActionLink'; import ConditionalWrapper from '../../common/ConditionalWrapper'; import { SummaryListItemProps, SummaryListProps } from './types'; import { ActionLinkProps } from '../../common/ActionLink/types'; import clsx from 'clsx'; const Item = ({ children, title }: SummaryListItemProps) => { const values: React.ReactElement[] = []; const actions: React.ReactElement[] = []; const describedById = useId(); Children.forEach(children, (child: React.ReactNode) => { const thisChild = child as React.ReactElement; if (thisChild && thisChild.type === Value) { values.push(thisChild); } else if (thisChild && thisChild.type === ActionLink) { actions.push(React.cloneElement(thisChild, { describedby: describedById })); } }); return (
  • {title} 1} wrapper={(children: React.JSX.Element) =>
      {children}
    } > {values && values.map((value, index: number) => ( 1} wrapper={(children: React.JSX.Element) =>
  • {children}
  • } key={'answer' + index} > {value} ))} {!!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}
    ))}
    } ); }; const Value = ({ children }: React.AllHTMLAttributes) => { return ( {children} ); }; const SummaryList = ({ children, className, isBorderless, ...props }: SummaryListProps) => { return (
      {children}
    ); }; SummaryList.Action = ActionLink; SummaryList.Item = Item; SummaryList.Value = Value; SummaryList.displayName = 'SummaryList'; SummaryList.Action.displayName = 'SummaryList.Action'; Item.displayName = 'SummaryList.Item'; Value.displayName = 'SummaryList.Value'; export default SummaryList;