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

feat(text): Add as prop while deprecating elementType #631

Merged
merged 8 commits into from
May 13, 2019

Conversation

jonnybel
Copy link
Contributor

@jonnybel jonnybel commented Apr 3, 2019

Summary

This PR adds a as prop to the Text components, as suggested by @tdeekens in #588 (comment).

Deprecates elementType prop of Text.Headline and Text.Subheadline components.
Deprecates isInline prop of Text.Body component.

Questions

  • Which element types should we allow to render for the Body component? (currently just span and p)

@jonnybel jonnybel added the 🚧 Status: WIP Work in progress label Apr 3, 2019
@jonnybel jonnybel force-pushed the ja-text-add-as-prop branch from 635d31b to c40685b Compare April 3, 2019 13:19
"${propName}" property of "${componentName}" has been deprecated
and will be removed in the next major version.\n
Please use "as" prop instead.`;
warning(false, message);
Copy link
Member

Choose a reason for hiding this comment

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

This will cause a massive amount of warnings.

I would proceed as following instead:

  • introduce the as prop without touching the other props
  • wait for a new major bump
  • deprecate the elementType prop and add the warning
  • wait for a new major bump
  • remove the elementType prop

Ideally, we would also provide a codemod to run the migration.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is what was aimed for here and also agreed upon before. Generally, I see the intend here to warn through prop-types given the prop is used. Then fix up the warnings (while still supporting the prop) by migrating to as and then in the next major dropping the elementType.

How did you read us wanting a quick breaking change from this code?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think providing a codemod is a bit overkill considering we could make the changes in the MC-FE in about 2 minutes with find and replace.

I think the path described by @tdeekens seems quite reasonable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, would be a nice learning experience to write a codemod during tech time if anybody wants but seems faster without. Assuming that not too many people use ui-kit yet (whom the find and replace is also quick an easy).

I am just lagging behind to how the suggested implementation here seemed to suggest another path than outlined above.

Copy link
Member

@emmenko emmenko left a comment

Choose a reason for hiding this comment

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

To be honest, I think there are several implications that need to be discussed first instead of jumping into the implementation.

I appreciate the thoughts and effort put into this but I would like to have an issue first where we discuss the usage and the API around this, as I feel it has bigger implications for the text components.

...rest
);
}
return PropTypes.oneOf(['h1', 'h2', 'h3'])(
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit confused now. What's the purpose of changing the prop elementType to as if you have the same exact restrictions as before? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

...to settle on a convention most other component libraries also have in offeing a prop called as not elementType. Other components, before we started with #628 assuming there too, would then offer an as prop too if needed and not elementType.

Copy link
Contributor

@tdeekens tdeekens Apr 3, 2019

Choose a reason for hiding this comment

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

To be honest, I think there are several implications that need to be discussed first instead of jumping into the implementation.

We have an issue where the prop name was suggested. We (three developers) have discused this before starting the implementation assuming that there was no arhm. Anyway, assuming that there is, lets move the discussion there. Can you lay out the specific bigger implication you have for text components there?

@tdeekens tdeekens changed the title WIP: feat(text): Add 'as' prop WIP: feat(text): Add as prop while deprecating elementType Apr 3, 2019
Copy link
Contributor

@tdeekens tdeekens left a comment

Choose a reason for hiding this comment

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

Thanks for giving this a spin. I really value trying to have offer an as prop instead of elementType with a deprecation migration plan.

}
}

return PropTypes.bool(props, propName, componentName, ...rest);
Copy link
Contributor

Choose a reason for hiding this comment

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

Idea. Maybe we can share these prop-types in typography/prop-types. I know that they will be removed but it makes the actual code less noisy.

@jonnybel jonnybel force-pushed the ja-text-add-as-prop branch from 00c334e to 73e7a79 Compare May 6, 2019 12:35
@jonnybel
Copy link
Contributor Author

jonnybel commented May 6, 2019

Thinking about merging this into 10.0.0, since it already implies breaking changes.

I'm updating the branch and we can discuss this further.

@jonnybel jonnybel force-pushed the ja-text-add-as-prop branch from 73e7a79 to 50ba651 Compare May 6, 2019 13:43
@jonnybel jonnybel changed the base branch from master to 10.0.0 May 6, 2019 13:43
@jonnybel jonnybel force-pushed the ja-text-add-as-prop branch from 50ba651 to 6c68f3f Compare May 6, 2019 13:54
@jonnybel jonnybel marked this pull request as ready for review May 6, 2019 14:11
@jonnybel
Copy link
Contributor Author

jonnybel commented May 6, 2019

I have a few things I'd like to discuss about the Text.Detail component and some positive implications of changing it a tiny bit.

  • The isInline prop is a bit counter-intuitive... Because the <small> element is inline by default and is supposed to be used inside a body text. If we want to use it as a block, I think it should be a p with different font size instead 🤔 So, in the end, I think it should either be removed or the logic inverted. (I prefer removing it since we're also removing isInline for all the other Text components).
  • It has a className prop. I searched on both the ui-kit and merchant-center-frontend but couldn't find any usage of it... Also, it's weird that it's the only Text component that has this prop. So it could also be removed?

As such, given these changes, almost all Text components (except for Wrap) could compose on top of the same "BaseText" component to reduce repetition of code, as they have almost the same API and mostly just accept different values as props.
For instance, the Text.Detail component is simply a Text as a <small> element, and the rest is all the same as the Text.Body.

Thoughts on this?

@montezume
Copy link
Contributor

@jonnybel

  1. Yeah, seems to me like the usage of isInline could just be replaced with a wrapping div. This makes more sense to me 🤔. I would remove it.
  2. Yes we should remove the className prop.

@montezume
Copy link
Contributor

The diff from the icon refactoring is showing in this PR even though this is aimed at 10.0.0. Can you rebase it maybe so it fixes that?

@jonnybel jonnybel force-pushed the ja-text-add-as-prop branch from 0b9eb76 to c59f17e Compare May 8, 2019 11:02
@jonnybel
Copy link
Contributor Author

jonnybel commented May 8, 2019

@montezume Done!

@jonnybel jonnybel changed the title WIP: feat(text): Add as prop while deprecating elementType feat(text): Add as prop while deprecating elementType May 8, 2019
Copy link
Contributor

@montezume montezume left a comment

Choose a reason for hiding this comment

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

Looks good to me now for 10.0.0

@jonnybel
Copy link
Contributor Author

@emmenko anything else you'd like to have changed?

We can use the same codemod I've added to #747 to automate the refactoring of these props!
This PR could be added to our v10 project, since it also implies breaking changes.

Copy link
Member

@emmenko emmenko left a comment

Choose a reason for hiding this comment

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

Nice, I like it!! 💯

Thanks a lot also for writing the codemod, pretty dope! 🙌

@jonnybel jonnybel force-pushed the ja-text-add-as-prop branch from 4cd45fb to f5f938b Compare May 13, 2019 13:09
@jonnybel jonnybel force-pushed the ja-text-add-as-prop branch from f5f938b to dcff062 Compare May 13, 2019 13:36
@jonnybel
Copy link
Contributor Author

Ok, the VRT detected changes now are only the prop name changes, in addition to the ones inherited from 10.0.0.

@jonnybel jonnybel merged commit 538ea3f into 10.0.0 May 13, 2019
@tdeekens tdeekens deleted the ja-text-add-as-prop branch May 13, 2019 15:13
jonnybel added a commit that referenced this pull request May 21, 2019
* feat(text): add as prop

* chore: update specs and story

* chore: update readme

* refactor: use requiredIf

* refactor: elementType to as

* refactor: remove className prop from Text.Details component

* refactor(text): use util for deprecation warning

* fix(tag): style text with css selector after removal of classname prop
jonnybel added a commit that referenced this pull request Jun 4, 2019
* feat(text): add as prop

* chore: update specs and story

* chore: update readme

* refactor: use requiredIf

* refactor: elementType to as

* refactor: remove className prop from Text.Details component

* refactor(text): use util for deprecation warning

* fix(tag): style text with css selector after removal of classname prop
jonnybel added a commit that referenced this pull request Jun 7, 2019
* feat(text): add as prop

* chore: update specs and story

* chore: update readme

* refactor: use requiredIf

* refactor: elementType to as

* refactor: remove className prop from Text.Details component

* refactor(text): use util for deprecation warning

* fix(tag): style text with css selector after removal of classname prop
jonnybel added a commit that referenced this pull request Jun 7, 2019
* feat(text): add as prop

* chore: update specs and story

* chore: update readme

* refactor: use requiredIf

* refactor: elementType to as

* refactor: remove className prop from Text.Details component

* refactor(text): use util for deprecation warning

* fix(tag): style text with css selector after removal of classname prop
montezume pushed a commit that referenced this pull request Jun 20, 2019
* feat(text): add as prop

* chore: update specs and story

* chore: update readme

* refactor: use requiredIf

* refactor: elementType to as

* refactor: remove className prop from Text.Details component

* refactor(text): use util for deprecation warning

* fix(tag): style text with css selector after removal of classname prop
montezume pushed a commit that referenced this pull request Jun 21, 2019
* feat(text): add as prop

* chore: update specs and story

* chore: update readme

* refactor: use requiredIf

* refactor: elementType to as

* refactor: remove className prop from Text.Details component

* refactor(text): use util for deprecation warning

* fix(tag): style text with css selector after removal of classname prop
@montezume montezume mentioned this pull request Jun 21, 2019
montezume pushed a commit that referenced this pull request Jun 24, 2019
* feat(text): add as prop

* chore: update specs and story

* chore: update readme

* refactor: use requiredIf

* refactor: elementType to as

* refactor: remove className prop from Text.Details component

* refactor(text): use util for deprecation warning

* fix(tag): style text with css selector after removal of classname prop
montezume pushed a commit that referenced this pull request Jun 25, 2019
* feat(text): add as prop

* chore: update specs and story

* chore: update readme

* refactor: use requiredIf

* refactor: elementType to as

* refactor: remove className prop from Text.Details component

* refactor(text): use util for deprecation warning

* fix(tag): style text with css selector after removal of classname prop
montezume pushed a commit that referenced this pull request Jul 4, 2019
* feat(text): add as prop

* chore: update specs and story

* chore: update readme

* refactor: use requiredIf

* refactor: elementType to as

* refactor: remove className prop from Text.Details component

* refactor(text): use util for deprecation warning

* fix(tag): style text with css selector after removal of classname prop
montezume pushed a commit that referenced this pull request Jul 8, 2019
* feat(text): add as prop

* chore: update specs and story

* chore: update readme

* refactor: use requiredIf

* refactor: elementType to as

* refactor: remove className prop from Text.Details component

* refactor(text): use util for deprecation warning

* fix(tag): style text with css selector after removal of classname prop
montezume pushed a commit that referenced this pull request Jul 8, 2019
* feat(text): add as prop

* chore: update specs and story

* chore: update readme

* refactor: use requiredIf

* refactor: elementType to as

* refactor: remove className prop from Text.Details component

* refactor(text): use util for deprecation warning

* fix(tag): style text with css selector after removal of classname prop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants