-
Notifications
You must be signed in to change notification settings - Fork 384
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
Changes from 12 commits
de8a1c5
954c14e
87cca23
9d79e01
6ec83eb
83d2c34
2774a1a
c7951bd
4fa18d3
bfdefb9
cd4d801
b9b410c
e5c84d0
912439d
6ff0bf6
b486847
b7afb23
dc87187
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} |
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 ); | ||
} | ||
}}> | ||
{ 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"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be an |
||
<LayerInserter { ...inserterProps }/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 We could potentially create another issue in Gutenberg repo for allowing the (As of now) the custom inserter basically just displays the allowed blocks and that's it: @westonruter Do you have any thoughts on if this makes sense for now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds good! |
||
{ links } | ||
</ul> | ||
); | ||
} | ||
} | ||
|
||
export default BlockSelector; |
There was a problem hiding this comment.
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 triggeringselectBlock
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.)There was a problem hiding this comment.
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?