From 698e32789883cca529a8bcdebf31b1a28e3126fb Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 26 Jul 2017 14:32:29 -0400 Subject: [PATCH 1/2] Simplify cover image markup structure --- blocks/library/cover-image/block.scss | 21 ++++---- blocks/library/cover-image/index.js | 51 ++++++++++--------- blocks/test/fixtures/core__cover-image.html | 8 ++- blocks/test/fixtures/core__cover-image.json | 1 + .../fixtures/core__cover-image.parsed.json | 5 +- .../core__cover-image.serialized.html | 8 ++- post-content.js | 4 +- 7 files changed, 48 insertions(+), 50 deletions(-) diff --git a/blocks/library/cover-image/block.scss b/blocks/library/cover-image/block.scss index e761ddea3c3af4..0ec7baf4363a7f 100644 --- a/blocks/library/cover-image/block.scss +++ b/blocks/library/cover-image/block.scss @@ -1,6 +1,12 @@ .wp-block-cover-image { - margin: 0; position: relative; + background-size: cover; + height: 430px; + width: 100%; + margin: 0; + display: flex; + justify-content: center; + align-items: center; h2 { color: white; @@ -12,20 +18,11 @@ text-align: center; } - .cover-image { - background-size: cover; - height: 430px; - width: 100%; - display: flex; - justify-content: center; - align-items: center; - } - - .has-parallax { + &.has-parallax { background-attachment: fixed; } - .has-background-dim.cover-image:before { + &.has-background-dim:before { content: ''; position: absolute; top: 0; diff --git a/blocks/library/cover-image/index.js b/blocks/library/cover-image/index.js index 18f185b5649b60..da9f98292a6931 100644 --- a/blocks/library/cover-image/index.js +++ b/blocks/library/cover-image/index.js @@ -34,6 +34,10 @@ registerBlockType( 'core/cover-image', { title: text( 'h2' ), }, + defaultAttributes: { + hasBackgroundDim: true, + }, + getEditWrapperProps( attributes ) { const { align } = attributes; if ( -1 !== validAlignments.indexOf( align ) ) { @@ -42,7 +46,7 @@ registerBlockType( 'core/cover-image', { }, edit( { attributes, setAttributes, focus, setFocus, className } ) { - const { url, title, align, id, hasParallax, hasBackgroundDim = true } = attributes; + const { url, title, align, id, hasParallax, hasBackgroundDim } = attributes; const updateAlignment = ( nextAlign ) => setAttributes( { align: nextAlign } ); const onSelectImage = ( media ) => setAttributes( { url: media.url, id: media.id } ); @@ -96,8 +100,7 @@ registerBlockType( 'core/cover-image', { } const style = { backgroundImage: `url(${ url })` }; - const sectionClasses = classnames( { - 'cover-image': true, + const classes = classnames( className, { 'has-parallax': hasParallax, 'has-background-dim': hasBackgroundDim, } ); @@ -124,40 +127,40 @@ registerBlockType( 'core/cover-image', { /> ), -
-
- { title || !! focus ? ( - setAttributes( { title: value } ) } - inlineToolbar - /> - ) : null } -
+
+ { title || !! focus ? ( + setAttributes( { title: value } ) } + inlineToolbar + /> + ) : null }
, ]; }, - save( { attributes } ) { + save( { attributes, className } ) { const { url, title, hasParallax, hasBackgroundDim } = attributes; const style = { backgroundImage: `url(${ url })`, }; - const sectionClasses = classnames( { - 'cover-image': true, + const classes = classnames( className, { 'has-parallax': hasParallax, 'has-background-dim': hasBackgroundDim, } ); return ( -
-
-

{ title }

-
+
+

{ title }

); }, diff --git a/blocks/test/fixtures/core__cover-image.html b/blocks/test/fixtures/core__cover-image.html index ac78109a092e21..1cf586ed87ef02 100644 --- a/blocks/test/fixtures/core__cover-image.html +++ b/blocks/test/fixtures/core__cover-image.html @@ -1,7 +1,5 @@ - -
-
-

Guten Berg!

-
+ +
+

Guten Berg!

diff --git a/blocks/test/fixtures/core__cover-image.json b/blocks/test/fixtures/core__cover-image.json index e2e8b0b72e6ce8..94a2de00806e46 100644 --- a/blocks/test/fixtures/core__cover-image.json +++ b/blocks/test/fixtures/core__cover-image.json @@ -4,6 +4,7 @@ "name": "core/cover-image", "isValid": true, "attributes": { + "hasBackgroundDim": true, "url": "https://cldup.com/uuUqE_dXzy.jpg", "title": "Guten Berg!" } diff --git a/blocks/test/fixtures/core__cover-image.parsed.json b/blocks/test/fixtures/core__cover-image.parsed.json index 21afba0f6d0039..bab2982cf36311 100644 --- a/blocks/test/fixtures/core__cover-image.parsed.json +++ b/blocks/test/fixtures/core__cover-image.parsed.json @@ -2,9 +2,10 @@ { "blockName": "core/cover-image", "attrs": { - "url": "https://cldup.com/uuUqE_dXzy.jpg" + "url": "https://cldup.com/uuUqE_dXzy.jpg", + "hasBackgroundDim": true }, - "rawContent": "\n
\n\t
\n\t\t

Guten Berg!

\n\t
\n
\n" + "rawContent": "\n
\n

Guten Berg!

\n
\n" }, { "attrs": {}, diff --git a/blocks/test/fixtures/core__cover-image.serialized.html b/blocks/test/fixtures/core__cover-image.serialized.html index 71dbaaf017f04c..e9643ec6638976 100644 --- a/blocks/test/fixtures/core__cover-image.serialized.html +++ b/blocks/test/fixtures/core__cover-image.serialized.html @@ -1,7 +1,5 @@ - -
-
-

Guten Berg!

-
+ +
+

Guten Berg!

diff --git a/post-content.js b/post-content.js index 735a830e9ad41a..c291dd4f0097f0 100644 --- a/post-content.js +++ b/post-content.js @@ -7,8 +7,8 @@ window._wpGutenbergPost.title = { window._wpGutenbergPost.content = { raw: [ - '', - '

Of mountains & printing presses

', + '', + '

Of mountains & printing presses

', '', '', From 40db4e8deacd4fa99e81fcb6387a6275a73b0215 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 28 Jul 2017 08:45:30 -0400 Subject: [PATCH 2/2] Deduplicate cover image styles in style.scss --- blocks/library/cover-image/style.scss | 43 --------------------------- 1 file changed, 43 deletions(-) diff --git a/blocks/library/cover-image/style.scss b/blocks/library/cover-image/style.scss index ebbe3a8d630cd0..80fa2f17294ff3 100644 --- a/blocks/library/cover-image/style.scss +++ b/blocks/library/cover-image/style.scss @@ -3,49 +3,6 @@ position: inherit; } - .wp-block-cover-image { - margin: 0; - - h2 { - color: white; - font-size: 24pt; - line-height: 1em; - max-width: $visual-editor-max-width; - padding: $block-padding; - text-align: center; - } - } - - .cover-image { - background-size: cover; - height: 430px; - width: 100%; - display: flex; - justify-content: center; - align-items: center; - } - - .has-parallax { - background-attachment: fixed; - } - - .cover-image.has-background-dim::before { - content: ''; - position: absolute; - top: 0; - right: 0; - bottom: 0; - left: 0; - background: rgba( 0,0,0,.5 ); - } - - &[data-align="full"] .cover-image::before { - right: 0; - left: 0; - } -} - -.cover-image { .blocks-editable__tinymce a { color: white; }