Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed Block: Border support added #66386

Open
wants to merge 13 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Add a block that displays content pulled from other sites, like Twitter or YouTu

- **Name:** core/embed
- **Category:** embed
- **Supports:** align, interactivity (clientNavigation), spacing (margin)
- **Supports:** align, interactivity (clientNavigation), spacing (margin, padding)
- **Attributes:** allowResponsive, caption, previewable, providerNameSlug, responsive, type, url

## File
Expand Down
20 changes: 19 additions & 1 deletion packages/block-library/src/embed/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,30 @@
"supports": {
"align": true,
"spacing": {
"margin": true
"margin": true,
"padding": true,
"__experimentalSkipSerialization": [ "padding" ]
},
"interactivity": {
"clientNavigation": true
},
"__experimentalBorder": {
"radius": true,
"color": true,
"width": true,
"style": true,
"__experimentalDefaultControls": {
"radius": true,
"color": true,
"width": true,
"style": true
},
"__experimentalSkipSerialization": true
}
},
"selectors": {
"border": ".wp-block-embed__wrapper"
},
"editorStyle": "wp-block-embed-editor",
"style": "wp-block-embed"
}
18 changes: 16 additions & 2 deletions packages/block-library/src/embed/embed-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import clsx from 'clsx';
*/
import { __, sprintf } from '@wordpress/i18n';
import { Placeholder, SandBox } from '@wordpress/components';
import { BlockIcon } from '@wordpress/block-editor';
import {
BlockIcon,
__experimentalUseBorderProps as useBorderProps,
__experimentalGetSpacingClassesAndStyles as getSpacingClassesAndStyles,
} from '@wordpress/block-editor';
import { useState } from '@wordpress/element';
import { getAuthority } from '@wordpress/url';

Expand All @@ -31,6 +35,7 @@ export default function EmbedPreview( {
className,
icon,
label,
attributes,
} ) {
const [ interactive, setInteractive ] = useState( false );

Expand Down Expand Up @@ -64,6 +69,8 @@ export default function EmbedPreview( {
className,
'wp-block-embed__wrapper'
);
const borderProps = useBorderProps( attributes );
const spacingProps = getSpacingClassesAndStyles( attributes );

// Disabled because the overlay div doesn't actually have a role or functionality
// as far as the user is concerned. We're just catching the first click so that
Expand All @@ -73,7 +80,14 @@ export default function EmbedPreview( {
'wp-embed' === type ? (
<WpEmbedPreview html={ html } />
) : (
<div className="wp-block-embed__wrapper">
<div
className={ clsx(
'wp-block-embed__wrapper',
borderProps.className,
spacingProps.className
) }
style={ { ...borderProps.style, ...spacingProps.style } }
>
<SandBox
html={ html }
scripts={ scripts }
Expand Down
13 changes: 12 additions & 1 deletion packages/block-library/src/embed/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
RichText,
useBlockProps,
__experimentalGetElementClassName,
__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,
__experimentalGetSpacingClassesAndStyles as getSpacingClassesAndStyles,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
Expand All @@ -18,6 +20,8 @@ export default function save( { attributes } ) {
if ( ! url ) {
return null;
}
const borderProps = getBorderClassesAndStyles( attributes );
const spacingProps = getSpacingClassesAndStyles( attributes );

const className = clsx( 'wp-block-embed', {
[ `is-type-${ type }` ]: type,
Expand All @@ -27,7 +31,14 @@ export default function save( { attributes } ) {

return (
<figure { ...useBlockProps.save( { className } ) }>
<div className="wp-block-embed__wrapper">
<div
className={ clsx(
'wp-block-embed__wrapper',
borderProps.className,
spacingProps.className
) }
style={ { ...borderProps.style, ...spacingProps.style } }
>
{ `\n${ url }\n` /* URL needs to be on its own line. */ }
</div>
{ ! RichText.isEmpty( caption ) && (
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/embed/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
.wp-block-embed {
overflow-wrap: break-word; // Break long strings of text without spaces so they don't overflow the block.

// This block has customizable padding, border-box makes that more predictable.
box-sizing: border-box;

// Supply caption styles to embeds, even if the theme hasn't opted in.
// Reason being: the new markup, figcaptions, are not likely to be styled in the majority of existing themes,
// so we supply the styles so as to not appear broken or unstyled in those.
Expand Down
Loading