@wordpress/components
Version:
UI components for WordPress.
42 lines (35 loc) • 1.01 kB
JavaScript
// @ts-nocheck
/**
* WordPress dependencies
*/
import { forwardRef, useContext } from '@wordpress/element';
/**
* Internal dependencies
*/
import ToolbarItem from '../toolbar-item';
import ToolbarContext from '../toolbar-context';
import DropdownMenu from '../../dropdown-menu';
function ToolbarDropdownMenu( props, ref ) {
const accessibleToolbarState = useContext( ToolbarContext );
if ( ! accessibleToolbarState ) {
return <DropdownMenu { ...props } />;
}
// ToobarItem will pass all props to the render prop child, which will pass
// all props to the toggle of DropdownMenu. This means that ToolbarDropdownMenu
// has the same API as DropdownMenu.
return (
<ToolbarItem ref={ ref } { ...props.toggleProps }>
{ ( toolbarItemProps ) => (
<DropdownMenu
{ ...props }
popoverProps={ {
variant: 'toolbar',
...props.popoverProps,
} }
toggleProps={ toolbarItemProps }
/>
) }
</ToolbarItem>
);
}
export default forwardRef( ToolbarDropdownMenu );