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

Make all components generics #2045

Merged
merged 13 commits into from Aug 4, 2020
Merged

Conversation

dmtrKovalenko
Copy link
Member

Unfortunately, our internal component's props keep returning unknown for date values so we must refactor all the components to be generics. Here is the beginning of refactoring – but with all core changes for makePickerWithState

@vercel
Copy link

vercel bot commented Jul 28, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/mui-org/material-ui-pickers/fhn2n4enz
✅ Preview: https://material-ui-pickers-git-bugfix-all-components-generics.mui-org.vercel.app

@cypress
Copy link

cypress bot commented Jul 28, 2020



Test summary

78 0 3 0


Run details

Project material-ui-pickers
Status Passed
Commit 9997cc3
Started Aug 4, 2020 9:12 AM
Ended Aug 4, 2020 9:13 AM
Duration 01:44 💡
OS Linux Debian - 10.0
Browser Chrome 80

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

A note for later.

I think that it would be great to explore the potential of only exposing a native date object or a string date in the public API. It seems that using a native date object has the potential to be a great way to remove the need for generics and to have examples that work with any date engines. The impact user-land seems small, people would only need to wrap the date with their library when they need to use it.

const {
allowKeyboardControl,
type,
Copy link
Member

Choose a reason for hiding this comment

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

sort asc

Comment on lines -12 to +13
import { withDefaultProps } from '../../_shared/withDefaultProps';
import { useDefaultProps } from '../../_shared/withDefaultProps';
Copy link
Member

Choose a reason for hiding this comment

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

This is a step in the right direction 👍 . In hindsight, I wish I pushed more against withDefaultProps and useStyles in the past.

@@ -95,7 +96,7 @@ export const useStyles = makeStyles(
muiComponentConfig
);

export const Clock: React.FC<ClockProps> = withDefaultProps(muiComponentConfig, (props) => {
export function Clock<TDate>(props: ClockProps<TDate>) {
Copy link
Member

Choose a reason for hiding this comment

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

Important question. What would it take to use withStyles here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't get the question. What the problem of using makeStyles could be?

Copy link
Member

Choose a reason for hiding this comment

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

We will need to use the HOC API for integrating the components back into the lab. So we might as well do it now.

Copy link
Member Author

Choose a reason for hiding this comment

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

No we cannot use HOCs with pickers sources. Because it breaks generics

Copy link
Member

Choose a reason for hiding this comment

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

In this case, we need to reconsider the approach, what about we expose a native Date object to remove the need for generics? It's the approach used by https://github.com/adobe/react-spectrum/blob/c700898916bbd076bcc63e49d77c16d80623a8e7/packages/%40react-spectrum/calendar/src/Calendar.tsx (even if they are using date-fns), it seems simpler :)

Copy link
Member

Choose a reason for hiding this comment

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

Also, I wonder, isn't the Autocomplete using generic and withStyles at the same time?

Copy link
Member Author

Choose a reason for hiding this comment

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

Generics lives only on the typescript side – autocomplete written in js.

it is possible to use withStyles. Simply by adding withStyles() as typeof CalendarView where CalendarView is generic. BUT why? I would be happy to make lab infrastructure to work without withStylea

Copy link
Member

Choose a reason for hiding this comment

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

BUT why?

A couple of reasons that come to mind:

  1. @mnajdova Is working on revamping how we write the components (at the style and unstyled level). I think that normalizing the approach will make her job easier.
  2. It bundles a couple of behavior that forces us to implement, which is great. classes API, theme default prop behavior.
  3. It's required for the API classes markdown generation to work correctly.
  4. It's required for the tests getClasses utility to work correctly.

I would be happy to make lab infrastructure to work without withStylea

I think that we should leave this to 1. and focus on the migration for now. But if you have insight, please raise them to Marija :).

lib/src/_helpers/time-utils.ts Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview August 3, 2020 10:03 Inactive
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.

None yet

3 participants