import React, { forwardRef } from 'react'; import styled, { css } from 'styled-components'; import { createBorderStyles, createDisabledTextStyles } from '../common'; import { noOp } from '../common/utils'; import { CommonStyledProps } from '../types'; type TableHeadCellProps = { children?: React.ReactNode; disabled?: boolean; sort?: 'asc' | 'desc' | null; } & React.TdHTMLAttributes & CommonStyledProps; const StyledHeadCell = styled.th<{ $disabled: boolean }>` position: relative; padding: 0 8px; display: table-cell; vertical-align: inherit; background: ${({ theme }) => theme.material}; cursor: default; user-select: none; &:before { box-sizing: border-box; content: ''; position: absolute; left: 0; top: 0; width: 100%; height: 100%; ${createBorderStyles()} border-left: none; border-top: none; } ${({ $disabled }) => !$disabled && css` &:active { &:before { ${createBorderStyles({ invert: true, style: 'window' })} border-left: none; border-top: none; padding-top: 2px; } & > div { position: relative; top: 2px; } } `} color: ${({ theme }) => theme.materialText}; ${({ $disabled }) => $disabled && createDisabledTextStyles()} &:hover { color: ${({ theme }) => theme.materialText}; ${({ $disabled }) => $disabled && createDisabledTextStyles()} } `; const TableHeadCell = forwardRef( function TableHeadCell( { disabled = false, children, onClick, onTouchStart = noOp, sort, ...otherProps }, ref ) { const ariaSort = sort === 'asc' ? 'ascending' : sort === 'desc' ? 'descending' : undefined; return (
{children}
); } ); TableHeadCell.displayName = 'TableHeadCell'; export { TableHeadCell, TableHeadCellProps };