-
Notifications
You must be signed in to change notification settings - Fork 832
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
[WIP] Replace moment #218
[WIP] Replace moment #218
Changes from all commits
90cb877
fc9402d
9f2d8fb
e20ec44
4245319
47850ef
bb3051c
46a1938
2e2db64
97ee95e
fad69c5
e8e5ec1
1b567fd
3ba037c
dc16540
9d6887c
36fa3e8
9d286e1
4b18c46
d2dae09
d986820
51d34ac
51be3bb
0006018
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,22 +10,35 @@ | |
Changelog available [here](https://github.com/dmtrKovalenko/material-ui-pickers/releases) | ||
|
||
### Installation | ||
Available as npm package. Please note that we are using moment as a peer dependency | ||
Available as npm package. | ||
```sh | ||
npm install moment material-ui-pickers -S | ||
npm install material-ui-pickers -S | ||
``` | ||
Now choose the library that pickers will use to work with date. We are providing interfaces for [moment](https://momentjs.com/) and [date-fns](https://date-fns.org/). If you are not using moment in the project (or dont have it in the bundle already) we suggest using date-fns, because it much more lightweight and will be correctly tree-shaked from the bundle. | ||
|
||
We are using material-ui-icons font to display icons. Just add this to your html | ||
Teach pickers how to use one of that library using `MuiPickersUtilsProvider`. This component takes an utils property, and makes it available down the React tree thanks to React context. It should preferably be used at the root of your component tree. | ||
|
||
```jsx | ||
import { MuiPickersUtilsProvider } from 'material-ui-pickers'; | ||
import MomentUtils from 'material-ui-pickers/utils/moment-utils'; | ||
import DateFnsUtils from 'material-ui-picker/utils/date-fns-utils' | ||
|
||
function App() { | ||
return ( | ||
<MuiPickersUtilsProvider utils={DateFnsUtils}> | ||
<Root /> | ||
</MuiPickersUtilsProvider> | ||
); | ||
} | ||
|
||
render(<App />, document.querySelector('#app')); | ||
``` | ||
|
||
We are using material-ui-icons icon font to display icons. Just add this to your html | ||
```html | ||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> | ||
``` | ||
|
||
If you dont want to use icon font, or you are already use `material-ui-icons` you can pass any icon to the components with the following props | ||
* leftArrowIcon - arrow left for datepicker | ||
* rightArrowIcon - arrow right for datepicker | ||
* dateRangeIcon - date tab icon for datetimepicker | ||
* timeIcon - time tab icon for datetimepicker | ||
* keyboardIcon - icon for keyboard end adornmentic | ||
If you dont want to use icon font, or you are already use `material-ui-icons` you can pass any icon to the components with [corresponding props](https://github.com/dmtrKovalenko/material-ui-pickers#props-documentation) | ||
|
||
### Usage | ||
Here is a quick example of how to use this package | ||
|
@@ -83,12 +96,12 @@ Here is a list of available props | |
**Note:** Any prop not recognized by the pickers and their sub-components are passed down to material-ui [TextField](https://material-ui-next.com/api/text-field/#props) component. | ||
|
||
#### Datepicker | ||
* date - string, number, Date object, Moment object ([anything](https://momentjs.com/docs/#/parsing/), that can be parsed by moment) | ||
* date - string, number, Date object or Moment object (if you are using moment utils) | ||
|
||
Prop | Type | Default | Definition | ||
------------ | ------------- | ------------- | ------------- | ||
value | date | new Date() | Datepicker value | ||
format | string | 'MMMM Do' | Moment format string for input | ||
format | string | 'MMMM Do' | Format string for input | ||
autoOk | boolean | false | Auto accept date on selection | ||
disablePast | boolean | false | Disable past dates | ||
disableFuture | boolean | false | Disable future dates | ||
|
@@ -97,7 +110,6 @@ openToYearSelection | boolean | false | Open datepicker from year selection | |
minDate | date | '1900-01-01' | Minimum selectable date | ||
maxDate | date | '2100-01-01' | Maximum selectable date | ||
onChange | func | required | Callback firing when date accepted | ||
returnMoment | boolean | true | Will return moment object in onChange | ||
invalidLabel | string | 'Unknown' | Displayed string if date cant be parsed | ||
emptyLabel | string | '' | Displayed string if date is `null` (e.g. after clear) | ||
okLabel | string | 'OK' | The label for the ok button | ||
|
@@ -123,7 +135,6 @@ value | date | new Date() | Timepicker value | |
format | string | 'MMMM Do' | Moment format string for input | ||
autoOk | boolean | false | Auto accept time on selection | ||
onChange | func | required | Callback firing when date accepted | ||
returnMoment | boolean | true | Will return moment object in onChange | ||
invalidLabel | string | 'Unknown' | Displayed string if date cant be parsed | ||
emptyLabel | string | '' | Displayed string if date is `null` (e.g. after clear) | ||
okLabel | string | 'OK' | The label for the ok button | ||
|
@@ -152,7 +163,6 @@ animateYearScrolling | boolean | false | Will animate year selection | |
minDate | date | '1900-01-01' | Minimum selectable date | ||
maxDate | date | '2100-01-01' | Maximum selectable date | ||
onChange | func | required | Callback firing when date accepted | ||
returnMoment | boolean | true | Will return moment object in onChangeg | ||
invalidLabel | string | 'Unknown' | Displayed string if date cant be parsed | ||
emptyLabel | string | '' | Displayed string if date is `null` (e.g. after clear) | ||
okLabel | string | 'OK' | The label for the ok button | ||
|
@@ -165,7 +175,7 @@ rightArrowIcon | react node | `<Icon>keyboard_arrow_right</Icon>`| Right arrow i | |
dateRangeIcon | react node | `<Icon>date_range</Icon>`| Date tab icon | ||
timeIcon | react node | `<Icon>access_time</Icon>`| Time tab icon | ||
ampm | boolean | true | 12h/24h view for hour selection clock | ||
shouldDisableDate | (date: Moment) => boolean | () => false | Allow to disable custom date in calendar | ||
shouldDisableDate | (date: Moment | Date) => boolean | () => false | Allow to disable custom date in calendar | ||
keyboard | boolean | false | Allow to manual input date to the text field | ||
keyboardIcon | react node | `<Icon>event</Icon>` | Keyboard adornment icon | ||
maxDateMessage | string | 'Date should not be after maximal date' | Maximum date error message for keyboard input | ||
|
@@ -175,15 +185,7 @@ mask | text mask (read more [here](https://github.com/text-mask/text-mask/blob/m | |
clearable | boolean | false | If `true`, clear button will be displayed | ||
TextFieldComponent | func, string | undefined | Component that should replace the default Material-UI TextField | ||
|
||
### l10n | ||
For l10n texts we're currently relying on moment which is stateful. To change the locale you have to import your langauge specific files an change the locale manually via `moment.locale(language)`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be great to provide at least links to moment/date-fns l10n docs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will be a part of next release |
||
``` | ||
import moment from 'moment' | ||
import 'moment/locale/fr'; | ||
|
||
moment.locale('fr') | ||
``` | ||
|
||
<!-- Delay support of material-ui-pickers probably to rc-2 | ||
### Jalali Calendar | ||
We are fully supporting Jalali calendar system and [right-to-left](https://material-ui-next.com/guides/right-to-left/) material-ui api. Special thanks to @alitaheri. | ||
Here is a little example of how to use it | ||
|
@@ -195,23 +197,17 @@ npm install material-ui-pickers-jalali-utils | |
``` | ||
|
||
```jsx | ||
import { TimePicker, DateTimePicker, DatePicker } from 'material-ui-pickers'; | ||
import { MuiPickersUtilsProvider } from 'material-ui-pickers'; | ||
import jalaliUtils from 'material-ui-pickers-jalali-utils'; | ||
|
||
jMoment.loadPersian({ dialect: 'persian-modern', usePersianDigits: true }); | ||
|
||
<DateTimePicker | ||
okLabel="تأیید" | ||
cancelLabel="لغو" | ||
labelFunc={date => date === null ? '' : jMoment(date).format('jYYYY/jMM/jDD hh:mm A')} | ||
value={selectedDate} | ||
onChange={this.handleDateChange} | ||
utils={jalaliUtils} | ||
/> | ||
``` | ||
|
||
### Migrate to date-fns? | ||
If you are interested of using moment or date-fns as the peer of this project, please mention that in [this issue](https://github.com/dmtrKovalenko/material-ui-pickers/issues/61), we need to know which library if more useful to be in the peer dependencies of this project. Thank you. | ||
function App() { | ||
return ( | ||
<MuiPickersUtilsProvider utils={jalaliUtils}> | ||
<Root /> | ||
</MuiPickersUtilsProvider> | ||
); | ||
} | ||
``` --> | ||
|
||
### Contributing | ||
For information about how to contribute, see the [CONTRIBUTING](https://github.com/dmtrKovalenko/material-ui-pickers/blob/master/CONTRIBUTING.md) file. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,15 +103,15 @@ class Demo extends Component { | |
> | ||
<DateTimePickers /> | ||
</SourcablePanel> | ||
|
||
{/* | ||
<SourcablePanel | ||
title="Custom Day Element" | ||
sourceFile="CustomElements.jsx" | ||
> | ||
<CustomElements /> | ||
</SourcablePanel> | ||
|
||
<SourcablePanel | ||
<SourcablePanel | ||
title="Persian Pickers" | ||
description={ | ||
<p key="persian-desc"> | ||
|
@@ -123,7 +123,7 @@ class Demo extends Component { | |
sourceFile="PersianPickers.jsx" | ||
> | ||
<PersianPickers /> | ||
</SourcablePanel> | ||
</SourcablePanel> */} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea 👍 I'll update my utils library and fix these demos 👍 👍 |
||
</div> | ||
</main> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we avoid passing moment object to this callback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. We are poviding moment for api consistent. Moment utils is a way to use moment in this callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if we pass
utils
as second argument? This will allow data processingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cherniavskii read my answer to your previous coment :)