/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import styles from "./react-table.module.scss"; import React from "react"; import { flexRender, useReactTable, getSortedRowModel, } from '@tanstack/react-table' import type { TableOptions, Table, SortingState } from "@tanstack/react-table"; interface TableProps extends TableOptions { className?: string; } export function Table({ columns, data, getCoreRowModel, className }: TableProps) { const [sorting, setSorting] = React.useState([]) const table = useReactTable({ data, columns, getCoreRowModel, state: { sorting, }, onSortingChange: setSorting, getSortedRowModel: getSortedRowModel(), }); return (
{table.getHeaderGroups().map(headerGroup => ( {headerGroup.headers.map(header => ( ))} ))} {table.getRowModel().rows.map(row => ( {row.getVisibleCells().map(cell => ( ))} ))}
{header.isPlaceholder ? null : (
{flexRender( header.column.columnDef.header, header.getContext() )} {{ asc: ' 🔼', desc: ' 🔽', }[header.column.getIsSorted() as string] ?? null}
)}
{flexRender(cell.column.columnDef.cell, cell.getContext())}
) }