@wordpress/block-library
Version:
Block library for the WordPress editor.
43 lines (36 loc) • 1.07 kB
JavaScript
/**
* WordPress dependencies
*/
import {
useBlockProps,
useInnerBlocksProps,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import AddTabToolbarControl from '../tab-panel/add-tab-toolbar-control';
import RemoveTabToolbarControl from '../tab-panel/remove-tab-toolbar-control';
const TAB_PANELS_TEMPLATE = [ [ 'core/tab-panel', {} ] ];
export default function Edit( { clientId } ) {
const blockProps = useBlockProps();
const innerBlocksProps = useInnerBlocksProps( blockProps, {
template: TAB_PANELS_TEMPLATE,
templateLock: false,
renderAppender: false, // Appender handled by individual tab blocks
} );
// Get the parent tabs block clientId
const tabsClientId = useSelect(
( select ) =>
select( blockEditorStore ).getBlockRootClientId( clientId ),
[ clientId ]
);
return (
<>
<AddTabToolbarControl tabsClientId={ tabsClientId } />
<RemoveTabToolbarControl tabsClientId={ tabsClientId } />
<div { ...innerBlocksProps } />
</>
);
}