"use client"; import { Row } from "@tanstack/react-table"; import { ChevronRightIcon } from "lucide-react"; import { cn } from "@/lib/utils"; interface DataTableExpandToggleProps { row: Row; /** * Explicit expanded state to ensure React Compiler re-renders when state changes. * TanStack Table Row instances keep stable references — getter methods like * `row.getIsExpanded()` read mutable state that React Compiler cannot track. * Pass this prop from the parent to break memoization. */ isExpanded?: boolean; } /** * DataTableExpandToggle provides a clickable chevron button for expanding/collapsing * table rows that have sub-rows. * * Features: * - Only shows for rows that can expand (have sub-rows) * - Provides consistent spacing for rows without sub-rows * - Animates chevron rotation on expand/collapse * - Accessible with proper aria-label * * @example * ```tsx * // In column definition: * { * id: "expand", * cell: ({ row }) => ( * * ), * } * ``` */ export function DataTableExpandToggle({ row, isExpanded: isExpandedProp, }: DataTableExpandToggleProps) { const isExpanded = isExpandedProp ?? row.getIsExpanded(); if (!row.getCanExpand()) { return
; } return ( ); }