-
Notifications
You must be signed in to change notification settings - Fork 2
/
weekview.tsx
89 lines (85 loc) · 2.31 KB
/
weekview.tsx
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { isSameWeek } from "date-fns";
import useWeekView, { Cell } from "./use-weekview";
import Header from "./header";
import DaysHeader from "./days-header";
import Grid from "./grid";
import EventGrid from "./event-grid";
export type Event = {
id: string;
title: string;
startDate: Date;
endDate: Date;
};
export default function WeekView({
initialDate,
minuteStep = 30,
weekStartsOn = 1,
locale,
rowHeight = 56,
disabledCell,
disabledDay,
disabledWeek,
events,
onCellClick,
onEventClick,
}: {
initialDate?: Date;
minuteStep?: number;
weekStartsOn?: Day;
locale?: Locale;
rowHeight?: number;
disabledCell?: (date: Date) => boolean;
disabledDay?: (date: Date) => boolean;
disabledWeek?: (startDayOfWeek: Date) => boolean;
events?: Event[];
onCellClick?: (cell: Cell) => void;
onEventClick?: (event: Event) => void;
}) {
const { days, nextWeek, previousWeek, goToToday, viewTitle } = useWeekView({
initialDate,
minuteStep,
weekStartsOn,
locale,
disabledCell,
disabledDay,
disabledWeek,
});
return (
<div className="flex flex-col h-full overflow-hidden">
<Header
title={viewTitle}
onNext={nextWeek}
onPrev={previousWeek}
onToday={goToToday}
showTodayButton={!isSameWeek(days[0].date, new Date())}
/>
<div className="flex flex-col flex-1 overflow-hidden select-none">
<div className="flex flex-col flex-1 isolate overflow-auto">
<div className="flex flex-col flex-none min-w-[700px]">
<DaysHeader days={days} />
<div className="grid grid-cols-1 grid-rows-1">
<div className="row-start-1 col-start-1">
<Grid
days={days}
rowHeight={rowHeight}
onCellClick={onCellClick}
/>
</div>
<div className="row-start-1 col-start-1">
<EventGrid
days={days}
events={events}
weekStartsOn={weekStartsOn}
locale={locale}
minuteStep={minuteStep}
rowHeight={rowHeight}
onEventClick={onEventClick}
/>
</div>
</div>
</div>
</div>
</div>
</div>
);
}