Skip to content

Commit

Permalink
FormFileUpload: Add lint rule for 40px size prop usage (WordPress#64585)
Browse files Browse the repository at this point in the history
* FormFileUpload: Document `__next40pxDefaultSize` prop

* Switch to explicit Button in MediaPlaceholder

* Add lint rule

Co-authored-by: mirka <[email protected]>
Co-authored-by: ciampo <[email protected]>
  • Loading branch information
3 people authored and bph committed Aug 31, 2024
1 parent 5328079 commit f2f9979
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@ module.exports = {
componentName +
' should have the `__next40pxDefaultSize` prop to opt-in to the new default size.',
} ) ),
{
// Falsy `__next40pxDefaultSize` without a `render` prop.
selector:
'JSXOpeningElement[name.name="FormFileUpload"]:not(:has(JSXAttribute[name.name="__next40pxDefaultSize"][value.expression.value!=false])):not(:has(JSXAttribute[name.name="render"]))',
message:
'FormFileUpload should have the `__next40pxDefaultSize` prop to opt-in to the new default size.',
},
// Temporary rules until all existing components have the `__next40pxDefaultSize` prop.
...[ 'SelectControl', 'TextControl' ].map(
( componentName ) => ( {
Expand Down
19 changes: 12 additions & 7 deletions packages/block-editor/src/components/media-placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,17 +491,22 @@ export function MediaPlaceholder( {
<>
{ renderDropZone() }
<FormFileUpload
variant="primary"
className={ clsx(
'block-editor-media-placeholder__button',
'block-editor-media-placeholder__upload-button'
render={ ( { openFileDialog } ) => (
<Button
onClick={ openFileDialog }
variant="primary"
className={ clsx(
'block-editor-media-placeholder__button',
'block-editor-media-placeholder__upload-button'
) }
>
{ __( 'Upload' ) }
</Button>
) }
onChange={ onUpload }
accept={ accept }
multiple={ !! multiple }
>
{ __( 'Upload' ) }
</FormFileUpload>
/>
{ uploadMediaLibraryButton }
{ renderUrlSelectionUI() }
{ renderFeaturedImageToggle() }
Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/form-file-upload/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import type Icon from '../icon';

// TODO: Replace `children` and `icon` types with props from Button once Button is typed.
export type FormFileUploadProps = {
/**
* Start opting into the larger default height that will become the default size in a future version.
*
* @default false
*/
__next40pxDefaultSize?: boolean;
/**
* A string passed to `input` element that tells the browser which file types can be
* upload to the upload by the user use. e.g: `image/*,video/*`.
Expand Down

0 comments on commit f2f9979

Please sign in to comment.