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

Get Navigation overlay icons from block editor settings #51527

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions lib/block-editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ function gutenberg_get_block_editor_settings( $settings ) {
);
}

$settings['navigationBlockOverlayIcons'] = array(
array(
'label' => __( 'Handle icon', 'gutenberg' ),
'icon' => 'handle',
),
array(
'label' => __( 'Menu icon', 'gutenberg' ),
'icon' => 'menu',
),

);

return $settings;
}
add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings', 0 );
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@ import {
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import OverlayMenuIcon from './overlay-menu-icon';

export default function OverlayMenuPreview( { setAttributes, hasIcon, icon } ) {
// get the icons from the block editor settings via a useSelect.
// they are under the key "navigationBlockOverlayIcons"

const navigationBlockOverlayIcons = useSelect(
( select ) =>
select( blockEditorStore ).getSettings()
.navigationBlockOverlayIcons,
[]
);

return (
<>
<ToggleControl
Expand All @@ -33,16 +45,16 @@ export default function OverlayMenuPreview( { setAttributes, hasIcon, icon } ) {
onChange={ ( value ) => setAttributes( { icon: value } ) }
isBlock
>
<ToggleGroupControlOption
value="handle"
aria-label={ __( 'handle' ) }
label={ <OverlayMenuIcon icon="handle" /> }
/>
<ToggleGroupControlOption
value="menu"
aria-label={ __( 'menu' ) }
label={ <OverlayMenuIcon icon="menu" /> }
/>
{ navigationBlockOverlayIcons.map(
( { label, icon: _icon } ) => (
<ToggleGroupControlOption
key={ _icon }
value={ _icon }
aria-label={ label }
label={ <OverlayMenuIcon icon={ _icon } /> }
/>
)
) }
</ToggleGroupControl>
</>
);
Expand Down