Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment: Try block inspector controls toggle in block toolbar #65118

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import clsx from 'clsx';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import { useRef } from '@wordpress/element';
import { useViewportMatch } from '@wordpress/compose';
import {
Expand All @@ -16,7 +16,9 @@ import {
isReusableBlock,
isTemplatePart,
} from '@wordpress/blocks';
import { ToolbarGroup } from '@wordpress/components';
import { ToolbarGroup, ToolbarButton } from '@wordpress/components';
import { settings as settingsIcon } from '@wordpress/icons';
import { store as interfaceStore } from '@wordpress/interface';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we can't do this as block-editor cannot depend on interface.


/**
* Internal dependencies
Expand Down Expand Up @@ -126,6 +128,16 @@ export function PrivateBlockToolbar( {
};
}, [] );

const { enableComplementaryArea, disableComplementaryArea } =
useDispatch( interfaceStore );

const isSelected = useSelect(
( select ) =>
select( interfaceStore ).getActiveComplementaryArea( 'core' ) ===
'edit-post/block',
[]
);

const toolbarWrapperRef = useRef( null );

// Handles highlighting the current block outline on hover or focus of the
Expand Down Expand Up @@ -235,6 +247,26 @@ export function PrivateBlockToolbar( {
</>
) }
<BlockEditVisuallyButton clientIds={ blockClientIds } />
<ToolbarGroup>
<ToolbarButton
icon={ settingsIcon }
label={ __( 'Toggle block settings' ) }
isPressed={ isSelected }
onClick={ () => {
if ( isSelected ) {
disableComplementaryArea(
'core',
'edit-post/block'
);
} else {
enableComplementaryArea(
'core',
'edit-post/block'
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting that this clearly doesn't belong in the block editor package. However, obviously this PR is a proof of concept only. Ultimately something like this would be in editor or something.

}
} }
/>
</ToolbarGroup>
{ isDefaultEditingMode && (
<BlockSettingsMenu clientIds={ blockClientIds } />
) }
Expand Down
Loading