-
Notifications
You must be signed in to change notification settings - Fork 359
Expand file tree
/
Copy pathTableHeader.tsx
More file actions
39 lines (34 loc) · 1.28 KB
/
TableHeader.tsx
File metadata and controls
39 lines (34 loc) · 1.28 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
import React, { forwardRef } from "react";
import { type VibeComponentProps, getTestId, ComponentDefaultTestId, useMergeRef } from "@vibe/shared";
import styles from "./TableHeader.module.scss";
import { type TableHeaderCellProps } from "../TableHeaderCell/TableHeaderCell";
import cx from "classnames";
import { useTable } from "../context/TableContext/TableContext";
export interface TableHeaderProps extends VibeComponentProps {
/**
* The child elements inside the table header, typically `<TableHeaderCell />` components.
*/
children?: React.ReactElement<TableHeaderCellProps> | React.ReactElement<TableHeaderCellProps>[];
}
const TableHeader = forwardRef(
(
{ id, className, "data-testid": dataTestId, children }: TableHeaderProps,
ref: React.ForwardedRef<HTMLDivElement>
) => {
const { headRef, onHeadScroll, isVirtualized } = useTable();
const mergedRef = useMergeRef(headRef, ref);
return (
<div
ref={mergedRef}
id={id}
className={cx(styles.tableHeader, { [styles.virtualized]: isVirtualized }, className)}
data-testid={dataTestId || getTestId(ComponentDefaultTestId.TABLE_HEADER, id)}
role="rowgroup"
onScroll={onHeadScroll}
>
{children}
</div>
);
}
);
export default TableHeader;