[V9] [HOW-TO] Need help with range_start background using tailwind. #2308
-
Hey, I am trying to style the Calendar with Tailwind CSS. I am almost there but cannot make this range_start class work as in the example provided in the docs. Whenever I assign this range_start background, I see that the whole background of the selected class changes. I want this half background so that my circle buttons integrate with range_middle seamlessly. Any help is appreciated! export type CalendarProps = DayPickerProps;
function Calendar({
className,
classNames,
showOutsideDays = true,
...props
}: CalendarProps) {
return (
<DayPicker
showOutsideDays={showOutsideDays}
className={cn('p-4', className)}
classNames={{
months: 'inline-flex gap-4 w-full justify-center',
month: 'space-y-4',
day_button:
'h-12 w-12 hover:border hover:border-primary hover:rounded-full',
selected: 'bg-primary rounded-full text-primary-foreground',
range_start: 'bg-accent rounded-none z-1',
range_middle: 'bg-accent rounded-none',
button_next: cn(
buttonVariants({
variant: 'ghost',
className: 'h-10 w-10 bg-transparent p-0 opacity-100',
})
),
day: 'h-12 w-12',
weekday: 'rounded-md w-12 h-12 font-[500]',
button_previous: cn(
buttonVariants({
variant: 'ghost',
className: 'h-10 w-10 bg-transparent p-0 opacity-100',
})
),
today: 'text-primary',
disabled: 'text-muted-foreground opacity-50',
caption_label: 'text-md font-bold',
nav: 'flex items-center justify-between absolute w-full z-10 px-6',
month_caption: 'flex justify-center items-center pt-2',
...classNames,
}}
components={{
Chevron: (props) => {
if (props.orientation === 'left') {
return <Icons.chevronLeft {...props} />;
}
return <Icons.chevronRight {...props} />;
},
}}
{...props}
/>
);
}
Calendar.displayName = 'Calendar';
export { Calendar }; |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 8 replies
-
It looks like |
Beta Was this translation helpful? Give feedback.
-
@gpbl do you have any idea? :/ |
Beta Was this translation helpful? Give feedback.
-
@berkerdemirer thanks with your feedback about using Tailwind with DayPicker. There's an easy fix for this - add these classes to the button as well. Let me try this solution. Do you have other suggestions to improve the use of DayPicker with tailwind? |
Beta Was this translation helpful? Give feedback.
-
@berkerdemirer If I understand correctly, you want to reproduce the style of a selected range, but using Tailwind. I believe the difficulty is to find the right Tailwind classes - not a problem in DayPicker itself. The For the range, I applied two backgrounds:
react-day-picker/src/style.css Lines 268 to 275 in 81f79fd To do the same in Tailwind CSS, you can use the classNames={{
// use the "arbitrary variant"
range_start: 'CELL_CSS [&>button]:BUTTON_CSS',
/* ... */
day_button: 'some css', // note this is applied to `range_start` too
selected: 'some css', // note this is applied to `range_start` too
}}
In conclusion, to style the range with Tailwind CSS,
I don't have the time to try this by myself at the moment - sorry for that. Yet I'm really curious about the solution here. |
Beta Was this translation helpful? Give feedback.
-
After Hours trying, that the only way it worked for me: |
Beta Was this translation helpful? Give feedback.
@berkerdemirer If I understand correctly, you want to reproduce the style of a selected range, but using Tailwind. I believe the difficulty is to find the right Tailwind classes - not a problem in DayPicker itself.
The
selected
class doesn't do much in DayPicker - it just add a border to the selected button, so you can ignore it.For the range, I applied two backgrounds:
td.rdp-range_start
elements,button.rdp-day_button
elements when children of suchtd
s.react-day-picker/src/style.css
Lines 268 to 275 in 81f79fd