'use client' import { useLgUp } from '../../../hooks/ui/use-media-query' import { cn } from '../../../utils/cn' import { Arrow01DownIcon } from '../../icons-v2-generated/arrows/arrow-01-down-icon' import { Arrow01UpIcon } from '../../icons-v2-generated/arrows/arrow-01-up-icon' import { SwitchVrIcon } from '../../icons-v2-generated/arrows/switch-vr-icon' import { Checkbox } from '../checkbox' import { TableColumnFilterDropdown } from './table-column-filter-dropdown' import type { TableColumn, TableHeaderProps } from './types' import { getHideClasses } from './utils' /** @deprecated Use `DataTableHeader` from `data-table` instead. */ export function TableHeader({ columns, className, sortBy, sortDirection, onSort, filters, onFilterChange, selectable, allSelected, someSelected, onSelectAll, totalItemsCount, stickyHeader, stickyHeaderOffset, }: TableHeaderProps) { const getAlignment = (align?: 'left' | 'center' | 'right') => { switch (align) { case 'center': return 'justify-center' case 'right': return 'justify-end' default: return 'justify-start' } } const handleSort = (column: TableColumn) => { if (!column.sortable || !onSort) return const columnKey = column.sortKey || column.key let newDirection: 'asc' | 'desc' = 'asc' if (sortBy === columnKey) { newDirection = sortDirection === 'asc' ? 'desc' : 'asc' } onSort(columnKey, newDirection) } const getSortIcon = (column: TableColumn) => { if (!column.sortable) return null const columnKey = column.sortKey || column.key const isActive = sortBy === columnKey if (!isActive) { return } return sortDirection === 'asc' ? : } const isLgUp = useLgUp() ?? false return (
{/* Selection checkbox */} {selectable && (
)} {columns.map((column) => { const isActionsColumn = column.key === '__actions__' const filterable = column.filterable && column.filterOptions && onFilterChange // Hide columns on mobile if they are not actions or filterable if (!isLgUp && !isActionsColumn && !filterable) { return null } return (
{isActionsColumn ? ( // Render total items count in actions column totalItemsCount > 0 && ( Showing {totalItemsCount} {totalItemsCount === 1 ? 'result' : 'results'} ) ) : column.filterable && column.filterOptions && onFilterChange ? ( /* Filterable column — label + icon are both inside the dropdown trigger */ ) : ( /* Non-filterable column — regular label with optional sort */
handleSort(column)} > {column.renderHeader ? ( <> {column.renderHeader()} {getSortIcon(column)} ) : ( <> {column.label} {getSortIcon(column)} )}
)}
) })}
) }