Skip to content

Commit

Permalink
Blocks: Revert supports align changes for the latest posts block
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Feb 28, 2018
1 parent 3a32e1c commit f903bb0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
10 changes: 9 additions & 1 deletion blocks/library/latest-posts/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import './style.scss';
import QueryPanel from '../../query-panel';
import InspectorControls from '../../inspector-controls';
import BlockControls from '../../block-controls';
import BlockAlignmentToolbar from '../../block-alignment-toolbar';

const MAX_POSTS_COLUMNS = 6;

Expand All @@ -49,7 +50,7 @@ class LatestPostsBlock extends Component {
render() {
const latestPosts = this.props.latestPosts.data;
const { attributes, isSelected, setAttributes } = this.props;
const { displayPostDate, layout, columns, order, orderBy, categories, postsToShow } = attributes;
const { displayPostDate, align, layout, columns, order, orderBy, categories, postsToShow } = attributes;

const inspectorControls = isSelected && (
<InspectorControls key="inspector">
Expand Down Expand Up @@ -120,6 +121,13 @@ class LatestPostsBlock extends Component {
inspectorControls,
isSelected && (
<BlockControls key="controls">
<BlockAlignmentToolbar
value={ align }
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
controls={ [ 'center', 'wide', 'full' ] }
/>
<Toolbar controls={ layoutControls } />
</BlockControls>
),
Expand Down
8 changes: 7 additions & 1 deletion blocks/library/latest-posts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ export const settings = {
keywords: [ __( 'recent posts' ) ],

supports: {
align: [ 'center', 'wide', 'full' ],
html: false,
},

getEditWrapperProps( attributes ) {
const { align } = attributes;
if ( 'left' === align || 'right' === align || 'wide' === align || 'full' === align ) {
return { 'data-align': align };
}
},

edit: LatestPostsBlock,

save() {
Expand Down
3 changes: 2 additions & 1 deletion blocks/library/latest-posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ function register_block_core_latest_posts() {
'default' => 3,
),
'align' => array(
'type' => 'string',
'type' => 'string',
'default' => 'center',
),
'order' => array(
'type' => 'string',
Expand Down
1 change: 1 addition & 0 deletions blocks/test/fixtures/core__latest-posts.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"displayPostDate": false,
"postLayout": "list",
"columns": 3,
"align": "center",
"order": "desc",
"orderBy": "date"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"displayPostDate": true,
"postLayout": "list",
"columns": 3,
"align": "center",
"order": "desc",
"orderBy": "date"
},
Expand Down
2 changes: 1 addition & 1 deletion blocks/test/server-registered.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}}}
{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string","default":"center"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}}}

0 comments on commit f903bb0

Please sign in to comment.