-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP for term-description block * load the block. * better safe than sorry * Add more supports * add fixtures files * use padding instead of height so border can adapt depending on font-size * Change the icon Use icon from #27989 (comment) * Update packages/icons/src/library/term-description.js Co-authored-by: Nik Tsekouras <ntsekouras@outlook.com> * address feedback * Add description * reverse condition & logic * Change placeholder text * Simplify Co-authored-by: Nik Tsekouras <ntsekouras@outlook.com>
- Loading branch information
1 parent
1182f97
commit 5d99e6c
Showing
14 changed files
with
192 additions
and
0 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
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,20 @@ | ||
{ | ||
"apiVersion": 2, | ||
"name": "core/term-description", | ||
"category": "design", | ||
"attributes": { | ||
"textAlign": { | ||
"type": "string" | ||
} | ||
}, | ||
"supports": { | ||
"align": [ "wide", "full" ], | ||
"html": false, | ||
"fontSize": true, | ||
"lineHeight": true, | ||
"color": { | ||
"link": true | ||
} | ||
}, | ||
"editorStyle": "wp-block-term-description-editor" | ||
} |
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,45 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
useBlockProps, | ||
BlockControls, | ||
AlignmentToolbar, | ||
} from '@wordpress/block-editor'; | ||
|
||
export default function TermDescriptionEdit( { | ||
attributes, | ||
setAttributes, | ||
mergedStyle, | ||
} ) { | ||
const { textAlign } = attributes; | ||
const blockProps = useBlockProps( { | ||
className: classnames( { | ||
[ `has-text-align-${ textAlign }` ]: textAlign, | ||
} ), | ||
style: mergedStyle, | ||
} ); | ||
return ( | ||
<> | ||
<BlockControls> | ||
<AlignmentToolbar | ||
value={ textAlign } | ||
onChange={ ( nextAlign ) => { | ||
setAttributes( { textAlign: nextAlign } ); | ||
} } | ||
/> | ||
</BlockControls> | ||
<div { ...blockProps }> | ||
<div className="wp-block-term-description__placeholder"> | ||
<span>{ __( 'Term description.' ) }</span> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} |
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,4 @@ | ||
.wp-block-term-description__placeholder { | ||
padding: 1em 0; | ||
border: 1px dashed; | ||
} |
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,23 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { _x, __ } from '@wordpress/i18n'; | ||
import { termDescription as icon } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import metadata from './block.json'; | ||
import edit from './edit'; | ||
|
||
const { name } = metadata; | ||
export { metadata, name }; | ||
|
||
export const settings = { | ||
title: _x( 'Term Description', 'block title' ), | ||
description: __( | ||
'Display the description of categories, tags and custom taxonomies when viewing an archive.' | ||
), | ||
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,41 @@ | ||
<?php | ||
/** | ||
* Server-side rendering of the `core/term-description` block. | ||
* | ||
* @package WordPress | ||
*/ | ||
|
||
/** | ||
* Renders the `core/term-description` block on the server. | ||
* | ||
* @param array $attributes Block attributes. | ||
* @param string $content Block default content. | ||
* @param WP_Block $block Block instance. | ||
* @return string Returns the filtered post content of the current post. | ||
*/ | ||
function render_block_core_term_description( $attributes, $content, $block ) { | ||
|
||
if ( ! is_category() && ! is_tag() && ! is_tax() ) { | ||
return ''; | ||
} | ||
|
||
$extra_attributes = ( isset( $attributes['textAlign'] ) ) | ||
? array( 'class' => 'has-text-align-' . $attributes['textAlign'] ) | ||
: array(); | ||
$wrapper_attributes = get_block_wrapper_attributes( $extra_attributes ); | ||
|
||
return '<div ' . $wrapper_attributes . '>' . term_description() . '</div>'; | ||
} | ||
|
||
/** | ||
* Registers the `core/term-description` block on the server. | ||
*/ | ||
function register_block_core_term_description() { | ||
register_block_type_from_metadata( | ||
__DIR__ . '/term-description', | ||
array( | ||
'render_callback' => 'render_block_core_term_description', | ||
) | ||
); | ||
} | ||
add_action( 'init', 'register_block_core_term_description' ); |
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 @@ | ||
<!-- wp:term-description {"align":"full"} /--> |
12 changes: 12 additions & 0 deletions
12
packages/e2e-tests/fixtures/blocks/core__term-description.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,12 @@ | ||
[ | ||
{ | ||
"clientId": "_clientId_0", | ||
"name": "core/term-description", | ||
"isValid": true, | ||
"attributes": { | ||
"align": "full" | ||
}, | ||
"innerBlocks": [], | ||
"originalContent": "" | ||
} | ||
] |
20 changes: 20 additions & 0 deletions
20
packages/e2e-tests/fixtures/blocks/core__term-description.parsed.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,20 @@ | ||
[ | ||
{ | ||
"blockName": "core/term-description", | ||
"attrs": { | ||
"align": "full" | ||
}, | ||
"innerBlocks": [], | ||
"innerHTML": "", | ||
"innerContent": [] | ||
}, | ||
{ | ||
"blockName": null, | ||
"attrs": {}, | ||
"innerBlocks": [], | ||
"innerHTML": "\n", | ||
"innerContent": [ | ||
"\n" | ||
] | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
packages/e2e-tests/fixtures/blocks/core__term-description.serialized.html
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 @@ | ||
<!-- wp:term-description {"align":"full"} /--> |
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,20 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { SVG, Path } from '@wordpress/primitives'; | ||
|
||
const tag = ( | ||
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> | ||
<Path | ||
stroke="#1E1E1E" | ||
strokeWidth="1.5" | ||
d="M9 19.25h6M4 19.25h4M12 15.25h8M4 15.25h7" | ||
/> | ||
<Path | ||
d="M8.994 10.103H6.08L5.417 12H4l2.846-8h1.383l2.845 8H9.657l-.663-1.897zm-.457-1.28l-.994-2.857-1.006 2.857h2z" | ||
fill="#1E1E1E" | ||
/> | ||
</SVG> | ||
); | ||
|
||
export default tag; |