From 64a2b5769057d7397e3618d7a176f5d415abc175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Wrede?= Date: Mon, 9 Oct 2017 13:55:37 +0200 Subject: [PATCH] Change audio wrapper tag to figure and add caption (#2921) --- blocks/library/audio/index.js | 35 ++++++++++++++----- blocks/library/audio/style.scss | 11 ++++++ blocks/test/fixtures/core__audio.html | 4 +-- blocks/test/fixtures/core__audio.json | 5 +-- blocks/test/fixtures/core__audio.parsed.json | 2 +- .../test/fixtures/core__audio.serialized.html | 2 +- 6 files changed, 45 insertions(+), 14 deletions(-) diff --git a/blocks/library/audio/index.js b/blocks/library/audio/index.js index 671191335f7136..c022d86c5580a7 100644 --- a/blocks/library/audio/index.js +++ b/blocks/library/audio/index.js @@ -15,12 +15,13 @@ import { Component } from '@wordpress/element'; import './style.scss'; import { registerBlockType, source } from '../../api'; import MediaUploadButton from '../../media-upload-button'; +import Editable from '../../editable'; import BlockControls from '../../block-controls'; import BlockAlignmentToolbar from '../../block-alignment-toolbar'; import InspectorControls from '../../inspector-controls'; import BlockDescription from '../../block-description'; -const { attr } = source; +const { attr, children } = source; registerBlockType( 'core/audio', { title: __( 'Audio' ), @@ -37,6 +38,10 @@ registerBlockType( 'core/audio', { align: { type: 'string', }, + caption: { + type: 'array', + source: children( 'figcaption' ), + }, }, getEditWrapperProps( attributes ) { @@ -58,8 +63,8 @@ registerBlockType( 'core/audio', { }; } render() { - const { align } = this.props.attributes; - const { setAttributes, focus } = this.props; + const { align, caption } = this.props.attributes; + const { setAttributes, focus, setFocus } = this.props; const { editing, className, src } = this.state; const updateAlignment = ( nextAlign ) => setAttributes( { align: nextAlign } ); const switchToEditing = () => { @@ -113,6 +118,8 @@ registerBlockType( 'core/audio', { ); + const focusCaption = ( focusValue ) => setFocus( { editable: 'caption', ...focusValue } ); + if ( editing ) { return [ inspectorControls, @@ -150,20 +157,32 @@ registerBlockType( 'core/audio', { return [ controls, inspectorControls, -
+
, + { ( ( caption && caption.length ) || !! focus ) && ( + setAttributes( { caption: value } ) } + inlineToolbar + /> + ) } + , ]; /* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */ } }, save( { attributes } ) { - const { align, src } = attributes; + const { align, src, caption } = attributes; return ( -
+
+ { caption && caption.length > 0 &&
{ caption }
} + ); }, } ); diff --git a/blocks/library/audio/style.scss b/blocks/library/audio/style.scss index d60399e36633e5..addac2b7f6b742 100644 --- a/blocks/library/audio/style.scss +++ b/blocks/library/audio/style.scss @@ -5,3 +5,14 @@ .wp-block-audio .button.button-large { margin-top: 0.5em; } + +.wp-block-audio audio { + width: 100%; +} + +.wp-block-audio figcaption { + margin-top: 0.5em; + color: $dark-gray-100; + text-align: center; + font-size: $default-font-size; +} diff --git a/blocks/test/fixtures/core__audio.html b/blocks/test/fixtures/core__audio.html index 0222d32fa88141..cfa3f20267c4bf 100644 --- a/blocks/test/fixtures/core__audio.html +++ b/blocks/test/fixtures/core__audio.html @@ -1,5 +1,5 @@ -
+
-
+ diff --git a/blocks/test/fixtures/core__audio.json b/blocks/test/fixtures/core__audio.json index a2a9a89a963daa..99b43e37d313d4 100644 --- a/blocks/test/fixtures/core__audio.json +++ b/blocks/test/fixtures/core__audio.json @@ -5,8 +5,9 @@ "isValid": true, "attributes": { "src": "https://media.simplecast.com/episodes/audio/80564/draft-podcast-51-livePublish2.mp3", - "align": "right" + "align": "right", + "caption": [] }, - "originalContent": "
\n \n
" + "originalContent": "
\n \n
" } ] diff --git a/blocks/test/fixtures/core__audio.parsed.json b/blocks/test/fixtures/core__audio.parsed.json index 1066d69b9570b4..b6afa780e2dea9 100644 --- a/blocks/test/fixtures/core__audio.parsed.json +++ b/blocks/test/fixtures/core__audio.parsed.json @@ -4,7 +4,7 @@ "attrs": { "align": "right" }, - "rawContent": "\n
\n \n
\n" + "rawContent": "\n
\n \n
\n" }, { "attrs": {}, diff --git a/blocks/test/fixtures/core__audio.serialized.html b/blocks/test/fixtures/core__audio.serialized.html index c3bef79c980c82..ed3205a8092ec9 100644 --- a/blocks/test/fixtures/core__audio.serialized.html +++ b/blocks/test/fixtures/core__audio.serialized.html @@ -1,3 +1,3 @@ -
+