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

Add block sidebar toggle to block settings menu #65185

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
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
63 changes: 63 additions & 0 deletions packages/editor/src/hooks/block-settings-inspector-toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* WordPress dependencies
*/
import { addFilter } from '@wordpress/hooks';
import { createHigherOrderComponent } from '@wordpress/compose';
import { __unstableBlockSettingsMenuFirstItem as BlockSettingsMenuFirstItem } from '@wordpress/block-editor';
import { MenuItem } from '@wordpress/components';
import { store as interfaceStore } from '@wordpress/interface';
import { useDispatch, useSelect } from '@wordpress/data';
import { __, isRTL } from '@wordpress/i18n';
import { drawerLeft, drawerRight } from '@wordpress/icons';

/**
* Override the default edit UI to include a new block inspector control for
* assigning a partial syncing controls to supported blocks in the pattern editor.
* Currently, only the `core/paragraph` block is supported.
getdave marked this conversation as resolved.
Show resolved Hide resolved
*
* @param {Component} BlockEdit Original component.
*
* @return {Component} Wrapped component.
*/
const withBlockSettingsInspectorToggle = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
return (
<>
<BlockEdit key="edit" { ...props } />
{ props.isSelected && <BlockInspectorToggle /> }
</>
);
},
'withBlockSettingsInspectorToggle'
);

const BlockInspectorToggle = () => {
const { enableComplementaryArea } = useDispatch( interfaceStore );

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

return (
<BlockSettingsMenuFirstItem>
<MenuItem
onClick={ () => {
enableComplementaryArea( 'core', 'edit-post/block' );
} }
icon={ isRTL() ? drawerLeft : drawerRight }
disabled={ isOpen }
getdave marked this conversation as resolved.
Show resolved Hide resolved
getdave marked this conversation as resolved.
Show resolved Hide resolved
>
{ __( 'Open Block settings' ) }
getdave marked this conversation as resolved.
Show resolved Hide resolved
</MenuItem>
</BlockSettingsMenuFirstItem>
);
};

addFilter(
'editor.BlockEdit',
'core/editor/with-block-settings-inspector-toggle',
withBlockSettingsInspectorToggle
);
1 change: 1 addition & 0 deletions packages/editor/src/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ import './custom-sources-backwards-compatibility';
import './default-autocompleters';
import './media-upload';
import './pattern-overrides';
import './block-settings-inspector-toggle';
Loading