Skip to content

Commit

Permalink
the background size panel displays by default in the site editor for …
Browse files Browse the repository at this point in the history
…top-level styles, but only when there's an image available.

Using constant for "image"
  • Loading branch information
ramonjd committed Apr 14, 2024
1 parent 2b8443c commit 133f9c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ import MediaReplaceFlow from '../media-replace-flow';
import { store as blockEditorStore } from '../../store';

const IMAGE_BACKGROUND_TYPE = 'image';
const DEFAULT_CONTROLS = {
backgroundImage: true,
backgroundSize: false,
};

/**
* Checks site settings to see if the background panel may be used.
Expand Down Expand Up @@ -248,7 +252,7 @@ function BackgroundImageToolsPanelItem( {

const onFilesDrop = ( filesList ) => {
mediaUpload( {
allowedTypes: [ 'image' ],
allowedTypes: [ IMAGE_BACKGROUND_TYPE ],
filesList,
onFileChange( [ image ] ) {
if ( isBlobURL( image?.url ) ) {
Expand Down Expand Up @@ -540,11 +544,6 @@ function BackgroundToolsPanel( {
);
}

const DEFAULT_CONTROLS = {
backgroundImage: true,
backgroundSize: false,
};

export default function BackgroundPanel( {
as: Wrapper = BackgroundToolsPanel,
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export default function BackgroundPanel() {
} );
const [ settings ] = useGlobalSetting( '' );

const defaultControls = {
backgroundImage: true,
backgroundSize:
!! style?.background?.backgroundImage &&
!! inheritedStyle?.background?.backgroundImage,
};

return (
<StylesBackgroundPanel
inheritedValue={ inheritedStyle }
Expand All @@ -37,6 +44,7 @@ export default function BackgroundPanel() {
settings={ settings }
headerLabel={ __( 'Image' ) }
defaultValues={ BACKGROUND_DEFAULT_VALUES }
defaultControls={ defaultControls }
/>
);
}

0 comments on commit 133f9c0

Please sign in to comment.