jamm
jamm

Reputation: 11

How do I change the background color of day?

I'm using react-day-picker, and I'm having trouble finding the ways to change the background color of the days when it's not hovered or focused. I was only able to change the background color by changing --rdp-background-color.

However, it only changes the background color for the hovered/focused elements.

.rdp {   
--rdp-cell-size: 40px; /* Size of the day cells. */   
--rdp-caption-font-size: 18px; /* Font size for the caption labels. */   
--rdp-accent-color: #0000ff; /* Accent color for the background of selected days. */   
--rdp-background-color: #e7edff; /* Background color for the hovered/focused elements. */   
--rdp-accent-color-dark: #3003e1; /* Accent color for the background of selected days (to use in dark-mode). */   
--rdp-background-color-dark: #180270; /* Background color for the hovered/focused elements (to use in dark-mode). */   
--rdp-outline: 2px solid var(--rdp-accent-color); /* Outline border for focused elements */   
--rdp-outline-selected: 3px solid var(--rdp-accent-color); /* Outline border for focused _and_ selected elements */   
--rdp-selected-color: #fff; /* Color of selected day text */ 
}

Here is the link to react-day-picker's style sheet. I also tried setting .rdp-day, it doesn't work.

Upvotes: 0

Views: 341

Answers (1)

WarlockJa
WarlockJa

Reputation: 11

In order to apply custom css to certain dates in react-day-picker you need to use custom modifiers as described here custom modifiers Basically you need to provide modifiersClassNames property with an object that would define custom css, and modifiers property that would associate an array of dates with the provided custom css:

const bookedDays = [
  new Date(2024, 5, 8),
  new Date(2024, 5, 9),
  new Date(2024, 5, 10),
  { from: new Date(2024, 5, 15), to: new Date(2024, 5, 20) }
];
export function ModifiersCustom() {
  return (
    <DayPicker
      modifiers={{ booked: bookedDays }}

      /* may contain tailwind css, css class names, or inline styling */
      modifiersClassNames={{ booked: "bg-primary" }} 
    />
  );
}

Upvotes: 0

Related Questions