Skip to content

Commit 523c716

Browse files
Move ResizableBox to BlockPopover for Cover block borders
1 parent 0832dba commit 523c716

File tree

8 files changed

+107
-59
lines changed

8 files changed

+107
-59
lines changed

packages/base-styles/_z-index.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ $z-layers: (
3232
".interface-interface-skeleton__content": 20,
3333
".edit-widgets-header": 30,
3434
".block-library-button__inline-link .block-editor-url-input__suggestions": 6, // URL suggestions for button block above sibling inserter
35-
".wp-block-cover__inner-container": 1, // InnerBlocks area inside cover image block
36-
".wp-block-cover.is-placeholder .components-placeholder.is-large": 1, // Cover block resizer component inside a large placeholder.
35+
".wp-block-cover__inner-container": 32, // InnerBlocks area inside cover image block. Must be higher than block popover and less than drop zone.
36+
".wp-block-cover.is-placeholder .components-placeholder.is-large": 32, // Cover block resizer component inside a large placeholder.
3737
".wp-block-cover.has-background-dim::before": 1, // Overlay area inside block cover need to be higher than the video background.
3838
".block-library-cover__padding-visualizer": 2, // BoxControl visualizer needs to be +1 higher than .wp-block-cover.has-background-dim::before
3939
".wp-block-cover__image-background": 0, // Image background inside cover block.

packages/block-editor/src/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export { default as MediaUpload } from './media-upload';
8181
export { default as MediaUploadCheck } from './media-upload/check';
8282
export { default as PanelColorSettings } from './panel-color-settings';
8383
export { default as PlainText } from './plain-text';
84+
export { default as __experimentalResizableBoxPopover } from './resizable-box-popover';
8485
export { default as __experimentalResponsiveBlockControl } from './responsive-block-control';
8586
export {
8687
default as RichText,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { ResizableBox } from '@wordpress/components';
5+
6+
/**
7+
* Internal dependencies
8+
*/
9+
import BlockPopover from '../block-popover';
10+
11+
export default function ResizableCoverPopover( {
12+
clientId,
13+
__unstableRefreshSize,
14+
...props
15+
} ) {
16+
return (
17+
<BlockPopover
18+
clientId={ clientId }
19+
__unstableCoverTarget
20+
__unstableRefreshSize={ __unstableRefreshSize }
21+
>
22+
<ResizableBox { ...props } />
23+
</BlockPopover>
24+
);
25+
}

packages/block-library/src/cover/block.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@
8888
"padding": true
8989
}
9090
},
91+
"__experimentalBorder": {
92+
"color": true,
93+
"radius": true,
94+
"style": true,
95+
"width": true,
96+
"__experimentalDefaultControls": {
97+
"color": true,
98+
"radius": true,
99+
"style": true,
100+
"width": true
101+
}
102+
},
91103
"color": {
92104
"__experimentalDuotone": "> .wp-block-cover__image-background, > .wp-block-cover__video-background",
93105
"text": false,

packages/block-library/src/cover/edit/index.js

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import namesPlugin from 'colord/plugins/names';
99
* WordPress dependencies
1010
*/
1111
import { useEntityProp, store as coreStore } from '@wordpress/core-data';
12-
import { useEffect, useRef } from '@wordpress/element';
12+
import { useEffect, useMemo, useRef } from '@wordpress/element';
1313
import { Placeholder, Spinner } from '@wordpress/components';
14-
import { compose } from '@wordpress/compose';
14+
import { compose, useResizeObserver } from '@wordpress/compose';
1515
import {
1616
withColors,
1717
ColorPalette,
@@ -42,7 +42,7 @@ import useCoverIsDark from './use-cover-is-dark';
4242
import CoverInspectorControls from './inspector-controls';
4343
import CoverBlockControls from './block-controls';
4444
import CoverPlaceholder from './cover-placeholder';
45-
import ResizableCover from './resizable-cover';
45+
import ResizableCoverPopover from './resizable-cover-popover';
4646

4747
extend( [ namesPlugin ] );
4848

@@ -142,6 +142,14 @@ function CoverEdit( {
142142
const isImageBackground = IMAGE_BACKGROUND_TYPE === backgroundType;
143143
const isVideoBackground = VIDEO_BACKGROUND_TYPE === backgroundType;
144144

145+
const [ resizeListener, { height, width } ] = useResizeObserver();
146+
const resizableBoxDimensions = useMemo( () => {
147+
return {
148+
height: minHeight ? parseFloat( minHeight ) : 'auto',
149+
width: 'auto',
150+
};
151+
}, [ minHeight ] );
152+
145153
const minHeightWithUnit =
146154
minHeight && minHeightUnit
147155
? `${ minHeight }${ minHeightUnit }`
@@ -242,24 +250,50 @@ function CoverEdit( {
242250
/>
243251
);
244252

253+
const resizableCoverProps = {
254+
className: 'block-library-cover__resize-container',
255+
clientId,
256+
height,
257+
minHeight: parseFloat( minHeight ),
258+
onResizeStart: () => {
259+
setAttributes( { minHeightUnit: 'px' } );
260+
toggleSelection( false );
261+
},
262+
onResize: ( value ) => {
263+
setAttributes( { minHeight: value } );
264+
},
265+
onResizeStop: ( newMinHeight ) => {
266+
toggleSelection( true );
267+
setAttributes( { minHeight: newMinHeight } );
268+
},
269+
showHandle: true,
270+
size: resizableBoxDimensions,
271+
width,
272+
};
273+
245274
if ( ! useFeaturedImage && ! hasInnerBlocks && ! hasBackground ) {
246275
return (
247276
<>
248277
{ blockControls }
249278
{ inspectorControls }
279+
{ isSelected && (
280+
<ResizableCoverPopover { ...resizableCoverProps } />
281+
) }
250282
<div
251283
{ ...blockProps }
252284
className={ classnames(
253285
'is-placeholder',
254286
blockProps.className
255287
) }
288+
style={ {
289+
...blockProps.style,
290+
minHeight: minHeightWithUnit || undefined,
291+
} }
256292
>
293+
{ resizeListener }
257294
<CoverPlaceholder
258295
onSelectMedia={ onSelectMedia }
259296
onError={ onUploadError }
260-
style={ {
261-
minHeight: minHeightWithUnit || undefined,
262-
} }
263297
toggleUseFeaturedImage={ toggleUseFeaturedImage }
264298
>
265299
<div className="wp-block-cover__placeholder-background-options">
@@ -271,21 +305,6 @@ function CoverEdit( {
271305
/>
272306
</div>
273307
</CoverPlaceholder>
274-
<ResizableCover
275-
className="block-library-cover__resize-container"
276-
onResizeStart={ () => {
277-
setAttributes( { minHeightUnit: 'px' } );
278-
toggleSelection( false );
279-
} }
280-
onResize={ ( value ) => {
281-
setAttributes( { minHeight: value } );
282-
} }
283-
onResizeStop={ ( newMinHeight ) => {
284-
toggleSelection( true );
285-
setAttributes( { minHeight: newMinHeight } );
286-
} }
287-
showHandle={ isSelected }
288-
/>
289308
</div>
290309
</>
291310
);
@@ -314,22 +333,7 @@ function CoverEdit( {
314333
style={ { ...style, ...blockProps.style } }
315334
data-url={ url }
316335
>
317-
<ResizableCover
318-
className="block-library-cover__resize-container"
319-
onResizeStart={ () => {
320-
setAttributes( { minHeightUnit: 'px' } );
321-
toggleSelection( false );
322-
} }
323-
onResize={ ( value ) => {
324-
setAttributes( { minHeight: value } );
325-
} }
326-
onResizeStop={ ( newMinHeight ) => {
327-
toggleSelection( true );
328-
setAttributes( { minHeight: newMinHeight } );
329-
} }
330-
showHandle={ isSelected }
331-
/>
332-
336+
{ resizeListener }
333337
{ ( ! useFeaturedImage || url ) && (
334338
<span
335339
aria-hidden="true"
@@ -400,6 +404,9 @@ function CoverEdit( {
400404
/>
401405
<div { ...innerBlocksProps } />
402406
</div>
407+
{ isSelected && (
408+
<ResizableCoverPopover { ...resizableCoverProps } />
409+
) }
403410
</>
404411
);
405412
}

packages/block-library/src/cover/edit/resizable-cover.js renamed to packages/block-library/src/cover/edit/resizable-cover-popover.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import classnames from 'classnames';
66
/**
77
* WordPress dependencies
88
*/
9-
import { useState } from '@wordpress/element';
10-
import { ResizableBox } from '@wordpress/components';
9+
import { useMemo, useState } from '@wordpress/element';
10+
import { __experimentalResizableBoxPopover as ResizableBoxPopover } from '@wordpress/block-editor';
1111

1212
const RESIZABLE_BOX_ENABLE_OPTION = {
1313
top: false,
@@ -20,17 +20,25 @@ const RESIZABLE_BOX_ENABLE_OPTION = {
2020
topLeft: false,
2121
};
2222

23-
export default function ResizableCover( {
23+
export default function ResizableCoverPopover( {
2424
className,
25-
onResizeStart,
25+
height,
26+
minHeight,
2627
onResize,
28+
onResizeStart,
2729
onResizeStop,
30+
width,
2831
...props
2932
} ) {
3033
const [ isResizing, setIsResizing ] = useState( false );
34+
const dimensions = useMemo(
35+
() => ( { height, minHeight, width } ),
36+
[ minHeight, height, width ]
37+
);
3138

3239
return (
33-
<ResizableBox
40+
<ResizableBoxPopover
41+
__unstableRefreshSize={ dimensions }
3442
className={ classnames( className, {
3543
'is-resizing': isResizing,
3644
} ) }

packages/block-library/src/cover/editor.scss

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,23 @@
77
// Override default cover styles
88
// because we're not ready yet to show the cover block.
99
&.is-placeholder {
10-
min-height: auto !important;
1110
padding: 0 !important;
11+
display: flex;
12+
align-items: stretch;
13+
overflow: visible;
14+
min-height: 240px;
1215

13-
// Resizable placeholder for placeholder.
14-
.block-library-cover__resize-container {
15-
display: none;
16-
}
1716
.components-placeholder {
1817
&.is-large {
19-
min-height: 240px;
2018
justify-content: flex-start;
2119
z-index: z-index(".wp-block-cover.is-placeholder .components-placeholder.is-large");
22-
+ .block-library-cover__resize-container {
23-
min-height: 240px;
24-
display: block;
25-
}
2620
}
2721
}
22+
23+
// Allow focus outline/box-shadow to align with block's min height.
24+
&:focus::after {
25+
min-height: auto;
26+
}
2827
}
2928

3029
&.components-placeholder h2 {
@@ -88,11 +87,6 @@
8887
min-height: 50px;
8988
}
9089

91-
.block-library-cover__resize-container:not(.is-resizing) {
92-
// Important is used to have higher specificity than the inline style set by re-resizable library.
93-
height: auto !important;
94-
}
95-
9690
// When uploading background images, show a transparent overlay.
9791
.wp-block-cover > .components-drop-zone .components-drop-zone__content {
9892
opacity: 0.8 !important;

packages/block-library/src/cover/style.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
box-sizing: border-box;
1212
// Keep the flex layout direction to the physical direction (LTR) in RTL languages.
1313
/*rtl:raw: direction: ltr; */
14+
overflow: hidden;
1415

1516
/**
1617
* Set a default background color for has-background-dim _unless_ it includes another

0 commit comments

Comments
 (0)