@@ -5,56 +5,60 @@ import {
55 InspectorControls ,
66 store as blockEditorStore ,
77} from '@wordpress/block-editor' ;
8- import { PanelBody , TextControl , CheckboxControl } from '@wordpress/components' ;
8+ import {
9+ CheckboxControl ,
10+ __experimentalToolsPanel as ToolsPanel ,
11+ __experimentalToolsPanelItem as ToolsPanelItem ,
12+ } from '@wordpress/components' ;
913import { __ } from '@wordpress/i18n' ;
1014import { useDispatch } from '@wordpress/data' ;
11- import { decodeEntities } from '@wordpress/html-entities' ;
1215
1316/**
1417 * Internal dependencies
1518 */
1619import AddTabToolbarControl from './add-tab-toolbar-control' ;
1720import RemoveTabToolbarControl from './remove-tab-toolbar-control' ;
18- import slugFromLabel from './slug-from-label' ;
19-
20- export default function Controls ( {
21- attributes,
22- setAttributes,
23- tabsClientId,
24- blockIndex,
25- isDefaultTab,
26- } ) {
27- const { label } = attributes ;
21+ import { useToolsPanelDropdownMenuProps } from '../utils/hooks' ;
2822
23+ export default function Controls ( { tabsClientId, blockIndex, isDefaultTab } ) {
2924 const { updateBlockAttributes } = useDispatch ( blockEditorStore ) ;
25+ const dropdownMenuProps = useToolsPanelDropdownMenuProps ( ) ;
3026
3127 return (
3228 < >
3329 < AddTabToolbarControl tabsClientId = { tabsClientId } />
3430 < RemoveTabToolbarControl tabsClientId = { tabsClientId } />
3531 < InspectorControls >
36- < PanelBody title = { __ ( 'Settings' ) } >
37- < TextControl
38- label = { __ ( 'Label' ) }
39- value = { decodeEntities ( label ) }
40- onChange = { ( value ) => {
41- setAttributes ( {
42- label : value ,
43- anchor : slugFromLabel ( value , blockIndex ) ,
44- } ) ;
45- } }
46- __next40pxDefaultSize
47- />
48- < CheckboxControl
32+ < ToolsPanel
33+ label = { __ ( 'Settings' ) }
34+ resetAll = { ( ) => {
35+ updateBlockAttributes ( tabsClientId , {
36+ activeTabIndex : 0 ,
37+ } ) ;
38+ } }
39+ dropdownMenuProps = { dropdownMenuProps }
40+ >
41+ < ToolsPanelItem
4942 label = { __ ( 'Default tab' ) }
50- checked = { isDefaultTab }
51- onChange = { ( value ) => {
43+ hasValue = { ( ) => isDefaultTab && blockIndex !== 0 }
44+ onDeselect = { ( ) => {
5245 updateBlockAttributes ( tabsClientId , {
53- activeTabIndex : value ? blockIndex : 0 ,
46+ activeTabIndex : 0 ,
5447 } ) ;
5548 } }
56- />
57- </ PanelBody >
49+ isShownByDefault
50+ >
51+ < CheckboxControl
52+ label = { __ ( 'Default tab' ) }
53+ checked = { isDefaultTab }
54+ onChange = { ( value ) => {
55+ updateBlockAttributes ( tabsClientId , {
56+ activeTabIndex : value ? blockIndex : 0 ,
57+ } ) ;
58+ } }
59+ />
60+ </ ToolsPanelItem >
61+ </ ToolsPanel >
5862 </ InspectorControls >
5963 </ >
6064 ) ;
0 commit comments