"use client";
import { cn } from "@/lib/utils";
import type { SortDir } from "./use-table-controls";
// ─── Search bar ──────────────────────────────────────────────────────────────
interface TableSearchProps {
value: string;
onChange: (v: string) => void;
placeholder?: string;
}
export function TableSearch({ value, onChange, placeholder = "Search…" }: TableSearchProps) {
return (
);
}
// ─── Filter chips ────────────────────────────────────────────────────────────
interface FilterChipsProps {
chips: string[];
active: string[];
onToggle: (chip: string) => void;
}
export function FilterChips({ chips, active, onToggle }: FilterChipsProps) {
return (
{chips.map((chip) => {
const isActive = active.includes(chip);
return (
);
})}
);
}
// ─── TableControls wrapper ────────────────────────────────────────────────────
interface TableControlsProps {
search: string;
onSearch: (v: string) => void;
searchPlaceholder?: string;
chips: string[];
activeFilters: string[];
onToggleFilter: (chip: string) => void;
}
export function TableControls({
search,
onSearch,
searchPlaceholder,
chips,
activeFilters,
onToggleFilter,
}: TableControlsProps) {
return (
{chips.length > 0 && (
)}
);
}
// ─── Sortable column header ───────────────────────────────────────────────────
interface SortableThProps extends React.ThHTMLAttributes {
sortKey: string;
activeSortKey: string | null;
sortDir: SortDir;
onSort: (key: string) => void;
}
export function SortableTh({
sortKey,
activeSortKey,
sortDir,
onSort,
children,
className,
...rest
}: SortableThProps) {
const isActive = activeSortKey === sortKey;
return (
onSort(sortKey)}
>
{children}
{isActive ? (sortDir === "asc" ? "↑" : "↓") : "⇅"}
|
);
}