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

ToggleGroupControl: Add lint rule for 40px size prop usage #64524

Merged
merged 7 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ module.exports = {
'BorderControl',
'DimensionControl',
'FontSizePicker',
'ToggleGroupControl',
].map( ( componentName ) => ( {
// Falsy `__next40pxDefaultSize` without a non-default `size` prop.
selector: `JSXOpeningElement[name.name="${ componentName }"]:not(:has(JSXAttribute[name.name="__next40pxDefaultSize"][value.expression.value!=false])):not(:has(JSXAttribute[name.name="size"][value.value!="default"]))`,
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/layouts/constrained.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export default {
) }
{ allowJustification && (
<ToggleGroupControl
__next40pxDefaultSize
Copy link
Member Author

Choose a reason for hiding this comment

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

This can be seen for example in the Group block.

Before After
Constrained layout controls, before Constrained layout controls, after

__nextHasNoMarginBottom
label={ __( 'Justification' ) }
value={ justifyContent }
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/layouts/flex.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ function FlexLayoutJustifyContentControl( {

return (
<ToggleGroupControl
__next40pxDefaultSize
Copy link
Member Author

Choose a reason for hiding this comment

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

This can be seen for example in the Row block.

Before After
Flex layout controls, before Flex layout controls, after

__nextHasNoMarginBottom
label={ __( 'Justification' ) }
value={ justifyContent }
Expand Down Expand Up @@ -370,6 +371,7 @@ function OrientationControl( { layout, onChange } ) {
} = layout;
return (
<ToggleGroupControl
__next40pxDefaultSize
__nextHasNoMarginBottom
className="block-editor-hooks__flex-layout-orientation-controls"
label={ __( 'Orientation' ) }
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/layouts/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ function GridLayoutTypeControl( { layout, onChange } ) {

return (
<ToggleGroupControl
__next40pxDefaultSize
Copy link
Member Author

Choose a reason for hiding this comment

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

This can be seen in the Grid block.

Before After
Grid layout controls, before Grid layout controls, after

__nextHasNoMarginBottom
label={ __( 'Grid item position' ) }
value={ gridPlacement }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
export function CommentsPaginationArrowControls( { value, onChange } ) {
return (
<ToggleGroupControl
__next40pxDefaultSize
Copy link
Member Author

Choose a reason for hiding this comment

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

Insert Comments block, and click the pagination block inside it.

Before After
Comments Pagination block inspector, before Comments Pagination block inspector, after

__nextHasNoMarginBottom
label={ __( 'Arrow' ) }
value={ value }
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,11 @@ function Navigation( {
</div>
</>
) }
<h3>{ __( 'Overlay Menu' ) }</h3>
Copy link
Member Author

Choose a reason for hiding this comment

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

Moving this unnecessary h3 to a label on ToggleGroupControl.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be curious (and also a bit scared) to see how many more h3s are being used as labels (since the styles are the same)

Copy link
Member Author

Choose a reason for hiding this comment

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

😅

May be alleviated if we add fieldset/legend support to BaseControl (or provide a new component for it)? Like the h3 below this is used as a heading for multiple ToggleControls.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it definitely sounds like we need to gather and brainstorm all requirements that we'd like for a new version of BaseControl. Support for fieldset/legend and for multiple/composed inputs seem to be important and more frequent that we thought

<ToggleGroupControl
__next40pxDefaultSize
Copy link
Member Author

Choose a reason for hiding this comment

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

See the "Settings" tab in the inspector for the Navigation block.

Before After
Navigation block inspector, before Navigation block inspector, after

__nextHasNoMarginBottom
label={ __( 'Configure overlay menu' ) }
label={ __( 'Overlay Menu' ) }
aria-label={ __( 'Configure overlay menu' ) }
value={ overlayMenu }
help={ __(
'Collapses the navigation options in a menu icon opening an overlay.'
Expand All @@ -638,7 +639,6 @@ function Navigation( {
setAttributes( { overlayMenu: value } )
}
isBlock
hideLabelFromVision
>
<ToggleGroupControlOption
value="never"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export default function OverlayMenuPreview( { setAttributes, hasIcon, icon } ) {
/>

<ToggleGroupControl
__next40pxDefaultSize
__nextHasNoMarginBottom
className="wp-block-navigation__overlay-menu-icon-toggle-group"
Copy link
Member Author

Choose a reason for hiding this comment

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

A bit of style wrangling going on here. See screenshot above.

label={ __( 'Icon' ) }
value={ icon }
onChange={ ( value ) => setAttributes( { icon: value } ) }
Expand Down
5 changes: 5 additions & 0 deletions packages/block-library/src/navigation/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -628,3 +628,8 @@ body.editor-styles-wrapper .wp-block-navigation__responsive-container.is-menu-op
.wp-block-navigation__menu-inspector-controls__empty-message {
margin-left: 24px;
}

.wp-block-navigation__overlay-menu-icon-toggle-group {
// Counteract the margin added by the block inspector.
margin-bottom: $grid-unit-20;
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const DimensionControls = ( {
panelId={ clientId }
>
<ToggleGroupControl
__next40pxDefaultSize
Copy link
Member Author

Choose a reason for hiding this comment

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

Choose an Aspect ratio that's not "Original".

Before After
Featured Image block inspector, before Featured Image block inspector, after

__nextHasNoMarginBottom
label={ scaleLabel }
value={ scale }
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/post-navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export default function PostNavigationLinkEdit( {
/>
) }
<ToggleGroupControl
__next40pxDefaultSize
Copy link
Member Author

Choose a reason for hiding this comment

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

This can be seen in the Next Post and Previous Post blocks.

Before After
Navigation link controls, before Navigation link controls, after

__nextHasNoMarginBottom
label={ __( 'Arrow' ) }
value={ arrow }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
export function QueryPaginationArrowControls( { value, onChange } ) {
return (
<ToggleGroupControl
__next40pxDefaultSize
Copy link
Member Author

Choose a reason for hiding this comment

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

Insert a Query Loop block, choose something with a pagination block in it, and select that pagination block.

Before After
Query pagination controls, before Query pagination controls, after

__nextHasNoMarginBottom
label={ __( 'Arrow' ) }
value={ value }
Expand Down
Loading