Skip to content
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

Comments Block: fixed issue with custom font sizes and links color #41627

Merged
merged 10 commits into from
Jun 16, 2022
8 changes: 4 additions & 4 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Displays the name of the author of the comment. ([Source](https://github.com/Wor
- **Name:** core/comment-author-name
- **Category:** theme
- **Supports:** color (background, gradients, link, text), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** fontSize, isLink, linkTarget, textAlign
- **Attributes:** isLink, linkTarget, textAlign

## Comment Content

Expand All @@ -141,7 +141,7 @@ Displays the date on which the comment was posted. ([Source](https://github.com/
- **Name:** core/comment-date
- **Category:** theme
- **Supports:** color (background, gradients, link, text), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** fontSize, format, isLink
- **Attributes:** format, isLink

## Comment Edit Link

Expand All @@ -150,7 +150,7 @@ Displays a link to edit the comment in the WordPress Dashboard. This link is onl
- **Name:** core/comment-edit-link
- **Category:** theme
- **Supports:** color (background, gradients, link, ~~text~~), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** fontSize, linkTarget, textAlign
- **Attributes:** linkTarget, textAlign

## Comment Reply Link

Expand All @@ -159,7 +159,7 @@ Displays a link to reply to a comment. ([Source](https://github.com/WordPress/gu
- **Name:** core/comment-reply-link
- **Category:** theme
- **Supports:** color (background, gradients, link, ~~text~~), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** fontSize, textAlign
- **Attributes:** textAlign

## Comment Template

Expand Down
4 changes: 0 additions & 4 deletions packages/block-library/src/comment-author-name/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
},
"textAlign": {
"type": "string"
},
"fontSize": {
"type": "string",
"default": "small"
Comment on lines -21 to -24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to keep the attribute in order for the default template settings to work? 🤔 After all, this PR is setting the blocks' fontSize attributes (e.g. here), isn't it?

In order to achieve the desired effect, would it be enough to only remove the default here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this locally, and it seems to do the trick 🙂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed with @c4rl0sbr4v0 in Slack, I was mistaken here -- the attribute is added implicitly thanks to fontSize block-supports 😅

}
},
"usesContext": [ "commentId" ],
Expand Down
15 changes: 3 additions & 12 deletions packages/block-library/src/comment-author-name/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function Edit( {
[ `has-text-align-${ textAlign }` ]: textAlign,
} ),
} );
const displayName = useSelect(
let displayName = useSelect(
( select ) => {
const { getEntityRecord } = select( coreStore );

Expand Down Expand Up @@ -92,15 +92,7 @@ export default function Edit( {
);

if ( ! commentId || ! displayName ) {
return (
<>
{ inspectorControls }
{ blockControls }
<div { ...blockProps }>
{ _x( 'Comment Author', 'block title' ) }
</div>
</>
);
displayName = _x( 'Comment Author', 'block title' );
}

const displayAuthor = isLink ? (
Expand All @@ -111,9 +103,8 @@ export default function Edit( {
{ displayName }
</a>
) : (
{ displayName }
displayName
);

return (
<>
{ inspectorControls }
Expand Down
4 changes: 0 additions & 4 deletions packages/block-library/src/comment-date/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
"isLink": {
"type": "boolean",
"default": true
},
"fontSize": {
"type": "string",
"default": "small"
}
},
"usesContext": [ "commentId" ],
Expand Down
24 changes: 10 additions & 14 deletions packages/block-library/src/comment-date/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function Edit( {
setAttributes,
} ) {
const blockProps = useBlockProps();
const [ date ] = useEntityProp( 'root', 'comment', 'date', commentId );
let [ date ] = useEntityProp( 'root', 'comment', 'date', commentId );
const [ siteFormat = getDateSettings().formats.date ] = useEntityProp(
'root',
'site',
Expand All @@ -60,21 +60,17 @@ export default function Edit( {
);

if ( ! commentId || ! date ) {
return (
<>
{ inspectorControls }
<div { ...blockProps }>
<time>{ _x( 'Comment Date', 'block title' ) }</time>
</div>
</>
);
date = _x( 'Comment Date', 'block title' );
}

let commentDate = (
<time dateTime={ dateI18n( 'c', date ) }>
{ dateI18n( format || siteFormat, date ) }
</time>
);
let commentDate =
date instanceof Date ? (
<time dateTime={ dateI18n( 'c', date ) }>
{ dateI18n( format || siteFormat, date ) }
</time>
) : (
date
);

if ( isLink ) {
commentDate = (
Expand Down
3 changes: 0 additions & 3 deletions packages/block-library/src/comment-date/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ function render_block_core_comment_date( $attributes, $content, $block ) {
}

$classes = '';
if ( isset( $attributes['fontSize'] ) ) {
$classes .= 'has-' . esc_attr( $attributes['fontSize'] ) . '-font-size';
}

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
$formatted_date = get_comment_date(
Expand Down
4 changes: 0 additions & 4 deletions packages/block-library/src/comment-edit-link/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
},
"textAlign": {
"type": "string"
},
"fontSize": {
"type": "string",
"default": "small"
}
},
"supports": {
Expand Down
4 changes: 0 additions & 4 deletions packages/block-library/src/comment-reply-link/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
"attributes": {
"textAlign": {
"type": "string"
},
"fontSize": {
"type": "string",
"default": "small"
}
},
"supports": {
Expand Down
28 changes: 24 additions & 4 deletions packages/block-library/src/comments/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ const TEMPLATE = [
'core/column',
{},
[
[ 'core/comment-author-name' ],
[
'core/comment-author-name',
{
fontSize: 'small',
},
],
[
'core/group',
{
Expand All @@ -52,12 +57,27 @@ const TEMPLATE = [
},
},
[
[ 'core/comment-date' ],
[ 'core/comment-edit-link' ],
[
'core/comment-date',
{
fontSize: 'small',
},
],
[
'core/comment-edit-link',
{
fontSize: 'small',
},
],
],
],
[ 'core/comment-content' ],
[ 'core/comment-reply-link' ],
[
'core/comment-reply-link',
{
fontSize: 'small',
},
],
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"isValid": true,
"attributes": {
"isLink": true,
"linkTarget": "_self",
"fontSize": "small"
"linkTarget": "_self"
},
"innerBlocks": []
}
Expand Down
3 changes: 1 addition & 2 deletions test/integration/fixtures/blocks/core__comment-date.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"name": "core/comment-date",
"isValid": true,
"attributes": {
"isLink": true,
"fontSize": "small"
"isLink": true
},
"innerBlocks": []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"isValid": true,
"attributes": {
"linkTarget": "_blank",
"fontSize": "extra-large",
"backgroundColor": "recommended-color-03",
"fontFamily": "system-monospace",
"fontSize": "extra-large",
"style": {
"typography": {
"fontStyle": "normal",
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!-- wp:comment-edit-link {"linkTarget":"_blank","fontSize":"extra-large","backgroundColor":"recommended-color-03","fontFamily":"system-monospace","style":{"typography":{"fontStyle":"normal","fontWeight":"700","lineHeight":"2","textTransform":"uppercase","letterSpacing":"13px"},"elements":{"link":{"color":{"text":"#ed1717"}}}}} /-->
<!-- wp:comment-edit-link {"linkTarget":"_blank","backgroundColor":"recommended-color-03","fontFamily":"system-monospace","fontSize":"extra-large","style":{"typography":{"fontStyle":"normal","fontWeight":"700","lineHeight":"2","textTransform":"uppercase","letterSpacing":"13px"},"elements":{"link":{"color":{"text":"#ed1717"}}}}} /-->
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"isValid": true,
"attributes": {
"textAlign": "right",
"fontSize": "extra-large",
"fontFamily": "cambria-georgia",
"fontSize": "extra-large",
"style": {
"typography": {
"lineHeight": "0.8",
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!-- wp:comment-reply-link {"textAlign":"right","fontSize":"extra-large","fontFamily":"cambria-georgia","style":{"typography":{"lineHeight":"0.8","textTransform":"uppercase","letterSpacing":"10px"},"elements":{"link":{"color":{"text":"var:preset|color|blue"}}},"color":{"background":"#c82222"}}} /-->
<!-- wp:comment-reply-link {"textAlign":"right","fontFamily":"cambria-georgia","fontSize":"extra-large","style":{"typography":{"lineHeight":"0.8","textTransform":"uppercase","letterSpacing":"10px"},"elements":{"link":{"color":{"text":"var:preset|color|blue"}}},"color":{"background":"#c82222"}}} /-->
13 changes: 4 additions & 9 deletions test/integration/fixtures/blocks/core__comments-query-loop.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@
"isValid": true,
"attributes": {
"isLink": true,
"linkTarget": "_self",
"fontSize": "small"
"linkTarget": "_self"
},
"innerBlocks": []
},
Expand All @@ -107,17 +106,15 @@
"name": "core/comment-date",
"isValid": true,
"attributes": {
"isLink": true,
"fontSize": "small"
"isLink": true
},
"innerBlocks": []
},
{
"name": "core/comment-edit-link",
"isValid": true,
"attributes": {
"linkTarget": "_self",
"fontSize": "small"
"linkTarget": "_self"
},
"innerBlocks": []
}
Expand All @@ -132,9 +129,7 @@
{
"name": "core/comment-reply-link",
"isValid": true,
"attributes": {
"fontSize": "small"
},
"attributes": {},
"innerBlocks": []
}
]
Expand Down