Skip to content

Commit

Permalink
Add shadow support for column, columns and image (#57982)
Browse files Browse the repository at this point in the history
This PR adds box shadow support to the following blocks:

- Columns
- Cover
- Group
- Image

Issue: #57103

* Add shadow support for image block

* add shadow support for columns block

* add shadow support for individual column block

* add shadow support to cover block

* fix issue where global shadow isn't applied

* revert additional shadow styling for column and columns blocks

* fix image block and skip serialization

* revert changes related to group block

---------

Co-authored-by: vcanales <[email protected]>
Co-authored-by: madhusudhand <[email protected]>
Co-authored-by: dianeco <[email protected]>
  • Loading branch information
4 people authored Feb 5, 2024
1 parent 331532c commit a10d303
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 4 deletions.
6 changes: 3 additions & 3 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 @@ -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
1 change: 1 addition & 0 deletions packages/block-library/src/column/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"text": true
}
},
"shadow": true,
"spacing": {
"blockGap": true,
"padding": true,
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/columns/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
},
"interactivity": {
"clientNavigation": true
}
},
"shadow": true
},
"editorStyle": "wp-block-columns-editor",
"style": "wp-block-columns"
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/image/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,14 @@
"radius": true,
"width": true
}
},
"shadow": {
"__experimentalSkipSerialization": true
}
},
"selectors": {
"border": ".wp-block-image img, .wp-block-image .wp-block-image__crop-area, .wp-block-image .components-placeholder",
"shadow": ".wp-block-image img, .wp-block-image .wp-block-image__crop-area, .wp-block-image .components-placeholder",
"filter": {
"duotone": ".wp-block-image img, .wp-block-image .components-placeholder"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
useBlockProps,
store as blockEditorStore,
__experimentalUseBorderProps as useBorderProps,
__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,
useBlockEditingMode,
} from '@wordpress/block-editor';
import { useEffect, useRef, useState } from '@wordpress/element';
Expand Down Expand Up @@ -316,6 +317,7 @@ export function ImageEdit( {
);

const borderProps = useBorderProps( attributes );
const shadowProps = getShadowClassesAndStyles( attributes );

const classes = classnames( className, {
'is-transient': temporaryURL,
Expand Down Expand Up @@ -377,6 +379,7 @@ export function ImageEdit( {
height: width && aspectRatio ? '100%' : height,
objectFit: scale,
...borderProps.style,
...shadowProps.style,
} }
>
{ lockUrlControls ? (
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
useSettings,
__experimentalImageEditor as ImageEditor,
__experimentalUseBorderProps as useBorderProps,
__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,
privateApis as blockEditorPrivateApis,
} from '@wordpress/block-editor';
import { useEffect, useMemo, useState, useRef } from '@wordpress/element';
Expand Down Expand Up @@ -594,6 +595,7 @@ export default function Image( {
}

const borderProps = useBorderProps( attributes );
const shadowProps = getShadowClassesAndStyles( attributes );
const isRounded = attributes.className?.includes( 'is-style-rounded' );

let img = (
Expand All @@ -620,6 +622,7 @@ export default function Image( {
( width && height ) || aspectRatio ? '100%' : undefined,
objectFit: scale,
...borderProps.style,
...shadowProps.style,
} }
/>
{ temporaryURL && <Spinner /> }
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/image/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
useBlockProps,
__experimentalGetElementClassName,
__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,
__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
Expand All @@ -34,6 +35,7 @@ export default function save( { attributes } ) {

const newRel = ! rel ? undefined : rel;
const borderProps = getBorderClassesAndStyles( attributes );
const shadowProps = getShadowClassesAndStyles( attributes );

const classes = classnames( {
// All other align classes are handled by block supports.
Expand All @@ -58,6 +60,7 @@ export default function save( { attributes } ) {
className={ imageClasses || undefined }
style={ {
...borderProps.style,
...shadowProps.style,
aspectRatio,
objectFit: scale,
width,
Expand Down

0 comments on commit a10d303

Please sign in to comment.