Skip to content

Commit

Permalink
A little refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed May 20, 2022
1 parent d38dacc commit 3256667
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 43 deletions.
2 changes: 1 addition & 1 deletion packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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": 32, // InnerBlocks area inside cover image block. Must be higher than block popover and less than drop zone.
".wp-block-cover.is-placeholder .components-placeholder.is-large": 1, // Cover block resizer component inside a large placeholder.
".wp-block-cover.is-placeholder .components-placeholder.is-large": 32, // 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.
".block-library-cover__padding-visualizer": 2, // BoxControl visualizer needs to be +1 higher than .wp-block-cover.has-background-dim::before
".wp-block-cover__image-background": 0, // Image background inside cover block.
Expand Down
67 changes: 25 additions & 42 deletions packages/block-library/src/cover/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,27 @@ function CoverEdit( {
overlayColor,
};

const resizableCoverProps = {
className: 'block-library-cover__resize-container',
clientId,
height,
minHeight: parseFloat( minHeight ),
onResizeStart: () => {
setAttributes( { minHeightUnit: 'px' } );
toggleSelection( false );
},
onResize: ( value ) => {
setAttributes( { minHeight: value } );
},
onResizeStop: ( newMinHeight ) => {
toggleSelection( true );
setAttributes( { minHeight: newMinHeight } );
},
showHandle: true,
size: resizableBoxDimensions,
width,
};

if ( ! hasInnerBlocks && ! hasBackground ) {
return (
<>
Expand All @@ -238,26 +259,7 @@ function CoverEdit( {
currentSettings={ currentSettings }
/>
{ isSelected && (
<ResizableCoverPopover
clientId={ clientId }
className="block-library-cover__resize-container is-placeholder"
minHeight={ parseFloat( minHeight ) }
onResizeStart={ () => {
setAttributes( { minHeightUnit: 'px' } );
toggleSelection( false );
} }
onResize={ ( value ) => {
setAttributes( { minHeight: value } );
} }
onResizeStop={ ( newMinHeight ) => {
toggleSelection( true );
setAttributes( { minHeight: newMinHeight } );
} }
showHandle={ true }
size={ { height: 'auto', width: 'auto' } }
width={ width }
height={ height }
/>
<ResizableCoverPopover { ...resizableCoverProps } />
) }
<div
{ ...blockProps }
Expand Down Expand Up @@ -319,28 +321,6 @@ function CoverEdit( {
coverRef={ ref }
currentSettings={ currentSettings }
/>
{ isSelected && (
<ResizableCoverPopover
clientId={ clientId }
className="block-library-cover__resize-container"
minHeight={ parseFloat( minHeight ) }
onResizeStart={ () => {
setAttributes( { minHeightUnit: 'px' } );
toggleSelection( false );
} }
onResize={ ( value ) => {
setAttributes( { minHeight: value } );
} }
onResizeStop={ ( newMinHeight ) => {
toggleSelection( true );
setAttributes( { minHeight: newMinHeight } );
} }
showHandle
size={ resizableBoxDimensions }
width={ width }
height={ height }
/>
) }
<div
{ ...blockProps }
className={ classnames( classes, blockProps.className ) }
Expand Down Expand Up @@ -396,6 +376,9 @@ function CoverEdit( {
/>
<div { ...innerBlocksProps } />
</div>
{ isSelected && (
<ResizableCoverPopover { ...resizableCoverProps } />
) }
</>
);
}
Expand Down

0 comments on commit 3256667

Please sign in to comment.