-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
290 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
theme/assets/src/block-editor/blocks/card-image/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |