Skip to content

Commit

Permalink
Add: Stack on mobile option on Media & Text block.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Oct 23, 2018
1 parent 1232f8f commit 4ad725c
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 17 deletions.
14 changes: 12 additions & 2 deletions packages/block-library/src/media-text/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
withColors,
} from '@wordpress/editor';
import { Component, Fragment } from '@wordpress/element';
import { Toolbar } from '@wordpress/components';
import { PanelBody, ToggleControl, Toolbar } from '@wordpress/components';

/**
* Internal dependencies
Expand Down Expand Up @@ -108,12 +108,13 @@ class MediaTextEdit extends Component {
setAttributes,
setBackgroundColor,
} = this.props;
const { mediaPosition, mediaWidth } = attributes;
const { mediaPosition, mediaWidth, isStackedOnMobile } = attributes;
const temporaryMediaWidth = this.state.mediaWidth;
const classNames = classnames( className, {
'has-media-on-the-right': 'right' === mediaPosition,
'is-selected': isSelected,
[ backgroundColor.class ]: backgroundColor.class,
'is-stacked-on-mobile': isStackedOnMobile,
} );
const widthString = `${ temporaryMediaWidth || mediaWidth }%`;
const style = {
Expand All @@ -139,6 +140,15 @@ class MediaTextEdit extends Component {
return (
<Fragment>
<InspectorControls>
<PanelBody title={ __( 'Media & Text Settings' ) }>
<ToggleControl
label={ __( 'Stack on mobile' ) }
checked={ isStackedOnMobile }
onChange={ () => setAttributes( {
isStackedOnMobile: ! isStackedOnMobile,
} ) }
/>
</PanelBody>
<PanelColorSettings
title={ __( 'Color Settings' ) }
initialOpen={ false }
Expand Down
17 changes: 12 additions & 5 deletions packages/block-library/src/media-text/editor.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
.wp-block-media-text,
.wp-block-media-text.aligncenter {
.wp-block-media-text {
grid-template-areas:
"media-text-media media-text-content"
"resizer resizer";
}

.wp-block-media-text.has-media-on-the-right,
.wp-block-media-text.has-media-on-the-right.aligncenter {
.wp-block-media-text.has-media-on-the-right {
grid-template-areas:
"media-text-content media-text-media"
"resizer resizer";
Expand Down Expand Up @@ -51,8 +49,17 @@ figure.block-library-media-text__media-container {
display: none;
}

.wp-block-media-text.is-selected {
.wp-block-media-text.is-selected:not(.is-stacked-on-mobile) {
.editor-media-container__resizer .components-resizable-box__handle {
display: block;
}
}

@include break-small {
.wp-block-media-text.is-selected.is-stacked-on-mobile {
.editor-media-container__resizer .components-resizable-box__handle {
display: block;
}
}
}

6 changes: 6 additions & 0 deletions packages/block-library/src/media-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export const settings = {
type: 'number',
default: 50,
},
isStackedOnMobile: {
type: 'boolean',
default: false,
},
},

supports: {
Expand All @@ -81,6 +85,7 @@ export const settings = {
const {
backgroundColor,
customBackgroundColor,
isStackedOnMobile,
mediaAlt,
mediaPosition,
mediaType,
Expand All @@ -96,6 +101,7 @@ export const settings = {
const className = classnames( {
'has-media-on-the-right': 'right' === mediaPosition,
[ backgroundClass ]: backgroundClass,
'is-stacked-on-mobile': isStackedOnMobile,
} );

let gridTemplateColumns;
Expand Down
24 changes: 18 additions & 6 deletions packages/block-library/src/media-text/style.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
.wp-block-media-text,
.wp-block-media-text.aligncenter {
.wp-block-media-text {
display: grid;
}

.wp-block-media-text {
grid-template-rows: auto;
grid-template-areas: "media-text-media media-text-content";
align-items: center;
grid-template-areas: "media-text-media media-text-content";
grid-template-columns: 50% auto;
.has-media-on-the-right {
grid-template-areas: "media-text-content media-text-media";
grid-template-columns: auto 50%;
}
}
Expand All @@ -23,13 +23,25 @@
grid-area: media-text-content;
padding: 0 8% 0 8%;
}
.wp-block-media-text.has-media-on-the-right {
grid-template-areas: "media-text-content media-text-media";
}

.wp-block-media-text > figure > img,
.wp-block-media-text > figure > video {
max-width: unset;
width: 100%;
margin-bottom: -6px;
}

@media (max-width: #{ ($break-small) }) {
.wp-block-media-text.is-stacked-on-mobile {
grid-template-columns: 100% !important;
grid-template-areas:
"media-text-media"
"media-text-content";
}

.wp-block-media-text.is-stacked-on-mobile.has-media-on-the-right {
grid-template-areas:
"media-text-content"
"media-text-media";
}
}
3 changes: 2 additions & 1 deletion test/integration/full-content/fixtures/core__media-text.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"mediaId": 17985,
"mediaUrl": "http://localhost/wp-content/uploads/2018/09/1600px-Mount_Everest_as_seen_from_Drukair2_PLW_edit.jpg",
"mediaType": "image",
"mediaWidth": 50
"mediaWidth": 50,
"isStackedOnMobile": false
},
"innerBlocks": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"mediaId": 17985,
"mediaUrl": "http://localhost/wp-content/uploads/2018/09/1600px-Mount_Everest_as_seen_from_Drukair2_PLW_edit.jpg",
"mediaType": "image",
"mediaWidth": 50
"mediaWidth": 50,
"isStackedOnMobile": false
},
"innerBlocks": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- wp:media-text {"mediaId":17897,"mediaType":"video", "isStackedOnMobile": true} -->
<div class="wp-block-media-text alignwide is-stacked-on-mobile">
<figure class="wp-block-media-text__media">
<video controls src="http://localhost/wp-content/uploads/2018/09/Jul-26-2018-11-34-54.mp4"></video>
</figure>
<div class="wp-block-media-text__content">
<!-- wp:paragraph {"placeholder":"Content…","fontSize":"large"} -->
<p class="has-large-font-size">My Content</p>
<!-- /wp:paragraph -->
</div>
</div>
<!-- /wp:media-text -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[
{
"clientId": "_clientId_0",
"name": "core/media-text",
"isValid": true,
"attributes": {
"align": "wide",
"mediaAlt": "",
"mediaPosition": "left",
"mediaId": 17897,
"mediaUrl": "http://localhost/wp-content/uploads/2018/09/Jul-26-2018-11-34-54.mp4",
"mediaType": "video",
"mediaWidth": 50,
"isStackedOnMobile": true
},
"innerBlocks": [
{
"clientId": "_clientId_0",
"name": "core/paragraph",
"isValid": true,
"attributes": {
"content": "My Content",
"dropCap": false,
"placeholder": "Content…",
"fontSize": "large"
},
"innerBlocks": [],
"originalContent": "<p class=\"has-large-font-size\">My Content</p>"
}
],
"originalContent": "<div class=\"wp-block-media-text alignwide is-stacked-on-mobile\">\n\t<figure class=\"wp-block-media-text__media\">\n\t\t<video controls src=\"http://localhost/wp-content/uploads/2018/09/Jul-26-2018-11-34-54.mp4\"></video>\n\t</figure>\n\t<div class=\"wp-block-media-text__content\">\n\t\t\n\t</div>\n</div>"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[
{
"blockName": "core/media-text",
"attrs": {
"mediaId": 17897,
"mediaType": "video",
"isStackedOnMobile": true
},
"innerBlocks": [
{
"blockName": "core/paragraph",
"attrs": {
"placeholder": "Content…",
"fontSize": "large"
},
"innerBlocks": [],
"innerHTML": "\n\t\t<p class=\"has-large-font-size\">My Content</p>\n\t\t"
}
],
"innerHTML": "\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile\">\n\t<figure class=\"wp-block-media-text__media\">\n\t\t<video controls src=\"http://localhost/wp-content/uploads/2018/09/Jul-26-2018-11-34-54.mp4\"></video>\n\t</figure>\n\t<div class=\"wp-block-media-text__content\">\n\t\t\n\t</div>\n</div>\n"
},
{
"blockName": null,
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- wp:media-text {"mediaId":17897,"mediaType":"video","isStackedOnMobile":true} -->
<div class="wp-block-media-text alignwide is-stacked-on-mobile"><figure class="wp-block-media-text__media"><video controls src="http://localhost/wp-content/uploads/2018/09/Jul-26-2018-11-34-54.mp4"></video></figure><div class="wp-block-media-text__content"><!-- wp:paragraph {"placeholder":"Content…","fontSize":"large"} -->
<p class="has-large-font-size">My Content</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:media-text -->
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"mediaId": 17897,
"mediaUrl": "http://localhost/wp-content/uploads/2018/09/Jul-26-2018-11-34-54.mp4",
"mediaType": "video",
"mediaWidth": 41
"mediaWidth": 41,
"isStackedOnMobile": false
},
"innerBlocks": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"mediaId": 17897,
"mediaUrl": "http://localhost/wp-content/uploads/2018/09/Jul-26-2018-11-34-54.mp4",
"mediaType": "video",
"mediaWidth": 50
"mediaWidth": 50,
"isStackedOnMobile": false
},
"innerBlocks": [
{
Expand Down

0 comments on commit 4ad725c

Please sign in to comment.