Skip to content

Commit

Permalink
docs: Update DatePicker docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Jul 30, 2020
1 parent 8800b56 commit cdefaec
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 26 deletions.
39 changes: 26 additions & 13 deletions components/date-picker/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The default locale is en-US, if you need to use other languages, recommend to us
If there are special needs (only modifying single component language), Please use the property: local. Example: [default](https://github.com/ant-design/ant-design/blob/master/components/date-picker/locale/example.json).

```jsx
import 'moment/locale/zh-cn';
import locale from 'antd/es/date-picker/locale/zh_CN';

<DatePicker locale={locale} />;
Expand All @@ -37,8 +38,12 @@ import locale from 'antd/es/date-picker/locale/zh_CN';
```jsx
// The default locale is en-US, if you want to use other locale, just set locale in entry file globally.
import moment from 'moment';
import 'moment/locale/zh-cn';
import locale from 'antd/es/locale/zh_CN';

<DatePicker defaultValue={moment('2015-01-01', 'YYYY-MM-DD')} />;
<ConfigProvider locale={locale}>
<DatePicker defaultValue={moment('2015-01-01', 'YYYY-MM-DD')} />
</ConfigProvider>;
```

### Common API
Expand Down Expand Up @@ -159,7 +164,7 @@ Added in `4.1.0`.
| showTime | To provide an additional time selection | object \| boolean | [TimePicker Options](/components/time-picker/#API) | |
| showTime.defaultValue | To set default time of selected date, [demo](#components-date-picker-demo-disabled-date) | [moment](http://momentjs.com/)\[] | \[moment(), moment()] | |
| value | To set date | \[[moment](http://momentjs.com/), [moment](http://momentjs.com/)] | - | |
| onCalendarChange | Callback function, can be executed when the start time or the end time of the range is changing. `info` argument is added in 4.4.0 | function(dates: \[moment, moment], dateStrings: \[string, string], info: { range:`start`\|`end` }) | - | |
| onCalendarChange | Callback function, can be executed when the start time or the end time of the range is changing. `info` argument is added in 4.4.0 | function(dates: \[moment, moment], dateStrings: \[string, string], info: { range:`start`\|`end` }) | - | |
| onChange | Callback function, can be executed when the selected time is changing | function(dates: \[moment, moment], dateStrings: \[string, string]) | - | |

<style>
Expand All @@ -173,18 +178,26 @@ Added in `4.1.0`.

## FAQ

- [When set mode to DatePicker/RangePicker, cannot select year or month anymore?](/docs/react/faq#When-set-mode-to-DatePicker/RangePicker,-cannot-select-year-or-month-anymore?)
### When set mode to DatePicker/RangePicker, cannot select year or month anymore?

- [How to use DatePicker with customize date library like dayjs?](/docs/react/replace-moment#DatePicker)
Please refer [FAQ](/docs/react/faq#When-set-mode-to-DatePicker/RangePicker,-cannot-select-year-or-month-anymore?)

- How to modify start day of week?
### How to use DatePicker with customize date library like dayjs?

Please use correct [language](/docs/react/i18n) ([#5605](https://github.com/ant-design/ant-design/issues/5605)), or update moment `locale` config: https://codesandbox.io/s/moment-day-of-week-b24k5
Please refer [replace moment](/docs/react/replace-moment#DatePicker)

```js
moment.locale('en', {
week: {
dow: 1,
},
});
```
### Why config moment.locale globally not work?

DatePicker default set `locale` as `en` in v4. You can config DatePicker `locale` prop or [ConfigProvider `locale`](/components/config-provider) prop instead.

### How to modify start day of week?

Please use correct [language](/docs/react/i18n) ([#5605](https://github.com/ant-design/ant-design/issues/5605)), or update moment `locale` config: https://codesandbox.io/s/moment-day-of-week-6dby5

```js
moment.locale('en', {
week: {
dow: 1,
},
});
```
38 changes: 25 additions & 13 deletions components/date-picker/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cover: https://gw.alipayobjects.com/zos/alicdn/RT_USzA48/DatePicker.svg
如有特殊需求(仅修改单一组件的语言),请使用 locale 参数,参考:[默认配置](https://github.com/ant-design/ant-design/blob/master/components/date-picker/locale/example.json)

```jsx
import 'moment/locale/zh-cn';
import locale from 'antd/es/date-picker/locale/zh_CN';

<DatePicker locale={locale} />;
Expand All @@ -39,8 +40,11 @@ import locale from 'antd/es/date-picker/locale/zh_CN';
// 默认语言为 en-US,如果你需要设置其他语言,推荐在入口文件全局设置 locale
import moment from 'moment';
import 'moment/locale/zh-cn';
import locale from 'antd/es/locale/zh_CN';

<DatePicker defaultValue={moment('2015-01-01', 'YYYY-MM-DD')} />;
<ConfigProvider locale={locale}>
<DatePicker defaultValue={moment('2015-01-01', 'YYYY-MM-DD')} />
</ConfigProvider>;
```

### 共同的 API
Expand Down Expand Up @@ -175,19 +179,27 @@ import 'moment/locale/zh-cn';

## FAQ

- [当我指定了 DatePicker/RangePicker 的 mode 属性后,点击后无法选择年份/月份?](/docs/react/faq#当我指定了-DatePicker/RangePicker-的-mode-属性后,点击后无法选择年份/月份?)
### 当我指定了 DatePicker/RangePicker 的 mode 属性后,点击后无法选择年份/月份?

请参考[常见问答](/docs/react/faq#当我指定了-DatePicker/RangePicker-的-mode-属性后,点击后无法选择年份/月份?)

### 如何在 DatePicker 中使用自定义日期库(如 dayjs )?

- [如何在 DatePicker 中使用自定义日期库(如 dayjs )?](/docs/react/replace-moment#DatePicker)
请参考[《替换 Moment.js》](/docs/react/replace-moment#DatePicker)

- 如何修改周的起始日
### 为何全局修改 moment.locale 不生效

请使用正确的[语言包](/docs/react/i18n)[#5605](https://github.com/ant-design/ant-design/issues/5605)),或者修改 moment `locale` 配置:https://codesandbox.io/s/moment-day-of-week-b24k5
v4 中,DatePicker 默认 `locale``en`。你可以通过 DatePicker `locale` 属性来单独设置,也可以通过 [ConfigProvider `locale`](/components/config-provider) 属性来配置。

```js
moment.locale('en', {
// 注意请修改你正在使用的 locale 语言,比如 zh-cn
week: {
dow: 1,
},
});
```
### 如何修改周的起始日?

请使用正确的[语言包](/docs/react/i18n)[#5605](https://github.com/ant-design/ant-design/issues/5605)),或者修改 moment 的 `locale` 配置:https://codesandbox.io/s/moment-day-of-week-6dby5

```js
moment.locale('en', {
// 注意请修改你正在使用的 locale 语言,比如 zh-cn
week: {
dow: 1,
},
});
```

0 comments on commit cdefaec

Please sign in to comment.