import { Card, CardHeader, CardBody, __experimentalVStack as VStack } from '@wordpress/components'; import { useInstanceId } from '@wordpress/compose'; import clsx from 'clsx'; import { isValidElement, cloneElement, Children } from 'react'; import { SectionHeader } from '../section-header'; import { SummaryButtonListProps } from './types'; import './style.scss'; /** * The SummaryButtonList is a utility component that wraps multiple SummaryButton instances * along with an optional section header. It provides consistent layout, spacing, and * grouping behavior for presenting a collection of summary actions or options. * * This component ensures visual coherence and structural alignment when multiple * SummaryButton elements are displayed together. It is intended for use in contexts * where a list of summarised items or actions needs to be grouped under a shared * label or heading. */ export function SummaryButtonList( { title, description, density = 'medium', children, }: SummaryButtonListProps ) { const titleId = useInstanceId( SummaryButtonList, 'dashboard-summary-button-list__title' ); const isMediumDensity = density === 'medium'; // Clone children and override their density prop. const clonedChildren = Children.map( children, ( child ) => { if ( isValidElement( child ) ) { return (
  • { cloneElement( child, { density } ) }
  • ); } return child; } ); const header = title && ( ); const className = clsx( 'dashboard-summary-button-list', `has-density-${ density }` ); const childrenList = ( ); if ( isMediumDensity ) { return ( { header && { header } } { childrenList } ); } return ( { header } { childrenList } ); }