Skip to content

Commit

Permalink
Merge 166ad31 into fbe3c43
Browse files Browse the repository at this point in the history
  • Loading branch information
PatelUtkarsh committed Feb 7, 2022
2 parents fbe3c43 + 166ad31 commit a61b66a
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 56 deletions.
1 change: 1 addition & 0 deletions theme/assets/css/src/front-end.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@
/* Block editor */
@import "./../../src/block-editor/plugins/hide-sections/style.css";
@import "./../../src/block-editor/style/horizontal-line/style.css";
@import "./../../src/block-editor/blocks/card-image/style.css";
19 changes: 19 additions & 0 deletions theme/assets/src/block-editor/blocks/card-image/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"name": "material/image-card-query",
"category": "material",
"attributes": {
"isEditMode": {
"type": "boolean",
"default": false
}
},
"title": "Material Image Card for Query loop",
"supports": {},
"apiVersion": 2,
"description": "Material image card for query loop block",
"editorStyle": ["material-google-fonts-cdn", "material-block-editor-css-theme"],
"editorScript": "material-block-editor-js-theme",
"usesContext": [ "postId", "postType", "queryId" ],
"textdomain": "material-design-google"
}
64 changes: 64 additions & 0 deletions theme/assets/src/block-editor/blocks/card-image/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Copyright 2020 Google LLC
*
* Licensed uder the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* External dependencies
*/
/**
* WordPress dependencies
*/
import { useBlockProps } from '@wordpress/block-editor';
import ServerSideRender from '@wordpress/server-side-render';

/**
* Internal dependencies
*/
import { name } from './block.json';

/**
* Edit.
*
* @param {Object} props
* @param {{postType:string,postId:number,queryId:number}} props.context
* @param {Object} props.attributes
* @return {JSX.Element} Block edit.
*/
const Edit = ( { context, attributes } ) => {
const urlQueryArgs = {
materialParamContext: [],
};
// Server side rendering doesn't support passing context yet. This hack adds context as url param to later manually parse in php.
for ( const key in context ) {
urlQueryArgs.materialParamContext[ key ] = context[ key ];
}
const ssrAttributes = {
...attributes,
...{ isEditMode: true },
};
return (
<>
<div { ...useBlockProps() }>
<ServerSideRender
block={ name }
urlQueryArgs={ urlQueryArgs }
attributes={ ssrAttributes }
/>
</div>
</>
);
};

export default Edit;
24 changes: 24 additions & 0 deletions theme/assets/src/block-editor/blocks/card-image/icon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Block Icon component.
*
* @return {JSX.Element} Function returning the HTML markup for the component.
*/
export const icon = () => (
<i className="material-icons-outlined">chrome_reader_mode</i>
);
33 changes: 33 additions & 0 deletions theme/assets/src/block-editor/blocks/card-image/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Internal dependencies
*/
import metadata from './block.json';
import { icon } from './icon';
import edit from './edit';

const { name, title } = metadata;

export { metadata, name };

export const settings = {
title,
description: metadata.description,
icon,
edit,
};
39 changes: 39 additions & 0 deletions theme/assets/src/block-editor/blocks/card-image/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

.wp-block-material-image-card-query a {
display: block;
}

.wp-block-material-image-card-query {
position: relative;

.mdc-image-list__supporting {
position: absolute;
background: rgba(0, 0, 0, .6);
bottom: 7.5px;
color: #fff;
height: auto;
width: 100%;
align-items: start;
border-bottom-left-radius: var(--mdc-image-list-radius, 4px);
border-bottom-right-radius: var(--mdc-image-list-radius, 4px);
max-height: 100%;
min-height: 48px;
overflow: hidden;
padding: 8px 16px;
}
}
2 changes: 1 addition & 1 deletion theme/assets/src/customizer/customize-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
};

api.bind( 'ready', () => {
api( 'archive_layout' ).bind( value => {
api( 'archive_layout' )?.bind( value => {
const isCardLayout = 'card' === value;

const controls = [
Expand Down
1 change: 1 addition & 0 deletions theme/inc/blocks/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Blocks {
const DYNAMIC_BLOCKS = [
'material/search' => 'template-parts/blocks/search.php',
'material/card-query' => 'template-parts/blocks/card-query.php',
'material/image-card-query' => 'template-parts/blocks/image-card-query.php',
'material/query-pagination' => 'template-parts/blocks/query-pagination.php',
'material/query-pagination-next' => 'template-parts/blocks/query-pagination-next.php',
'material/query-pagination-previous' => 'template-parts/blocks/query-pagination-previous.php',
Expand Down
120 changes: 65 additions & 55 deletions theme/inc/customizer/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace MaterialDesign\Theme\Customizer\Layout;

use MaterialDesign\Theme\Customizer;
use function MaterialDesign\Theme\BlockEditor\is_fse;

/**
* Attach hooks
Expand Down Expand Up @@ -95,61 +96,7 @@ function add_settings( $wp_customize ) {
* @return array
*/
function get_controls() {
return [
[
'id' => 'archive_width',
'label' => esc_html__( 'Posts layout width', 'material-design-google' ),
'type' => 'radio',
'choices' => [
'wide' => esc_html__( 'Wide', 'material-design-google' ),
'normal' => esc_html__( 'Normal', 'material-design-google' ),
],
],
[
'id' => 'archive_layout',
'label' => esc_html__( 'Posts layout', 'material-design-google' ),
'type' => 'radio',
'choices' => [
'card' => esc_html__( 'Card', 'material-design-google' ),
'image' => esc_html__( 'Image List', 'material-design-google' ),
],
],
[
'id' => 'archive_card_options',
'label' => esc_html__( 'Card display options', 'material-design-google' ),
'type' => 'hidden',
'active_callback' => __NAMESPACE__ . '\is_card_layout',
],
[
'id' => 'archive_comments',
'label' => esc_html__( 'Comments', 'material-design-google' ),
'type' => 'checkbox',
'active_callback' => __NAMESPACE__ . '\is_card_layout',
],
[
'id' => 'archive_author',
'label' => esc_html__( 'Author', 'material-design-google' ),
'type' => 'checkbox',
'active_callback' => __NAMESPACE__ . '\is_card_layout',
],
[
'id' => 'archive_excerpt',
'label' => esc_html__( 'Excerpt', 'material-design-google' ),
'type' => 'checkbox',
'active_callback' => __NAMESPACE__ . '\is_card_layout',
],
[
'id' => 'archive_date',
'label' => esc_html__( 'Date', 'material-design-google' ),
'type' => 'checkbox',
'active_callback' => __NAMESPACE__ . '\is_card_layout',
],
[
'id' => 'archive_outlined',
'label' => esc_html__( 'Outlined', 'material-design-google' ),
'type' => 'checkbox',
'active_callback' => __NAMESPACE__ . '\is_card_layout',
],
$controls = [
[
'id' => 'comment_fields_style',
'label' => esc_html__( 'Comment field display options', 'material-design-google' ),
Expand All @@ -161,6 +108,69 @@ function get_controls() {
],
],
];

if ( ! is_fse() ) {
$non_fse_controls = [
[
'id' => 'archive_width',
'label' => esc_html__( 'Posts layout width', 'material-design-google' ),
'type' => 'radio',
'choices' => [
'wide' => esc_html__( 'Wide', 'material-design-google' ),
'normal' => esc_html__( 'Normal', 'material-design-google' ),
],
],
[
'id' => 'archive_layout',
'label' => esc_html__( 'Posts layout', 'material-design-google' ),
'type' => 'radio',
'choices' => [
'card' => esc_html__( 'Card', 'material-design-google' ),
'image' => esc_html__( 'Image List', 'material-design-google' ),
],
],
[
'id' => 'archive_card_options',
'label' => esc_html__( 'Card display options', 'material-design-google' ),
'type' => 'hidden',
'active_callback' => __NAMESPACE__ . '\is_card_layout',
],
[
'id' => 'archive_comments',
'label' => esc_html__( 'Comments', 'material-design-google' ),
'type' => 'checkbox',
'active_callback' => __NAMESPACE__ . '\is_card_layout',
],
[
'id' => 'archive_author',
'label' => esc_html__( 'Author', 'material-design-google' ),
'type' => 'checkbox',
'active_callback' => __NAMESPACE__ . '\is_card_layout',
],
[
'id' => 'archive_excerpt',
'label' => esc_html__( 'Excerpt', 'material-design-google' ),
'type' => 'checkbox',
'active_callback' => __NAMESPACE__ . '\is_card_layout',
],
[
'id' => 'archive_date',
'label' => esc_html__( 'Date', 'material-design-google' ),
'type' => 'checkbox',
'active_callback' => __NAMESPACE__ . '\is_card_layout',
],
[
'id' => 'archive_outlined',
'label' => esc_html__( 'Outlined', 'material-design-google' ),
'type' => 'checkbox',
'active_callback' => __NAMESPACE__ . '\is_card_layout',
],
];

$controls = array_merge( $controls, $non_fse_controls );
}

return $controls;
}

/**
Expand Down
43 changes: 43 additions & 0 deletions theme/template-parts/blocks/image-card-query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package MaterialDesign
*/

/**
* Image list layout
*/

$block = isset( $args['block'] ) ? $args['block'] : [];
$attributes = isset( $args['attributes'] ) ? $args['attributes'] : [];
$is_edit = $attributes['isEditMode'];
$post_ID = $block->context['postId']; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$post_link = $is_edit ? '#link-to-' . $post_ID : get_the_permalink( $post );
if ( has_post_thumbnail( $post_ID ) ) {
$thumbnail = get_the_post_thumbnail_url( $post_ID );
} else {
$thumbnail = get_template_directory_uri() . '/assets/images/placeholder.png';
}
$wrapper_attributes = get_block_wrapper_attributes();
?>
<div <?php echo $wrapper_attributes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<a href="<?php echo esc_url( $post_link ); ?>">
<img class="mdc-image-list__image" src="<?php echo esc_url( $thumbnail ); ?>" alt="">
<div class="mdc-image-list__supporting">
<?php echo esc_html( get_the_title( $post_ID ) ); ?>
</div>
</a>
</div>

0 comments on commit a61b66a

Please sign in to comment.