File tree Expand file tree Collapse file tree 5 files changed +49
-1
lines changed Expand file tree Collapse file tree 5 files changed +49
-1
lines changed Original file line number Diff line number Diff line change 133
133
color : #f00 ;
134
134
}
135
135
136
+ .react-datepicker__week.highlighted {
137
+ background-color : #ddffdd ;
138
+ border-radius : 5px ;
139
+ }
140
+
136
141
.example-custom-input {
137
142
cursor : pointer ;
138
143
padding : 5px 15px ;
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import CustomDateFormat from "../../examples/customDateFormat?raw";
18
18
import CustomClassName from "../../examples/customClassName?raw" ;
19
19
import CustomCalendarClassName from "../../examples/customCalendarClassName?raw" ;
20
20
import CustomDayClassName from "../../examples/customDayClassName?raw" ;
21
+ import CustomWeekClassName from "../../examples/customWeekClassName?raw" ;
21
22
import CustomTimeClassName from "../../examples/customTimeClassName?raw" ;
22
23
import Today from "../../examples/today?raw" ;
23
24
import PlaceholderText from "../../examples/placeholderText?raw" ;
@@ -223,6 +224,10 @@ export default class exampleComponents extends React.Component {
223
224
title : "Custom day class name" ,
224
225
component : CustomDayClassName ,
225
226
} ,
227
+ {
228
+ title : "Custom week class name" ,
229
+ component : CustomWeekClassName ,
230
+ } ,
226
231
{
227
232
title : "Custom date format" ,
228
233
component : CustomDateFormat ,
Original file line number Diff line number Diff line change
1
+ ( ) => {
2
+ const [ selectedDate , setSelectedDate ] = useState ( new Date ( ) ) ;
3
+ return (
4
+ < DatePicker
5
+ selected = { selectedDate }
6
+ onChange = { ( date ) => setSelectedDate ( date ) }
7
+ weekClassName = { ( date ) =>
8
+ getDate ( date ) % 2 === 0 ? "highlighted" : undefined
9
+ }
10
+ />
11
+ ) ;
12
+ } ;
Original file line number Diff line number Diff line change @@ -23,6 +23,23 @@ describe("Week", () => {
23
23
expect ( container . querySelector ( ".react-datepicker__week" ) ) . not . toBeNull ( ) ;
24
24
} ) ;
25
25
26
+ it ( "should apply className returned from passed weekClassName prop function" , ( ) => {
27
+ const className = "customClassNameWeek" ;
28
+ const monthClassNameFunc = ( ) => className ;
29
+ const { container } = render (
30
+ < Week
31
+ day = { newDate ( ) }
32
+ month = { getMonth ( newDate ( ) ) }
33
+ weekClassName = { monthClassNameFunc }
34
+ /> ,
35
+ ) ;
36
+ expect (
37
+ container
38
+ . querySelector ( ".react-datepicker__week" )
39
+ ?. classList . contains ( className ) ,
40
+ ) . toBe ( true ) ;
41
+ } ) ;
42
+
26
43
it ( "should render the days of the week" , ( ) => {
27
44
const weekStart = getStartOfWeek ( newDate ( "2015-12-20" ) ) ;
28
45
const { container } = render (
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import Day from "./day";
12
12
import WeekNumber from "./week_number" ;
13
13
14
14
interface DayProps extends React . ComponentPropsWithoutRef < typeof Day > { }
15
+
15
16
interface WeekNumberProps
16
17
extends React . ComponentPropsWithoutRef < typeof WeekNumber > { }
17
18
@@ -38,6 +39,7 @@ interface WeekProps
38
39
weekNumber : number ,
39
40
event : React . MouseEvent < HTMLDivElement > ,
40
41
) => void ;
42
+ weekClassName ?: ( date : Date ) => string ;
41
43
}
42
44
43
45
export default class Week extends Component < WeekProps > {
@@ -192,6 +194,13 @@ export default class Week extends Component<WeekProps> {
192
194
) ,
193
195
"react-datepicker__week--keyboard-selected" : this . isKeyboardSelected ( ) ,
194
196
} ;
195
- return < div className = { clsx ( weekNumberClasses ) } > { this . renderDays ( ) } </ div > ;
197
+ const customWeekClassName = this . props . weekClassName
198
+ ? this . props . weekClassName ( this . startOfWeek ( ) )
199
+ : undefined ;
200
+ return (
201
+ < div className = { clsx ( weekNumberClasses , customWeekClassName ) } >
202
+ { this . renderDays ( ) }
203
+ </ div >
204
+ ) ;
196
205
}
197
206
}
You can’t perform that action at this time.
0 commit comments