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

Add NumberControl to support min/max font size for Tag Cloud Block #37311

Merged

Conversation

amustaque97
Copy link
Member

@amustaque97 amustaque97 commented Dec 12, 2021

Fixes: #37166

Description

Add NumberControl input to enter minimum and maximum font size value. It will help user to decide how they want tag cloud to look. Earlier it used to modify fontsize based on the number of post for a particular tag.

NOTE: When I reload the page these values reset to default values. 😞

How has this been tested?

  1. Checkout to this branch
  2. Create multiple tags here http://localhost:8888/wp-admin/edit-tags.php?taxonomy=post_tag
  3. Create multiple different post and add tags created in the above step.
  4. Create/edit a post and add /tag cloud block.
  5. For /tag cloud block go to settings, there you can see 2 new input has been added to control font size.
  6. Adjust/modify those numbers and save the post.
  7. Open same post that has /tag cloud block and check its font size.

Screenshots

  • NumberControl
    image

  • After post publish

Screenshot 2021-12-12 at 11 00 10 AM

Types of changes

Feature

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@amustaque97 amustaque97 marked this pull request as ready for review December 12, 2021 06:31
@mtias mtias added [Block] Tag Cloud Affects the Tag Cloud Block Needs Design Feedback Needs general design feedback. labels Dec 15, 2021
Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

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

Thanks for your work @amustaque97! 💯

This works well code wise! I left a couple of notes about making the controls a bit more compact and it would be ready to land. After the changes we would just need a design approval of course maybe by @jasmussen?

packages/block-library/src/tag-cloud/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/tag-cloud/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/tag-cloud/edit.js Outdated Show resolved Hide resolved
@ntsekouras ntsekouras requested a review from jasmussen January 27, 2022 10:35
@ntsekouras
Copy link
Contributor

You need to add the changes to block docs since you changed block attributes. Run npm run api-docs:ref and npm run api-docs:blocks.

@amustaque97 amustaque97 requested a review from mkaz as a code owner January 27, 2022 14:51
@jasmussen
Copy link
Contributor

Thank you for the PR! Here's how the tag cloud looks in trunk:
before

Here's this PR applied:

after

I thought about whether there was a better way to combine min/max font sizes into a singular control, but for comparison the paragraph font size looks like this:
Typography panel states

So it's probably best to not diverge too far from this.

The following is a mockup that uses new components from the effort outlined in #27331, so it looks a bit different from what's shipping but it's what it could eventually look like:

mockup

But one single recommedation I'd make is to adopt the unit-selector input field. That would both let us remove the (pt) from the label, and pick other units. Is that feasible?

In smaller changes, if it isn't too much, I'd change the panel title from "Tag Cloud settings" to just "Settings" — there really isn't need for the redundancy.

Nice work!

@amustaque97
Copy link
Member Author

amustaque97 commented Jan 28, 2022

Thank you for the reply! I can change the units from pt to px but not sure how to add px keyword to the right side of the NumberControl input field. Maybe reviewers can suggest me something!

@amustaque97
Copy link
Member Author

amustaque97 commented Jan 28, 2022

I tried my best to implement UI as shown in the illustration. I testing it making mobile/ipad responsive. Here is the screenshot!
Screenshot 2022-01-28 at 3 58 48 PM

In order to implement this I have used InputControl instead of NumberControl

@ntsekouras
Copy link
Contributor

Thanks for the iterations here @amustaque97!

In order to implement properly what @jasmussen suggests you should use UnitControl component. What this means in practice is that:

  1. You should update the new attributes to being strings with default values in pt
  2. This will also require extra handling (splitting) these values in (value/unit) in order to be passed properly in wp_tag_cloud (php part).

We can't change the default behavior to px because it will change the existing blocks appearance.

This is a bit more extra work but provides more flexibility.

@ntsekouras
Copy link
Contributor

What occurred to me right now is that with unit control we can set different units per size (smallest, largest), but there is no support for this in wp_tag_cloud. So we can't go this way as is a case I don't think we've encountered before(design wise).

Maybe a first iteration of this could be to support only the pt as it was before the updates in the PR with the px related changes and find a design about this? 🤔 What do you think @jasmussen ?

@amustaque97
Copy link
Member Author

@ntsekouras Again! this was too quick 😅 💨 . TBH I was not ready for the review yet. I was trying few things. Best thing to do right now is to wait for the reply from design team.

@amustaque97
Copy link
Member Author

amustaque97 commented Feb 1, 2022

I would suggest is to make both smallestFontSize and largestFontSize unit in sync. Example if we are updating unit for any one of it. It should set the same unit for the other one. I was trying to implement the same using useState hooks. Umm. for some reason it is not able to sync correctly! Not sure whether it will be useful or not!

Adding a link for sample example though it is not an actual implementation but the idea would be same.

@jasmussen
Copy link
Contributor

Took this one for a spin:
tag cloud

This looks great to me! Thanks for the extra effort. I don't think we need to sync the two unit types, it adds only limited value and I could imagine in the future someone wanting a minimum font size in pixels, and a max font size in responsive vw units, so having the two unchained feels like a feature.

Honestly this one is good to go pending just a code sanity check. Is there a reason we limit support to px and pt or could we support the full range of font size units? This wouldn't be a blocker for the PR, just a question.

@amustaque97
Copy link
Member Author

wp_tag_cloud supports only single font size unit at any time. So if font size is not in sync. User will get confuse which font unit is currently in use. User may assume that there is a bug. This is another reason why initially I hardcoded pt.

@jasmussen
Copy link
Contributor

wp_tag_cloud supports only single font size unit at any time. So if font size is not in sync. User will get confuse which font unit is currently in use. User may assume that there is a bug. This is another reason why initially I hardcoded pt.

Oh that's helpful context. 🤔

The unit selector you've implemented, though, is useful, and it would be nice to keep it. How hard would it be to keep those two in sync after all?

@ntsekouras
Copy link
Contributor

I would suggest is to make both smallestFontSize and largestFontSize unit in sync. Example if we are updating unit for any one of it. It should set the same unit for the other one.

In order to do that I guess we would just handle this on onChange function of each input and conditionally update the other one (check the unit of both attributes).

Noting that changing the two attributes(smallest, largest) into type string is still needed and we will not need a third attribute of the unit.

@amustaque97
Copy link
Member Author

Addressed review comments. Code wise it is functional but on UI it doesn't update when we update font unit. I wanted to use something like unit so that it will be easy to update UI if we are changing units at code level.

Looking forward to your inputs Nik!

@jasmussen
Copy link
Contributor

Took it for a quick spin, and I'm seeing this:
units

This looks great. Thank you for going the extra mile. This feels good to me.

I'd appreciate if Nik could give this one a quick code review, but the user experience is good! 👏

Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

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

Thanks for iterating on this one once again @amustaque97! Great work!

I've left some comments, but it's getting really close!

packages/block-library/src/tag-cloud/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/tag-cloud/index.php Outdated Show resolved Hide resolved
packages/block-library/src/tag-cloud/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/tag-cloud/edit.js Outdated Show resolved Hide resolved
Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

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

Thanks for the iterations here @amustaque97!

The other thing that sometimes doesn't update the unit in the control, is something that seems to be internal to UnitControl. The values are updated properly in the block and when the controls are rerendered everything seems fine. --cc @ciampo for this issue.

I can reproduce sometimes when changing one font size and then change the unit of the other fontSize control.

Screen.Recording.2022-02-25.at.12.51.05.PM.mov

packages/block-library/src/tag-cloud/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/tag-cloud/index.php Outdated Show resolved Hide resolved
@ciampo
Copy link
Contributor

ciampo commented Feb 28, 2022

The other thing that sometimes doesn't update the unit in the control, is something that seems to be internal to UnitControl. The values are updated properly in the block and when the controls are rerendered everything seems fine. --cc @ciampo for this issue.

I can reproduce sometimes when changing one font size and then change the unit of the other fontSize control.

Hey @ntsekouras! Out of curiosity, are you able to reproduce that bug also in Storybook, or is it just happening in the context of the Tag Clouds settings?

@ntsekouras
Copy link
Contributor

Hey @ntsekouras! Out of curiosity, are you able to reproduce that bug also in Storybook, or is it just happening in the context of the Tag Clouds settings?

If you add another UnitControl in the stories that update both values, you can reproduce as well. It has to do with updating both values in one onChange..

amustaque97 and others added 19 commits March 21, 2022 18:56
test cases were failing because of new attribute `fontSizeUnit`. It is fixed now.
given a comment to handle decimal value case when passed to `unit`
property. I updated the regex to `/^\d*\.?\d*/`. This regex can parse
values like `123.3px` or `.33px` or `123px`.
Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
@amustaque97 amustaque97 force-pushed the feature/add-min-max-font-size-tag-cloud branch from 06437ea to db24fd3 Compare March 21, 2022 13:26
Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

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

Thanks for all the iterations and your patience here @amustaque97! Great work! 💯

I've left a minor change to the min value, but tested and this looks good! Attribute sanitization looks good too.

packages/block-library/src/tag-cloud/edit.js Outdated Show resolved Hide resolved
Co-authored-by: Nik Tsekouras <ntsekouras@outlook.com>
@ntsekouras ntsekouras merged commit d2ab852 into WordPress:trunk Mar 23, 2022
@github-actions github-actions bot added this to the Gutenberg 12.9 milestone Mar 23, 2022
@amustaque97 amustaque97 deleted the feature/add-min-max-font-size-tag-cloud branch March 23, 2022 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Tag Cloud Affects the Tag Cloud Block Needs Design Feedback Needs general design feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Minimum/Maximum font size in tag cloud block
8 participants