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

Normalize block inspector controls spacing #64526

Merged
merged 9 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
}

.components-base-control {
margin-bottom: #{ $grid-unit-30 };

&:last-child {
margin-bottom: $grid-unit-10;
Comment on lines -16 to -17
Copy link
Member Author

Choose a reason for hiding this comment

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

I am assuming this style on :last-child was an intentional optical adjustment (if not, it would've been margin-bottom: 0).

I think we should move this optical adjustment to the padding on the containers, i.e. PanelBody and ToolsPanel. It would be less hacky, and apply more universally (for example if the last control in the container was not wrapped in a BaseControl).

Copy link
Contributor

Choose a reason for hiding this comment

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

While we work on this, could we also find a way to move away from using .components-base-control at all?

Apart from the fact that is a private API of the components package and that it makes the UI fragile to future changes, it also doesn't work for controls that are not wrapped in base control.

Maybe we can introduce a block-editor package-specific classname instead (ie. block-editor-inspector-controls__control or something) and apply it where relevant? Or switch to VStack or similar, where the vertical spacing is defined on the parent and not the children?

Copy link
Member Author

Choose a reason for hiding this comment

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

The pathway I have in mind at the moment is:

  1. Add a __next prop and/or data attribute so certain container components can opt out of the automatic margin-bottom on BaseControl. Ideally we'd expose the prop only on InspectorControls and not on any @wordpress/components components.
  2. Figure out a standard way we can recommend to WP devs for spacing out their inspector controls. Is it VStack (not ideal because the current default spacing is 8px instead of the 16px we want in the inspector)? Is it a new, dedicated layout component (Implement a standard "controls grid" component for sidebar #43423)? To be decided.
  3. Migrate everything in the codebase.
  4. Deprecate the automatic margin-bottom on BaseControl.

Another long journey 😇

Copy link
Member Author

Choose a reason for hiding this comment

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

Extracted to a tracking issue: #65191

Copy link
Contributor

Choose a reason for hiding this comment

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

Figure out a standard way we can recommend to WP devs for spacing out their inspector controls.

Shouldn't this be built into the component? Should these panels consume DataForms?

Copy link
Member Author

Choose a reason for hiding this comment

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

Shouldn't this be built into the component?

We can consider it, for example making the container component a flexbox with a 16px gap. Not immediately sure if that would be too restrictive though.

Should these panels consume DataForms?

Hmm, interesting. @oandregal Are they meant for the block inspector at all? My first impression is that it could be used for some cases, but it wouldn't cover everything.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, interesting. @oandregal Are they meant for the block inspector at all? My first impression is that it could be used for some cases, but it wouldn't cover everything.

I presume any place that uses a complex form is a potential consumer of DataForm. I don't think it is ready for replacing inspector controls yet.

&:where(:not(:last-child)) {
margin-bottom: $grid-unit-20;
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
### Enhancements

- `Modal`: Decrease close button size and remove horizontal offset ([#65131](https://github.com/WordPress/gutenberg/pull/65131)).
- `Panel`: Increase bottom padding as an optical adjustment ([#64526](https://github.com/WordPress/gutenberg/pull/64526)).
- `ToolsPanel`: Increase bottom padding as an optical adjustment ([#64526](https://github.com/WordPress/gutenberg/pull/64526)).

### Internal

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/panel/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}

&.is-opened {
padding: $grid-unit-20;
padding: $grid-unit-20 $grid-unit-20 #{$grid-unit-20 + $grid-unit-05} $grid-unit-20;
Copy link
Contributor

Choose a reason for hiding this comment

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

Appreciate it's out of scope but do you know why is the bottom padding larger than the rest?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm assuming it was meant as an optical adjustment (see also #64526 (comment)). We can easily remove the larger bottom padding as part of this PR if the design team prefers that.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems unnecessary to me, and doesn't feature in the specs. I don't have the full history but would lean towards removing it.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW this felt weird when reviewing it. If there's no good reason to have it, let's use the opportunity to remove it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, we can remove it then.

Before After
ToolsPanel spacing, before ToolsPanel spacing, after

For the record, I do understand why someone would want to add an optical adjustment here. The bottom padding looks more equal to the side padding for some reason 😂

}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/tools-panel/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const ToolsPanel = ( columns: number ) => css`

border-top: ${ CONFIG.borderWidth } solid ${ COLORS.gray[ 300 ] };
margin-top: -1px;
padding: ${ space( 4 ) };
padding: ${ space( 4 ) } ${ space( 4 ) } ${ space( 5 ) } ${ space( 4 ) };
`;

/**
Expand Down
Loading