-
Notifications
You must be signed in to change notification settings - Fork 1k
Add theme.icon.matchSize #6653
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
Add theme.icon.matchSize #6653
Conversation
src/js/utils/icon.js
Outdated
@@ -0,0 +1,13 @@ | |||
import { cloneElement } from 'react'; | |||
|
|||
export const useSizedIcon = (iconArg, size, theme) => { |
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.
Is it too confusing to do:
export const useSizedIcon = (icon, size, theme) =>
(icon && theme?.icon?.matchSize && !icon.props.size && cloneElement(icon, { size })) || undefined;
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 like it -- pushing a change that is along these lines with slight tweak to logic. (need to return icon as is if the conditions return false)
What does this PR do?
Adds
theme.icon.matchSize
as a boolean in the theme. When this is true, components withicon
andsize
will pass thesize
onto theicon
.This still allows for any custom overrides via
size
prop on icon to come through.For TextInput and MaskedInput, I had to adjust how the padding was calculating to account for the variable icon size. I ensured that there was a 12px gap between icon and placeholder text/value across all sizes.
Where should the reviewer start?
Any component.
What testing has been done on this PR?
Tested in storybook (see screenshot) and added jest tests.
How should this be manually tested?
Do Jest tests follow these best practices?
screen
is used for querying.userEvent
is used in place offireEvent
.asFragment()
is used for snapshot testing.Any background context you want to provide?
What are the relevant issues?
Screenshots (if appropriate)
Do the grommet docs need to be updated?
Yes.
Should this PR be mentioned in the release notes?
Yes.
Is this change backwards compatible or is it a breaking change?
Backwards compatible.