'use client'; 'use no memo'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { cn } from '@/lib/utils'; import type { Column } from '@tanstack/react-table'; import { type VariantProps, cva } from 'class-variance-authority'; import { ArrowDownUp, EyeOff, SortAsc, SortDesc } from 'lucide-react'; import type { HTMLAttributes, PropsWithChildren } from 'react'; const headerVariants = cva('', { variants: { variant: { default: '', numeric: 'text-right', }, }, defaultVariants: { variant: 'default', }, }); const wrapperVariants = cva('flex items-center space-x-2', { variants: { variant: { default: '', numeric: 'justify-end', }, }, defaultVariants: { variant: 'default', }, }); const buttonVariants = cva('-ml-3 h-8 data-[state=open]:bg-accent', { variants: { variant: { default: '', numeric: 'ml-auto', }, }, defaultVariants: { variant: 'default', }, }); /** * Props for the DataTableColumnHeader component. * @template TData The type of data in the table. * @template TValue The type of value in the column. */ interface DataTableColumnHeaderProps extends HTMLAttributes, VariantProps { /** The column object from react-table. */ column: Column; /** The type of the column. */ variant?: 'default' | 'numeric'; } /** * Renders a header for a data table column with sorting and visibility options. * @template TData The type of data in the table. * @template TValue The type of value in the column. * @param props The component props. * @returns The rendered DataTableColumnHeader component. */ export function DataTableColumnHeader({ column, className, variant = 'default', children, }: PropsWithChildren>) { if (!column.getCanSort()) { return
{children}
; } const sortIcon = () => { if (column.getIsSorted() === 'desc') { return ; } if (column.getIsSorted() === 'asc') { return ; } return ; }; return (
column.toggleSorting(false)}> Sort Ascending column.toggleSorting(true)}> Sort Descending column.toggleVisibility(false)}> Hide
); }