Table.tsx
1.7 KB
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
import { Footer } from 'components/Footer';
import { Head } from 'components/Head';
import { Row } from 'components/Row';
import { useDayPicker } from 'contexts/DayPicker';
import { getMonthWeeks } from './utils/getMonthWeeks';
/** The props for the {@link Table} component. */
export interface TableProps {
/** ID of table element */
id?: string;
/** The ID of the label of the table (the same given to the Caption). */
['aria-labelledby']?: string;
/** The month where the table is displayed. */
displayMonth: Date;
}
/** Render the table with the calendar. */
export function Table(props: TableProps): JSX.Element {
const {
locale,
classNames,
styles,
hideHead,
fixedWeeks,
components,
weekStartsOn,
firstWeekContainsDate,
ISOWeek
} = useDayPicker();
const weeks = getMonthWeeks(props.displayMonth, {
useFixedWeeks: Boolean(fixedWeeks),
ISOWeek,
locale,
weekStartsOn,
firstWeekContainsDate
});
const HeadComponent = components?.Head ?? Head;
const RowComponent = components?.Row ?? Row;
const FooterComponent = components?.Footer ?? Footer;
return (
<table
id={props.id}
className={classNames.table}
style={styles.table}
role="grid"
aria-labelledby={props['aria-labelledby']}
>
{!hideHead && <HeadComponent />}
<tbody className={classNames.tbody} style={styles.tbody}>
{weeks.map((week) => (
<RowComponent
displayMonth={props.displayMonth}
key={week.weekNumber}
dates={week.dates}
weekNumber={week.weekNumber}
/>
))}
</tbody>
<FooterComponent displayMonth={props.displayMonth} />
</table>
);
}