Skip to content

Commit

Permalink
revert additional shadow styling for column and columns blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
madhusudhand committed Feb 5, 2024
1 parent 804ed07 commit e333d9f
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 91 deletions.
8 changes: 4 additions & 4 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ A single column within a columns block. ([Source](https://github.com/WordPress/g
- **Name:** core/column
- **Category:** design
- **Parent:** core/columns
- **Supports:** anchor, color (background, button, gradients, heading, link, text), interactivity (clientNavigation), layout, spacing (blockGap, padding), typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
- **Supports:** anchor, color (background, button, gradients, heading, link, text), interactivity (clientNavigation), layout, shadow, spacing (blockGap, padding), typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
- **Attributes:** allowedBlocks, templateLock, verticalAlignment, width

## Columns
Expand All @@ -106,7 +106,7 @@ Display content in multiple columns, with blocks added to each column. ([Source]

- **Name:** core/columns
- **Category:** design
- **Supports:** align (full, wide), anchor, color (background, button, gradients, heading, link, text), interactivity (clientNavigation), layout (default, ~~allowEditing~~, ~~allowInheriting~~, ~~allowSwitching~~), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Supports:** align (full, wide), anchor, color (background, button, gradients, heading, link, text), interactivity (clientNavigation), layout (default, ~~allowEditing~~, ~~allowInheriting~~, ~~allowSwitching~~), shadow, spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** isStackedOnMobile, templateLock, verticalAlignment

## Comment Author Avatar (deprecated)
Expand Down Expand Up @@ -341,7 +341,7 @@ Gather blocks in a layout container. ([Source](https://github.com/WordPress/gute

- **Name:** core/group
- **Category:** design
- **Supports:** align (full, wide), anchor, ariaLabel, background (backgroundImage, backgroundSize), color (background, button, gradients, heading, link, text), dimensions (minHeight), interactivity (clientNavigation), layout (allowSizingOnChildren), position (sticky), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Supports:** align (full, wide), anchor, ariaLabel, background (backgroundImage, backgroundSize), color (background, button, gradients, heading, link, text), dimensions (minHeight), interactivity (clientNavigation), layout (allowSizingOnChildren), position (sticky), shadow, spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** allowedBlocks, tagName, templateLock

## Heading
Expand Down Expand Up @@ -378,7 +378,7 @@ Insert an image to make a visual statement. ([Source](https://github.com/WordPre

- **Name:** core/image
- **Category:** media
- **Supports:** align (center, full, left, right, wide), anchor, color (~~background~~, ~~text~~), filter (duotone), interactivity
- **Supports:** align (center, full, left, right, wide), anchor, color (~~background~~, ~~text~~), filter (duotone), interactivity, shadow
- **Attributes:** alt, aspectRatio, caption, height, href, id, lightbox, linkClass, linkDestination, linkTarget, rel, scale, sizeSlug, title, url, width

## Latest Comments
Expand Down
18 changes: 6 additions & 12 deletions packages/block-library/src/column/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
useSettings,
useInnerBlocksProps,
store as blockEditorStore,
__experimentalUseShadowProps as useShadowProps,
} from '@wordpress/block-editor';
import {
__experimentalUseCustomUnits as useCustomUnits,
Expand All @@ -25,9 +24,11 @@ import {
import { useSelect, useDispatch } from '@wordpress/data';
import { sprintf, __ } from '@wordpress/i18n';

function ColumnEdit( { attributes, setAttributes, clientId } ) {
const { verticalAlignment, width, templateLock, allowedBlocks } =
attributes;
function ColumnEdit( {
attributes: { verticalAlignment, width, templateLock, allowedBlocks },
setAttributes,
clientId,
} ) {
const classes = classnames( 'block-core-columns', {
[ `is-vertically-aligned-${ verticalAlignment }` ]: verticalAlignment,
} );
Expand Down Expand Up @@ -65,16 +66,9 @@ function ColumnEdit( { attributes, setAttributes, clientId } ) {
};

const widthWithUnit = Number.isFinite( width ) ? width + '%' : width;
const shadowProps = useShadowProps( attributes );
const flexBasisStyle = widthWithUnit
? { flexBasis: widthWithUnit }
: undefined;
const blockProps = useBlockProps( {
className: classes,
style: {
...shadowProps.style,
...flexBasisStyle,
},
style: widthWithUnit ? { flexBasis: widthWithUnit } : undefined,
} );

const columnsCount = columnsIds.length;
Expand Down
15 changes: 3 additions & 12 deletions packages/block-library/src/column/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import {
useInnerBlocksProps,
useBlockProps,
__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,
} from '@wordpress/block-editor';
import { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { verticalAlignment, width } = attributes;
Expand All @@ -19,7 +15,7 @@ export default function save( { attributes } ) {
[ `is-vertically-aligned-${ verticalAlignment }` ]: verticalAlignment,
} );

let widthStyle;
let style;

if ( width && /\d/.test( width ) ) {
// Numbers are handled for backward compatibility as they can be still provided with templates.
Expand All @@ -33,14 +29,9 @@ export default function save( { attributes } ) {
multiplier +
'%';
}
widthStyle = { flexBasis };
style = { flexBasis };
}

const style = {
...getShadowClassesAndStyles( attributes ).style,
...widthStyle,
};

const blockProps = useBlockProps.save( {
className: wrapperClasses,
style,
Expand Down
10 changes: 2 additions & 8 deletions packages/block-library/src/columns/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
BlockControls,
BlockVerticalAlignmentToolbar,
__experimentalBlockVariationPicker,
__experimentalUseShadowProps as useShadowProps,
useBlockProps,
store as blockEditorStore,
} from '@wordpress/block-editor';
Expand Down Expand Up @@ -89,10 +88,8 @@ function ColumnsEditContainer( {
[ `is-not-stacked-on-mobile` ]: ! isStackedOnMobile,
} );

const shadowProps = useShadowProps( attributes );
const blockProps = useBlockProps( {
className: classes,
style: shadowProps.style,
} );
const innerBlocksProps = useInnerBlocksProps( blockProps, {
orientation: 'horizontal',
Expand Down Expand Up @@ -253,7 +250,7 @@ const ColumnsEditContainerWrapper = withDispatch(
} )
)( ColumnsEditContainer );

function Placeholder( { attributes, clientId, name, setAttributes } ) {
function Placeholder( { clientId, name, setAttributes } ) {
const { blockType, defaultVariation, variations } = useSelect(
( select ) => {
const {
Expand All @@ -271,10 +268,7 @@ function Placeholder( { attributes, clientId, name, setAttributes } ) {
[ name ]
);
const { replaceInnerBlocks } = useDispatch( blockEditorStore );
const shadowProps = useShadowProps( attributes );
const blockProps = useBlockProps( {
style: shadowProps.style,
} );
const blockProps = useBlockProps();

return (
<div { ...blockProps }>
Expand Down
12 changes: 2 additions & 10 deletions packages/block-library/src/columns/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,17 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import {
useInnerBlocksProps,
useBlockProps,
__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,
} from '@wordpress/block-editor';
import { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { isStackedOnMobile, verticalAlignment } = attributes;

const shadowProps = getShadowClassesAndStyles( attributes );
const className = classnames( {
[ `are-vertically-aligned-${ verticalAlignment }` ]: verticalAlignment,
[ `is-not-stacked-on-mobile` ]: ! isStackedOnMobile,
} );

const blockProps = useBlockProps.save( {
className,
style: shadowProps.style,
} );
const blockProps = useBlockProps.save( { className } );
const innerBlocksProps = useInnerBlocksProps.save( blockProps );

return <div { ...innerBlocksProps } />;
Expand Down
3 changes: 1 addition & 2 deletions packages/block-library/src/cover/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@
},
"interactivity": {
"clientNavigation": true
},
"shadow": true
}
},
"editorStyle": "wp-block-cover-editor",
"style": "wp-block-cover"
Expand Down
3 changes: 0 additions & 3 deletions packages/block-library/src/cover/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
useSettings,
useInnerBlocksProps,
__experimentalUseGradient,
__experimentalUseShadowProps as useShadowProps,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
Expand Down Expand Up @@ -290,9 +289,7 @@ function CoverEdit( {

const isImgElement = ! ( hasParallax || isRepeated );

const shadowProps = useShadowProps( attributes );
const style = {
...shadowProps.style,
minHeight: minHeightWithUnit || undefined,
};

Expand Down
71 changes: 31 additions & 40 deletions packages/block-library/src/cover/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
useInnerBlocksProps,
getColorClassName,
__experimentalGetGradientClass,
__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,
useBlockProps,
} from '@wordpress/block-editor';

Expand Down Expand Up @@ -62,9 +61,7 @@ export default function save( { attributes } ) {

const isImgElement = ! ( hasParallax || isRepeated );

const shadowProps = getShadowClassesAndStyles( attributes );
const style = {
...shadowProps.style,
minHeight: minHeight || undefined,
};

Expand Down Expand Up @@ -127,48 +124,42 @@ export default function save( { attributes } ) {
style={ bgStyle }
/>

{ /* @todo: added background wrapper in order to avoid repeating shared props between background types, test compatibility */ }
<div
className="wp-block-cover__background-wrapper"
style={ shadowProps.style }
>
{ ! useFeaturedImage &&
isImageBackground &&
url &&
( isImgElement ? (
<img
className={ imgClasses }
alt={ alt }
src={ url }
style={ { objectPosition } }
data-object-fit="cover"
data-object-position={ objectPosition }
/>
) : (
<div
role={ alt ? 'img' : undefined }
aria-label={ alt ? alt : undefined }
className={ imgClasses }
style={ { backgroundPosition, backgroundImage } }
/>
) ) }
{ isVideoBackground && url && (
<video
className={ classnames(
'wp-block-cover__video-background',
'intrinsic-ignore'
) }
autoPlay
muted
loop
playsInline
{ ! useFeaturedImage &&
isImageBackground &&
url &&
( isImgElement ? (
<img
className={ imgClasses }
alt={ alt }
src={ url }
style={ { objectPosition } }
data-object-fit="cover"
data-object-position={ objectPosition }
/>
) }
</div>
) : (
<div
role={ alt ? 'img' : undefined }
aria-label={ alt ? alt : undefined }
className={ imgClasses }
style={ { backgroundPosition, backgroundImage } }
/>
) ) }
{ isVideoBackground && url && (
<video
className={ classnames(
'wp-block-cover__video-background',
'intrinsic-ignore'
) }
autoPlay
muted
loop
playsInline
src={ url }
style={ { objectPosition } }
data-object-fit="cover"
data-object-position={ objectPosition }
/>
) }
<div
{ ...useInnerBlocksProps.save( {
className: 'wp-block-cover__inner-container',
Expand Down

0 comments on commit e333d9f

Please sign in to comment.