import React, { ForwardedRef, PropsWithChildren } from 'react';
import { cx } from '@leafygreen-ui/emotion';
import { useTableContext } from '../../TableContext';
import { LGRowData } from '../../useLeafyGreenTable';
import SortIcon from './SortIcon/SortIcon';
import { getHeaderCellState } from './utils/getHeaderCellState';
import {
getBaseHeaderCellStyles,
getHeaderCellContentStyles,
} from './HeaderCell.styles';
import { HeaderCellComponentType, HeaderCellProps } from './HeaderCell.types';
/**
* Component to wrap `
` elements for use inside `` elements.
*/
const HeaderCellWithRef = (
{
children,
className,
header,
align,
...rest
}: PropsWithChildren>,
ref: ForwardedRef,
) => {
const { isSelectable, lgIds } = useTableContext();
const { columnName, sortState, onSortIconClick } = getHeaderCellState(header);
return (
|
{children}
{sortState && onSortIconClick && (
)}
|
);
};
// React.forwardRef can only work with plain function types, i.e. types with a single call signature and no other members.
// Asserts that `HeaderCell` is of type `HeaderCellComponentType` which works with generics
export const HeaderCell = React.forwardRef(
HeaderCellWithRef,
) as HeaderCellComponentType;
export default HeaderCell;
|