@wordpress/block-library
Version:
Block library for the WordPress editor.
65 lines (60 loc) • 1.65 kB
JavaScript
/**
* WordPress dependencies
*/
import {
InspectorControls,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { PanelBody, TextControl, ToggleControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useDispatch } from '@wordpress/data';
import { decodeEntities } from '@wordpress/html-entities';
/**
* Internal dependencies
*/
import AddTabToolbarControl from './add-tab-toolbar-control';
import RemoveTabToolbarControl from './remove-tab-toolbar-control';
import slugFromLabel from './slug-from-label';
export default function Controls( {
attributes,
setAttributes,
tabsClientId,
blockIndex,
isDefaultTab,
} ) {
const { label } = attributes;
const { updateBlockAttributes } = useDispatch( blockEditorStore );
return (
<>
<AddTabToolbarControl tabsClientId={ tabsClientId } />
<RemoveTabToolbarControl tabsClientId={ tabsClientId } />
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<TextControl
label={ __( 'Tab Label' ) }
value={ decodeEntities( label ) }
onChange={ ( value ) => {
setAttributes( {
label: value,
anchor: slugFromLabel( value, blockIndex ),
} );
} }
__next40pxDefaultSize
/>
<ToggleControl
label={ __( 'Default Tab' ) }
checked={ isDefaultTab }
onChange={ ( value ) => {
updateBlockAttributes( tabsClientId, {
activeTabIndex: value ? blockIndex : 0,
} );
} }
help={ __(
'If toggled, this tab will be selected when the page loads.'
) }
/>
</PanelBody>
</InspectorControls>
</>
);
}