From bdab9913d201d87f021af5ba1c793739fe08e5da Mon Sep 17 00:00:00 2001 From: ramon Date: Wed, 19 Jun 2024 17:52:35 +1000 Subject: [PATCH] Rejigging components, catering for no-background-image-controls --- .../global-styles/background-panel.js | 115 ++++++++++-------- .../src/components/global-styles/style.scss | 20 ++- 2 files changed, 80 insertions(+), 55 deletions(-) diff --git a/packages/block-editor/src/components/global-styles/background-panel.js b/packages/block-editor/src/components/global-styles/background-panel.js index 0af1ae06757331..d5e584e70f049f 100644 --- a/packages/block-editor/src/components/global-styles/background-panel.js +++ b/packages/block-editor/src/components/global-styles/background-panel.js @@ -28,7 +28,13 @@ import { import { __, _x, sprintf } from '@wordpress/i18n'; import { store as noticesStore } from '@wordpress/notices'; import { getFilename } from '@wordpress/url'; -import { useCallback, Platform, useRef, useState } from '@wordpress/element'; +import { + useCallback, + Platform, + useRef, + useState, + useEffect, +} from '@wordpress/element'; import { useDispatch, useSelect } from '@wordpress/data'; import { focus } from '@wordpress/dom'; import { isBlobURL } from '@wordpress/blob'; @@ -53,6 +59,7 @@ const BACKGROUND_POPOVER_PROPS = { offset: 36, shift: true, }; +const noop = () => {}; /** * Checks site settings to see if the background panel may be used. @@ -156,7 +163,13 @@ function InspectorImagePreviewItem( { filename, label, className, + onToggleCallback = noop, } ) { + useEffect( () => { + if ( typeof toggleProps?.isOpen !== 'undefined' ) { + onToggleCallback( toggleProps?.isOpen ); + } + }, [ toggleProps?.isOpen ] ); return ( - - { imgUrl && ( + { imgUrl && ( + - ) } - - + + ) } + {}; - function InspectorImagePreviewToggle( { label, filename, url: imgUrl, children, - allowPopover = false, onToggle: onToggleCallback = noop, hasImageValue, } ) { @@ -222,16 +232,6 @@ function InspectorImagePreviewToggle( { const imgLabel = label || getFilename( imgUrl ) || __( 'Add background image' ); - if ( ! allowPopover ) { - return ( - - ); - } return ( ); } } @@ -275,6 +276,7 @@ function BackgroundImageToolsPanelItem( { onChange, style, inheritedValue, + shouldShowBackgroundImageControls, } ) { const mediaUpload = useSelect( ( select ) => select( blockEditorStore ).getSettings().mediaUpload, @@ -390,16 +392,23 @@ function BackgroundImageToolsPanelItem( { const canRemove = ! hasValue && hasBackgroundImageValue( inheritedValue ); const imgLabel = title || getFilename( url ) || __( 'Add background image' ); + return ( hasValue } label={ __( 'Background image' ) } onDeselect={ resetBackgroundImage } isShownByDefault={ isShownByDefault } resetAllFilter={ resetAllFilter } panelId={ panelId } - style={ hasImageValue ? {} : { width: '100%' } } >
) : ( - setIsDropDownOpen( isOpen ) } - hasImageValue={ hasImageValue } - > - - + { shouldShowBackgroundImageControls && ( + + + + ) }
diff --git a/packages/block-editor/src/components/global-styles/style.scss b/packages/block-editor/src/components/global-styles/style.scss index cfd114ab9f649c..689ac4c90c6f1c 100644 --- a/packages/block-editor/src/components/global-styles/style.scss +++ b/packages/block-editor/src/components/global-styles/style.scss @@ -75,12 +75,15 @@ position: relative; border: 1px solid $gray-300; border-radius: 2px; - display: flex; justify-content: center; align-items: stretch; // Full width. ToolsPanel lays out children in a grid. grid-column: 1 / -1; + &.has-image { + display: flex; + } + &.is-open { background-color: $gray-100; } @@ -89,6 +92,15 @@ height: 100%; } + .block-editor-global-styles-background-panel__image-tools-panel-item { + &.is-wide { + width: 100%; + .block-editor-global-styles-background-panel__inspector-preview-inner { + justify-content: center; + } + } + } + .block-editor-global-styles-background-panel__image-preview, .block-editor-global-styles-background-panel__inspector-media-replace { flex-grow: 1; @@ -115,7 +127,7 @@ button.components-button { color: $gray-900; - box-shadow: inset 0 0 0 $border-width $gray-400; + //box-shadow: inset 0 0 0 $border-width $gray-400; width: 100%; display: block; @@ -180,7 +192,7 @@ } .block-editor-global-styles-background-panel__hidden-tools-panel-item { - height: 0px; + height: 0; + width: 0; position: absolute; - width: 0px; }