Skip to content

Commit

Permalink
ToggleGroupControl: Add lint rule for 40px size prop usage (#64524)
Browse files Browse the repository at this point in the history
* Fix in blocks

* Fix in Navigation block

* Fix in Comments Pagination block

* Fix in Grid layout

* Fix in Flex layout

* Fix in Constrained layout (e.g. Group block)

* Add lint rule

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
  • Loading branch information
3 people authored Aug 15, 2024
1 parent 787895e commit cdbd582
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 3 deletions.
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
__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
__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
__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
__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>
<ToggleGroupControl
__next40pxDefaultSize
__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"
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
__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
__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
__nextHasNoMarginBottom
label={ __( 'Arrow' ) }
value={ value }
Expand Down

0 comments on commit cdbd582

Please sign in to comment.