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

TextInput: refresh adornment API #770

Closed
wants to merge 15 commits into from

Conversation

stvtortora
Copy link
Contributor

@stvtortora stvtortora commented May 24, 2020

Fixes #656

Do changes need to be made where this component is utilized throughout your other repositories?

As a heads up, I accidentally added the changes from https://github.com/aragon/aragon-ui/pull/769 to this PR because I initially forgot to create a new branch.

@auto-assign auto-assign bot requested a review from bpierre May 24, 2020 03:14
Copy link
Contributor

@sohkai sohkai left a comment

Choose a reason for hiding this comment

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

🙌 🙌 🙌 Thanks @stvtortora!

I've left a few comments and questions, but this is looking pretty good at the moment! The main one was about the backwards compatibility, since it looks like the padding values may be different (and we do use some hand-measured values for this API in aragon/aragon and aragon-apps).


Do changes need to be made where this component is utilized throughout your other repositories?

If you'd like to—by all means, we'd appreciate it! Otherwise we may end up upgrading this along with a few other changes published in the last few versions of aragonUI :).

As a heads up, I accidentally added the changes from #769

All good, I've merged this branch with master!

/>
<TextInput />
<TextInput adornment={{ start: <IconBlank /> }} />
<TextInput adornment={{ end: <IconBlank /> }} />
<TextInput
css="width: 80px"
adornment="ETH"
Copy link
Contributor

Choose a reason for hiding this comment

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

For these older examples, perhaps we can either remove them or update them to use the new API?

src/components/Input/TextInput.js Show resolved Hide resolved
src/components/Input/TextInput.js Outdated Show resolved Hide resolved
src/components/Input/TextInput.js Show resolved Hide resolved
@@ -154,8 +208,6 @@ WrapperTextInput.propTypes = {
WrapperTextInput.defaultProps = {
...TextInput.defaultProps,
adornment: null,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure, but should we add null to the list of allowed types for adornment? Not sure how PropTypes.oneOf() handles this, but I could see it erroring.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sadly, React doesn't seem to have null as an available propType. :(

Copy link
Contributor

Choose a reason for hiding this comment

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

Prop types interpret null and undefined as the same thing, so it shouldn’t be a problem as long as isRequired is not used. 👍

To combine a value with a type, the trick is to use PropType.oneOf() with only the value, making it a standard PropType type:

PropTypes.oneOfType([
  PropTypes.oneOf([null]),
  PropTypes.number,
])

This is what we are doing for the aragonUI’s _null prop type.

src/components/Input/TextInput.js Outdated Show resolved Hide resolved
const usingDeprecatedAPI =
React.isValidElement(adornment) ||
typeof adornment === 'string' ||
(typeof adornment === 'object' && adornment.constructor === Array)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would also assume a user wants the old API if they use adornmentPosition and adornmentSettings, and widen the PropTypes.node check a bit:

E.g. something like:

(React.isValidElement(adornment) || typeof adornment !== 'object' || Array.isArray(adornment)) ||
  adornmentPosition ||
  adornmentSettings

The main part that changes for the PropTypes.node check is changing typeof adornment === 'string' to typeof adornment !== object. PropTypes.node covers numbers and potentially other renderable types.

position: relative;
width: ${props.wide ? '100%' : 'max-content'};
${start && `padding-left: ${startWidth}`}
${end && `padding-right: ${endWidth}`}
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the backwards compatibility above might not reproduce this exactly, since it just uses the adornmentSettings.padding as the padding.

@@ -154,8 +208,6 @@ WrapperTextInput.propTypes = {
WrapperTextInput.defaultProps = {
...TextInput.defaultProps,
adornment: null,
adornmentPosition: 'start',
adornmentSettings: {},
}

// <input type=number> (only for compat)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we also update this component's documentation with the new changes? We can remove (or mark) the deprecated props :).

@sohkai sohkai changed the title #656 Refresh TextInput API TextInput: Refresh API Jun 7, 2020
@sohkai sohkai changed the title TextInput: Refresh API TextInput: fefresh adornment API Jun 7, 2020
@sohkai sohkai changed the title TextInput: fefresh adornment API TextInput: refresh adornment API Jun 7, 2020
@stale stale bot added the abandoned label Jul 8, 2020
@aragon aragon deleted a comment from stale bot Jul 8, 2020
@stale stale bot removed the abandoned label Jul 8, 2020
@bpierre bpierre added this to the 2.0.0 milestone Jul 10, 2020
@stale stale bot added the abandoned label Aug 15, 2020
@aragon aragon deleted a comment from stale bot Aug 15, 2020
@stale stale bot removed the abandoned label Aug 15, 2020
@stale stale bot added the abandoned label Sep 14, 2020
@aragon aragon deleted a comment from stale bot Sep 14, 2020
@stale stale bot removed the abandoned label Sep 14, 2020
@stale stale bot added the abandoned label Oct 15, 2020
@aragon aragon deleted a comment from stale bot Oct 15, 2020
@stale stale bot closed this Oct 23, 2020
@sohkai sohkai reopened this Oct 23, 2020
@stale stale bot removed the abandoned label Oct 23, 2020
@stale
Copy link

stale bot commented Nov 24, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for contributing to Aragon! 🦅

@stale stale bot added the abandoned label Nov 24, 2020
@stale stale bot closed this Dec 1, 2020
@nivida nivida reopened this Feb 25, 2021
@stale stale bot removed the abandoned label Feb 25, 2021
@stale
Copy link

stale bot commented Jun 2, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for contributing to Aragon! 🦅

@stale stale bot added the abandoned label Jun 2, 2021
@stale stale bot closed this Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TextInput: refresh the adornment API
5 participants