File tree Expand file tree Collapse file tree 4 files changed +60
-3
lines changed Expand file tree Collapse file tree 4 files changed +60
-3
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ import IncludeTimes from "./examples/include_times";
52
52
import InjectTimes from "./examples/inject_times" ;
53
53
import DontCloseOnSelect from "./examples/dont_close_onSelect" ;
54
54
import RenderCustomHeader from "./examples/render_custom_header" ;
55
+ import RenderCustomDay from "./examples/render_custom_day" ;
55
56
import TimeInput from "./examples/timeInput" ;
56
57
import StrictParsing from "./examples/strict_parsing" ;
57
58
import "react-datepicker/dist/react-datepicker.css" ;
@@ -263,6 +264,10 @@ export default class exampleComponents extends React.Component {
263
264
title : "Custom header" ,
264
265
component : < RenderCustomHeader />
265
266
} ,
267
+ {
268
+ title : "Custom Day" ,
269
+ component : < RenderCustomDay />
270
+ } ,
266
271
{
267
272
title : "Input time" ,
268
273
component : < TimeInput />
Original file line number Diff line number Diff line change
1
+ import React from "react" ;
2
+ import DatePicker from "react-datepicker" ;
3
+ import getDate from "date-fns/getDate" ;
4
+
5
+ export default class RenderCustomDay extends React . Component {
6
+ constructor ( props ) {
7
+ super ( props ) ;
8
+ this . state = {
9
+ startDate : new Date ( )
10
+ } ;
11
+ }
12
+
13
+ handleChange = date => {
14
+ this . setState ( {
15
+ startDate : date
16
+ } ) ;
17
+ } ;
18
+
19
+ renderDayContents = ( day , date ) => {
20
+ const tooltipText = `Tooltip for date: ${ date } ` ;
21
+ return < span title = { tooltipText } > { getDate ( date ) } </ span > ;
22
+ } ;
23
+
24
+ render ( ) {
25
+ return (
26
+ < div className = "row" >
27
+ < pre className = "column example__code" >
28
+ < code className = "jsx" >
29
+ { `
30
+ <DatePicker
31
+ selected={this.state.startDate}
32
+ onChange={this.handleChange}
33
+ renderDayContents={this.renderDayContents}
34
+ />
35
+ ` }
36
+ </ code >
37
+ </ pre >
38
+ < div className = "column" >
39
+ < DatePicker
40
+ selected = { this . state . startDate }
41
+ onChange = { this . handleChange }
42
+ renderDayContents = { this . renderDayContents }
43
+ />
44
+ </ div >
45
+ </ div >
46
+ ) ;
47
+ }
48
+ }
Original file line number Diff line number Diff line change @@ -203,7 +203,10 @@ export default class Day extends React.Component {
203
203
role = "option"
204
204
>
205
205
{ this . props . renderDayContents
206
- ? this . props . renderDayContents ( getDate ( this . props . day ) )
206
+ ? this . props . renderDayContents (
207
+ getDate ( this . props . day ) ,
208
+ this . props . day
209
+ )
207
210
: getDate ( this . props . day ) }
208
211
</ div >
209
212
) ;
Original file line number Diff line number Diff line change @@ -37,8 +37,9 @@ describe("Day", () => {
37
37
38
38
it ( "should render custom day contents" , ( ) => {
39
39
const day = newDate ( ) ;
40
- function renderDayContents ( day ) {
41
- return < span > { day } </ span > ;
40
+ function renderDayContents ( day , date ) {
41
+ const tooltipText = `Tooltip for date: ${ date } ` ;
42
+ return < span title = { tooltipText } > { getDate ( date ) } </ span > ;
42
43
}
43
44
const shallowDay = renderDay ( day , { renderDayContents } ) ;
44
45
expect ( shallowDay . find ( "span" ) ) ;
You can’t perform that action at this time.
0 commit comments