Changes record ordering.
| Order | Status | ||
|---|---|---|---|
| #1042 | A. Whitfield | Shipped | £64.00 |
| #1041 | R. Okafor | Processing | £128.50 |
| #1040 | M. Iqbal | Shipped | £22.00 |
| #1039 | S. Novak | Refunded | £40.00 |
<div class="sort" style="--accent:#241430;">
<div class="sort__scroll">
<table class="sort__table">
<caption>Customer orders</caption>
<thead><tr>
<th scope="col">Order</th>
<th scope="col" aria-sort="none"><button type="button" class="sort__btn">Customer <span class="sort__arrow" aria-hidden="true">▲</span></button></th>
<th scope="col">Status</th>
<th scope="col" aria-sort="ascending"><button type="button" class="sort__btn">Total <span class="sort__arrow" aria-hidden="true">▲</span></button></th>
</tr></thead>
<tbody>
<tr><td>#1042</td><td>A. Whitfield</td><td>Shipped</td><td>£64.00</td></tr>
<tr><td>#1041</td><td>R. Okafor</td><td>Processing</td><td>£128.50</td></tr>
<tr><td>#1040</td><td>M. Iqbal</td><td>Shipped</td><td>£22.00</td></tr>
<tr><td>#1039</td><td>S. Novak</td><td>Refunded</td><td>£40.00</td></tr>
</tbody>
</table>
</div>
</div>
<style>
.sort { font: 14px system-ui, sans-serif; color: #241430; background: #FAF7F2; max-width: 480px; border: 1px solid #24143020; border-radius: 10px; overflow: hidden; }
.sort__scroll { overflow-x: auto; }
.sort__table { border-collapse: collapse; width: 100%; }
.sort__table caption { text-align: left; font-weight: 600; padding: 10px 14px; }
.sort__table th, .sort__table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid #24143020; white-space: nowrap; }
.sort__table th { background: var(--accent); color: #FAF7F2; }
.sort__btn { background: none; border: 0; font: inherit; color: inherit; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; padding: 0; }
.sort__btn:hover { text-decoration: underline; }
.sort__btn:focus-visible { outline: 2px solid #FAF7F2; outline-offset: 2px; }
th[aria-sort="descending"] .sort__arrow { transform: rotate(180deg); display: inline-block; }
</style><div class="max-w-[480px] rounded-[10px] border border-[#24143020] font-sans text-sm text-[#241430] bg-[#FAF7F2] overflow-hidden" style="--accent:#241430;">
<div class="overflow-x-auto">
<table class="border-collapse w-full">
<caption class="text-left font-semibold px-3.5 py-2.5">Customer orders</caption>
<thead><tr class="text-[#FAF7F2]" style="background:#241430">
<th scope="col" class="p-3.5 text-left whitespace-nowrap">Order</th>
<th scope="col" class="p-3.5 text-left whitespace-nowrap" aria-sort="none"><button type="button" class="bg-transparent border-0 font-inherit text-inherit cursor-pointer inline-flex gap-1 items-center p-0 hover:underline">Customer <span aria-hidden="true" class="sort__arrow inline-block">▲</span></button></th>
<th scope="col" class="p-3.5 text-left whitespace-nowrap">Status</th>
<th scope="col" class="p-3.5 text-left whitespace-nowrap" aria-sort="ascending"><button type="button" class="bg-transparent border-0 font-inherit text-inherit cursor-pointer inline-flex gap-1 items-center p-0 hover:underline">Total <span aria-hidden="true" class="sort__arrow inline-block">▲</span></button></th>
</tr></thead>
<tbody>
<tr><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">#1042</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">A. Whitfield</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">Shipped</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">£64.00</td></tr>
<tr><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">#1041</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">R. Okafor</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">Processing</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">£128.50</td></tr>
<tr><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">#1040</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">M. Iqbal</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">Shipped</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">£22.00</td></tr>
<tr><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">#1039</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">S. Novak</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">Refunded</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">£40.00</td></tr>
</tbody>
</table>
</div>
</div>
<style>
th[aria-sort="descending"] .sort__arrow { transform: rotate(180deg); display: inline-block; }
</style>function Sort({
caption = "Customer orders",
accent = "#241430",
customerSort = "none",
totalSort = "ascending",
reverseOrder = false,
}) {
const rows = [
["#1042", "A. Whitfield", "Shipped", "£64.00"],
["#1041", "R. Okafor", "Processing", "£128.50"],
["#1040", "M. Iqbal", "Shipped", "£22.00"],
["#1039", "S. Novak", "Refunded", "£40.00"],
];
const ordered = reverseOrder ? [...rows].reverse() : rows;
const cell = { padding: "10px 14px", borderBottom: "1px solid #24143020", whiteSpace: "nowrap" };
const sortHeader = (label, dir) => (
<th scope="col" style={cell} aria-sort={dir}>
<button type="button" style={{ background: "none", border: 0, font: "inherit", color: "inherit", cursor: "pointer", display: "inline-flex", gap: 4, alignItems: "center", padding: 0 }}>
{label} <span aria-hidden="true" style={{ display: "inline-block", transform: dir === "descending" ? "rotate(180deg)" : "none" }}>{dir !== "none" && "▲"}</span>
</button>
</th>
);
return (
<div style={{ maxWidth: 480, borderRadius: 10, border: "1px solid #24143020", overflow: "hidden", font: "14px system-ui, sans-serif", color: "#241430", background: "#FAF7F2" }}>
<div style={{ overflowX: "auto" }}>
<table style={{ borderCollapse: "collapse", width: "100%" }}>
<caption style={{ textAlign: "left", fontWeight: 600, padding: "10px 14px" }}>{caption}</caption>
<thead>
<tr style={{ background: accent, color: "#FAF7F2" }}>
<th scope="col" style={cell}>Order</th>
{sortHeader("Customer", customerSort)}
<th scope="col" style={cell}>Status</th>
{sortHeader("Total", totalSort)}
</tr>
</thead>
<tbody>
{ordered.map((row) => (
<tr key={row[0]}>{row.map((c, j) => <td key={j} style={cell}>{c}</td>)}</tr>
))}
</tbody>
</table>
</div>
</div>
);
}