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

LocalizationProvider #1537

Merged
merged 28 commits into from
Mar 1, 2020
Merged

LocalizationProvider #1537

merged 28 commits into from
Mar 1, 2020

Conversation

dmtrKovalenko
Copy link
Member

@dmtrKovalenko dmtrKovalenko commented Feb 25, 2020

Closes #1504

User facing changes

LocalizationProvider

Rename and changes in API for MuiPickersUtilsProvider. It is renamed to LocalizationProvider. In future this provider may be moved to the @material-ui/core

- <MuiPickersUtilsProvider utils={DateFnsUtils} />
+ <LocalizationProvider dateAdapter={DateFnsUtils}  />

Also, LocalizationProvider now accepts special dateFormats prop that allows globally override formats used for displaying dates

const formats = {
  normalDate: 'd MMM yyy',
  keyboardDate: 'd MMM yyy',
};

<LocalizationProvider
  dateAdapter={DateFnsAdapter}
  locale={frLocale}
  dateFormats={formats}
/>

Also, libInstance from now renamed to dateLibInstance which is a more meaningful name in case of reusable LocalizationProvider

dateAdapter prop

There is a new prop dateAdapter in each component which allows passing configured date adapter object without context

const memoizedDateAdapter = useMemo(() => {
    return new DateFnsAdapter({ locale });
  }, [locale]);

<DatePicker
  value={selectedDate}
  onChange={date => handleDateChange(date)}
  dateAdapter={staticDateAdapter}
/>;

@vercel
Copy link

vercel bot commented Feb 25, 2020

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

🔍 Inspect: https://zeit.co/mui-org/material-ui-pickers/pl8kib09x
✅ Preview: https://material-ui-pickers-git-feature-localizationprovider.mui-org.now.sh

@cypress
Copy link

cypress bot commented Feb 25, 2020



Test summary

61 0 0 0


Run details

Project material-ui-pickers
Status Passed
Commit e0a3f71
Started Mar 1, 2020 5:17 PM
Ended Mar 1, 2020 5:18 PM
Duration 00:59 💡
OS Linux Debian - 9.11
Browser Chrome 78

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

@codecov
Copy link

codecov bot commented Feb 25, 2020

Codecov Report

Merging #1537 into next will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             next    #1537   +/-   ##
=======================================
  Coverage   91.83%   91.83%           
=======================================
  Files          63       63           
  Lines        1763     1763           
  Branches      320      304   -16     
=======================================
  Hits         1619     1619           
  Misses        109      109           
  Partials       35       35
Impacted Files Coverage Δ
lib/src/_shared/KeyboardDateInput.tsx 88.57% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b2c19b0...e0a3f71. Read the comment docs.

@vercel vercel bot temporarily deployed to Preview February 25, 2020 21:44 Inactive
README.md Outdated
import { MuiPickersUtilsProvider } from '@material-ui/pickers';
import Luxon from '@date-io/luxon';
import Moment from '@date-io/moment';
import DateFns from '@date-io/date-fns';
Copy link
Member

Choose a reason for hiding this comment

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

Should the import come from?

Suggested change
import DateFns from '@date-io/date-fns';
import dateFns from '@material-ui/pickers/adapter/date-fns';

But I wonder about keeping the file system flat?

Suggested change
import DateFns from '@date-io/date-fns';
import dateFnsAdapter from '@material-ui/pickers/dateFnsAdapter';

Copy link
Member Author

@dmtrKovalenko dmtrKovalenko Feb 27, 2020

Choose a reason for hiding this comment

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

I think the main point is to make library names the same (date-fns) and not dateFnsAdapter? What do you think about it, IMHO it will be more clear for users

Copy link
Member

Choose a reason for hiding this comment

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

I don't have a clear idea of the best approach. There is a tradeoff between the consitency of the filenames and the npm name of the dependencies. Both seem OK.

README.md Outdated Show resolved Hide resolved
@@ -0,0 +1,35 @@
import React, { useState } from 'react';
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of using React.useState?

Suggested change
import React, { useState } from 'react';
import React from 'react';

Copy link
Member Author

Choose a reason for hiding this comment

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

It is even more invalid, somewhere I thought that this kind of import will be deprecated. We are primarily using import * as React, but in examples using this notation.
I have no preference and can change

Copy link
Member

Choose a reason for hiding this comment

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

There is a related thread on this topic at mui/material-ui#19802.
What approach have you seen the more frequently used by TypeScript users on one side? And by JavaScript users on the other?

There are no clear guidelines by React on the matter, but I could find these two examples:

Copy link
Member Author

@dmtrKovalenko dmtrKovalenko Feb 28, 2020

Choose a reason for hiding this comment

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

For typescript codebase, it is much easier to use import * as React because a lot of internal types are also exported, like React.ReactNode, React.HtmlProps and so on.

My own notice: It is easier to visual recognize default react hooks like useEffect or useState when they are used like React.useEffect, thus all custom hooks are easily distinguishable

docs/pages/guides/Formats.example.jsx Outdated Show resolved Hide resolved
@dmtrKovalenko
Copy link
Member Author

Should we update Readme? Because it will affect new v3.x, because next is our default branch.

@oliviertassinari
Copy link
Member

oliviertassinari commented Feb 29, 2020

Maybe the Readme should point to the documentation websit and be kept generic?

@vercel vercel bot temporarily deployed to Preview March 1, 2020 16:12 Inactive
@dmtrKovalenko dmtrKovalenko merged commit 3cd58d6 into next Mar 1, 2020
@oliviertassinari oliviertassinari deleted the feature/LocalizationProvider branch March 18, 2020 19:41
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.

2 participants