Skip to content

Commit

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

* Add lint rule

* Fix in Author block

* Fix in File block

* Fix in Audio block

* Fix in Archives block

* Fix formatting

Co-authored-by: mirka <[email protected]>
Co-authored-by: ciampo <[email protected]>
  • Loading branch information
3 people authored Aug 15, 2024
1 parent 9fc46be commit 8559790
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 12 deletions.
16 changes: 9 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,15 @@ module.exports = {
' should have the `__next40pxDefaultSize` prop to opt-in to the new default size.',
} ) ),
// Temporary rules until all existing components have the `__next40pxDefaultSize` prop.
...[ 'TextControl' ].map( ( componentName ) => ( {
// Not strict. Allows pre-existing __next40pxDefaultSize={ false } usage until they are all manually updated.
selector: `JSXOpeningElement[name.name="${ componentName }"]:not(:has(JSXAttribute[name.name="__next40pxDefaultSize"])):not(:has(JSXAttribute[name.name="size"]))`,
message:
componentName +
' should have the `__next40pxDefaultSize` prop to opt-in to the new default size.',
} ) ),
...[ 'SelectControl', 'TextControl' ].map(
( componentName ) => ( {
// Not strict. Allows pre-existing __next40pxDefaultSize={ false } usage until they are all manually updated.
selector: `JSXOpeningElement[name.name="${ componentName }"]:not(:has(JSXAttribute[name.name="__next40pxDefaultSize"])):not(:has(JSXAttribute[name.name="size"]))`,
message:
componentName +
' should have the `__next40pxDefaultSize` prop to opt-in to the new default size.',
} )
),
],
},
},
Expand Down
13 changes: 11 additions & 2 deletions packages/block-editor/src/components/font-family/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,18 @@ The current font family value.

The rest of the props are passed down to the underlying `<SelectControl />` instance.

#### `__next40pxDefaultSize`

- Type: `boolean`
- Required: No
- Default: `false`

Start opting into the larger default height that will become the default size in a future version.

#### `__nextHasNoMarginBottom`

- **Type:** `boolean`
- **Default:** `false`
- Type: `boolean`
- Required: No
- Default: `false`

Start opting into the new margin-free styles that will become the default in a future version.
3 changes: 3 additions & 0 deletions packages/block-editor/src/components/font-family/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { __ } from '@wordpress/i18n';
import { useSettings } from '../use-settings';

export default function FontFamilyControl( {
/** Start opting into the larger default height that will become the default size in a future version. */
__next40pxDefaultSize = false,
/** Start opting into the new margin-free styles that will become the default in a future version. */
__nextHasNoMarginBottom = false,
value = '',
Expand Down Expand Up @@ -50,6 +52,7 @@ export default function FontFamilyControl( {

return (
<SelectControl
__next40pxDefaultSize={ __next40pxDefaultSize }
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
label={ __( 'Font' ) }
options={ options }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const renderTestDefaultControlComponent = ( labelComponent, device ) => {
return (
<>
<SelectControl
__next40pxDefaultSize
label={ labelComponent }
options={ sizeOptions }
__nextHasNoMarginBottom
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/archives/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default function ArchivesEdit( { attributes, setAttributes } ) {
}
/>
<SelectControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Group by:' ) }
options={ [
Expand Down
7 changes: 4 additions & 3 deletions packages/block-library/src/audio/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ function AudioEdit( {
checked={ loop }
/>
<SelectControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ _x( 'Preload', 'noun; Audio block parameter' ) }
value={ preload || '' }
Expand All @@ -197,9 +198,9 @@ function AudioEdit( {
</InspectorControls>
<figure { ...blockProps }>
{ /*
Disable the audio tag if the block is not selected
so the user clicking on it won't play the
file or change the position slider when the controls are enabled.
Disable the audio tag if the block is not selected
so the user clicking on it won't play the
file or change the position slider when the controls are enabled.
*/ }
<Disabled isDisabled={ ! isSingleSelected }>
<audio controls="controls" src={ src ?? temporaryURL } />
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/file/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default function FileBlockInspector( {
) }
<PanelBody title={ __( 'Settings' ) }>
<SelectControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Link to' ) }
value={ textLinkHref }
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/form/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ const Edit = ( { attributes, setAttributes, clientId } ) => {
{ submissionMethod !== 'email' && (
<InspectorControls group="advanced">
<SelectControl
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
__nextHasNoMarginBottom
label={ __( 'Method' ) }
options={ [
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/post-author/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function PostAuthorEdit( {
/>
) ) || (
<SelectControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Author' ) }
value={ authorId }
Expand All @@ -129,6 +130,7 @@ function PostAuthorEdit( {
/>
{ showAvatar && (
<SelectControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Avatar size' ) }
value={ attributes.avatarSize }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ const DimensionControls = ( {
panelId={ clientId }
>
<SelectControl
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
__nextHasNoMarginBottom
label={ __( 'Aspect ratio' ) }
value={ aspectRatio }
Expand Down Expand Up @@ -233,6 +235,8 @@ const DimensionControls = ( {
panelId={ clientId }
>
<SelectControl
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
__nextHasNoMarginBottom
label={ __( 'Resolution' ) }
value={ sizeSlug || DEFAULT_SIZE }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export function TemplatePartAdvancedControls( {
/>

<SelectControl
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
__nextHasNoMarginBottom
label={ __( 'Area' ) }
labelPosition="top"
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/video/tracks-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ function SingleTrackEditor( { track, onChange, onClose, onRemove } ) {
</Grid>
<VStack spacing="8">
<SelectControl
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
__nextHasNoMarginBottom
className="block-library-video-tracks-editor__single-track-editor-kind-select"
options={ KIND_OPTIONS }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default function WidgetTypeSelector( { selectedId, onSelect } ) {

return (
<SelectControl
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
__nextHasNoMarginBottom
label={ __( 'Select a legacy widget to display:' ) }
value={ selectedId ?? '' }
Expand Down

0 comments on commit 8559790

Please sign in to comment.