Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ Settings related to the lightbox.
| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| enabled | Defines whether the lightbox is enabled or not. | `boolean` | |
| overlayBackgroundColor | The background color of the lightbox overlay. Accepts any valid CSS color value. | `string` | |
| allowEditing | Defines whether to show the Lightbox UI in the block editor. If set to `false`, the user won't be able to change the lightbox settings in the block editor. | `boolean` | |

---
Expand Down
5 changes: 3 additions & 2 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,9 @@ class WP_Theme_JSON_Gutenberg {
'allowCustomContentAndWideSize' => null,
),
'lightbox' => array(
'enabled' => true,
'allowEditing' => true,
'enabled' => true,
'allowEditing' => true,
'overlayBackgroundColor' => null,
),
'position' => array(
'fixed' => null,
Expand Down
21 changes: 20 additions & 1 deletion packages/block-library/src/image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,25 @@ function block_core_image_print_lightbox_overlay() {
}
}

// Check for a lightbox specific overlay background color.
// Themes can set this in theme.json under:
// settings.blocks.core/image.lightbox.overlayBackgroundColor (block-level)
// settings.lightbox.overlayBackgroundColor (global fallback).
$lightbox_overlay_background_color = null;
$lightbox_block_settings = wp_get_global_settings( array( 'lightbox' ), array( 'block_name' => 'core/image' ) );
if ( isset( $lightbox_block_settings['overlayBackgroundColor'] ) ) {
$lightbox_overlay_background_color = esc_attr( $lightbox_block_settings['overlayBackgroundColor'] );
} else {
$lightbox_global_settings = wp_get_global_settings( array( 'lightbox' ) );
if ( isset( $lightbox_global_settings['overlayBackgroundColor'] ) ) {
$lightbox_overlay_background_color = esc_attr( $lightbox_global_settings['overlayBackgroundColor'] );
}
}

// Prefer the lightbox specific color when set, otherwise fall back to
// the global background color.
$overlay_background_color = $lightbox_overlay_background_color ?? $background_color;

echo <<<HTML
<div
class="wp-lightbox-overlay zoom"
Expand Down Expand Up @@ -400,7 +419,7 @@ class="wp-lightbox-overlay zoom"
<span class="wp-lightbox-navigation-icon" data-wp-bind--hidden="!state.hasNavigationIcon">{$next_button_icon}</span>
</button>
<div data-wp-text="state.ariaLabel" aria-live="polite" aria-atomic="true" class="screen-reader-text"></div>
<div class="scrim" style="background-color: {$background_color}" aria-hidden="true"></div>
<div class="scrim" style="--wp--lightbox--overlay-background-color: {$overlay_background_color}" aria-hidden="true"></div>
</div>
HTML;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/image/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@
height: 100%;
position: absolute;
z-index: 2000000;
background-color: rgb(255, 255, 255);
background-color: var(--wp--lightbox--overlay-background-color, rgb(255, 255, 255));
opacity: 0.9;
}

Expand Down
4 changes: 4 additions & 0 deletions schemas/json/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@
"description": "Defines whether the lightbox is enabled or not.",
"type": "boolean"
},
"overlayBackgroundColor": {
"description": "The background color of the lightbox overlay. Accepts any valid CSS color value.",
"type": "string"
},
"allowEditing": {
"description": "Defines whether to show the Lightbox UI in the block editor. If set to `false`, the user won't be able to change the lightbox settings in the block editor.",
"type": "boolean"
Expand Down
Loading