@wordpress/block-library
Version:
Block library for the WordPress editor.
45 lines (38 loc) • 1.1 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/add-tab-toolbar-control';
import RemoveTabToolbarControl from '../tab/remove-tab-toolbar-control';
const TAB_PANELS_TEMPLATE = [ [ 'core/tab', {} ] ];
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 ) => {
const { getBlockRootClientId } = select( blockEditorStore );
return getBlockRootClientId( clientId );
},
[ clientId ]
);
return (
<>
<AddTabToolbarControl tabsClientId={ tabsClientId } />
<RemoveTabToolbarControl tabsClientId={ tabsClientId } />
<div { ...innerBlocksProps } />
</>
);
}