Customize navbar and weekdays
Using the weekdayElement
and navbarElement
props you can change the weekdays and the navigation bar.
Code
import React from 'react';
import DayPicker from 'react-day-picker';
import 'react-day-picker/lib/style.css';
function Weekday({ weekday, className, localeUtils, locale }) {
const weekdayName = localeUtils.formatWeekdayLong(weekday, locale);
return (
<div className={className} title={weekdayName}>
{weekday} {weekdayName.slice(0, 1)}
</div>
);
}
function Navbar({
nextMonth,
previousMonth,
onPreviousClick,
onNextClick,
className,
localeUtils,
}) {
const months = localeUtils.getMonths();
const prev = months[previousMonth.getMonth()];
const next = months[nextMonth.getMonth()];
const styleLeft = {
float: 'left',
};
const styleRight = {
float: 'right',
};
return (
<div className={className}>
<button style={styleLeft} onClick={() => onPreviousClick()}>
← {prev.slice(0, 3)}
</button>
<button style={styleRight} onClick={() => onNextClick()}>
{next.slice(0, 3)} →
</button>
</div>
);
}
export default function Example() {
return (
<div>
<DayPicker weekdayElement={<Weekday />} navbarElement={<Navbar />} />
</div>
);
}
Result
March 2021
0 S
1 M
2 T
3 W
4 T
5 F
6 S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31