diff --git a/components/date-picker/RangePicker.tsx b/components/date-picker/RangePicker.tsx index cd58bef875..caf13f2a47 100644 --- a/components/date-picker/RangePicker.tsx +++ b/components/date-picker/RangePicker.tsx @@ -179,6 +179,7 @@ export default class RangePicker extends React.Component { disabledDate, disabledTime, showTime, showToday, ranges, onOk, locale, format, + dateRender, } = props; warning(!('onOK' in props), 'It should be `RangePicker[onOk]`, instead of `onOK`!'); @@ -221,6 +222,7 @@ export default class RangePicker extends React.Component { dateInputPlaceholder={[startPlaceholder, endPlaceholder]} locale={locale.lang} onOk={onOk} + dateRender={dateRender} value={showDate} onValueChange={this.handleShowDateChange} hoverValue={hoverValue} diff --git a/components/date-picker/__tests__/__snapshots__/demo.test.js.snap b/components/date-picker/__tests__/__snapshots__/demo.test.js.snap index 1a138cdf2b..3eaf9456d4 100644 --- a/components/date-picker/__tests__/__snapshots__/demo.test.js.snap +++ b/components/date-picker/__tests__/__snapshots__/demo.test.js.snap @@ -81,6 +81,54 @@ exports[`renders ./components/date-picker/demo/basic.md correctly 1`] = ` `; +exports[`renders ./components/date-picker/demo/date-render.md correctly 1`] = ` +
+ +
+ + +
+
+ + + + + ~ + + + + + +
+`; + exports[`renders ./components/date-picker/demo/disabled.md correctly 1`] = `
+ en-US: Customized Date Rendering +--- + +## zh-CN + + + +## en-US + +We can customize the rendering of date cells in the calendar by providing a `dateRender` function to `DatePicker`. + +````jsx +import { DatePicker } from 'antd'; +const { RangePicker } = DatePicker; + +ReactDOM.render( +
+ { + const style = {}; + if (current.date() === 1) { + style.border = '1px solid'; + style.borderRadius = '50%'; + } + + return ( +
+ {current.date()} +
+ ); + }} + /> + { + const style = {}; + if (current.date() === 1) { + style.border = '1px solid'; + style.borderRadius = '50%'; + } + + return ( +
+ {current.date()} +
+ ); + }} + /> +
+, mountNode); +```` diff --git a/components/date-picker/index.en-US.md b/components/date-picker/index.en-US.md index a6ac716adf..dd205c56b2 100644 --- a/components/date-picker/index.en-US.md +++ b/components/date-picker/index.en-US.md @@ -49,6 +49,7 @@ The following APIs are shared by DatePicker, MonthPicker, RangePicker, WeekPicke | open | open state of picker | boolean | - | | onOpenChange | a callback function, can be executed whether the popup calendar is popped up or closed | function(status) | - | | placeholder | placeholder of date input | string\|RangePicker[] | - | +| dateRender | custom rendering function for date cells | function(currentDate: moment, today: moment) => React.ReactNode | - | ### DatePicker diff --git a/components/date-picker/index.tsx b/components/date-picker/index.tsx index 17640b9cc7..2c94d5f964 100755 --- a/components/date-picker/index.tsx +++ b/components/date-picker/index.tsx @@ -25,6 +25,7 @@ export interface PickerProps { onOpenChange?: (status: boolean) => void; disabledDate?: (current: moment.Moment) => boolean; renderExtraFooter?: () => React.ReactNode; + dateRender?: (current: moment.Moment, today: moment.Moment) => React.ReactNode; } export interface SinglePickerProps { diff --git a/components/date-picker/index.zh-CN.md b/components/date-picker/index.zh-CN.md index 777f0753ac..d89817578c 100644 --- a/components/date-picker/index.zh-CN.md +++ b/components/date-picker/index.zh-CN.md @@ -50,6 +50,7 @@ moment.locale('zh-cn'); | open | 控制弹层是否展开 | boolean | - | | onOpenChange | 弹出日历和关闭日历的回调 | function(status) | 无 | | placeholder | 输入框提示文字 | string\|RangePicker[] | - | +| dateRender | ... | function(currentDate: moment, today: moment) => React.ReactNode | - | ### DatePicker