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 133133 color : #f00 ;
134134}
135135
136+ .react-datepicker__week.highlighted {
137+ background-color : #ddffdd ;
138+ border-radius : 5px ;
139+ }
140+
136141.example-custom-input {
137142 cursor : pointer ;
138143 padding : 5px 15px ;
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import CustomDateFormat from "../../examples/customDateFormat?raw";
1818import CustomClassName from "../../examples/customClassName?raw" ;
1919import CustomCalendarClassName from "../../examples/customCalendarClassName?raw" ;
2020import CustomDayClassName from "../../examples/customDayClassName?raw" ;
21+ import CustomWeekClassName from "../../examples/customWeekClassName?raw" ;
2122import CustomTimeClassName from "../../examples/customTimeClassName?raw" ;
2223import Today from "../../examples/today?raw" ;
2324import PlaceholderText from "../../examples/placeholderText?raw" ;
@@ -223,6 +224,10 @@ export default class exampleComponents extends React.Component {
223224 title : "Custom day class name" ,
224225 component : CustomDayClassName ,
225226 } ,
227+ {
228+ title : "Custom week class name" ,
229+ component : CustomWeekClassName ,
230+ } ,
226231 {
227232 title : "Custom date format" ,
228233 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", () => {
2323 expect ( container . querySelector ( ".react-datepicker__week" ) ) . not . toBeNull ( ) ;
2424 } ) ;
2525
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+
2643 it ( "should render the days of the week" , ( ) => {
2744 const weekStart = getStartOfWeek ( newDate ( "2015-12-20" ) ) ;
2845 const { container } = render (
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import Day from "./day";
1212import WeekNumber from "./week_number" ;
1313
1414interface DayProps extends React . ComponentPropsWithoutRef < typeof Day > { }
15+
1516interface WeekNumberProps
1617 extends React . ComponentPropsWithoutRef < typeof WeekNumber > { }
1718
@@ -38,6 +39,7 @@ interface WeekProps
3839 weekNumber : number ,
3940 event : React . MouseEvent < HTMLDivElement > ,
4041 ) => void ;
42+ weekClassName ?: ( date : Date ) => string ;
4143}
4244
4345export default class Week extends Component < WeekProps > {
@@ -192,6 +194,13 @@ export default class Week extends Component<WeekProps> {
192194 ) ,
193195 "react-datepicker__week--keyboard-selected" : this . isKeyboardSelected ( ) ,
194196 } ;
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+ ) ;
196205 }
197206}
You can’t perform that action at this time.
0 commit comments