PluginProbe
Gutenberg / 23.7.2
Gutenberg v23.7.2
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / scripts / block-library / navigation-overlay-close.php

navigation-overlay-close.php in Gutenberg 23.7.2, at build/scripts/block-library/navigation-overlay-close.php

57 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Server-side registering of the `core/navigation-overlay-close` block.
4 *
5 * @package WordPress
6 */
7
8 /**
9 * Renders the `core/navigation-overlay-close` block on server.
10 *
11 * @since 7.0.0
12 *
13 * @param array $attributes The block attributes.
14 *
15 * @return string Returns the block content.
16 */
17 function gutenberg_render_block_core_navigation_overlay_close( $attributes ) {
18 $text = empty( $attributes['text'] ) ? __( 'Close' ) : $attributes['text'];
19 $display_mode = empty( $attributes['displayMode'] ) ? 'icon' : $attributes['displayMode'];
20 $show_icon = 'both' === $display_mode || 'icon' === $display_mode;
21 $show_text = 'both' === $display_mode || 'text' === $display_mode;
22 $button_text = '';
23
24 if ( $show_icon ) {
25 $button_text .= '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M13 11.8l6.1-6.3-1.1-1-6.1 6.2-6.1-6.2-1.1 1 6.1 6.3-6.5 6.7 1.1 1 6.5-6.6 6.5 6.6 1.1-1z" /></svg>';
26 }
27
28 if ( $show_text ) {
29 $button_text .= '<span class="wp-block-navigation-overlay-close__text">' . wp_kses_post( $text ) . '</span>';
30 }
31
32 $wrapper_attributes = get_block_wrapper_attributes();
33 $html_content = sprintf(
34 '<button %1$s type="button" %2$s >%3$s</button>',
35 $wrapper_attributes,
36 ! $show_text ? 'aria-label="' . __( 'Close' ) . '"' : '',
37 $button_text
38 );
39
40 return $html_content;
41 }
42
43 /**
44 * Registers the navigation overlay close block.
45 *
46 * @since 7.0.0
47 */
48 function gutenberg_register_block_core_navigation_overlay_close() {
49 register_block_type_from_metadata(
50 __DIR__ . '/navigation-overlay-close',
51 array(
52 'render_callback' => 'gutenberg_render_block_core_navigation_overlay_close',
53 )
54 );
55 }
56 add_action( 'init', 'gutenberg_register_block_core_navigation_overlay_close', 20 );
57