-
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
Add video block attributes: Autoplay, Controls, Loop, Muted #7672
Changes from 4 commits
7e5bd6d
8ed0045
ba31ed5
03f4b07
c39e5a6
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 |
---|---|---|
|
@@ -2,12 +2,19 @@ | |
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { IconButton, Toolbar, withNotices } from '@wordpress/components'; | ||
import { | ||
IconButton, | ||
PanelBody, | ||
Toolbar, | ||
ToggleControl, | ||
withNotices, | ||
} from '@wordpress/components'; | ||
import { Component, Fragment } from '@wordpress/element'; | ||
import { | ||
BlockControls, | ||
InspectorControls, | ||
MediaPlaceholder, | ||
RichText, | ||
BlockControls, | ||
} from '@wordpress/editor'; | ||
|
||
/** | ||
|
@@ -23,10 +30,18 @@ class VideoEdit extends Component { | |
this.state = { | ||
editing: ! this.props.attributes.src, | ||
}; | ||
|
||
this.toggleAttribute = this.toggleAttribute.bind( this ); | ||
} | ||
|
||
toggleAttribute( attribute ) { | ||
return ( newValue ) => { | ||
this.props.setAttributes( { [ attribute ]: newValue } ); | ||
}; | ||
} | ||
|
||
render() { | ||
const { caption, src } = this.props.attributes; | ||
const { autoplay, caption, controls, loop, muted, src } = this.props.attributes; | ||
const { setAttributes, isSelected, className, noticeOperations, noticeUI } = this.props; | ||
const { editing } = this.state; | ||
const switchToEditing = () => { | ||
|
@@ -86,6 +101,30 @@ class VideoEdit extends Component { | |
/> | ||
</Toolbar> | ||
</BlockControls> | ||
<InspectorControls> | ||
<PanelBody title={ __( 'Playback Controls' ) }> | ||
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 know this was already changed, but I actually think "Playback controls" for audio is maybe something I should have caught before and isn't the right fit. Calling this "playback controls" when "autoplay" and "loop" aren't "controls" per-se is weird, and it also is redundant as you have "Playback Controls > Controls". Realistically this should just be "Video Options" and the option underneath labelled "Controls" should arguably be "Playback Controls". |
||
<ToggleControl | ||
label={ __( 'Autoplay' ) } | ||
onChange={ this.toggleAttribute( 'autoplay' ) } | ||
checked={ autoplay } | ||
/> | ||
<ToggleControl | ||
label={ __( 'Controls' ) } | ||
onChange={ this.toggleAttribute( 'controls' ) } | ||
checked={ controls } | ||
/> | ||
<ToggleControl | ||
label={ __( 'Loop' ) } | ||
onChange={ this.toggleAttribute( 'loop' ) } | ||
checked={ loop } | ||
/> | ||
<ToggleControl | ||
label={ __( 'Muted' ) } | ||
onChange={ this.toggleAttribute( 'muted' ) } | ||
checked={ muted } | ||
/> | ||
</PanelBody> | ||
</InspectorControls> | ||
<figure className={ className }> | ||
<video controls src={ src } /> | ||
{ ( ( caption && caption.length ) || !! isSelected ) && ( | ||
|
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.
Seems like this would make a handy higher-order-component components could use as a sort of mixin, given it's the second place we've used this pattern (after
Audio
).If you could either create a HOC for this and
Audio
(and probably other) components to use that'd be neat… or if that's too much of a pain could you at least file an issue with the "code quality" label for it and link to this comment? 😄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.
Thanks for your comment. I am not a React expert (yet). So I created an issue for this: #7717