File size: 914 Bytes
cf86710
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
import { DayMouseEventHandler, DayPicker } from "./react-day-picker-v8";

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) }
];

const css = `
.booked {
  position: relative;
}
/* Strikeout */
.booked::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  background: currentColor;
  z-index: 1;
  transform: rotate(-45deg);
}`;

export function ModifiersCustom() {
  const handleDayClick: DayMouseEventHandler = (day, { booked }) => {
    alert(`Day ${day.toLocaleDateString()} is booked? ` + booked);
  };

  return (
    <>
      <style>{css}</style>
      <DayPicker
        defaultMonth={new Date(2024, 5)}
        modifiers={{ booked: bookedDays }}
        modifiersClassNames={{ booked: "booked" }}
        onDayClick={handleDayClick}
      />
    </>
  );
}