-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Comment Content Block: Add typography, color and padding support #35183
Conversation
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @DAreRodz! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
Commenting here but we should transfer to the general tracking issue — the "Post" prefix is a bit pointless, we should simplify the naming of all these blocks to be "Comment Content", "Comment Author" etc. |
"lineHeight": true | ||
}, | ||
"html": false, | ||
"__experimentalLayout": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we will not need to add the __experimentalLayout
for this block. Layout is for container blocks that enables controlling width/height
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ntsekouras. I did that because @SantosGuillamot suggested adding that specific setting. I'll talk with him to clarify that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggested adding that because it's something supported in the Post Content block, and I thought it could be a good idea to follow a similar pattern. It seemed to me that it would add more flexibility for editing the layout, but I don't have a strong opinion here, so no problem if you feel it's better to change it 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scruffian @MaggieCabrera @jffng curious what has come up in themes as uses here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've not seen a real life use case where we'd want to use this outside of a post comment block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think layout
would make more sense in the parent blocks like Comment Loop
Correct. Example: editing the single post template in isolation, with no post data.
I presume you're referring to this interface in the current "Post Comment" block: I don't think we should offer this functionality in the Comment Content block since it is strictly a template-only block, IE it will always have an ID passed to it by the queried post.
Perfect! Here's the SVG:
Good point, these should probably be omitted :) |
I agree with @jameskoster , but let's change this when we have the |
Edit: I understand now. Imo we should update the Post Comment block to check the ID when the user adds it, and throw an "comment not found" error (or similar) if they input a bad ID. |
Makes completely sense, I'll do that. Thanks for all your feedback, guys. 🙌 |
b98c625
to
5714fef
Compare
@@ -15,13 +24,23 @@ export default function Edit( { context: { commentId } } ) { | |||
'content', | |||
commentId | |||
); | |||
|
|||
// Show a placeholder when there is no context. | |||
if ( ! commentId ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If no commentId
exists the message should be something like no comment exists
.
If content
is undefined
has two cases:
- still loading
- comment doesn't exist (this can be handled in a separate PR though and has to do with
useEntityProp
)
The below if ( ! content?.rendered )
check (I had hastily added yesterday) is not correct as it should be shown when the comment exists and there is no content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If no
commentId
exists the message should be something likeno comment exists
.
Maybe (or probably 😅) I'm wrong, but from what @jameskoster wrote in this comment, I understood that, if you don't have commentId
defined, it could be one of these two cases:
- You haven't defined
commentId
in the parent block (i.e., the Comment block). In that case, I assumed that the block responsible for showing a message likeInput the comment ID
would be the Comment block, and the Comment Content block wouldn't be rendered. - You are editing a template / template part / etc. that would be rendered inside a Comment block. For this one, I thought you would see a generic message like
The content of the comment
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
content
isundefined
has two cases:
- still loading
- comment doesn't exist (this can be handled in a separate PR though and has to do with
useEntityProp
)
I see. Is there a way to know if an entity is still loading or if it doesn't exist after calling useEntityProp
? I mean, like a value or a prop returned by that hook? That would be useful. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The below
if ( ! content?.rendered )
check (I had hastily added yesterday) is not correct, as it should be shown when the comment exists and there is no content.
You mean that, if content
is not defined, it's not that the comment has no content but that it doesn't exist, right? So I guess I should write something like if ( content && ! content.rendered )
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could have a placeholder chip like here when no commentId
is provided.
You mean that, if content is not defined, it's not that the comment has no content but that it doesn't exist,
Correct.
Probably there is a couple of things we could do for this first version, where we do not have the comment content editable - also not sure if we need to..
- Skip the check/placeholder for a comment that exists and has no content
- Instead of
useEntityProp
, use thecore/data
selectors like:
const { comment, isLoading } = useSelect(
( select ) => {
const { getEntityRecord, hasFinishedResolution } = select( coreStore );
const queryArgs = [ 'root', 'comment', commentId ];
return {
comment: getEntityRecord( ...queryArgs ),
isLoading: ! hasFinishedResolution( 'getEntityRecord', queryArgs ),
};
},
[ commentId ]
);
5714fef
to
b5b968a
Compare
Sorry for the temp close - bad gh cli command 😄 |
Hey there, I've just created a simple schema in order to organize things better in my mind. The following diagram shows how (IMHO) the Comment Content block should behave in the context of the Comment block. While doing so, I came up with some questions:
Apart from that, I've also been thinking about when the Comment block is rendered inside the Comment List block. In that case, I guess the Comment block should know whether it's being rendered inside or outside a Comment List. Is there a way for doing so, or would it need to be two different blocks? |
b5b968a
to
bea31f9
Compare
I've done the changes that @ntsekouras suggested in #35183 (comment). About the placeholder chip, I guess I would need some help here from the designers (cc: @jameskoster ). 😊 Also, if anyone can take a look at what I've posted right before, that would be great. 👍 |
return ( | ||
<div { ...blockProps }> | ||
<Warning> | ||
{ __( 'The specified comment does not exist.' ) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I change the warning message to include the block name? Just to make it more meaningful.
{ __( 'The specified comment does not exist.' ) } | |
{ __( 'Comment Content: The specified comment does not exist.' ) } |
Hmm, I'm a little confused as to why we need this state: The UX is particularly poor because if I choose a bad ID when inserting the Post Comment block then I need to manually remove everything to start over. Shouldn't we run the ID validation on this save button instead? If this "The specified comment does not exist." state is just an interim until we can do that, then I suppose it's ok. But ultimately I don't think a user should ever actually see this? 🤔 |
A comment could be deleted, or the ID could be modified using the html editor, or coming from a different template, WordPress import, etc. |
Makes sense. In that case I think it's ok for now, but we might want to revisit holistically later. Just to clarify @DAreRodz, this is the "placeholder chip" you were referring to, correct? :D |
Thanks for your feedback! 🙌 @jameskoster I agree with you: the ID validation should run on the save button of the Comment block (actually, it's more or less what I posted in the previous diagram 😅). I can implement it (if that's okay with you), although I'm not sure if it's outside the scope of this PR. 🙃
@mtias good point, I didn't think of that. Wondering if it would make sense to show a similar message in the SSR from PHP. 🤔
Nope, I was referring to this one I've added to show something while the comment is being loaded, as suggested in #35183 (comment), but he was proposing to use it when |
Yeah let's do it separately.
Ah, the no-context placeholder :D There's an ongoing initiative to simplify the styling of these. The Post Content block for example just outputs a paragraph now. I think we can do the same here. |
04abec7
to
7b2eaa3
Compare
It seems for actual rendering on the front it should skip doing anything if an ID is not matched? |
It's what it does right now, I'll leave as it is then. 👍 |
7b2eaa3
to
6c22993
Compare
I've updated the PR description to reflect the changes I've done. Not sure if there's anything I missed, so asking for reviewers. 🙂 |
57f895b
to
5404513
Compare
I think everything is ready now. 😊 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code still looks good 👍🏻
Did I break something? There's a test failing that hadn't failed before. 👀 |
This is important to get right before merge imo, because in some rare cases none of these settings would work and the block would feel broken. Ultimately if you're changing a setting on the block, it's because you don't like what is supplied by the theme, so I feel the block should take priority here if possible.
Correct :D It's working now 👍 |
Hey there 👋 the fix for that issue is now merged into |
Settings are: * Typography and color settings (same as the Paragraph block) * Layout settings (same as Post Content block)
I've also removed some cases that I think should be handled in the parent block: - When the comment is not ready yet - When the comment does not exist
Added experimental settings for changing - Font family - Font weight - Font style - Text transform - Letter spacing
5404513
to
1fa7d39
Compare
I’m still unsure if that is a fixable issue with code. Block themes should leave the styling to blocks when it is supported. Maybe it’s only specific to a theme you tested with and we can sort it out by publishing a dev note for theme authors. They might be able to use |
That seems fair. |
Description
This PR continues the implementation of the Post Comment Content block that already existed. It adds support for text alignment, font size, family, style and weight, line height, colors (including links and gradients), and vertical/horizontal padding.
Will close #30574.
How has this been tested?
The content of the comment.
) is shown.Types of changes
Enhancement
Checklist:
*.native.js
files for terms that need renaming or removal).