Skip to content

Commit

Permalink
Try moving application of border in the editor to improve UX
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Apr 29, 2022
1 parent 858ca1b commit 9f987f2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/block-library/src/cover/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"radius": true,
"style": true,
"width": true,
"__experimentalSkipSerialization": true,
"__experimentalDefaultControls": {
"color": true,
"radius": true,
Expand Down
10 changes: 8 additions & 2 deletions packages/block-library/src/cover/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
__experimentalPanelColorGradientSettings as PanelColorGradientSettings,
__experimentalBlockAlignmentMatrixControl as BlockAlignmentMatrixControl,
__experimentalBlockFullHeightAligmentControl as FullHeightAlignmentControl,
__experimentalUseBorderProps as useBorderProps,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
Expand Down Expand Up @@ -651,6 +652,7 @@ function CoverEdit( {

const ref = useRef();
const blockProps = useBlockProps( { ref } );
const borderProps = useBorderProps( attributes );

// Check for fontSize support before we pass a fontSize attribute to the innerBlocks.
const hasFontSizes = !! useSetting( 'typography.fontSizes' )?.length;
Expand Down Expand Up @@ -755,12 +757,12 @@ function CoverEdit( {
} }
showHandle={ isSelected }
/>

<span
aria-hidden="true"
className={ classnames(
'wp-block-cover__background',
dimRatioToClass( dimRatio ),
borderProps.className,
{
[ overlayColor.class ]: overlayColor.class,
'has-background-dim': dimRatio !== undefined,
Expand All @@ -773,7 +775,11 @@ function CoverEdit( {
[ gradientClass ]: gradientClass,
}
) }
style={ { backgroundImage: gradientValue, ...bgStyle } }
style={ {
backgroundImage: gradientValue,
...bgStyle,
...borderProps.style,
} }
/>

{ url && isImageBackground && isImgElement && (
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/cover/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* Extra specificity needed because the reset.css applied in the editor context is overriding this rule. */
.editor-styles-wrapper & {
box-sizing: border-box;
overflow: initial;
}

// Override default cover styles
Expand Down
6 changes: 5 additions & 1 deletion packages/block-library/src/cover/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getColorClassName,
__experimentalGetGradientClass,
useBlockProps,
__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,
} from '@wordpress/block-editor';

/**
Expand Down Expand Up @@ -59,12 +60,14 @@ export default function save( { attributes } ) {
const isVideoBackground = VIDEO_BACKGROUND_TYPE === backgroundType;

const isImgElement = ! ( hasParallax || isRepeated );
const borderProps = getBorderClassesAndStyles( attributes );

const style = {
...( isImageBackground && ! isImgElement && ! useFeaturedImage
? backgroundImageStyles( url )
: {} ),
minHeight: minHeight || undefined,
...borderProps.style,
};

const bgStyle = {
Expand All @@ -87,7 +90,8 @@ export default function save( { attributes } ) {
contentPosition
),
},
getPositionClassName( contentPosition )
getPositionClassName( contentPosition ),
borderProps.className
);

const gradientValue = gradient || customGradient;
Expand Down

0 comments on commit 9f987f2

Please sign in to comment.