-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Site Editor: Add show more settings to block toolbars (#31305)
- Loading branch information
1 parent
fb200d7
commit c367c4e
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
packages/edit-site/src/components/block-editor/block-inspector-button.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { speak } from '@wordpress/a11y'; | ||
import { MenuItem } from '@wordpress/components'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { store as interfaceStore } from '@wordpress/interface'; | ||
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editSiteStore } from '../../store'; | ||
import { STORE_NAME } from '../../store/constants'; | ||
import { SIDEBAR_BLOCK } from '../sidebar/constants'; | ||
|
||
export default function BlockInspectorButton( { onClick = () => {} } ) { | ||
const { shortcut, isBlockInspectorOpen } = useSelect( | ||
( select ) => ( { | ||
shortcut: select( | ||
keyboardShortcutsStore | ||
).getShortcutRepresentation( | ||
'core/edit-site/toggle-block-settings-sidebar' | ||
), | ||
isBlockInspectorOpen: | ||
select( interfaceStore ).getActiveComplementaryArea( | ||
editSiteStore.name | ||
) === SIDEBAR_BLOCK, | ||
} ), | ||
[] | ||
); | ||
const { enableComplementaryArea, disableComplementaryArea } = useDispatch( | ||
interfaceStore | ||
); | ||
|
||
const label = isBlockInspectorOpen | ||
? __( 'Hide more settings' ) | ||
: __( 'Show more settings' ); | ||
|
||
return ( | ||
<MenuItem | ||
onClick={ () => { | ||
if ( isBlockInspectorOpen ) { | ||
disableComplementaryArea( STORE_NAME ); | ||
speak( __( 'Block settings closed' ) ); | ||
} else { | ||
enableComplementaryArea( STORE_NAME, SIDEBAR_BLOCK ); | ||
speak( | ||
__( | ||
'Additional settings are now available in the Editor block settings sidebar' | ||
) | ||
); | ||
} | ||
// Close dropdown menu. | ||
onClick(); | ||
} } | ||
shortcut={ shortcut } | ||
> | ||
{ label } | ||
</MenuItem> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters