-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
base: trunk
Are you sure you want to change the base?
Changes from 11 commits
1398e28
99b4f17
519f7b7
4184b4b
03a5108
920cf53
a2e68b4
e267978
38ca863
cc18957
b0e2645
3be64f4
cc10820
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,10 @@ 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, | ||
} from '@wordpress/block-editor'; | ||
import { useState } from '@wordpress/element'; | ||
import { getAuthority } from '@wordpress/url'; | ||
|
||
|
@@ -31,6 +34,7 @@ export default function EmbedPreview( { | |
className, | ||
icon, | ||
label, | ||
attributes, | ||
} ) { | ||
const [ interactive, setInteractive ] = useState( false ); | ||
|
||
|
@@ -64,16 +68,27 @@ export default function EmbedPreview( { | |
className, | ||
'wp-block-embed__wrapper' | ||
); | ||
const borderProps = useBorderProps( 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 | ||
// the block can be selected without interacting with the embed preview that the overlay covers. | ||
/* eslint-disable jsx-a11y/no-static-element-interactions */ | ||
const embedWrapper = | ||
'wp-embed' === type ? ( | ||
<WpEmbedPreview html={ html } /> | ||
<WpEmbedPreview | ||
html={ html } | ||
className={ borderProps.className } | ||
style={ { ...borderProps.style } } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about these new props. Would it be more forward-compatible for them to be combined into something like It might also help get other reviewers if we can update the test instructions to cover this scenario as well as others (e.g. explaining to test with a WordPress post as an embed, youtube video, tweet, spotify link etc.) Even better if you could include some test URLs 🙏 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in last commit. |
||
/> | ||
) : ( | ||
<div className="wp-block-embed__wrapper"> | ||
<div | ||
className={ clsx( | ||
'wp-block-embed__wrapper', | ||
borderProps.className | ||
) } | ||
style={ { ...borderProps.style } } | ||
> | ||
<SandBox | ||
html={ html } | ||
scripts={ scripts } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ const attributeMap = { | |
marginwidth: 'marginWidth', | ||
}; | ||
|
||
export default function WpEmbedPreview( { html } ) { | ||
export default function WpEmbedPreview( { html, className, style } ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As noted in my earlier comment, these new props might be better combined into a single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in last commit. |
||
const ref = useRef(); | ||
const props = useMemo( () => { | ||
const doc = new window.DOMParser().parseFromString( html, 'text/html' ); | ||
|
@@ -68,7 +68,10 @@ export default function WpEmbedPreview( { html } ) { | |
}, [] ); | ||
|
||
return ( | ||
<div className="wp-block-embed__wrapper"> | ||
<div | ||
className={ `wp-block-embed__wrapper ${ className }` } | ||
style={ style } | ||
> | ||
<iframe | ||
ref={ useMergeRefs( [ ref, useFocusableIframe() ] ) } | ||
title={ props.title } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The border support is opt-in by default so we shouldn't have to explicitly set it to
false
. That said, this does communicate that it was a conscious decision to omit border-radius support so we can leave it..