"use client"; import { Table } from "@tanstack/react-table"; import { Maximize2Icon, Minimize2Icon } from "lucide-react"; import { cn } from "@/lib/utils"; interface DataTableExpandAllToggleProps { table: Table; } /** * DataTableExpandAllToggle provides a button in the table header to expand * or collapse all rows at once. * * Features: * - Shows Maximize2 icon when rows are collapsed (click to expand all) * - Shows Minimize2 icon when rows are expanded (click to collapse all) * - Accessible with proper aria-label * - Only renders when the table has expandable rows * * @example * ```tsx * // In column definition header: * { * id: "name", * header: ({ table }) => ( *
* * Name *
* ), * cell: ({ row }) => ( * * {row.original.name} * * ), * } * ``` */ export function DataTableExpandAllToggle({ table, }: DataTableExpandAllToggleProps) { const isAllExpanded = table.getIsAllRowsExpanded(); const canExpand = table.getCanSomeRowsExpand(); if (!canExpand) { return
; } return ( ); }