|
1
|
import { getWeeksInMonth } from "@internationalized/date" |
|
2
|
import * as React from "react" |
|
3
|
import { AriaCalendarGridProps, useCalendarGrid, useLocale } from "react-aria" |
|
4
|
|
|
5
|
import { CalendarState } from "react-stately" |
|
6
|
import { CalendarCell } from "./calendar-cell" |
|
7
|
|
|
8
|
interface CalendarGridProps extends AriaCalendarGridProps { |
|
9
|
state: CalendarState |
|
10
|
} |
|
11
|
|
|
12
|
const CalendarGrid = ({ state, ...props }: CalendarGridProps) => { |
|
13
|
const { locale } = useLocale() |
|
14
|
const { gridProps, headerProps, weekDays } = useCalendarGrid(props, state) |
|
15
|
|
|
16
|
const weeksInMonth = getWeeksInMonth(state.visibleRange.start, locale) |
|
17
|
|
|
18
|
return ( |
|
19
|
<table {...gridProps}> |
|
20
|
<thead {...headerProps}> |
|
21
|
<tr> |
|
22
|
{weekDays.map((day, index) => ( |
|
23
|
<th key={index} className="txt-compact-small-plus text-ui-fg-muted size-8 p-1 rounded-md">{day}</th> |
|
24
|
))} |
|
25
|
</tr> |
|
26
|
</thead> |
|
27
|
<tbody> |
|
28
|
{[...new Array(weeksInMonth).keys()].map((weekIndex) => ( |
|
29
|
<tr key={weekIndex}> |
|
30
|
{state |
|
31
|
.getDatesInWeek(weekIndex) |
|
32
|
.map((date, i) => |
|
33
|
date ? ( |
|
34
|
<CalendarCell key={i} state={state} date={date} /> |
|
35
|
) : ( |
|
36
|
<td key={i} /> |
|
37
|
) |
|
38
|
)} |
|
39
|
</tr> |
|
40
|
))} |
|
41
|
</tbody> |
|
42
|
</table> |
|
43
|
) |
|
44
|
} |
|
45
|
|
|
46
|
export { CalendarGrid } |