-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
FormFileUpload: Add lint rule for 40px size prop usage #64585
Conversation
{ | ||
// 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"]))', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Custom rule different from the others because FormFileUpload can take a render
prop.
render={ ( { openFileDialog } ) => ( | ||
<Button | ||
onClick={ openFileDialog } | ||
variant="primary" | ||
className={ clsx( | ||
'block-editor-media-placeholder__button', | ||
'block-editor-media-placeholder__upload-button' | ||
) } | ||
> | ||
{ __( 'Upload' ) } | ||
</Button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this to an explicit render prop, so the upsizing can be resolved along with the other Button components surrounding it.
The resulting output should remain the same. This is the render
prop logic in FormFileUpload:
gutenberg/packages/components/src/form-file-upload/index.tsx
Lines 43 to 49 in 68dd5ce
const ui = render ? ( | |
render( { openFileDialog } ) | |
) : ( | |
<Button onClick={ openFileDialog } { ...props }> | |
{ children } | |
</Button> | |
); |
An instance of MediaPlaceholder, with other buttons:
/** | ||
* Start opting into the larger default height that will become the default size in a future version. | ||
* | ||
* @default false | ||
*/ | ||
__next40pxDefaultSize?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was passed through as rest props to the underlying Button, but adding it here so it shows up explicitly in Storybook.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +8 B (0%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
Should we also add __next40pxDefaultSize={true}
to JSDoc examples / Storybook default args ?
Will be done when we start logging deprecation warnings 👍 |
* FormFileUpload: Document `__next40pxDefaultSize` prop * Switch to explicit Button in MediaPlaceholder * Add lint rule Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: ciampo <mciampini@git.wordpress.org>
Part of #63871
What?
Add a lint rule to prevent people from introducing new usages of FormFileUpload that do not adhere to the new default size.
Testing Instructions
The lint error should trigger for violations as expected.