} from '@tanstack/react-table'
import { ArrowUpDown, ChevronDown, MoreHorizontal } from 'lucide-react'
import * as React from 'react'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/checkbox'
DropdownMenuCheckboxItem,
} from '@/components/ui/dropdown-menu'
import { Input } from '@/components/ui/input'
} from '@/components/ui/table'
const data: Payment[] = [
email: 'ken99@yahoo.com',
email: 'Abe45@gmail.com',
email: 'Monserrat44@gmail.com',
email: 'Silas22@gmail.com',
email: 'carmella@hotmail.com',
status: 'pending' | 'processing' | 'success' | 'failed'
export const columns: ColumnDef<Payment>[] = [
table.getIsAllPageRowsSelected() ||
(table.getIsSomePageRowsSelected() && 'indeterminate')
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
<div className="capitalize">{row.getValue('status')}</div>
header: ({ column }) => {
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
<ArrowUpDown className="ml-2 h-4 w-4" />
cell: ({ row }) => <div className="lowercase">{row.getValue('email')}</div>,
header: () => <div className="text-right">Amount</div>,
const amount = parseFloat(row.getValue('amount'))
// Format the amount as a dollar amount
const formatted = new Intl.NumberFormat('en-US', {
return <div className="text-right font-base">{formatted}</div>
const payment = row.original
<DropdownMenuTrigger asChild>
<Button variant="noShadow" className="h-8 w-8 p-0">
<span className="sr-only">Open menu</span>
<MoreHorizontal className="h-4 w-4" />
<DropdownMenuContent align="end">
<DropdownMenuLabel>Actions</DropdownMenuLabel>
onClick={() => navigator.clipboard.writeText(payment.id)}
<DropdownMenuSeparator />
<DropdownMenuItem>View customer</DropdownMenuItem>
<DropdownMenuItem>View payment details</DropdownMenuItem>
export default function DataTableDemo() {
const [sorting, setSorting] = React.useState<SortingState>([])
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
const [columnVisibility, setColumnVisibility] =
React.useState<VisibilityState>({})
const [rowSelection, setRowSelection] = React.useState({})
const table = useReactTable({
onSortingChange: setSorting,
onColumnFiltersChange: setColumnFilters,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
getSortedRowModel: getSortedRowModel(),
getFilteredRowModel: getFilteredRowModel(),
onColumnVisibilityChange: setColumnVisibility,
onRowSelectionChange: setRowSelection,
<div className="w-full font-base text-text">
<div className="flex items-center py-4">
placeholder="Filter emails..."
value={(table.getColumn('email')?.getFilterValue() as string) ?? ''}
table.getColumn('email')?.setFilterValue(event.target.value)
<DropdownMenuTrigger asChild>
<Button variant="noShadow" className="ml-auto">
Columns <ChevronDown className="ml-2 h-4 w-4" />
<DropdownMenuContent align="end">
.filter((column) => column.getCanHide())
<DropdownMenuCheckboxItem
checked={column.getIsVisible()}
onCheckedChange={(value) =>
column.toggleVisibility(!!value)
</DropdownMenuCheckboxItem>
<div className="rounded-md">
<TableHeader className="font-heading">
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id}>
{headerGroup.headers.map((header) => {
<TableHead key={header.id}>
header.column.columnDef.header,
{table.getRowModel().rows?.length ? (
table.getRowModel().rows.map((row) => (
data-state={row.getIsSelected() && 'selected'}
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>
cell.column.columnDef.cell,
className="h-24 text-center"
<div className="flex items-center justify-end space-x-2 py-4">
<div className="text-text dark:text-darkText flex-1 text-sm">
{table.getFilteredSelectedRowModel().rows.length} of{' '}
{table.getFilteredRowModel().rows.length} row(s) selected.
<div className="space-x-2">
onClick={() => table.previousPage()}
disabled={!table.getCanPreviousPage()}
onClick={() => table.nextPage()}
disabled={!table.getCanNextPage()}