Skip to content

Commit f1a8eea

Browse files
committed
Merge pull request #94 from gpbl/utils-export
Update docs for new exports
2 parents 880184c + 353992c commit f1a8eea

File tree

13 files changed

+43
-49
lines changed

13 files changed

+43
-49
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ react-day-picker is a flexible date picker component for [React](https://faceboo
3131

3232
## Quick start
3333

34-
Install via npm
34+
**Install via npm**
3535

3636
```
3737
npm install react-day-picker --save

docs/APIProps.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ The last allowed month. Users won't be able to navigate or interact with the day
9999
#### localeUtils (Object)
100100

101101
Object of functions to format dates and to get the first day of the week. Pass your own utils to support localization.
102-
By default the used locale is English (US). See also [Localization](Localization.md).
102+
By default the used locale is English (US). See also [Localization](Localization.md) and [LocaleUtils](LocaleUtils.md).
103103

104104
---
105105

docs/DateUtils.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
# dateUtils
1+
# DateUtils
22

3-
`dateUtils` is a set of functions useful to work with dates and modifiers.
3+
`DateUtils` is a set of functions useful to work with dates and modifiers.
44

55
```js
6-
import { dateUtils } from "react-day-picker/utils";
7-
8-
console.log(dateUtils.isPastDay(new Date())); // false
6+
import { DateUtils } from "react-day-picker";
7+
console.log(DateUtils.isPastDay(new Date())); // false
98
```
109

1110
## Functions
@@ -30,20 +29,20 @@ Returns `true` if `day` is between the days `d1` and `d2`, without including tho
3029

3130
Add `day` to a range of days, returning a new range including that dy. A range is an object with `from` and `to` keys.
3231

33-
See the [range examples](http://www.gpbl.org/react-day-picker/#examples/range) for an example using this function.
32+
See the [range example](http://www.gpbl.org/react-day-picker/#examples/range) for an example using this function.
3433

3534
```js
36-
import { dateUtils } from "react-day-picker/utils";
35+
import { DateUtils } from "react-day-picker";
3736

3837
const range = {
3938
from: new Date(2015, 5, 14),
4039
to: new Date(2015, 5, 18)
4140
}
42-
const newRange = dateUtils.addDayToRange(new Date(2015, 5, 24), range);
41+
const newRange = DateUtils.addDayToRange(new Date(2015, 5, 24), range);
4342

4443
console.log(newRange.from) // 2015-05-24
4544
```
4645

4746
### `isDayInRange(day: date, range: object<from: ?date, to: ?date>) -> bool`
4847

49-
Returns `true` if `day` is included in the specified range of days. See the [range examples](http://www.gpbl.org/react-day-picker/#examples/range) for an example using this function.
48+
Returns `true` if `day` is included in the specified range of days. See the [range example](http://www.gpbl.org/react-day-picker/#examples/range) for an example using this function.

docs/GettingStarted.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,20 @@ then, the click handler stops the interaction when the day contains the `isSunda
146146

147147
```javascript
148148
handleDayClick(e, day, modifiers) {
149-
if (modifiers.indefOf("isDisabled") > -1) {
149+
if (modifiers.indexOf("isDisabled") > -1) {
150150
return;
151151
}
152152
// etc.
153153
}
154154

155155
```
156156

157-
### Use the included utilities to simplify the code
157+
### Use DateUtils to simplify the code
158158

159-
react-day-picker comes with some utilities to simplify the creation of modifiers. For example, [dateUtils](DateUtils.md) contains a function called `isSameDay` useful to detect if two days are the same. We can use it for the `selected` modifier:
159+
react-day-picker includes [DateUtils](DateUtils.md), a function library to simplify the creation of modifiers. For example, we can use `isSameDay()` to detect if two days are the same. We can use it for the `selected` modifier:
160160

161161
```jsx
162-
import { dateUtils } from "react-day-picker/utils";
162+
import DayPicker, { DateUtils } from "react-day-picker/utils";
163163

164164
// snip
165165

docs/LocaleUtils.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
# localeUtils
1+
# LocaleUtils
22

3-
`localeUtils` is a set of functions used to work with localization. See also [Custom localization](LocalizationCustom.md).
3+
`LocaleUtils` is a set of functions used to localize the component (see: [Custom localization](LocalizationCustom.md)). You may want to implement your own `LocaleUtils`, or override some of its functions.
44

5-
Usually, you want to implement your own `localeUtils`, or override the behavior of some of its functions. For example, the following code will render the month title as `M/YYYY` instead of the default:
5+
For example, this code renders the month's title as `M/YYYY` instead of the default:
66

77
```jsx
8-
import DayPicker from "react-day-picker";
9-
import { localeUtils } from "react-day-picker/utils"
8+
import DayPicker, { LocaleUtils } from "react-day-picker";
109

1110
function formatMonthTitle(d, locale) {
1211
return `${d.getMonth() + 1}/${d.getFullYear}`

docs/LocalizationMoment.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ To localize the calendar with [moment.js](http://www.momentjs.com):
44

55
1. make sure [moment](https://www.npmjs.com/package/moment) is included in your dependencies
66
2. make sure the required moment's locale data is loaded
7-
3. import `localeUtils` from `react-day-picker/moment` and pass it to the `localeUtils` props
7+
3. import `LocaleUtils` from `react-day-picker/moment` and pass it to the `localeUtils` props
88
4. use the `locale` prop to pass the current locale
99

1010
### Example
@@ -18,7 +18,7 @@ import DayPicker from "react-day-picker";
1818

1919
// Use this util to format the calendar values according to the
2020
// selected locale with moment.js
21-
import { localeUtils } from "react-day-picker/moment";
21+
import LocaleUtils from "react-day-picker/moment";
2222

2323
// Make sure moment.js has the required locale data
2424
import "moment/locale/ja";
@@ -30,16 +30,16 @@ function LocalizedExample() {
3030
<div>
3131

3232
<p>English</p>
33-
<DayPicker localeUtils={ localeUtils } locale="en" />
33+
<DayPicker localeUtils={ LocaleUtils } locale="en" />
3434

3535
<p>Japanese</p>
36-
<DayPicker localeUtils={ localeUtils } locale="jp" />
36+
<DayPicker localeUtils={ LocaleUtils } locale="jp" />
3737

3838
<p>Arabic</p>
39-
<DayPicker localeUtils={ localeUtils } locale="ar" />
39+
<DayPicker localeUtils={ LocaleUtils } locale="ar" />
4040

4141
<p>Italian</p>
42-
<DayPicker localeUtils={ localeUtils } locale="it" />
42+
<DayPicker localeUtils={ LocaleUtils } locale="it" />
4343

4444
</div>
4545
);

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
* [Custom localization](/docs/LocalizationCustom.md)
1212
* [Tips](/docs/Tips.md)
1313
* [Utilities](/docs/Utilities.md)
14-
* [dateUtils](/docs/DateUtils.md)
15-
* [localeUtils](/docs/LocaleUtils.md)
14+
* [DateUtils](/docs/DateUtils.md)
15+
* [LocaleUtils](/docs/LocaleUtils.md)

docs/Utilities.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Utilities
22

3-
* [dateUtils](DateUtils.md)
4-
* [localeUtils](LocaleUtils.md)
3+
* [DateUtils](DateUtils.md)
4+
* [LocaleUtils](LocaleUtils.md)

examples/src/examples/InputField.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React from "react";
22
import moment from "moment";
33
import reactTapEvent from "react-tap-event-plugin";
44

5-
import DayPicker from "react-day-picker";
6-
import { dateUtils } from "react-day-picker/utils";
5+
import DayPicker, { DateUtils } from "react-day-picker";
6+
77
import "react-day-picker/lib/style.css";
88

99
// enable touch-tap events
@@ -49,8 +49,8 @@ export default class InputField extends React.Component {
4949
const selectedDay = moment(this.state.value, "L", true).toDate();
5050

5151
const modifiers = {
52-
disabled: dateUtils.isPastDay,
53-
selected: day => dateUtils.isSameDay(selectedDay, day)
52+
disabled: DateUtils.isPastDay,
53+
selected: day => DateUtils.isSameDay(selectedDay, day)
5454
};
5555

5656
return (

examples/src/examples/Localized.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import DayPicker from "react-day-picker";
33

44
// Use a custom util to format the calendar values according to the
55
// selected locale. This one is based on moment.js
6-
import { localeUtils } from "react-day-picker/moment";
6+
import MomentLocaleUtils from "react-day-picker/moment";
77

88
// Make sure moment.js has the required locale data
99
import "moment/locale/ja";
@@ -26,12 +26,6 @@ export default class Localized extends React.Component {
2626
render() {
2727
const { locale } = this.state;
2828

29-
const modifiers = {
30-
sunday(day) {
31-
return day.getDay() === 0
32-
}
33-
};
34-
3529
return (
3630
<div>
3731
<p>
@@ -42,7 +36,10 @@ export default class Localized extends React.Component {
4236
<option value="ar">Arabic</option>
4337
</select>
4438
</p>
45-
<DayPicker locale={ locale } localeUtils={ localeUtils } modifiers={ modifiers } />
39+
<DayPicker
40+
locale={ locale }
41+
localeUtils={ MomentLocaleUtils }
42+
modifiers={{ sunday: day => day.getDay() === 0 }} />
4643
</div>
4744
);
4845
}

0 commit comments

Comments
 (0)