diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index e51aa40a9677ed..be6f58e1ea875e 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -212,6 +212,29 @@ function Navigation( { }, } ); + const overlayClassnames = classnames( { + 'has-text-color': + !! overlayTextColor.color || !! overlayTextColor?.class, + [ getColorClassName( + 'color', + overlayTextColor?.slug + ) ]: !! overlayTextColor?.slug, + 'has-background': + !! overlayBackgroundColor.color || overlayBackgroundColor?.class, + [ getColorClassName( + 'background-color', + overlayBackgroundColor?.slug + ) ]: !! overlayBackgroundColor?.slug, + } ); + + const overlayStyles = { + color: ! overlayTextColor?.slug && overlayTextColor?.color, + backgroundColor: + ! overlayBackgroundColor?.slug && + overlayBackgroundColor?.color && + overlayBackgroundColor.color, + }; + // Turn on contrast checker for web only since it's not supported on mobile yet. const enableContrastChecking = Platform.OS === 'web'; @@ -494,6 +517,8 @@ function Navigation( { isOpen={ isResponsiveMenuOpen } isResponsive={ 'never' !== overlayMenu } isHiddenByDefault={ 'always' === overlayMenu } + classNames={ overlayClassnames } + styles={ overlayStyles } > { isEntityAvailable && ( ) } -
+
array(), - 'inline_styles' => '', + 'css_classes' => array(), + 'inline_styles' => '', + 'overlay_css_classes' => array(), + 'overlay_inline_styles' => '', ); // Text color. @@ -54,6 +56,42 @@ function block_core_navigation_build_css_colors( $attributes ) { $colors['inline_styles'] .= sprintf( 'background-color: %s;', $attributes['customBackgroundColor'] ); } + // Overlay text color. + $has_named_overlay_text_color = array_key_exists( 'overlayTextColor', $attributes ); + $has_custom_overlay_text_color = array_key_exists( 'customOverlayTextColor', $attributes ); + + // If has overlay text color. + if ( $has_custom_overlay_text_color || $has_named_overlay_text_color ) { + // Add has-text-color class. + $colors['overlay_css_classes'][] = 'has-text-color'; + } + + if ( $has_named_overlay_text_color ) { + // Add the overlay color class. + $colors['overlay_css_classes'][] = sprintf( 'has-%s-color', $attributes['overlayTextColor'] ); + } elseif ( $has_custom_overlay_text_color ) { + // Add the custom overlay color inline style. + $colors['overlay_inline_styles'] .= sprintf( 'color: %s;', $attributes['customOverlayTextColor'] ); + } + + // Overlay background color. + $has_named_overlay_background_color = array_key_exists( 'overlayBackgroundColor', $attributes ); + $has_custom_overlay_background_color = array_key_exists( 'customOverlayBackgroundColor', $attributes ); + + // If has overlay background color. + if ( $has_custom_overlay_background_color || $has_named_overlay_background_color ) { + // Add has-background class. + $colors['overlay_css_classes'][] = 'has-background'; + } + + if ( $has_named_overlay_background_color ) { + // Add the overlay background-color class. + $colors['overlay_css_classes'][] = sprintf( 'has-%s-background-color', $attributes['overlayBackgroundColor'] ); + } elseif ( $has_custom_overlay_background_color ) { + // Add the custom overlay background-color inline style. + $colors['overlay_inline_styles'] .= sprintf( 'background-color: %s;', $attributes['customOverlayBackgroundColor'] ); + } + return $colors; } @@ -247,6 +285,7 @@ function( $block ) { $responsive_container_classes = array( 'wp-block-navigation__responsive-container', $is_hidden_by_default ? 'hidden-by-default' : '', + implode( ' ', $colors['overlay_css_classes'] ), ); $open_button_classes = array( 'wp-block-navigation__responsive-container-open', @@ -255,7 +294,7 @@ function( $block ) { $responsive_container_markup = sprintf( ' -