2022-11-28 02:00:28 +00:00
|
|
|
import { ChevronDown, ChevronUp } from 'lucide-react';
|
2023-05-02 06:42:16 +00:00
|
|
|
import { ColumnDef } from '@tanstack/react-table';
|
2022-11-22 12:16:34 +00:00
|
|
|
|
|
|
|
import { Button } from '@@/buttons';
|
|
|
|
|
2023-05-02 06:42:16 +00:00
|
|
|
export function buildExpandColumn<
|
|
|
|
T extends Record<string, unknown>
|
|
|
|
>(): ColumnDef<T> {
|
2022-11-22 12:16:34 +00:00
|
|
|
return {
|
|
|
|
id: 'expand',
|
2023-05-02 06:42:16 +00:00
|
|
|
header: ({ table }) => {
|
2023-08-13 17:09:40 +00:00
|
|
|
const hasExpandableItems = table.getCanSomeRowsExpand();
|
2022-11-22 12:16:34 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
hasExpandableItems && (
|
|
|
|
<Button
|
2023-05-02 06:42:16 +00:00
|
|
|
onClick={table.getToggleAllRowsExpandedHandler()}
|
2022-11-22 12:16:34 +00:00
|
|
|
color="none"
|
2023-05-02 06:42:16 +00:00
|
|
|
icon={table.getIsAllRowsExpanded() ? ChevronDown : ChevronUp}
|
2022-11-22 12:16:34 +00:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
2023-05-02 06:42:16 +00:00
|
|
|
cell: ({ row }) =>
|
|
|
|
row.getCanExpand() && (
|
|
|
|
<Button
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
row.toggleExpanded();
|
|
|
|
}}
|
|
|
|
color="none"
|
|
|
|
icon={row.getIsExpanded() ? ChevronDown : ChevronUp}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
enableColumnFilter: false,
|
|
|
|
enableGlobalFilter: false,
|
|
|
|
enableHiding: false,
|
|
|
|
|
|
|
|
meta: {
|
|
|
|
width: 40,
|
|
|
|
},
|
2022-11-22 12:16:34 +00:00
|
|
|
};
|
|
|
|
}
|