/** * "Add element" dropdown for the docked builder — lists the elements not yet * placed, and places the one picked. The click-to-add alternative to dragging * a card from the Elements tab. Also optionally carries an "Add column" item, * so a row's trailing "+" is the one place to grow it. */ import { __ } from '@wordpress/i18n'; import { Dropdown } from '@wordpress/components'; import { Columns3 } from '../../icons'; import DockMenu, { type DockMenuGroup } from './dock-menu'; import { iconFor } from './element-registry'; import type { ElementDef } from './element-groups'; import type { ReactElement } from 'react'; interface AddElementMenuProps { available: ElementDef[]; onAdd: ( id: string ) => void; onAddColumn?: () => void; renderToggle: ( args: { isOpen: boolean; onToggle: () => void; } ) => ReactElement; } export default function AddElementMenu( { available, onAdd, onAddColumn, renderToggle, }: AddElementMenuProps ) { const groups: DockMenuGroup[] = [ { key: 'elements', label: __( 'Add element', 'aureon' ), empty: __( 'Every element is already placed.', 'aureon' ), items: available.map( ( el ) => ( { key: el.id, label: el.label, icon: iconFor( el.id ), onClick: () => onAdd( el.id ), } ) ), }, ]; if ( onAddColumn ) { groups.push( { key: 'layout', items: [ { key: 'add-column', label: __( 'Add column', 'aureon' ), icon: Columns3, onClick: onAddColumn, }, ], } ); } return ( ( ) } /> ); }