diff --git a/blocks/library/audio/index.js b/blocks/library/audio/index.js new file mode 100644 index 00000000000000..eb17ec718b382f --- /dev/null +++ b/blocks/library/audio/index.js @@ -0,0 +1,76 @@ +/** + * External dependencies + */ + +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { Placeholder } from '@wordpress/components'; + +/** + * Internal dependencies + */ +import './style.scss'; +import { registerBlockType, source } from '../../api'; +import MediaUploadButton from '../../media-upload-button'; + +const { attr } = source; + +registerBlockType( 'core/audio', { + title: __( 'Audio' ), + + icon: 'media-audio', + + category: 'common', + + attributes: { + src: { + type: 'string', + source: attr( 'audio', 'src' ), + }, + }, + + edit( { attributes, setAttributes, className } ) { + const { src } = attributes; + const onSelectAudio = ( media ) => { + if ( media && media.url ) { + setAttributes( { src: media.url } ); + } + }; + + if ( ! src ) { + return [ + + + { __( 'Insert from Media Library' ) } + + , + ]; + } + + /* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */ + return [ +
+
, + ]; + /* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */ + }, + + save( { attributes } ) { + const { src } = attributes; + return ( +