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

Editor: Bring back Inspector Advanced Controls #5952

Merged
merged 5 commits into from
Apr 5, 2018

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Apr 3, 2018

Description

Fixes: #5884.
Related PR: #3475.

From @DannyCooper:

Has it been considered to visually separate the 'Additional CSS Class' setting from the above Panel? By default, it could be mistaken as part of the previous panel.

From @mtias:

It was supposed to be inside an "Advanced Settings" panel, together with "anchor" setting.

I tried to do the similar in #3475 but we decided to defer this decision. This PR introduces revised changes to make it happen.

This PR also introduces createSlotFill factory method to simplify the process of creating a pair of Slot and Fill components.

How Has This Been Tested?

  1. Open Gutenberg editor.
  2. Add a Paragraph block.
  3. Open block settings.
  4. Make sure there are no advanced settings.
  5. Add a Heading block.
  6. Open block settings.
  7. Make sure there are advanced settings in the collapsed state.
  8. Make sure they open and work properly after you click toggle icon.
  9. Add an Image block.
  10. Make sure there are advanced settings in the collapsed state.
  11. Make sure they open and work properly after you click toggle icon.

Screenshots (jpeg or gifs if applicable):

Before

screen shot 2017-11-14 at 15 34 29

Note: this screenshot is old but should be enough to show the difference :)

After

screen shot 2018-04-04 at 12 12 49

Note: this one is up to date 👍

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows has proper inline documentation.

@gziolo gziolo added [Type] Enhancement A suggestion for improvement. [Feature] Blocks Overall functionality of blocks Needs Design Feedback Needs general design feedback. labels Apr 3, 2018
@gziolo gziolo added this to the 2.6 milestone Apr 3, 2018
@gziolo gziolo self-assigned this Apr 3, 2018
@gziolo gziolo requested a review from a team April 3, 2018 12:44
@gziolo
Copy link
Member Author

gziolo commented Apr 3, 2018

I added missing documentation and unit tests.

@gziolo gziolo force-pushed the update/inspector-advanced-controls branch from ed3cc17 to 7d5d1ac Compare April 3, 2018 14:33
@mtias
Copy link
Member

mtias commented Apr 3, 2018

@jasmussen does this look good to you? I believe we discussed it before we just never got around to doing it.

return (
<Fragment>
<BlockEdit { ...props } />
{ hasAnchor && (
Copy link
Member

@jorgefilipecosta jorgefilipecosta Apr 3, 2018

Choose a reason for hiding this comment

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

Minor: Given that we are changing this zone, hasAnchor may be confusing has it includes the isSelected condition. Maybe we can have a condition that checks this hasBlockSupport( props.name, 'anchor' ) && props.isSelected and if true returns what the fragment we have without other checks.
Otherwise we just return <BlockEdit { ...props } />.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated, good idea. Thanks 👍

@@ -9,4 +9,19 @@ export { Slot };
export { Fill };
export { Provider };

export default { Slot, Fill, Provider };
export function createSlotFill( name ) {
Copy link
Member

Choose a reason for hiding this comment

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

Nice helper method 👍 It simplifies a lot the slot fill creation.

@gziolo gziolo force-pushed the update/inspector-advanced-controls branch 2 times, most recently from de16a67 to 39c4715 Compare April 4, 2018 07:04
@jasmussen
Copy link
Contributor

This looks good to me except for a few small things.

The margins on the top panel collapse now causing the text settings header to be a bit snug up against the border:

screen shot 2018-04-04 at 09 07 00

screen shot 2018-04-04 at 09 07 05

I think this is due to the addition of a div to group all the non-advanced content. But this div allows margins to collapse, because it has no border and no padding. You could hack your way out of that, but given another change I'd love to see, perhaps there's a different approach. More in a second.

Can you add a top border to the Advanced section, so it looks like this?

screen shot 2018-04-04 at 09 07 36

As you can see, there's a "separator" between the block type description at the top, and the advanced section below. Right now that description has a border, and in the mockup above I added a border to the bottom section as well.

If you remove those borders, and instead create a "separator" component or something in that vein, we can insert that between divs, and not have to worry about collapsing margins. Make sense? Otherwise hit me up on chat and we'll walk through it.

Nice work! 👍 👍

@gziolo gziolo force-pushed the update/inspector-advanced-controls branch from 3fca331 to 36ca30c Compare April 4, 2018 09:51
@jasmussen
Copy link
Contributor

With latest changes, looks good designwise 👍 👍

@gziolo
Copy link
Member Author

gziolo commented Apr 4, 2018

I applied the following changes:

  • Fixed the regression in the master with 78cbb9a and rebased branch.
  • Added border to the Advanced panel as suggested with 0d9961d.
  • Refactored hooks to work as @jorgefilipecosta recommended with 36ca30c.

@gziolo gziolo removed the Needs Design Feedback Needs general design feedback. label Apr 4, 2018
@jorgefilipecosta
Copy link
Member

jorgefilipecosta commented Apr 4, 2018

Thank you for your @gziolo, the code looks good to me and is working well.
I just noticed a possible improvement, that in my option does not block the PR. When the block has advanced controls but hasn't normal controls we show two bars:
image.
The fix for this is not easy because even when normal inspector controls and advanced ones are empty, we render empty container divs, so using nth-child or first/last is not possible. We can either remove this container divs if possible. Or add classes to them with empty/not empty state and we could add the border when advanced controls with content follow normal controls with content (using + selector).

@jorgefilipecosta
Copy link
Member

jorgefilipecosta commented Apr 4, 2018

There is also a pure CSS solution which should work well which is use the selector
.edit-post-block-inspector-panel > div:nth-child(2):not(:empty) + div:not(:empty) to apply the border. The big downside is that it assumes that normal inspector controls are the second div and advanced controls are the third div, which sounds hacky.

@gziolo
Copy link
Member Author

gziolo commented Apr 4, 2018

@jorgefilipecosta, good catch. I think we can also try to apply border-top to the inspector controls instead of having border-bottom applied to the block details. I'm wondering now what happens where there are no controls at all :)

@gziolo
Copy link
Member Author

gziolo commented Apr 5, 2018

I will open a follow up because I have a fix that touches a half of the core blocks. The good part is that it greatly improves UI for all of them 👍

@gziolo gziolo merged commit fc2d87d into master Apr 5, 2018
@gziolo gziolo deleted the update/inspector-advanced-controls branch April 5, 2018 04:34
return cloneElement( child, { key: childKey } );
} );
} ) }
{ isFunction( children ) ? children( fills.filter( Boolean ) ) : fills }
Copy link
Member

Choose a reason for hiding this comment

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

Why do we filter here?

Copy link
Member Author

Choose a reason for hiding this comment

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

To get rid of empty elements. Some fills render nothing based on Redux state. If you want to prevent rendering a slot wrapper it it has no fill which render something this is the way to go. In retrospective, I think this could be also done outside. Should we move it out or improve here and add some comments?

Copy link
Member

Choose a reason for hiding this comment

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

Comments would be good.

It was also strange to me that we filter only if the children is passed as a function, but not otherwise.

Copy link
Member

Choose a reason for hiding this comment

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

Also, filter( Boolean ) doesn't sound like a sufficient way to imitate React's treatment of "empty". For example, a child of 0 would be omitted here, but is a valid / non-empty child to render.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I will open PR with all your comments addressed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done #9371.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants