Skip to content
Merged
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
61 changes: 41 additions & 20 deletions packages/block-library/src/cover/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { __ } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import { isBlobURL } from '@wordpress/blob';
import { SVG, Path } from '@wordpress/primitives';
import { store as noticesStore } from '@wordpress/notices';

/**
Expand All @@ -46,6 +47,18 @@ import ResizableCover from './resizable-cover';

extend( [ namesPlugin ] );

const placeholderIllustration = (
<SVG
className="components-placeholder__illustration"
fill="none"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 60 60"
preserveAspectRatio="none"
>
<Path vectorEffect="non-scaling-stroke" d="M60 60 0 0" />
</SVG>
);

function getInnerBlocksTemplate( attributes ) {
return [
[
Expand Down Expand Up @@ -212,7 +225,7 @@ function CoverEdit( {
overlayColor,
};

if ( ! hasInnerBlocks && ! hasBackground ) {
if ( ! useFeaturedImage && ! hasInnerBlocks && ! hasBackground ) {
return (
<>
<CoverBlockControls
Expand Down Expand Up @@ -324,25 +337,33 @@ function CoverEdit( {
showHandle={ isSelected }
/>

<span
aria-hidden="true"
className={ classnames(
'wp-block-cover__background',
dimRatioToClass( dimRatio ),
{
[ overlayColor.class ]: overlayColor.class,
'has-background-dim': dimRatio !== undefined,
// For backwards compatibility. Former versions of the Cover Block applied
// `.wp-block-cover__gradient-background` in the presence of
// media, a gradient and a dim.
'wp-block-cover__gradient-background':
url && gradientValue && dimRatio !== 0,
'has-background-gradient': gradientValue,
[ gradientClass ]: gradientClass,
}
) }
style={ { backgroundImage: gradientValue, ...bgStyle } }
/>
{ ( ! useFeaturedImage || url ) && (
<span
aria-hidden="true"
className={ classnames(
'wp-block-cover__background',
dimRatioToClass( dimRatio ),
{
[ overlayColor.class ]: overlayColor.class,
'has-background-dim': dimRatio !== undefined,
// For backwards compatibility. Former versions of the Cover Block applied
// `.wp-block-cover__gradient-background` in the presence of
// media, a gradient and a dim.
'wp-block-cover__gradient-background':
url && gradientValue && dimRatio !== 0,
'has-background-gradient': gradientValue,
[ gradientClass ]: gradientClass,
}
) }
style={ { backgroundImage: gradientValue, ...bgStyle } }
/>
) }

{ ! url && useFeaturedImage && (
<div className="wp-block-cover__image--placeholder-image">
{ placeholderIllustration }
</div>
) }

{ url &&
isImageBackground &&
Expand Down
22 changes: 22 additions & 0 deletions packages/block-library/src/cover/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@
.wp-block-cover__placeholder-background-options {
width: 100%;
}

.wp-block-cover__image--placeholder-image {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;

// Style the placeholder illustration.
.components-placeholder__illustration {
position: absolute;
left: 0;
width: 100%;
height: 100%;
stroke: currentColor;
stroke-dasharray: 3;
opacity: 0.4;
}

border: $border-width dashed currentColor;
}

}

[data-align="left"] > .wp-block-cover,
Expand Down