import { StoryObj } from '@storybook/react-vite'; import { ColumnDef, ColumnFiltersState, SortingState, VisibilityState, flexRender, getCoreRowModel, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, useReactTable, } from "@tanstack/react-table"; import { MoreHorizontal } from "lucide-react"; import { useState } from "react"; import { Button } from "../Button"; import { Checkbox } from "../Checkbox"; import { DropdownMenu } from "../DropdownMenu"; import { Pagination } from "../Pagination"; import { Table } from "../Table"; import { DataTable } from "."; const data = Array(6).fill({ cell1: "Data Label", cell2: "Data Label", cell3: "Data Label", cell4: "Data Label", cell5: "Data Label", cell6: "Data Label", }); const menuCell = () => ( Ações Visualizar Editar Apagar ); const columns: ColumnDef[] = [ { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label="Select all" /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} aria-label="Select row" /> ), enableSorting: false, enableHiding: false, }, ...data.map((_, index) => ({ accessorKey: `cell${index + 1}`, header: "Header", })), { id: "actions", cell: menuCell, }, ]; type DataTableProps = {}; export default { title: "Data Table", parameters: { docs: { description: { component: "São grids estruturados, responsivos e organizados para apresentar dados em formato de tabulação.", }, }, }, }; type Story = StoryObj; export const PaginationStory: Story = { name: "Data Table", args: {}, argTypes: {}, render: () => { const [sorting, setSorting] = useState([]); const [columnFilters, setColumnFilters] = useState([]); const [columnVisibility, setColumnVisibility] = useState( {} ); const [rowSelection, setRowSelection] = useState({}); const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel(), getPaginationRowModel: getPaginationRowModel(), onSortingChange: setSorting, getSortedRowModel: getSortedRowModel(), onColumnFiltersChange: setColumnFilters, getFilteredRowModel: getFilteredRowModel(), onColumnVisibilityChange: setColumnVisibility, onRowSelectionChange: setRowSelection, state: { sorting, columnFilters, columnVisibility, rowSelection, }, }); return ( {table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => { return ( {header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext() )} ); })} ))} {table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( {row.getVisibleCells().map((cell) => ( {flexRender( cell.column.columnDef.cell, cell.getContext() )} ))} )) ) : ( Sem resultados. )}
console.log("previous")} /> console.log("next")} /> console.log("last")} />
); }, };