Skip to content

Commit

Permalink
Add navigation overlay block
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Oct 23, 2023
1 parent 2788a9c commit d6e3464
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,15 @@ Add a page, link, or another item to your navigation. ([Source](https://github.c
- **Supports:** typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
- **Attributes:** description, id, isTopLevelLink, kind, label, opensInNewTab, rel, title, type, url

## Navigation Overlay

Display your navigation in an overlay. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/navigation-overlay))

- **Name:** core/navigation-overlay
- **Category:** navigation, theme, design
- **Supports:** inserter
- **Attributes:**

## Submenu

Add a submenu to your navigation. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/navigation-submenu))
Expand Down
1 change: 1 addition & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function gutenberg_reregister_core_block_types() {
'loginout.php' => 'core/loginout',
'navigation.php' => 'core/navigation',
'navigation-link.php' => 'core/navigation-link',
'navigation-overlay.php' => 'core/navigation-overlay',
'navigation-submenu.php' => 'core/navigation-submenu',
'page-list.php' => 'core/page-list',
'page-list-item.php' => 'core/page-list-item',
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import * as missing from './missing';
import * as more from './more';
import * as navigation from './navigation';
import * as navigationLink from './navigation-link';
import * as navigationOverlay from './navigation-overlay';
import * as navigationSubmenu from './navigation-submenu';
import * as nextpage from './nextpage';
import * as pattern from './pattern';
Expand Down Expand Up @@ -185,6 +186,7 @@ const getAllBlocks = () => {
// theme blocks
navigation,
navigationLink,
navigationOverlay,
navigationSubmenu,
siteLogo,
siteTitle,
Expand Down
13 changes: 13 additions & 0 deletions packages/block-library/src/navigation-overlay/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "core/navigation-overlay",
"title": "Navigation Overlay",
"category": "navigation, theme, design",
"description": "Display your navigation in an overlay.",
"supports": {
"inserter": true
},
"textdomain": "default",
"attributes": {}
}
16 changes: 16 additions & 0 deletions packages/block-library/src/navigation-overlay/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* WordPress dependencies
*/
import { useBlockProps } from '@wordpress/block-editor';

const NavigationOverlayEdit = () => {
const props = useBlockProps();

return (
<>
<div { ...props }>hello</div>
</>
);
};

export default NavigationOverlayEdit;
15 changes: 15 additions & 0 deletions packages/block-library/src/navigation-overlay/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Internal dependencies
*/
import initBlock from '../utils/init-block';
import metadata from './block.json';
import NavigationOverlayEdit from './edit';

const { name } = metadata;
export { metadata, name };

export const settings = {
edit: NavigationOverlayEdit,
};

export const init = () => initBlock( { name, metadata, settings } );
32 changes: 32 additions & 0 deletions packages/block-library/src/navigation-overlay/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Server-side rendering of the `core/overlay` block.
*
* @package WordPress
*/

/**
* Registers the `core/navigation-overlay` block on the server.
*/
function register_block_core_navigation_overlay() {
register_block_type_from_metadata(
__DIR__ . '/navigation-overlay',
array(
'render_callback' => 'render_block_core_navigation_overlay',
)
);
}

/**
* Renders the `core/navigation-overlay` block on the server.
*
*
* @param array $attributes Block attributes.
*
* @return string Returns the output of the overlay.
*/
function render_block_core_navigation_overlay( $attributes ) {
return 'navigation overlay';
}

add_action( 'init', 'register_block_core_navigation_overlay' );
6 changes: 6 additions & 0 deletions packages/block-library/src/navigation-overlay/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Internal dependencies
*/
import { init } from '.';

export default init();

0 comments on commit d6e3464

Please sign in to comment.