Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cover block: Allow setting the height from the placeholder state. #35068

Merged
merged 9 commits into from Oct 13, 2021
1 change: 1 addition & 0 deletions packages/base-styles/_z-index.scss
Expand Up @@ -37,6 +37,7 @@ $z-layers: (
".edit-widgets-header": 30,
".block-library-button__inline-link .block-editor-url-input__suggestions": 6, // URL suggestions for button block above sibling inserter
".wp-block-cover__inner-container": 1, // InnerBlocks area inside cover image block
".wp-block-cover.is-placeholder .components-placeholder.is-large": 1, // Cover block resizer component inside a large placeholder.
".wp-block-cover.has-background-dim::before": 1, // Overlay area inside block cover need to be higher than the video background.
".wp-block-cover__image-background": 0, // Image background inside cover block.
".wp-block-cover__video-background": 0, // Video background inside cover block.
Expand Down
Expand Up @@ -78,6 +78,7 @@ export function MediaPlaceholder( {
children,
mediaLibraryButton,
placeholder,
style,
} ) {
const mediaUpload = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
Expand Down Expand Up @@ -248,6 +249,7 @@ export function MediaPlaceholder( {
notices={ notices }
onDoubleClick={ onDoubleClick }
preview={ mediaPreview }
style={ style }
>
{ content }
{ children }
Expand Down
18 changes: 17 additions & 1 deletion packages/block-library/src/cover/edit.js
Expand Up @@ -198,7 +198,6 @@ function ResizableCover( {
onResizeStop( elt.clientHeight );
setIsResizing( false );
} }
minHeight={ COVER_MIN_HEIGHT }
{ ...props }
/>
);
Expand Down Expand Up @@ -274,6 +273,7 @@ function CoverPlaceholder( {
noticeUI,
noticeOperations,
onSelectMedia,
style,
} ) {
const { removeAllNotices, createErrorNotice } = noticeOperations;
return (
Expand All @@ -294,6 +294,7 @@ function CoverPlaceholder( {
removeAllNotices();
createErrorNotice( message );
} }
style={ style }
>
{ children }
</MediaPlaceholder>
Expand Down Expand Up @@ -641,6 +642,7 @@ function CoverEdit( {
noticeUI={ noticeUI }
onSelectMedia={ onSelectMedia }
noticeOperations={ noticeOperations }
style={ { minHeight: temporaryMinHeight || minHeight } }
>
<div className="wp-block-cover__placeholder-background-options">
<ColorPalette
Expand All @@ -651,6 +653,20 @@ function CoverEdit( {
/>
</div>
</CoverPlaceholder>
<ResizableCover
className="block-library-cover__resize-container"
onResizeStart={ () => {
setAttributes( { minHeightUnit: 'px' } );
toggleSelection( false );
} }
onResize={ setTemporaryMinHeight }
onResizeStop={ ( newMinHeight ) => {
toggleSelection( true );
setAttributes( { minHeight: newMinHeight } );
setTemporaryMinHeight( null );
} }
showHandle={ isSelected }
/>
</div>
</>
);
Expand Down
17 changes: 17 additions & 0 deletions packages/block-library/src/cover/editor.scss
Expand Up @@ -9,6 +9,22 @@
&.is-placeholder {
min-height: auto !important;
padding: 0 !important;

// Resizeable placeholder for placeholder.
.block-library-cover__resize-container {
display: none;
}
.components-placeholder {
&.is-large {
min-height: 240px;
justify-content: flex-start;
z-index: z-index(".wp-block-cover.is-placeholder .components-placeholder.is-large");
+ .block-library-cover__resize-container {
min-height: 240px;
display: block;
}
}
}
}

&.components-placeholder h2 {
Expand Down Expand Up @@ -64,6 +80,7 @@
left: 0;
right: 0;
bottom: 0;
min-height: 50px;
}

.block-library-cover__resize-container:not(.is-resizing) {
Expand Down