forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-tab-toolbar-control.js
More file actions
48 lines (44 loc) · 1.25 KB
/
add-tab-toolbar-control.js
File metadata and controls
48 lines (44 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* WordPress dependencies
*/
import { createBlock } from '@wordpress/blocks';
import {
BlockControls,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { ToolbarGroup, ToolbarButton } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useDispatch } from '@wordpress/data';
/**
* "Add Tab" button in the block toolbar for the tab block.
* @param {Object} props
* @param {Object} props.attributes The block attributes.
* @param {string} props.tabsClientId The client ID of the parent tabs block.
* @return {JSX.Element} The toolbar control element.
*/
export default function AddTabToolbarControl( { attributes, tabsClientId } ) {
const { insertBlock } = useDispatch( blockEditorStore );
const { className, fontFamily, fontSize } = attributes;
const addTab = () => {
const newTabBlock = createBlock( 'core/tab', {
label: __( 'New Tab' ),
className,
fontFamily,
fontSize,
} );
insertBlock( newTabBlock, undefined, tabsClientId );
};
return (
<BlockControls group="block">
<ToolbarGroup>
<ToolbarButton
className="components-toolbar__control"
label={ __( 'Add Tab' ) }
onClick={ addTab }
showTooltip
text="Add Tab"
/>
</ToolbarGroup>
</BlockControls>
);
}