Bulk Invoices
Invoice table with row checkboxes, select-all, status pills and a header that swaps to bulk reminder and export actions.
"use client"
import { useState } from "react"
import {
DownloadSimpleIcon,
EnvelopeSimpleIcon,
XIcon,
} from "@phosphor-icons/react"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import { Checkbox } from "@/components/ui/checkbox"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"
// The copy: change text here, not in the markup.
const COPY = {
title: "Invoices",
selectAll: "Select all invoices",
number: "Invoice",
customer: "Customer",
due: "Due",
amount: "Amount",
status: "Status",
selected: (n: number) => `${n} selected`,
remind: "Send reminder",
export: "Export",
clear: "Clear selection",
reminded: "Reminder sent",
csvName: "invoices.csv",
} as const
type Invoice = {
id: string
customer: string
due: string
amount: string
status: "Paid" | "Open" | "Overdue"
}
const INVOICES: Invoice[] = [
{
id: "INV-4021",
customer: "Harlow & Finch",
due: "Nov 14",
amount: "$4,200.00",
status: "Open",
},
{
id: "INV-4020",
customer: "Northwind Dental",
due: "Nov 9",
amount: "$1,180.50",
status: "Paid",
},
{
id: "INV-4019",
customer: "Juniper Studio",
due: "Oct 28",
amount: "$960.00",
status: "Overdue",
},
{
id: "INV-4018",
customer: "Brightwater Co-op",
due: "Nov 21",
amount: "$7,450.00",
status: "Open",
},
{
id: "INV-4017",
customer: "Kestrel Logistics",
due: "Oct 30",
amount: "$2,310.75",
status: "Overdue",
},
{
id: "INV-4016",
customer: "Ostrava Books",
due: "Nov 2",
amount: "$615.00",
status: "Paid",
},
{
id: "INV-4015",
customer: "Pinecrest Realty",
due: "Nov 28",
amount: "$3,800.00",
status: "Open",
},
]
export default function TablesInvoicesBulk01() {
const [selected, setSelected] = useState<string[]>(["INV-4019"])
const [reminded, setReminded] = useState<string[]>([])
const all = selected.length === INVOICES.length
const some = selected.length > 0 && !all
function toggle(id: string) {
setSelected((s) =>
s.includes(id) ? s.filter((x) => x !== id) : [...s, id]
)
}
function remind() {
setReminded((r) => [...new Set([...r, ...selected])])
setSelected([])
}
function exportCsv() {
const rows = INVOICES.filter((i) => selected.includes(i.id)).map((i) =>
[i.id, i.customer, i.due, i.amount, i.status]
.map((v) => `"${v.replaceAll('"', '""')}"`)
.join(",")
)
const head = [
COPY.number,
COPY.customer,
COPY.due,
COPY.amount,
COPY.status,
]
.map((v) => `"${v}"`)
.join(",")
const blob = new Blob([[head, ...rows].join("\n")], {
type: "text/csv;charset=utf-8",
})
const url = URL.createObjectURL(blob)
const a = document.createElement("a")
a.href = url
a.download = COPY.csvName
document.body.appendChild(a)
a.click()
a.remove()
URL.revokeObjectURL(url)
setSelected([])
}
return (
<Card className="mx-auto w-full max-w-3xl">
<CardHeader className="flex min-h-9 flex-row items-center justify-between gap-3">
{selected.length === 0 ? (
<CardTitle>{COPY.title}</CardTitle>
) : (
<>
<div className="flex items-center gap-2">
<Button
variant="ghost"
size="icon-xs"
aria-label={COPY.clear}
onClick={() => setSelected([])}
>
<XIcon />
</Button>
<span className="text-sm font-medium">
{COPY.selected(selected.length)}
</span>
</div>
<div className="flex gap-2">
<Button variant="outline" size="sm" onClick={remind}>
<EnvelopeSimpleIcon />
{COPY.remind}
</Button>
<Button size="sm" onClick={exportCsv}>
<DownloadSimpleIcon />
{COPY.export}
</Button>
</div>
</>
)}
</CardHeader>
<CardContent>
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-10">
<Checkbox
aria-label={COPY.selectAll}
checked={all}
indeterminate={some}
onCheckedChange={(c) =>
setSelected(c ? INVOICES.map((i) => i.id) : [])
}
/>
</TableHead>
<TableHead>{COPY.number}</TableHead>
<TableHead>{COPY.customer}</TableHead>
<TableHead>{COPY.due}</TableHead>
<TableHead>{COPY.status}</TableHead>
<TableHead className="text-right">{COPY.amount}</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{INVOICES.map((inv) => (
<TableRow
key={inv.id}
data-state={selected.includes(inv.id) ? "selected" : undefined}
>
<TableCell>
<Checkbox
aria-label={`Select ${inv.id}`}
checked={selected.includes(inv.id)}
onCheckedChange={() => toggle(inv.id)}
/>
</TableCell>
<TableCell className="font-medium">{inv.id}</TableCell>
<TableCell>{inv.customer}</TableCell>
<TableCell className="text-muted-foreground">
{inv.due}
</TableCell>
<TableCell>
<Badge
variant={
reminded.includes(inv.id)
? "secondary"
: inv.status === "Overdue"
? "destructive"
: inv.status === "Paid"
? "secondary"
: "outline"
}
>
{reminded.includes(inv.id) ? COPY.reminded : inv.status}
</Badge>
</TableCell>
<TableCell className="text-right tabular-nums">
{inv.amount}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</CardContent>
</Card>
)
}
Installation
pnpm dlx shadcn@latest add @01orbital/invoices-bulk-01npx shadcn@latest add @01orbital/invoices-bulk-01yarn dlx shadcn@latest add @01orbital/invoices-bulk-01bunx --bun shadcn@latest add @01orbital/invoices-bulk-01Make it yours
- Its words are in
COPYat the top ofcomponents/blocks/billing/invoices-bulk-01/index.tsx: change them there, not in the markup. INVOICES, also at the top of the file, holds its lists and settings.
Built from
npm: @phosphor-icons/react. The CLI installs it for you.
Built from these parts. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:
The shadcn parts here are their Base UI versions, and this piece uses Base UI's API. A Radix version you already have won't work with it.
Last updated on