Skip to content
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

[amp-stories sub-task] Grid layers layout #1347

Merged
merged 18 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
de8a1c5
Modify CSS for having the layer on top of each other and hiding the t…
miina Aug 20, 2018
954c14e
Merge remote-tracking branch 'origin/amp-stories' into amp-story/layouts
miina Aug 20, 2018
87cca23
Merge remote-tracking branch 'origin/develop' into amp-story/layouts
miina Aug 20, 2018
9d79e01
Add initial take on BlockSelector for selecting layers.
miina Aug 21, 2018
6ec83eb
Merge branch 'amp-stories' into amp-story/layouts
westonruter Aug 21, 2018
83d2c34
Use Button instead of links. Make strings translatable.
miina Aug 21, 2018
2774a1a
Merge branch 'amp-story/layouts' of github.com:Automattic/amp-wp into…
miina Aug 21, 2018
c7951bd
Add grid system to the grid layers. Place layers exactly on top of ea…
miina Aug 22, 2018
4fa18d3
Add inserter for grid layers.
miina Aug 22, 2018
bfdefb9
Fix style for fill template. Remove importing lodash since it breaks …
miina Aug 22, 2018
cd4d801
Fix eslint.
miina Aug 22, 2018
b9b410c
Add CTA Layer to the block inserter dropdown.
miina Aug 22, 2018
e5c84d0
Extend blocks to allow configuring the position in thirds template.
miina Aug 23, 2018
912439d
Merge branch 'amp-stories' into amp-story/layouts
miina Aug 29, 2018
6ff0bf6
Add a partly working workaround for selectBlock issue.
miina Aug 29, 2018
b486847
Merge amp-stories and resolve conflicts.
miina Aug 29, 2018
b7afb23
Ensure a singular AMP story always is_amp_endpoint
westonruter Aug 29, 2018
dc87187
Ensure amp-runtime and Gutenberg block styles are included on story t…
westonruter Aug 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 143 additions & 8 deletions assets/css/amp-editor-story-blocks.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,149 @@
div[data-type="amp/amp-story-page"] {
border: 1px solid #ffdddd;
}

.editor-block-list__layout div[data-type="amp/amp-story-page"] {
padding: 0;
margin: 0 auto 30px;
}

.editor-block-list__layout {
background-color: #ffdddd;
@media (min-width: 600px) {
div[data-type="amp/amp-story-page"] .editor-block-list__block {
margin: 0;
padding: 0;
}
div[data-type="amp/amp-story-page"] .editor-inserter__popover:not(.is-mobile) > .components-popover__content {
height: 200px;
}
}
.editor-block-list__layout .editor-block-list__layout {
background-color: white;

div[data-type="amp/amp-story-page"] * {
max-width: 100%;
max-height: 100%;
}
div[data-type="amp/amp-story-page"] {
background-color: #ddffdd;

div[data-type="amp/amp-story-page"],
div[data-type="amp/amp-story-page"] .editor-inner-blocks .editor-block-list__layout:first-of-type {
margin: auto;
max-height: 75vh !important;
max-width: 45vh !important;
min-width: 320px !important;
min-height: 533px;
}

.editor-block-list__layout div[data-type="amp/amp-story-cta-layer"] .editor-inner-blocks .editor-block-list__layout {
min-height: initial !important;
}

/* Make layer be exactly on top of each other */
.editor-block-list__layout div[data-type="amp/amp-story-page"].editor-block-list__block:first-child .editor-block-list__block-edit {
margin: 0;
}

.editor-block-list__layout div[data-type="amp/amp-story-page"].editor-block-list__block .editor-block-list__block-edit, .editor-block-list__layout .editor-block-list__layout .editor-block-list__block .editor-block-list__block-edit {
margin: 0;
}

div[data-type="amp/amp-story-page"] .editor-inner-blocks .editor-block-list__layout .editor-block-list__layout {
background-color: initial;
}

.editor-block-list__layout div[data-type="amp/amp-story-grid-layer"] {
position: absolute;
height: 100%;
width: 100%;
}

.amp-grid-template .editor-block-list__layout:first-of-type {
display: grid;
overflow: hidden;
padding: 68px 32px 32px;
}

.amp-grid-template .editor-block-list__layout:first-of-type * {
margin: 0;
box-sizing: border-box;
}

.amp-grid-template-horizontal .editor-block-list__layout:first-of-type {
grid-auto-flow: column !important;
grid-template-rows: 100% !important;
-ms-flex-line-pack: stretch;
align-content: stretch;
-webkit-box-align: start;
-ms-flex-align: start;
align-items: start;
grid-gap: 16px;
-webkit-box-pack: start;
-ms-flex-pack: start;
justify-content: start;
}

.amp-grid-template-vertical .editor-block-list__layout:first-of-type {
grid-auto-flow: row;
grid-template-columns: 100%;
align-content: start;
grid-gap: 16px;
-webkit-box-pack: stretch;
-ms-flex-pack: stretch;
justify-content: stretch;
justify-items: start;
}

.amp-grid-template-thirds .editor-block-list__layout:first-of-type {
grid-template-rows: 1fr 1fr 1fr;
grid-template-areas: "upper-third" "middle-third" "lower-third";
}


.amp-grid-template-fill .editor-block-list__layout > :first-child {
bottom: 0;
display: block;
height: auto;
left: 0;
position: absolute;
right: 0;
top: 0;
width: auto;
}

.amp-grid-template-fill > :not(:first-child) {
display: none;
}

.editor-block-list__layout div[data-type="amp/amp-story-cta-layer"] {
position: absolute;
height: 20%;
width: 100%;
bottom: 0;
}

.editor-block-list__layout div[data-type="amp/amp-story-grid-layer"],
.editor-block-list__layout div[data-type="amp/amp-story-cta-layer"] {
border: 1px solid #ddffdd;
}
div[data-type="amp/amp-story-grid-layer"] {
background-color: #ddddff;

.editor-block-list__layout div[data-type="amp/amp-story-grid-layer"].is-selected ~ div[data-type="amp/amp-story-grid-layer"],
.editor-block-list__layout div[data-type="amp/amp-story-grid-layer"].is-selected-parent ~ div[data-type="amp/amp-story-grid-layer"]{
display: none;
}

.editor-selectors {
position: absolute;
right: -150px;
bottom: 0;
width: 100px;
z-index: 80;
}

.editor-selectors .component-editor__selector {
margin-bottom: 2px;
}

.editor-selectors .component-editor__selector button {
cursor: pointer;
}

.editor-selectors .is-selected.component-editor__selector button {
text-decoration: underline;
}
4 changes: 3 additions & 1 deletion blocks/amp-story/amp-story-grid-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export default registerBlockType(
onChange={ value => ( setAttributes( { template: value } ) ) }
/>
</InspectorControls>,
<InnerBlocks key='contents' allowedBlocks={ ALLOWED_BLOCKS } />
<div key='contents' className={ 'amp-grid-template amp-grid-template-' + props.attributes.template }>
<InnerBlocks allowedBlocks={ ALLOWED_BLOCKS } />
</div>
];
},

Expand Down
7 changes: 4 additions & 3 deletions blocks/amp-story/amp-story-page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import memoize from 'memize';
import uuid from 'uuid/v4';
import BlockSelector from './block-selector';

const { __ } = wp.i18n;
const {
Expand Down Expand Up @@ -27,7 +28,6 @@ const ALLOWED_BLOCKS = [
const getStoryPageTemplate = memoize( ( grids, hasCTA ) => {
let template = _.times( grids, () => [
'amp/amp-story-grid-layer',
[],
[
[
'core/paragraph',
Expand Down Expand Up @@ -101,10 +101,11 @@ export default registerBlockType(
grids = 1;
}

return (
return [
<BlockSelector key="selectors" rootClientId={ props.clientId } />,
// Get the template dynamically.
<InnerBlocks key='contents' template={ getStoryPageTemplate( grids, hasCTALayer ) } allowedBlocks={ ALLOWED_BLOCKS } />
);
];
},

save( { attributes } ) {
Expand Down
92 changes: 92 additions & 0 deletions blocks/amp-story/block-selector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

const { __, sprintf } = wp.i18n;
const { Component } = wp.element;
const { Button } = wp.components;
const {
dispatch,
select
} = wp.data;
const {
getBlock,
isBlockSelected,
hasSelectedInnerBlock,
getSelectedBlock
} = select( 'core/editor' );
const {
selectBlock
} = dispatch( 'core/editor' );

import LayerInserter from './layer-inserter';

class BlockSelector extends Component {
render() {
if ( ! this.props.rootClientId ) {
return null;
}

const rootBlock = getBlock( this.props.rootClientId );

if ( ! rootBlock.innerBlocks.length ) {
return null;
}

let links = [];

window.lodash.forEachRight( rootBlock.innerBlocks, function( block, index ) {
let className = 'component-editor__selector';
if ( isBlockSelected( block.clientId ) || hasSelectedInnerBlock( block.clientId ) ) {
className += ' is-selected';
}

let title = sprintf( __( 'Layout %d ', 'amp' ), index + 1 );
if ( 'amp/amp-story-cta-layer' === block.name ) {
title = __( 'CTA Layer', 'amp' );
}
links.push(
<li className={ className } key={ 'selector-' + index }>
<Button onClick={ ( e ) => {
e.stopPropagation();
if ( getSelectedBlock.clientId !== block.clientId ) {
// @todo This selects the first inner child instead for some reason.
selectBlock( block.clientId );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter For some reason selectBlock here is triggering selectBlock for its first inner block, too, and ends up selecting the first inner block of the layer (e.g. the first paragraph within the layer block) instead of the layer itself. Any thoughts on why this might happen? (If not, I'll just continue looking into it, perhaps it's an issue to report.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why. Is this why I am unable to insert a grid layer upon selecting the page?

}
}}>
{ title }
</Button>
</li>
);
} );

let className = 'component-editor__selector';
if ( isBlockSelected( this.props.rootClientId ) ) {
className += ' is-selected';
}

const inserterProps = {
rootClientId: this.props.rootClientId
};

links.push(
<li className={ className } key='page-selector'>
<Button onClick={ ( e ) => {
e.stopPropagation();
if ( getSelectedBlock.clientId !== this.props.rootClientId ) {
selectBlock( this.props.rootClientId );
}
}}>
{ __( 'Page', 'amp' ) }
</Button>
</li>
);

// @todo Creating a custom inserter since the default inserter doesn't allow taking the root client ID dynamically. Change if that becomes available.
return (
<ul className="editor-selectors">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be an ol since the layers are ordered.

<LayerInserter { ...inserterProps }/>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a custom block inserter which just displays the relevant items in the list since it looks like the default Inserter is automatically taking the clientId of the selected block and then inserts a block after that. Since the list of layouts is fixed with the page block then this would mean that the inserter would always take the amp-story-page as the selected block and thus add the new block to the root level instead of inside the AMP Story page block (since the inserter inserts AFTER the selected block by default).

We could potentially create another issue in Gutenberg repo for allowing the Inserter to also accept the selected block ID as a param, however, it's likely not the most pressing issue right now and might take some time to get implemented.

(As of now) the custom inserter basically just displays the allowed blocks and that's it:
screen shot 2018-08-22 at 9 37 58 pm

@westonruter Do you have any thoughts on if this makes sense for now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good!

{ links }
</ul>
);
}
}

export default BlockSelector;
Loading