Skip to content
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 variants to InputControl prefix/suffix wrappers #64824

Merged
merged 4 commits into from
Aug 27, 2024

Conversation

mirka
Copy link
Member

@mirka mirka commented Aug 27, 2024

Prerequisite for remaining UnitControl migrations in #63871

What?

Adds a variant prop to InputControlPrefixWrapper and InputControlSuffixWrapper components to better handle icons and buttons.

Why?

We currently have to add custom CSS to decrease paddings when the prefix/suffix content is an icon or control (e.g. button). This should be easier, as it is a common use case.

Currently, the icon and control variant have the same styles, but I kept them separate variants for future proofing.

Testing Instructions

  • There should be no visual changes to existing usages of the prefix/suffix wrappers.
  • For usages of the new variants, see the new InputControl story "With Icon or Control", as well as the "Show Password" story.

Screenshots or screencast

Paddings adhere to the current specs.

Default size

InputControl with prefix and suffix content at 40px size

Compact size

InputControl with prefix and suffix content at 32px size

@mirka mirka added [Type] Enhancement A suggestion for improvement. [Package] Components /packages/components labels Aug 27, 2024
@mirka mirka self-assigned this Aug 27, 2024
@mirka mirka requested a review from ajitbohra as a code owner August 27, 2024 11:01
Copy link

github-actions bot commented Aug 27, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Comment on lines -93 to -102
const { paddingLeft, paddingRight } = getSizeConfig( {
inputSize: size,
__next40pxDefaultSize,
} );
const prefixSuffixContextValue = useMemo( () => {
return {
InputControlPrefixWrapper: { paddingLeft: `${ paddingLeft }px` },
InputControlSuffixWrapper: { paddingRight: `${ paddingRight }px` },
InputControlPrefixWrapper: { __next40pxDefaultSize, size },
InputControlSuffixWrapper: { __next40pxDefaultSize, size },
};
}, [ paddingLeft, paddingRight ] );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving all the style logic into the styles file.

@mirka mirka requested review from a team August 27, 2024 11:04
Copy link

github-actions bot commented Aug 27, 2024

Flaky tests detected in 2633c4c.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10578497331
📝 Reported issues:

Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

Apart from UnitControl, do you see other places where we may use an explicit variant? I thought SearchControl but then I remembered that we probably never got to refactor it to use InputControl internally

Comment on lines +218 to +228
* Internal prop used to control the padding size of the wrapper.
*
* @ignore
*/
children: ReactNode;
size?: BaseProps[ 'size' ];
/**
* Internal prop used to control the padding size of the wrapper.
*
* @ignore
*/
__next40pxDefaultSize?: BaseProps[ '__next40pxDefaultSize' ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is @ignore-ing a prop and writing "internal" in the description enough in your opinion to allow us to make future changes to it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Also in this case I do consider these props to be pretty much part of the API, just set through context by InputBase for convenience.

@mirka
Copy link
Member Author

mirka commented Aug 27, 2024

Apart from UnitControl, do you see other places where we may use an explicit variant? I thought SearchControl but then I remembered that we probably never got to refactor it to use InputControl internally

It is refactored actually 😄 In the components package, these wrapper variants can potentially be used for UnitControl (unit select), NumberControl (custom steppers), SearchControl (search icon), SelectControl (caret), CustomSelectControl (caret), etc. Not all of them currently use a suffix wrapper for their suffix content, so it would likely remove some ad hoc CSS if replaced. Not a priority though, since they aren't currently broken or anything.

In my mind this is more for consumer usage, so they can easily implement prefixes/suffixes like this.

@ciampo
Copy link
Contributor

ciampo commented Aug 27, 2024

it would likely remove some ad hoc CSS if replaced. Not a priority though, since they aren't currently broken or anything.
[...]
In my mind this is more for consumer usage, so they can easily implement prefixes/suffixes #64520 (comment).

Makes sense. Thank you for the explanation!

@mirka mirka merged commit 8f2555c into trunk Aug 27, 2024
63 of 64 checks passed
@mirka mirka deleted the adjust-input-prefix-suffix-wrapper branch August 27, 2024 15:35
@github-actions github-actions bot added this to the Gutenberg 19.2 milestone Aug 27, 2024
bph pushed a commit to bph/gutenberg that referenced this pull request Aug 31, 2024
* Add variants to InputControl prefix/suffix wrappers

* Use smaller close icon

* Add changelog

* Update snapshot

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants