Skip to content

Commit

Permalink
makes the navigation list view implementation a gutenberg experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu committed Oct 17, 2022
1 parent 4662cda commit 2e15920
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/experimental/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,15 @@ function gutenberg_enable_zoomed_out_view() {
}

add_action( 'admin_init', 'gutenberg_enable_zoomed_out_view' );

/**
* Sets a global JS variable used to trigger the availability of zoomed out view.
*/
function gutenberg_enable_off_canvas_navigation_editor() {
$gutenberg_experiments = get_option( 'gutenberg-experiments' );
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-off-canvas-navigation-editor', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableOffCanvasNavigationEditor = true', 'before' );
}
}

add_action( 'admin_init', 'gutenberg_enable_off_canvas_navigation_editor' );
11 changes: 11 additions & 0 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ function gutenberg_initialize_experiments_settings() {
'id' => 'gutenberg-zoomed-out-view',
)
);
add_settings_field(
'gutenberg-off-canvas-navigation-editor',
__( 'Off canvas navigation editor ', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Test a new off canvas editor for navigation block', 'gutenberg' ),
'id' => 'gutenberg-off-canvas-navigation-editor',
)
);
register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
Expand Down
17 changes: 15 additions & 2 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ function Navigation( {
hasColorSettings = true,
customPlaceholder: CustomPlaceholder = null,
} ) {
const isOffCanvasNavigationEditorEnabled =
window?.__experimentalEnableOffCanvasNavigationEditor === true;

const {
openSubmenusOnClick,
overlayMenu,
Expand Down Expand Up @@ -679,7 +682,12 @@ function Navigation( {
/* translators: %s: The name of a menu. */
actionLabel={ __( "Switch to '%s'" ) }
/>
<ListView blocks={ innerBlocks } isExpanded={ true } />
{ isOffCanvasNavigationEditorEnabled && (
<ListView
blocks={ innerBlocks }
isExpanded={ true }
/>
) }
</PanelBody>
</InspectorControls>
{ stylingInspectorControls }
Expand Down Expand Up @@ -857,7 +865,12 @@ function Navigation( {
/* translators: %s: The name of a menu. */
actionLabel={ __( "Switch to '%s'" ) }
/>
<ListView blocks={ innerBlocks } isExpanded={ true } />
{ isOffCanvasNavigationEditorEnabled && (
<ListView
blocks={ innerBlocks }
isExpanded={ true }
/>
) }
</PanelBody>
</InspectorControls>
{ stylingInspectorControls }
Expand Down

0 comments on commit 2e15920

Please sign in to comment.