Custom Months Navigation Component Example #2404
Replies: 4 comments 8 replies
-
Beta Was this translation helpful? Give feedback.
-
This looks great! Question: how did you get the current 2 months to render between the nav arrows in the demo example? |
Beta Was this translation helpful? Give feedback.
-
The css file I used to customize the Calendar styles. Context: I was having some troubles with Tailwind and conflicting states like .rdp-root {
width: 100%;
color: #3E3E3E;
}
.rdp-root .rdp-month_grid,
.rdp-root .rdp-month {
display: flex;
flex-direction: column;
width: 100%;
}
.rdp-root .rdp-weekdays {
display: flex;
justify-content: space-between;
width: 100%;
}
.rdp-root .rdp-weeks {
display: flex;
flex-wrap: wrap;
width: 100%;
}
.rdp-root .rdp-week {
display: flex;
justify-content: space-between;
width: 100%;
}
.rdp-root .rdp-month .rdp-month_caption {
display: flex;
align-items: center;
justify-content: center;
height: 32px;
font-size: 12px;
font-weight: 700;
text-transform: capitalize;
user-select: none;
}
.rdp-root .rdp-today:not(.rdp-outside) {
color: #3E3E3E;
}
.rdp-root .rdp-day {
flex: 1;
width: auto;
height: 32px;
font-size: 14px;
font-weight: 400;
}
.rdp-root .rdp-day.rdp-disabled .rdp-day_button {
opacity: 35%;
background-color: #FFF;
}
.rdp-root .rdp-day .rdp-day_button {
background: #EBEBEB70;
border-radius: 0;
border: 0;
width: 100%;
height: 100%;
}
.rdp-root .rdp-day.rdp-selected .rdp-day_button,
.rdp-root .rdp-day.rdp-range_start .rdp-day_button,
.rdp-root .rdp-day.range_end .rdp-day_button {
background-color: #19398A;
color: #FFF;
border: 0;
}
.rdp-root .rdp-day.rdp-range_middle .rdp-day_button {
background: #E5ECF9 !important;
color: #5893EC !important;
border: 0;
}
@media (min-width: 640px) {
.rdp-root .rdp-month_grid,
.rdp-root .rdp-month {
width: 240px;
}
.rdp-root .rdp-day {
height: 40px;
}
} |
Beta Was this translation helpful? Give feedback.
-
@alessandrodias thanks so much for your dive into the custom components. We are looking for more examples to include in the documentation and I was interested in your use case.
I have a question - isn't that the same when using <DayPicker startMonth={new Date(2024, 0)} endMonth={new Date(2025, 11)} /> Or I am wondering is just an example you wanted to provide here? 🤔 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
If anyone is looking for a custom months navigation example, maybe this could help.
Create the
Nav
component inside the<DayPicker components={}
propThen you'll have access to the
useDayPicker
hook to get thepreviousMonth
,nextMonth
andgoToMonth
method:From there, you can write your own logic to handle months navigation, or to disable navigation to previous months before the current date. Here is what I had to do in my case:
Full Working Example:
You can abstract this to another component, to improve the logic and the readability.
Hope this can help someone ✌️
Beta Was this translation helpful? Give feedback.
All reactions