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

Video: Add border block support #63777

Open
wants to merge 18 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
10 changes: 10 additions & 0 deletions packages/block-library/src/video/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,18 @@
},
"interactivity": {
"clientNavigation": true
},
"__experimentalBorder": {
"radius": true,
"color": true,
"width": true,
"style": true,
"__experimentalSkipSerialization": true
}
},
"selectors": {
"border": ".wp-block-video video, .wp-block-video .components-placeholder"
},
"editorStyle": "wp-block-video-editor",
"style": "wp-block-video"
}
10 changes: 9 additions & 1 deletion packages/block-library/src/video/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
MediaUploadCheck,
MediaReplaceFlow,
useBlockProps,
__experimentalUseBorderProps as useBorderProps,
} from '@wordpress/block-editor';
import { useRef, useEffect, useState } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
Expand Down Expand Up @@ -58,6 +59,7 @@ function VideoEdit( {
const posterImageButton = useRef();
const { id, controls, poster, src, tracks } = attributes;
const [ temporaryURL, setTemporaryURL ] = useState( attributes.blob );
const borderProps = useBorderProps( attributes );

useUploadMediaFromBlobURL( {
url: temporaryURL,
Expand Down Expand Up @@ -136,13 +138,17 @@ function VideoEdit( {
const placeholder = ( content ) => {
return (
<Placeholder
className="block-editor-media-placeholder"
className={ clsx( 'block-editor-media-placeholder', {
[ borderProps.className ]:
!! borderProps.className && ! isSingleSelected,
} ) }
withIllustration={ ! isSingleSelected }
icon={ icon }
label={ __( 'Video' ) }
instructions={ __(
'Upload a video file, pick one from your media library, or add one with a URL.'
) }
style={ ! isSingleSelected ? borderProps.style : {} }
>
{ content }
</Placeholder>
Expand Down Expand Up @@ -280,9 +286,11 @@ function VideoEdit( {
*/ }
<Disabled isDisabled={ ! isSingleSelected }>
<video
className={ borderProps.className }
controls={ controls }
poster={ poster }
src={ src || temporaryURL }
style={ borderProps.style }
ref={ videoPlayer }
>
<Tracks tracks={ tracks } />
Expand Down
7 changes: 7 additions & 0 deletions packages/block-library/src/video/editor.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.wp-block-video.wp-block-video {
// Hide border style on-select, when placeholder is visible.
&.is-selected .components-placeholder {
border: none;
}
}

.wp-block[data-align="center"] > .wp-block-video {
text-align: center;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/block-library/src/video/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
RichText,
useBlockProps,
__experimentalGetElementClassName,
__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,
} from '@wordpress/block-editor';

/**
Expand All @@ -25,6 +26,9 @@ export default function save( { attributes } ) {
playsInline,
tracks,
} = attributes;

const borderProps = getBorderClassesAndStyles( attributes );

return (
<figure { ...useBlockProps.save() }>
{ src && (
Expand All @@ -37,6 +41,8 @@ export default function save( { attributes } ) {
preload={ preload !== 'metadata' ? preload : undefined }
src={ src }
playsInline={ playsInline }
className={ borderProps.className }
style={ borderProps.style }
>
<Tracks tracks={ tracks } />
</video>
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/video/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
video {
width: 100%;
vertical-align: middle;
// Video tag has customizable border, border-box makes that more predictable.
box-sizing: border-box;
}

@supports (position: sticky) {
Expand Down
Loading