UNPKG

937 BTypeScriptView Raw
1import React from "react";
2
3import { DayMouseEventHandler, DayPicker } from "react-day-picker";
4
5const bookedDays = [
6 new Date(2024, 5, 8),
7 new Date(2024, 5, 9),
8 new Date(2024, 5, 10),
9 { from: new Date(2024, 5, 15), to: new Date(2024, 5, 20) }
10];
11
12const css = `
13.booked {
14 position: relative;
15}
16/* Strikeout */
17.booked::before {
18 content: "";
19 position: absolute;
20 top: 50%;
21 left: 0;
22 right: 0;
23 height: 2px;
24 background: currentColor;
25 z-index: 1;
26 transform: rotate(-45deg);
27}`;
28
29export function ModifiersCustom() {
30 const handleDayClick: DayMouseEventHandler = (day, { booked }) => {
31 alert(`Day ${day.toLocaleDateString()} is booked? ` + booked);
32 };
33
34 return (
35 <>
36 <style>{css}</style>
37 <DayPicker
38 defaultMonth={new Date(2024, 5)}
39 modifiers={{ booked: bookedDays }}
40 modifiersClassNames={{ booked: "booked" }}
41 onDayClick={handleDayClick}
42 />
43 </>
44 );
45}