Skip to content

Open source alternative to Semrush and Ahrefs

Style the shadcn Table for OpenSEO and add the DataTable shell (EVE-297) (#737)

Carter Smithd831c8717d46
diff --git a/src/client/components/table/AppDataTable.tsx b/src/client/components/table/AppDataTable.tsx
index 501a9460..bdc31be7 100644
--- a/src/client/components/table/AppDataTable.tsx
+++ b/src/client/components/table/AppDataTable.tsx
@@ -1,130 +1,19 @@
import {
flexRender,
- getCoreRowModel,
- getExpandedRowModel,
- getPaginationRowModel,
- getSortedRowModel,
- useReactTable,
- type ColumnDef,
type Header,
type Row,
type Table,
- type TableOptions,
} from "@tanstack/react-table";
-import {
- useRef,
- type MouseEvent,
- type MutableRefObject,
- type ReactNode,
-} from "react";
-import {
- applyShiftRangeSelection,
- type SelectionAnchor,
-} from "./tableSelection";
-
-type AppColumnMeta<TData> = {
- headerClassName?: string;
- cellClassName?: string | ((row: Row<TData>) => string | undefined);
-};
-
-declare module "@tanstack/react-table" {
- interface ColumnMeta<TData, TValue> extends AppColumnMeta<TData> {
- readonly __valueType?: TValue;
- }
-}
-
-type UseAppTableOptions<TData> = Omit<
- TableOptions<TData>,
- "getCoreRowModel"
-> & {
- withSorting?: boolean;
- withExpanded?: boolean;
- withPagination?: boolean;
-};
-
-export function useAppTable<TData>(options: UseAppTableOptions<TData>) {
- const { withSorting, withExpanded, withPagination, ...tableOptions } =
- options;
- return useReactTable({
- ...tableOptions,
- getCoreRowModel: getCoreRowModel(),
- ...(withSorting ? { getSortedRowModel: getSortedRowModel() } : {}),
- ...(withExpanded ? { getExpandedRowModel: getExpandedRowModel() } : {}),
- ...(withPagination
- ? { getPaginationRowModel: getPaginationRowModel() }
- : {}),
- });
-}
-
-export function useSelectionAnchor(): MutableRefObject<SelectionAnchor | null> {
- return useRef<SelectionAnchor | null>(null);
-}
+import type { MouseEvent, ReactNode } from "react";
-export function makeSelectionColumn<TData>(
- anchorRef: MutableRefObject<SelectionAnchor | null>,
-): ColumnDef<TData> {
- return {
- id: "select",
- size: 32,
- enableSorting: false,
- header: ({ table }) => (
- <input
- type="checkbox"
- className="checkbox checkbox-xs [--radius-selector:0.25rem]"
- checked={table.getIsAllRowsSelected()}
- onChange={table.getToggleAllRowsSelectedHandler()}
- aria-label="Select all rows"
- />
- ),
- cell: ({ row, table }) => (
- <SelectionCheckbox row={row} table={table} anchorRef={anchorRef} />
- ),
- };
-}
-
-function SelectionCheckbox<TData>({
- row,
- table,
- anchorRef,
-}: {
- row: Row<TData>;
- table: Table<TData>;
- anchorRef: MutableRefObject<SelectionAnchor | null>;
-}) {
- const rangeHandledRef = useRef(false);
- return (
- <input
- type="checkbox"
- className="checkbox checkbox-xs [--radius-selector:0.25rem]"
- checked={row.getIsSelected()}
- aria-label="Select row"
- onClick={(event) => {
- event.stopPropagation();
- rangeHandledRef.current = applyShiftRangeSelection(
- event,
- row,
- table,
- anchorRef,
- );
- }}
- onChange={(event) => {
- if (rangeHandledRef.current) {
- rangeHandledRef.current = false;
- return;
- }
- row.getToggleSelectedHandler()(event);
- }}
- />
- );
-}
+// The DaisyUI table, for pages that have not moved to `DataTable` yet. Each
+// page port moves its tables to `DataTable`. The last port deletes this file.
export function AppDataTable<TData>({
table,
className = "table table-sm",
wrapperClassName = "overflow-x-auto",
empty,
- isLoading,
- loading,
getRowClassName,
getRowProps,
getCellClassName,
@@ -135,8 +24,6 @@ export function AppDataTable<TData>({
className?: string;
wrapperClassName?: string;
empty?: ReactNode;
- isLoading?: boolean;
- loading?: ReactNode;
getRowClassName?: (row: Row<TData>) => string | undefined;
getRowProps?: (row: Row<TData>) => {
onClick?: (event: MouseEvent<HTMLTableRowElement>) => void;
@@ -146,7 +33,6 @@ export function AppDataTable<TData>({
fixedLayout?: boolean;
stickyHeader?: boolean;
}) {
- if (isLoading && loading) return <>{loading}</>;
if (table.getRowModel().rows.length === 0 && empty) return <>{empty}</>;
return (
diff --git a/src/client/components/table/DataTable.tsx b/src/client/components/table/DataTable.tsx
new file mode 100644
index 00000000..06ea710b
--- /dev/null
+++ b/src/client/components/table/DataTable.tsx
@@ -0,0 +1,243 @@
+import {
+ flexRender,
+ getCoreRowModel,
+ getExpandedRowModel,
+ getPaginationRowModel,
+ getSortedRowModel,
+ useReactTable,
+ type ColumnDef,
+ type Row,
+ type Table as TanStackTable,
+ type TableOptions,
+} from "@tanstack/react-table";
+import { useRef, type MutableRefObject, type ReactNode } from "react";
+import { EmptyState } from "@/client/components/EmptyState";
+import { Button } from "@/client/components/ui/button";
+import { Checkbox } from "@/client/components/ui/checkbox";
+import { Skeleton } from "@/client/components/ui/skeleton";
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from "@/client/components/ui/table";
+import {
+ applyShiftRangeSelection,
+ type SelectionAnchor,
+} from "./tableSelection";
+
+type AppColumnMeta<TData> = {
+ headerClassName?: string;
+ cellClassName?: string | ((row: Row<TData>) => string | undefined);
+};
+
+declare module "@tanstack/react-table" {
+ interface ColumnMeta<TData, TValue> extends AppColumnMeta<TData> {
+ readonly __valueType?: TValue;
+ }
+}
+
+type UseDataTableOptions<TData> = Omit<
+ TableOptions<TData>,
+ "getCoreRowModel"
+> & {
+ withSorting?: boolean;
+ withExpanded?: boolean;
+ withPagination?: boolean;
+};
+
+export function useDataTable<TData>(options: UseDataTableOptions<TData>) {
+ const { withSorting, withExpanded, withPagination, ...tableOptions } =
+ options;
+ return useReactTable({
+ ...tableOptions,
+ getCoreRowModel: getCoreRowModel(),
+ ...(withSorting ? { getSortedRowModel: getSortedRowModel() } : {}),
+ ...(withExpanded ? { getExpandedRowModel: getExpandedRowModel() } : {}),
+ ...(withPagination
+ ? { getPaginationRowModel: getPaginationRowModel() }
+ : {}),
+ });
+}
+
+export function useSelectionAnchor(): MutableRefObject<SelectionAnchor | null> {
+ return useRef<SelectionAnchor | null>(null);
+}
+
+export function makeSelectionColumn<TData>(
+ anchorRef: MutableRefObject<SelectionAnchor | null>,
+): ColumnDef<TData> {
+ return {
+ id: "select",
+ size: 32,
+ enableSorting: false,
+ header: ({ table }) => (
+ <Checkbox
+ checked={table.getIsAllRowsSelected()}
+ indeterminate={table.getIsSomeRowsSelected()}
+ disabled={table.getRowModel().rows.length === 0}
+ onCheckedChange={(checked) => table.toggleAllRowsSelected(checked)}
+ aria-label="Select all rows"
+ />
+ ),
+ cell: ({ row, table }) => (
+ <SelectionCheckbox row={row} table={table} anchorRef={anchorRef} />
+ ),
+ };
+}
+
+function SelectionCheckbox<TData>({
+ row,
+ table,
+ anchorRef,
+}: {
+ row: Row<TData>;
+ table: TanStackTable<TData>;
+ anchorRef: MutableRefObject<SelectionAnchor | null>;
+}) {
+ return (
+ <Checkbox
+ checked={row.getIsSelected()}
+ aria-label="Select row"
+ // The checkbox is a span, so a shift+click would also select page text.
+ onMouseDown={(event) => {
+ if (event.shiftKey) event.preventDefault();
+ }}
+ onClick={(event) => {
+ event.stopPropagation();
+ // A shift+click selects the range, so the checkbox must not toggle.
+ if (applyShiftRangeSelection(event, row, table, anchorRef)) {
+ event.preventBaseUIHandler();
+ }
+ }}
+ onCheckedChange={(checked) => row.toggleSelected(checked)}
+ />
+ );
+}
+
+/**
+ * The table body of a data table: sortable headers, skeleton rows while the
+ * first page loads, and an empty state that says whether filters hide rows.
+ *
+ * The page owns sorting, pagination, filters and selection. It passes that
+ * state to `useDataTable` and to `TablePagination`, usually from its search
+ * params. Put the toolbar and the pagination footer in `toolbar` and `footer`.
+ */
+export function DataTable<TData>({
+ table,
+ isLoading = false,
+ empty,
+ isFiltered = false,
+ onClearFilters,
+ toolbar,
+ footer,
+}: {
+ table: TanStackTable<TData>;
+ /** The first load: shows skeleton rows under the real headers. */
+ isLoading?: boolean;
+ /** Shown when there are no rows and no filters. */
+ empty: { title: ReactNode; description?: ReactNode; action?: ReactNode };
+ /** True when filters are active. An empty table then offers `onClearFilters`. */
+ isFiltered?: boolean;
+ onClearFilters?: () => void;
+ toolbar?: ReactNode;
+ footer?: ReactNode;
+}) {
+ const columns = table.getVisibleLeafColumns();
+ const rows = table.getRowModel().rows;
+
+ return (
+ <div className="overflow-hidden rounded-xl border border-border bg-card">
+ {toolbar}
+ <Table>
+ <TableHeader>
+ {table.getHeaderGroups().map((headerGroup) => (
+ <TableRow key={headerGroup.id} className="hover:bg-transparent">
+ {headerGroup.headers.map((header) => (
+ <TableHead
+ key={header.id}
+ className={header.column.columnDef.meta?.headerClassName}
+ >
+ {header.isPlaceholder
+ ? null
+ : flexRender(
+ header.column.columnDef.header,
+ header.getContext(),
+ )}
+ </TableHead>
+ ))}
+ </TableRow>
+ ))}
+ </TableHeader>
+ <TableBody>
+ {isLoading ? (
+ Array.from({ length: 8 }, (_, index) => (
+ <TableRow key={index} aria-hidden>
+ {columns.map((column) => (
+ <TableCell key={column.id}>
+ <Skeleton
+ className={
+ column.id === "select" ? "size-4" : "h-4 w-full"
+ }
+ />
+ </TableCell>
+ ))}
+ </TableRow>
+ ))
+ ) : rows.length === 0 ? (
+ <TableRow className="hover:bg-transparent">
+ <TableCell colSpan={columns.length}>
+ {isFiltered ? (
+ <EmptyState
+ kind="filtered"
+ variant="plain"
+ title="No rows match these filters"
+ description="Change or clear the filters to see more rows."
+ action={
+ onClearFilters ? (
+ <Button
+ variant="outline"
+ size="sm"
+ onClick={onClearFilters}
+ >
+ Clear filters
+ </Button>
+ ) : undefined
+ }
+ />
+ ) : (
+ <EmptyState variant="plain" {...empty} />
+ )}
+ </TableCell>
+ </TableRow>
+ ) : (
+ rows.map((row) => (
+ <TableRow
+ key={row.id}
+ data-state={row.getIsSelected() ? "selected" : undefined}
+ >
+ {row.getVisibleCells().map((cell) => {
+ const meta = cell.column.columnDef.meta?.cellClassName;
+ return (
+ <TableCell
+ key={cell.id}
+ className={typeof meta === "function" ? meta(row) : meta}
+ >
+ {flexRender(
+ cell.column.columnDef.cell,
+ cell.getContext(),
+ )}
+ </TableCell>
+ );
+ })}
+ </TableRow>
+ ))
+ )}
+ </TableBody>
+ </Table>
+ {footer}
+ </div>
+ );
+}
diff --git a/src/client/components/table/DataTableToolbar.tsx b/src/client/components/table/DataTableToolbar.tsx
new file mode 100644
index 00000000..26819f93
--- /dev/null
+++ b/src/client/components/table/DataTableToolbar.tsx
@@ -0,0 +1,136 @@
+import { RotateCcw, SlidersHorizontal } from "lucide-react";
+import type { ComponentProps, ReactNode } from "react";
+import { Badge } from "@/client/components/ui/badge";
+import { Button } from "@/client/components/ui/button";
+import { Input } from "@/client/components/ui/input";
+
+// The parts above a `DataTable`: a toolbar row and a collapsible filter panel.
+// The page owns the filter values and the open state.
+
+/** Filter controls on the left, actions such as `ExportMenu` on the right. */
+export function DataTableToolbar({
+ children,
+ actions,
+}: {
+ children?: ReactNode;
+ actions?: ReactNode;
+}) {
+ return (
+ <div className="flex flex-wrap items-center justify-between gap-3 border-b border-border px-4 py-2.5">
+ <div className="flex flex-wrap items-center gap-2">{children}</div>
+ {actions ? (
+ <div className="flex flex-wrap items-center gap-2">{actions}</div>
+ ) : null}
+ </div>
+ );
+}
+
+export function DataTableFilterToggle({
+ open,
+ activeCount,
+ onToggle,
+}: {
+ open: boolean;
+ activeCount: number;
+ onToggle: () => void;
+}) {
+ return (
+ <Button variant="ghost" size="sm" aria-expanded={open} onClick={onToggle}>
+ <SlidersHorizontal data-icon="inline-start" />
+ Filters
+ {activeCount > 0 ? (
+ <Badge size="sm" aria-label={`${activeCount} active`}>
+ {activeCount}
+ </Badge>
+ ) : null}
+ </Button>
+ );
+}
+
+export function DataTableFilterPanel({
+ activeCount,
+ onReset,
+ children,
+}: {
+ activeCount: number;
+ onReset: () => void;
+ children: ReactNode;
+}) {
+ return (
+ <div className="space-y-3 border-b border-border bg-foreground/[0.02] px-4 py-3">
+ <div className="flex flex-wrap items-center justify-between gap-2">
+ <div className="flex items-center gap-2">
+ <p className="text-sm font-semibold">Refine results</p>
+ {activeCount > 0 ? (
+ <Badge size="sm">{activeCount} active</Badge>
+ ) : null}
+ </div>
+ <Button
+ variant="ghost"
+ size="xs"
+ onClick={onReset}
+ disabled={activeCount === 0}
+ >
+ <RotateCcw data-icon="inline-start" />
+ Clear all
+ </Button>
+ </div>
+ {children}
+ </div>
+ );
+}
+
+/** A labelled box for one filter, for example a Min/Max range. */
+export function DataTableFilterGroup({
+ label,
+ icon,
+ children,
+}: {
+ label: string;
+ icon?: ReactNode;
+ children: ReactNode;
+}) {
+ return (
+ <div className="space-y-2 rounded-lg border border-border bg-card p-2.5">
+ <div className="flex items-center gap-2">
+ {icon}
+ <p className="text-[11px] font-semibold tracking-wide text-muted-foreground uppercase">
+ {label}
+ </p>
+ </div>
+ {children}
+ </div>
+ );
+}
+
+/** A Min/Max range filter. Bind each input to a form field. */
+export function DataTableRangeFilter({
+ label,
+ min,
+ max,
+}: {
+ label: string;
+ min: ComponentProps<typeof Input>;
+ max: ComponentProps<typeof Input>;
+}) {
+ return (
+ <DataTableFilterGroup label={label}>
+ <div className="grid grid-cols-2 gap-2">
+ <Input
+ type="number"
+ placeholder="Min"
+ aria-label={`${label} min`}
+ className="h-7"
+ {...min}
+ />
+ <Input
+ type="number"
+ placeholder="Max"
+ aria-label={`${label} max`}
+ className="h-7"
+ {...max}
+ />
+ </div>
+ </DataTableFilterGroup>
+ );
+}
diff --git a/src/client/components/table/SortableHeader.tsx b/src/client/components/table/SortableHeader.tsx
index c30f179a..14181723 100644
--- a/src/client/components/table/SortableHeader.tsx
+++ b/src/client/components/table/SortableHeader.tsx
@@ -26,7 +26,7 @@ export function SortableHeader({
const content = (
<button
type="button"
- className={`inline-flex items-center gap-1 font-medium transition-colors hover:text-base-content ${className ?? ""}`}
+ className={`inline-flex items-center gap-1 font-medium transition-colors hover:text-foreground ${className ?? ""}`}
onClick={column.getToggleSortingHandler()}
title={title}
aria-label={`Sort by ${label}`}
diff --git a/src/client/components/table/TableBulkActionBar.tsx b/src/client/components/table/TableBulkActionBar.tsx
index ba9bacbc..a23507e7 100644
--- a/src/client/components/table/TableBulkActionBar.tsx
+++ b/src/client/components/table/TableBulkActionBar.tsx
@@ -1,5 +1,12 @@
-import { ChevronDown, Download, Loader2, X } from "lucide-react";
+import { ChevronDown, Download, X } from "lucide-react";
import type { ReactNode } from "react";
+import { Button } from "@/client/components/ui/button";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+} from "@/client/components/ui/dropdown-menu";
export function TableBulkActionBar({
selectedCount,
@@ -19,19 +26,20 @@ export function TableBulkActionBar({
<div
role="toolbar"
aria-label="Bulk actions"
- className="pointer-events-auto flex items-stretch overflow-visible rounded-xl border border-base-content/15 bg-base-300/85 shadow-2xl backdrop-blur"
+ className="pointer-events-auto flex items-stretch rounded-xl border border-border bg-popover/90 text-popover-foreground shadow-2xl backdrop-blur"
>
- <div className="flex items-center gap-2 border-r border-base-content/10 px-3 py-2 text-sm">
- <button
- type="button"
+ <div className="flex items-center gap-2 border-r border-border py-2 pr-3 pl-2 text-sm">
+ <Button
+ variant="ghost"
+ size="icon-xs"
aria-label="Clear selection"
- className="-ml-1 rounded p-1 text-base-content/55 hover:bg-base-content/10 hover:text-base-content"
+ className="text-muted-foreground"
onClick={onClear}
>
- <X className="size-3.5" />
- </button>
+ <X />
+ </Button>
<span className="font-medium tabular-nums">{selectedCount}</span>
- <span className="text-base-content/60">{selectedLabel}</span>
+ <span className="text-muted-foreground">{selectedLabel}</span>
</div>
{actions}
</div>
@@ -52,21 +60,21 @@ export function TableBulkActionButton({
disabled?: boolean;
variant?: "default" | "danger";
}) {
- const color =
- variant === "danger"
- ? "text-error hover:bg-error/10"
- : "text-base-content/85 hover:bg-base-content/10";
-
return (
- <button
- type="button"
+ <Button
+ variant="ghost"
+ size="sm"
onClick={onClick}
disabled={disabled}
- className={`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1.5 text-sm disabled:opacity-50 ${color}`}
+ className={
+ variant === "danger"
+ ? "text-destructive hover:bg-destructive/10 hover:text-destructive"
+ : undefined
+ }
>
{icon}
{children}
- </button>
+ </Button>
);
}
@@ -83,41 +91,27 @@ export function TableBulkExportMenu({
busy?: boolean;
}) {
return (
- <div className="dropdown dropdown-top dropdown-end">
- <button
- type="button"
- tabIndex={0}
- disabled={busy}
- aria-haspopup="menu"
- className="inline-flex items-center gap-1.5 rounded-md px-2.5 py-1.5 text-sm text-base-content/85 hover:bg-base-content/10 disabled:opacity-50"
+ <DropdownMenu>
+ <DropdownMenuTrigger
+ render={<Button variant="ghost" size="sm" pending={busy} />}
>
- {busy ? (
- <Loader2 className="size-3.5 animate-spin" />
- ) : (
- <Download className="size-3.5" />
- )}
+ {busy ? null : <Download data-icon="inline-start" />}
Export
- <ChevronDown className="size-3 opacity-60" />
- </button>
- <ul
- tabIndex={0}
- role="menu"
- className="dropdown-content menu z-10 mb-2 w-52 rounded-box border border-base-300 bg-base-100 p-2 shadow-lg"
- >
+ <ChevronDown data-icon="inline-end" className="opacity-60" />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent side="top" align="end" className="w-52">
{actions.map((action, index) => (
- <li key={index}>
- <button
- type="button"
- onClick={action.onClick}
- disabled={busy || action.disabled}
- >
- {action.icon}
- {action.label}
- </button>
- </li>
+ <DropdownMenuItem
+ key={index}
+ onClick={action.onClick}
+ disabled={busy || action.disabled}
+ >
+ {action.icon}
+ {action.label}
+ </DropdownMenuItem>
))}
- </ul>
- </div>
+ </DropdownMenuContent>
+ </DropdownMenu>
);
}
diff --git a/src/client/components/table/TablePagination.tsx b/src/client/components/table/TablePagination.tsx
index 9ab03426..8789d6ba 100644
--- a/src/client/components/table/TablePagination.tsx
+++ b/src/client/components/table/TablePagination.tsx
@@ -1,5 +1,14 @@
import { ChevronLeft, ChevronRight } from "lucide-react";
import { useEffect, type ReactNode } from "react";
+import { Button } from "@/client/components/ui/button";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/client/components/ui/select";
+import { Spinner } from "@/client/components/ui/spinner";
export type PageButtonProps = {
page: number;
@@ -60,41 +69,45 @@ export function TablePagination<TSize extends number>({
}, [currentPage, isLoading, isOutOfRange, onPageChange]);
return (
- <div className="flex flex-col gap-3 border-t border-base-300 px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
- <div className="flex items-center gap-2 text-sm text-base-content/70 tabular-nums">
+ <div className="flex flex-col gap-3 border-t border-border px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
+ <div className="flex items-center gap-2 text-sm text-muted-foreground tabular-nums">
<span className="whitespace-nowrap">
{formatRange(currentPage, pageSize, totalCount, pageRange)}
</span>
- {isLoading ? (
- <span className="loading loading-spinner loading-xs" />
- ) : null}
+ {isLoading ? <Spinner className="size-3.5" /> : null}
</div>
<div className="flex flex-wrap items-center gap-x-6 gap-y-2">
{pageSizes && onPageSizeChange ? (
- <label className="flex items-center gap-2 text-sm text-base-content/70">
+ <div className="flex items-center gap-2 text-sm text-muted-foreground">
<span className="whitespace-nowrap">Rows per page</span>
- <select
- className="select select-bordered select-sm w-20"
+ <Select
value={pageSize}
- onChange={(event) => {
- const size = pageSizes.find(
- (option) => option === Number(event.target.value),
- );
+ onValueChange={(value) => {
+ const size = pageSizes.find((option) => option === value);
if (size != null) onPageSizeChange(size);
}}
>
- {pageSizes.map((size) => (
- <option key={size} value={size}>
- {size}
- </option>
- ))}
- </select>
- </label>
+ <SelectTrigger
+ size="sm"
+ className="w-20"
+ aria-label="Rows per page"
+ >
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {pageSizes.map((size) => (
+ <SelectItem key={size} value={size}>
+ {size}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </div>
) : null}
<div className="flex items-center gap-2">
- <span className="whitespace-nowrap text-sm tabular-nums text-base-content/70">
+ <span className="whitespace-nowrap text-sm tabular-nums text-muted-foreground">
Page {currentPage.toLocaleString()}
{totalPages != null ? ` of ${totalPages.toLocaleString()}` : ""}
</span>
@@ -103,25 +116,25 @@ export function TablePagination<TSize extends number>({
page: currentPage - 1,
disabled: !canGoPrev || isLoading,
label: "Previous page",
- children: <ChevronLeft className="size-4" />,
+ children: <ChevronLeft />,
onPageChange,
})}
{isLastPage && loadMoreLabel != null ? (
- <button
- type="button"
- className="btn btn-ghost btn-sm"
+ <Button
+ variant="ghost"
+ size="sm"
disabled={isLoading}
onClick={() => onPageChange(currentPage + 1)}
>
{loadMoreLabel}
- <ChevronRight className="size-4" />
- </button>
+ <ChevronRight data-icon="inline-end" />
+ </Button>
) : (
renderPageButton({
page: currentPage + 1,
disabled: !canGoNext || isLoading,
label: "Next page",
- children: <ChevronRight className="size-4" />,
+ children: <ChevronRight />,
onPageChange,
})
)}
@@ -140,15 +153,15 @@ function PageButton({
onPageChange,
}: PageButtonProps) {
return (
- <button
- type="button"
+ <Button
+ variant="ghost"
+ size="icon-sm"
aria-label={label}
- className="btn btn-ghost btn-sm btn-square"
disabled={disabled}
onClick={() => onPageChange(page)}
>
{children}
- </button>
+ </Button>
);
}
diff --git a/src/client/components/ui/checkbox.tsx b/src/client/components/ui/checkbox.tsx
index 776a1671..4a56b20b 100644
--- a/src/client/components/ui/checkbox.tsx
+++ b/src/client/components/ui/checkbox.tsx
@@ -1,13 +1,13 @@
import { Checkbox as CheckboxPrimitive } from "@base-ui/react/checkbox";
import { cn } from "cn";
-import { CheckIcon } from "lucide-react";
+import { CheckIcon, MinusIcon } from "lucide-react";
function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) {
return (
<CheckboxPrimitive.Root
data-slot="checkbox"
className={cn(
- "peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-colors outline-none group-has-disabled/field:opacity-50 group-has-[:focus-visible]/field-label:ring-0 group-has-[:focus-visible]/field-label:not-data-checked:border-input after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground group-has-[:focus-visible]/field-label:data-checked:border-primary dark:data-checked:bg-primary",
+ "group/checkbox peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-colors outline-none group-has-disabled/field:opacity-50 group-has-[:focus-visible]/field-label:ring-0 group-has-[:focus-visible]/field-label:not-data-checked:border-input after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground data-indeterminate:border-primary data-indeterminate:bg-primary data-indeterminate:text-primary-foreground dark:data-indeterminate:bg-primary group-has-[:focus-visible]/field-label:data-checked:border-primary dark:data-checked:bg-primary",
className,
)}
{...props}
@@ -16,7 +16,8 @@ function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) {
data-slot="checkbox-indicator"
className="grid place-content-center text-current transition-none [&>svg]:size-3.5"
>
- <CheckIcon />
+ <CheckIcon className="group-data-indeterminate/checkbox:hidden" />
+ <MinusIcon className="hidden group-data-indeterminate/checkbox:block" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
);
diff --git a/src/client/components/ui/table.tsx b/src/client/components/ui/table.tsx
index e25e7ecb..d4256d84 100644
--- a/src/client/components/ui/table.tsx
+++ b/src/client/components/ui/table.tsx
@@ -1,6 +1,10 @@
import * as React from "react";
import { cn } from "cn";
+// Row hover and selection use a foreground and primary tint: bg-muted is the
+// page background in the light theme, so it would not show on a card.
+// Cells wrap, because tables hold long URLs and titles.
+
function Table({ className, ...props }: React.ComponentProps<"table">) {
return (
<div
@@ -20,7 +24,7 @@ function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
return (
<thead
data-slot="table-header"
- className={cn("[&_tr]:border-b", className)}
+ className={cn("[&_tr]:border-b [&_tr]:border-border", className)}
{...props}
/>
);
@@ -41,7 +45,7 @@ function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
<tfoot
data-slot="table-footer"
className={cn(
- "border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
+ "border-t border-border bg-muted/50 font-medium [&>tr]:last:border-b-0",
className,
)}
{...props}
@@ -54,7 +58,7 @@ function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
<tr
data-slot="table-row"
className={cn(
- "border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted",
+ "border-b border-border transition-colors hover:bg-foreground/[0.03] has-aria-expanded:bg-foreground/[0.03] data-[state=selected]:bg-primary/5",
className,
)}
{...props}
@@ -67,7 +71,7 @@ function TableHead({ className, ...props }: React.ComponentProps<"th">) {
<th
data-slot="table-head"
className={cn(
- "h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0",
+ "h-9 px-3 text-left align-middle text-xs font-medium whitespace-nowrap text-muted-foreground first:pl-4 last:pr-4 [&:has([role=checkbox])]:pr-0",
className,
)}
{...props}
@@ -80,7 +84,7 @@ function TableCell({ className, ...props }: React.ComponentProps<"td">) {
<td
data-slot="table-cell"
className={cn(
- "p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0",
+ "px-3 py-2 align-middle first:pl-4 last:pr-4 [&:has([role=checkbox])]:pr-0",
className,
)}
{...props}
diff --git a/src/client/features/ai-search/components/BrandLookupCitationsCard.tsx b/src/client/features/ai-search/components/BrandLookupCitationsCard.tsx
index 175e8cef..0879667c 100644
--- a/src/client/features/ai-search/components/BrandLookupCitationsCard.tsx
+++ b/src/client/features/ai-search/components/BrandLookupCitationsCard.tsx
@@ -1,7 +1,7 @@
import { useMemo, useState } from "react";
import { type SortingState } from "@tanstack/react-table";
import { ChevronDown, Download, Sheet, SlidersHorizontal } from "lucide-react";
-import { useAppTable } from "@/client/components/table/AppDataTable";
+import { useDataTable } from "@/client/components/table/DataTable";
import { exportRows } from "@/client/lib/exportRows";
import {
buildBrandLookupExport,
@@ -100,7 +100,7 @@ export function CitationTabsCard({
[showQueryPlatform, projectId, brand],
);
- const pagesTable = useAppTable({
+ const pagesTable = useDataTable({
data: filteredPages,
columns: pagesColumns,
state: { sorting: pagesSort },
@@ -111,7 +111,7 @@ export function CitationTabsCard({
// reorders rows, not stick to whatever row lands in the same slot.
getRowId: (row) => `${row.platform}:${row.url}`,
});
- const queriesTable = useAppTable({
+ const queriesTable = useDataTable({
data: filteredQueries,
columns: queriesColumns,
state: { sorting: queriesSort },
diff --git a/src/client/features/audit/launch/AuditHistorySection.tsx b/src/client/features/audit/launch/AuditHistorySection.tsx
index 154f4c72..05fe56c8 100644
--- a/src/client/features/audit/launch/AuditHistorySection.tsx
+++ b/src/client/features/audit/launch/AuditHistorySection.tsx
@@ -4,6 +4,15 @@ import { ScanSearch, Trash2 } from "lucide-react";
import type { getAuditHistory } from "@/serverFunctions/audit";
import { PortalMenu } from "@/client/components/PortalMenu";
import { QueryState } from "@/client/components/QueryState";
+import { Badge } from "@/client/components/ui/badge";
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from "@/client/components/ui/table";
import { formatDate, StatusBadge } from "@/client/features/audit/shared";
type AuditHistory = Awaited<ReturnType<typeof getAuditHistory>>;
@@ -57,46 +66,48 @@ function AuditHistoryTable({
<div className="card bg-base-100 border border-base-300">
<div className="card-body gap-3">
<h2 className="card-title text-base">Previous Audits</h2>
- <div className="overflow-x-auto">
- <table className="table table-sm">
- <thead>
- <tr>
- <th>Date</th>
- <th>URL</th>
- <th>Status</th>
- <th>Pages</th>
- <th>Lighthouse</th>
- <th></th>
- </tr>
- </thead>
- <tbody>
- {history.map((audit) => (
- <tr key={audit.id} className="hover group">
- <td className="text-xs text-base-content/70">
- {formatDate(audit.startedAt)}
- </td>
- <td className="max-w-[220px] truncate">{audit.startUrl}</td>
- <td>
- <StatusBadge status={audit.status} />
- </td>
- <td>{audit.pagesTotal || audit.pagesCrawled}</td>
- <td>
- {audit.ranLighthouse ? (
- <span className="badge badge-ghost badge-xs">Yes</span>
- ) : null}
- </td>
- <td>
- <HistoryActions
- projectId={projectId}
- auditId={audit.id}
- onDelete={onDelete}
- />
- </td>
- </tr>
- ))}
- </tbody>
- </table>
- </div>
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead>Date</TableHead>
+ <TableHead>URL</TableHead>
+ <TableHead>Status</TableHead>
+ <TableHead>Pages</TableHead>
+ <TableHead>Lighthouse</TableHead>
+ <TableHead />
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {history.map((audit) => (
+ <TableRow key={audit.id} className="group">
+ <TableCell className="text-xs text-muted-foreground">
+ {formatDate(audit.startedAt)}
+ </TableCell>
+ <TableCell className="max-w-[220px] truncate">
+ {audit.startUrl}
+ </TableCell>
+ <TableCell>
+ <StatusBadge status={audit.status} />
+ </TableCell>
+ <TableCell>{audit.pagesTotal || audit.pagesCrawled}</TableCell>
+ <TableCell>
+ {audit.ranLighthouse ? (
+ <Badge variant="outline" size="sm">
+ Yes
+ </Badge>
+ ) : null}
+ </TableCell>
+ <TableCell>
+ <HistoryActions
+ projectId={projectId}
+ auditId={audit.id}
+ onDelete={onDelete}
+ />
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
</div>
</div>
);
diff --git a/src/client/features/audit/results/PagesTable.tsx b/src/client/features/audit/results/PagesTable.tsx
index 62c1ca70..2411239f 100644
--- a/src/client/features/audit/results/PagesTable.tsx
+++ b/src/client/features/audit/results/PagesTable.tsx
@@ -5,10 +5,8 @@ import {
type SortingState,
} from "@tanstack/react-table";
import { ExternalLink } from "lucide-react";
-import {
- AppDataTable,
- useAppTable,
-} from "@/client/components/table/AppDataTable";
+import { AppDataTable } from "@/client/components/table/AppDataTable";
+import { useDataTable } from "@/client/components/table/DataTable";
import { SortableHeader } from "@/client/components/table/SortableHeader";
import {
extractHostname,
@@ -217,7 +215,7 @@ export function PagesTable({
}),
[issues, pages, startUrl],
);
- const table = useAppTable({
+ const table = useDataTable({
data: filteredPages,
columns,
state: { sorting },
diff --git a/src/client/features/audit/results/ResultsTables.tsx b/src/client/features/audit/results/ResultsTables.tsx
index ddee9b21..8724db80 100644
--- a/src/client/features/audit/results/ResultsTables.tsx
+++ b/src/client/features/audit/results/ResultsTables.tsx
@@ -5,10 +5,8 @@ import {
type SortingState,
} from "@tanstack/react-table";
import { Link } from "@tanstack/react-router";
-import {
- AppDataTable,
- useAppTable,
-} from "@/client/components/table/AppDataTable";
+import { AppDataTable } from "@/client/components/table/AppDataTable";
+import { useDataTable } from "@/client/components/table/DataTable";
import { TableExportMenu } from "@/client/components/table/TableBulkActionBar";
import { SortableHeader } from "@/client/components/table/SortableHeader";
import {
@@ -77,7 +75,7 @@ export function PerformanceTable({
() => buildPerformanceColumns({ auditId, projectId }),
[auditId, projectId],
);
- const table = useAppTable({
+ const table = useDataTable({
data: filteredRows,
columns,
state: { sorting },
diff --git a/src/client/features/backlinks/BacklinksTable.tsx b/src/client/features/backlinks/BacklinksTable.tsx
index d0d78a5b..c0e33dfb 100644
--- a/src/client/features/backlinks/BacklinksTable.tsx
+++ b/src/client/features/backlinks/BacklinksTable.tsx
@@ -1,9 +1,7 @@
import { useMemo } from "react";
import type { OnChangeFn, SortingState } from "@tanstack/react-table";
-import {
- AppDataTable,
- useAppTable,
-} from "@/client/components/table/AppDataTable";
+import { AppDataTable } from "@/client/components/table/AppDataTable";
+import { useDataTable } from "@/client/components/table/DataTable";
import { EmptyTableState } from "./BacklinksPageStates";
import {
buildBacklinksColumns,
@@ -97,7 +95,7 @@ export function BacklinksTable({
[rows, expansion],
);
- const table = useAppTable({
+ const table = useDataTable({
data: displayRows,
columns,
state: { sorting },
diff --git a/src/client/features/backlinks/ReferringDomainsTable.tsx b/src/client/features/backlinks/ReferringDomainsTable.tsx
index 01013d1e..e111acd8 100644
--- a/src/client/features/backlinks/ReferringDomainsTable.tsx
+++ b/src/client/features/backlinks/ReferringDomainsTable.tsx
@@ -2,10 +2,8 @@ import { createColumnHelper } from "@tanstack/react-table";
import type { OnChangeFn, SortingState } from "@tanstack/react-table";
import { useMemo } from "react";
import { SafeExternalLink } from "@/client/components/SafeExternalLink";
-import {
- AppDataTable,
- useAppTable,
-} from "@/client/components/table/AppDataTable";
+import { AppDataTable } from "@/client/components/table/AppDataTable";
+import { useDataTable } from "@/client/components/table/DataTable";
import { SortableHeader } from "@/client/components/table/SortableHeader";
import { HelpLabel } from "@/client/components/HelpLabel";
import { EmptyTableState } from "./BacklinksPageStates";
@@ -182,7 +180,7 @@ export function ReferringDomainsTable({
[domainRatings],
);
- const table = useAppTable({
+ const table = useDataTable({
data: rows,
columns,
state: { sorting },
diff --git a/src/client/features/backlinks/TopPagesTable.tsx b/src/client/features/backlinks/TopPagesTable.tsx
index e5ca2422..bd549723 100644
--- a/src/client/features/backlinks/TopPagesTable.tsx
+++ b/src/client/features/backlinks/TopPagesTable.tsx
@@ -1,10 +1,8 @@
import { createColumnHelper } from "@tanstack/react-table";
import type { OnChangeFn, SortingState } from "@tanstack/react-table";
import { SafeExternalLink } from "@/client/components/SafeExternalLink";
-import {
- AppDataTable,
- useAppTable,
-} from "@/client/components/table/AppDataTable";
+import { AppDataTable } from "@/client/components/table/AppDataTable";
+import { useDataTable } from "@/client/components/table/DataTable";
import { SortableHeader } from "@/client/components/table/SortableHeader";
import { HelpLabel } from "@/client/components/HelpLabel";
import { EmptyTableState } from "./BacklinksPageStates";
@@ -98,7 +96,7 @@ export function TopPagesTable({
sorting: SortingState;
onSortingChange: OnChangeFn<SortingState>;
}) {
- const table = useAppTable({
+ const table = useDataTable({
data: rows,
columns,
state: { sorting },
diff --git a/src/client/features/domain/components/DomainKeywordsTable.tsx b/src/client/features/domain/components/DomainKeywordsTable.tsx
index fb827320..aa01a5c4 100644
--- a/src/client/features/domain/components/DomainKeywordsTable.tsx
+++ b/src/client/features/domain/components/DomainKeywordsTable.tsx
@@ -4,12 +4,12 @@ import {
type ColumnDef,
type RowSelectionState,
} from "@tanstack/react-table";
+import { AppDataTable } from "@/client/components/table/AppDataTable";
import {
- AppDataTable,
makeSelectionColumn,
- useAppTable,
+ useDataTable,
useSelectionAnchor,
-} from "@/client/components/table/AppDataTable";
+} from "@/client/components/table/DataTable";
import { ExternalUrlCell } from "@/client/components/table/url";
import { ScoreBadge } from "@/client/components/table/ScoreBadge";
import { SortableHeader } from "@/client/components/table/SortableHeader";
@@ -149,7 +149,7 @@ function DomainKeywordsTableComponent({
],
[currentSortOrder, domain, onSortClick, selectAnchorRef, sortMode],
);
- const table = useAppTable({
+ const table = useDataTable({
data: rows,
columns,
state: { rowSelection },
diff --git a/src/client/features/domain/components/DomainPageLink.tsx b/src/client/features/domain/components/DomainPageLink.tsx
index 4334aabc..ad39be01 100644
--- a/src/client/features/domain/components/DomainPageLink.tsx
+++ b/src/client/features/domain/components/DomainPageLink.tsx
@@ -1,5 +1,6 @@
import { Link } from "@tanstack/react-router";
import type { PageButtonProps } from "@/client/components/table/TablePagination";
+import { buttonVariants } from "@/client/components/ui/button";
/** Prev/next as real links, so a page can open in a new tab. */
export function DomainPageLink({
@@ -19,7 +20,11 @@ export function DomainPageLink({
})}
aria-label={label}
aria-disabled={disabled}
- className={`btn btn-ghost btn-sm btn-square ${disabled ? "btn-disabled" : ""}`}
+ className={buttonVariants({
+ variant: "ghost",
+ size: "icon-sm",
+ className: disabled && "pointer-events-none opacity-50",
+ })}
onClick={(event) => {
if (disabled) {
event.preventDefault();
diff --git a/src/client/features/domain/components/DomainPagesTable.tsx b/src/client/features/domain/components/DomainPagesTable.tsx
index a60d77c8..1990ed9d 100644
--- a/src/client/features/domain/components/DomainPagesTable.tsx
+++ b/src/client/features/domain/components/DomainPagesTable.tsx
@@ -1,9 +1,7 @@
import { memo, useMemo } from "react";
import { createColumnHelper, type ColumnDef } from "@tanstack/react-table";
-import {
- AppDataTable,
- useAppTable,
-} from "@/client/components/table/AppDataTable";
+import { AppDataTable } from "@/client/components/table/AppDataTable";
+import { useDataTable } from "@/client/components/table/DataTable";
import { ExternalUrlCell } from "@/client/components/table/url";
import { SortableHeader } from "@/client/components/table/SortableHeader";
import {
@@ -85,7 +83,7 @@ function DomainPagesTableComponent({
// data-keyed memo, so _autoResetPageIndex fires each render and its setState
// schedules another one — an unbounded render loop that freezes the tab.
const tableData = useMemo(() => rows.slice(0, 100), [rows]);
- const table = useAppTable({
+ const table = useDataTable({
data: tableData,
columns,
});
diff --git a/src/client/features/keywords/page/KeywordResearchTable.tsx b/src/client/features/keywords/page/KeywordResearchTable.tsx
index 572d866e..4c33e91d 100644
--- a/src/client/features/keywords/page/KeywordResearchTable.tsx
+++ b/src/client/features/keywords/page/KeywordResearchTable.tsx
@@ -4,12 +4,12 @@ import {
type ColumnDef,
type RowSelectionState,
} from "@tanstack/react-table";
+import { AppDataTable } from "@/client/components/table/AppDataTable";
import {
- AppDataTable,
makeSelectionColumn,
- useAppTable,
+ useDataTable,
useSelectionAnchor,
-} from "@/client/components/table/AppDataTable";
+} from "@/client/components/table/DataTable";
import {
IntentBadge,
SortHeader,
@@ -181,7 +181,7 @@ export function KeywordResearchTable({
],
[selectAnchorRef, sortDir, sortField, toggleSort],
);
- const table = useAppTable({
+ const table = useDataTable({
data: filteredRows,
columns,
state: { rowSelection },
diff --git a/src/client/features/rank-tracking/KeywordSuggestionStep.tsx b/src/client/features/rank-tracking/KeywordSuggestionStep.tsx
index d1a8796a..9d665ea4 100644
--- a/src/client/features/rank-tracking/KeywordSuggestionStep.tsx
+++ b/src/client/features/rank-tracking/KeywordSuggestionStep.tsx
@@ -10,11 +10,11 @@ import { toast } from "sonner";
import { getDomainKeywordSuggestions } from "@/serverFunctions/domain";
import { addTrackingKeywords } from "@/serverFunctions/rank-tracking";
import { isLabsLocationCode } from "@/client/features/keywords/locations";
+import { AppDataTable } from "@/client/components/table/AppDataTable";
import {
- AppDataTable,
makeSelectionColumn,
- useAppTable,
-} from "@/client/components/table/AppDataTable";
+ useDataTable,
+} from "@/client/components/table/DataTable";
import { SortableHeader } from "@/client/components/table/SortableHeader";
import { RANK_TRACKING_HEADER_CLASS } from "./RankTrackingColumns";
import {
@@ -192,7 +192,7 @@ export function KeywordSuggestionStep({
}
}, [suggestionsQuery.data, hasInitialized]);
- const table = useAppTable({
+ const table = useDataTable({
data,
columns,
state: { rowSelection, sorting },
diff --git a/src/client/features/rank-tracking/RankTrackingColumns.tsx b/src/client/features/rank-tracking/RankTrackingColumns.tsx
index c737184c..63e0393b 100644
--- a/src/client/features/rank-tracking/RankTrackingColumns.tsx
+++ b/src/client/features/rank-tracking/RankTrackingColumns.tsx
@@ -1,6 +1,6 @@
import { useMemo, type MutableRefObject } from "react";
import type { ColumnDef } from "@tanstack/react-table";
-import { makeSelectionColumn } from "@/client/components/table/AppDataTable";
+import { makeSelectionColumn } from "@/client/components/table/DataTable";
import { ScoreBadge } from "@/client/components/table/ScoreBadge";
import { SortableHeader } from "@/client/components/table/SortableHeader";
import type { RankTrackingRow } from "@/types/schemas/rank-tracking";
diff --git a/src/client/features/rank-tracking/RankTrackingTable.tsx b/src/client/features/rank-tracking/RankTrackingTable.tsx
index b0d3061c..aa2cce9d 100644
--- a/src/client/features/rank-tracking/RankTrackingTable.tsx
+++ b/src/client/features/rank-tracking/RankTrackingTable.tsx
@@ -2,10 +2,8 @@ import { useCallback, useRef, useState } from "react";
import { toast } from "sonner";
import { FileDown, Loader2, Sheet, Trash2 } from "lucide-react";
import { Modal } from "@/client/components/Modal";
-import {
- AppDataTable,
- useAppTable,
-} from "@/client/components/table/AppDataTable";
+import { AppDataTable } from "@/client/components/table/AppDataTable";
+import { useDataTable } from "@/client/components/table/DataTable";
import {
TableBulkActionBar,
TableBulkActionButton,
@@ -77,7 +75,7 @@ export function RankTrackingTable({
locationName,
});
- const table = useAppTable({
+ const table = useDataTable({
data: rows,
columns,
state: { sorting },
diff --git a/src/client/features/reports/ReportsList.tsx b/src/client/features/reports/ReportsList.tsx
index e957339e..106a8f88 100644
--- a/src/client/features/reports/ReportsList.tsx
+++ b/src/client/features/reports/ReportsList.tsx
@@ -2,6 +2,14 @@ import { Link } from "@tanstack/react-router";
import { FileText, Trash2 } from "lucide-react";
import { EmptyState } from "@/client/components/EmptyState";
import { PortalMenu } from "@/client/components/PortalMenu";
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from "@/client/components/ui/table";
import { formatCreatedBy } from "@/client/features/reports/shared";
import { formatRelativeTime } from "@/client/lib/relative-time";
import type { ReportListItem } from "@/serverFunctions/reports";
@@ -28,42 +36,42 @@ export function ReportsList({
return (
<div className="space-y-3">
- <div className="overflow-x-auto rounded-lg border border-base-300">
- <table className="table table-sm">
- <thead>
- <tr>
- <th>Title</th>
- <th>Created by</th>
- <th>Type</th>
- <th>Updated</th>
- <th></th>
- </tr>
- </thead>
- <tbody>
+ <div className="rounded-lg border border-border">
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead>Title</TableHead>
+ <TableHead>Created by</TableHead>
+ <TableHead>Type</TableHead>
+ <TableHead>Updated</TableHead>
+ <TableHead />
+ </TableRow>
+ </TableHeader>
+ <TableBody>
{reports.map((report) => (
- <tr key={report.id} className="hover:bg-base-200">
- <td className="max-w-[420px]">
+ <TableRow key={report.id}>
+ <TableCell className="max-w-[420px]">
<Link
to="/p/$projectId/reports/$reportId"
params={{ projectId, reportId: report.id }}
- className="link link-hover font-medium"
+ className="font-medium hover:underline"
>
{report.title}
</Link>
- </td>
- <td className="text-base-content/70">
+ </TableCell>
+ <TableCell className="text-muted-foreground">
{formatCreatedBy(report)}
- </td>
+ </TableCell>
{/* The template the report was written from, else the skill
that produced it: what a reader needs to tell two reports
on the same site apart. */}
- <td className="text-base-content/70">
+ <TableCell className="text-muted-foreground">
{report.templateName ?? report.skill ?? "-"}
- </td>
- <td className="whitespace-nowrap text-base-content/70">
+ </TableCell>
+ <TableCell className="whitespace-nowrap text-muted-foreground">
{formatRelativeTime(report.updatedAt)}
- </td>
- <td className="w-10 text-right">
+ </TableCell>
+ <TableCell className="w-10 text-right">
<PortalMenu ariaLabel={`Actions for ${report.title}`}>
{(close) => (
<li>
@@ -80,14 +88,14 @@ export function ReportsList({
</li>
)}
</PortalMenu>
- </td>
- </tr>
+ </TableCell>
+ </TableRow>
))}
- </tbody>
- </table>
+ </TableBody>
+ </Table>
</div>
{reports.length === REPORT_APP_LIST_LIMIT ? (
- <p className="text-xs text-base-content/60">
+ <p className="text-xs text-muted-foreground">
Showing the {REPORT_APP_LIST_LIMIT} most recent reports.
</p>
) : null}
diff --git a/src/client/features/saved-keywords/SavedKeywordsFilterPanel.tsx b/src/client/features/saved-keywords/SavedKeywordsFilterPanel.tsx
index 4b45a1b2..390080f0 100644
--- a/src/client/features/saved-keywords/SavedKeywordsFilterPanel.tsx
+++ b/src/client/features/saved-keywords/SavedKeywordsFilterPanel.tsx
@@ -1,5 +1,10 @@
-import { Minus, Plus, RotateCcw, X } from "lucide-react";
+import { Minus, Plus, X } from "lucide-react";
import { useState, type KeyboardEvent } from "react";
+import {
+ DataTableFilterGroup,
+ DataTableFilterPanel,
+ DataTableRangeFilter,
+} from "@/client/components/table/DataTableToolbar";
import type { SavedKeywordsFilterValues } from "./savedKeywordsFilterTypes";
import type { SavedKeywordsFilterForm } from "./useSavedKeywordsFilters";
@@ -13,27 +18,7 @@ export function SavedKeywordsFilterPanel({
onReset: () => void;
}) {
return (
- <div className="space-y-3 border-b border-base-300 bg-gradient-to-b from-base-100 to-base-200/30 px-4 py-3">
- <div className="flex flex-wrap items-center justify-between gap-2">
- <div className="flex items-center gap-2">
- <p className="text-sm font-semibold">Refine results</p>
- {activeFilterCount > 0 ? (
- <span className="badge badge-xs badge-primary border-0 text-primary-content">
- {activeFilterCount} active
- </span>
- ) : null}
- </div>
- <button
- type="button"
- className="btn btn-xs btn-ghost gap-1"
- onClick={onReset}
- disabled={activeFilterCount === 0}
- >
- <RotateCcw className="size-3" />
- Clear all
- </button>
- </div>
-
+ <DataTableFilterPanel activeCount={activeFilterCount} onReset={onReset}>
<div className="grid grid-cols-1 gap-2 lg:grid-cols-2">
<TermsTokenInput
form={form}
@@ -76,7 +61,7 @@ export function SavedKeywordsFilterPanel({
max={100}
/>
</div>
- </div>
+ </DataTableFilterPanel>
);
}
@@ -127,17 +112,16 @@ function TermsTokenInput({
const Icon = styles.icon;
return (
- <div className="space-y-2 rounded-lg border border-base-300 bg-base-100 p-2.5">
- <div className="flex items-center gap-2">
+ <DataTableFilterGroup
+ label={label}
+ icon={
<span
className={`inline-flex size-4 items-center justify-center rounded ${styles.iconBg}`}
>
<Icon className="size-2.5" />
</span>
- <p className="text-[11px] font-semibold uppercase tracking-wide text-base-content/60">
- {label}
- </p>
- </div>
+ }
+ >
<form.Field name={name}>
{(field) => {
const terms = splitTerms(field.state.value);
@@ -164,7 +148,7 @@ function TermsTokenInput({
}
};
return (
- <div className="flex min-h-9 flex-wrap items-center gap-1.5 rounded-md border border-base-300 bg-base-200/30 px-2 py-1.5 focus-within:border-primary">
+ <div className="flex min-h-9 flex-wrap items-center gap-1.5 rounded-md border border-input px-2 py-1.5 focus-within:border-ring">
{terms.map((term) => (
<span
key={term}
@@ -189,13 +173,16 @@ function TermsTokenInput({
onKeyDown={handleKeyDown}
onBlur={addFromDraft}
placeholder={terms.length === 0 ? placeholder : ""}
- className="min-w-[6rem] flex-1 bg-transparent text-xs outline-none placeholder:text-base-content/40"
+ // data-slot opts out of the global 16px input rule, so the
+ // text matches the shadcn inputs: 16px on phones, 14px from md.
+ data-slot="input"
+ className="min-w-[6rem] flex-1 bg-transparent text-base outline-none placeholder:text-muted-foreground md:text-sm"
/>
</div>
);
}}
</form.Field>
- </div>
+ </DataTableFilterGroup>
);
}
@@ -221,61 +208,27 @@ function FilterRangeInputs({
min?: number;
max?: number;
}) {
+ const limits = { step, min, max };
return (
- <div className="space-y-2 rounded-lg border border-base-300 bg-base-100 p-2.5">
- <p className="text-[11px] font-semibold uppercase tracking-wide text-base-content/60">
- {title}
- </p>
- <div className="grid grid-cols-2 gap-2">
- <CompactRangeInput
- form={form}
- name={minName}
- placeholder="Min"
- step={step}
- min={min}
- max={max}
- />
- <CompactRangeInput
- form={form}
- name={maxName}
- placeholder="Max"
- step={step}
- min={min}
- max={max}
- />
- </div>
- </div>
- );
-}
-
-function CompactRangeInput({
- form,
- name,
- placeholder,
- step,
- min,
- max,
-}: {
- form: SavedKeywordsFilterForm;
- name: RangeFieldName;
- placeholder: string;
- step?: string;
- min?: number;
- max?: number;
-}) {
- return (
- <form.Field name={name}>
- {(field) => (
- <input
- className="input input-bordered input-xs bg-base-100"
- placeholder={placeholder}
- type="number"
- step={step}
- min={min}
- max={max}
- value={field.state.value}
- onChange={(event) => field.handleChange(event.target.value)}
- />
+ <form.Field name={minName}>
+ {(minField) => (
+ <form.Field name={maxName}>
+ {(maxField) => (
+ <DataTableRangeFilter
+ label={title}
+ min={{
+ ...limits,
+ value: minField.state.value,
+ onChange: (event) => minField.handleChange(event.target.value),
+ }}
+ max={{
+ ...limits,
+ value: maxField.state.value,
+ onChange: (event) => maxField.handleChange(event.target.value),
+ }}
+ />
+ )}
+ </form.Field>
)}
</form.Field>
);
diff --git a/src/client/features/saved-keywords/SavedKeywordsFilters.tsx b/src/client/features/saved-keywords/SavedKeywordsFilters.tsx
index 893f1248..efffe1ba 100644
--- a/src/client/features/saved-keywords/SavedKeywordsFilters.tsx
+++ b/src/client/features/saved-keywords/SavedKeywordsFilters.tsx
@@ -1,4 +1,7 @@
-import { SlidersHorizontal } from "lucide-react";
+import {
+ DataTableFilterToggle,
+ DataTableToolbar,
+} from "@/client/components/table/DataTableToolbar";
import { SavedKeywordsFilterPanel } from "./SavedKeywordsFilterPanel";
import { SavedKeywordsTagFilter } from "./SavedKeywordsTagFilter";
import type { TagColorKey } from "@/shared/tag-colors";
@@ -14,8 +17,7 @@ export function SavedKeywordsFilters({
availableTags,
selectedTagIds,
busyTagIds,
- onToggleTagFilter,
- onClearTagSelection,
+ onSelectedTagIdsChange,
onUpdateTag,
onDeleteTag,
}: {
@@ -27,8 +29,7 @@ export function SavedKeywordsFilters({
availableTags: SavedKeywordTagSummary[];
selectedTagIds: string[];
busyTagIds: Set<string>;
- onToggleTagFilter: (tagId: string) => void;
- onClearTagSelection: () => void;
+ onSelectedTagIdsChange: (tagIds: string[]) => void;
onUpdateTag: (input: {
tagId: string;
name?: string;
@@ -38,31 +39,31 @@ export function SavedKeywordsFilters({
}) {
return (
<>
- <div className="flex flex-wrap items-center justify-between gap-3 border-b border-base-300 px-4 py-2.5">
- <button
- type="button"
- className={`btn btn-ghost btn-sm gap-1.5 ${showFilters ? "btn-active" : ""}`}
- onClick={onToggleFilters}
- title="Toggle table filters"
- >
- <SlidersHorizontal className="size-3.5" />
- Filters
- {activeFilterCount > 0 ? (
- <span className="badge badge-xs badge-primary border-0 text-primary-content">
- {activeFilterCount}
- </span>
- ) : null}
- </button>
- <SavedKeywordsTagFilter
- availableTags={availableTags}
- selectedTagIds={selectedTagIds}
- busyTagIds={busyTagIds}
- onToggleTagFilter={onToggleTagFilter}
- onClearSelection={onClearTagSelection}
- onUpdateTag={onUpdateTag}
- onDeleteTag={onDeleteTag}
+ <DataTableToolbar
+ actions={
+ <SavedKeywordsTagFilter
+ availableTags={availableTags}
+ selectedTagIds={selectedTagIds}
+ busyTagIds={busyTagIds}
+ onToggleTagFilter={(tagId) =>
+ onSelectedTagIdsChange(
+ selectedTagIds.includes(tagId)
+ ? selectedTagIds.filter((id) => id !== tagId)
+ : [...selectedTagIds, tagId],
+ )
+ }
+ onClearSelection={() => onSelectedTagIdsChange([])}
+ onUpdateTag={onUpdateTag}
+ onDeleteTag={onDeleteTag}
+ />
+ }
+ >
+ <DataTableFilterToggle
+ open={showFilters}
+ activeCount={activeFilterCount}
+ onToggle={onToggleFilters}
/>
- </div>
+ </DataTableToolbar>
{showFilters ? (
<SavedKeywordsFilterPanel
diff --git a/src/client/features/saved-keywords/SavedKeywordsTable.tsx b/src/client/features/saved-keywords/SavedKeywordsTable.tsx
index b473a5b8..2fd0a8cd 100644
--- a/src/client/features/saved-keywords/SavedKeywordsTable.tsx
+++ b/src/client/features/saved-keywords/SavedKeywordsTable.tsx
@@ -5,14 +5,13 @@ import {
type RowSelectionState,
type SortingState,
} from "@tanstack/react-table";
-import { Search } from "lucide-react";
-import { useMemo } from "react";
+import { useMemo, type ReactNode } from "react";
import {
- AppDataTable,
+ DataTable,
makeSelectionColumn,
- useAppTable,
+ useDataTable,
useSelectionAnchor,
-} from "@/client/components/table/AppDataTable";
+} from "@/client/components/table/DataTable";
import { SortableHeader } from "@/client/components/table/SortableHeader";
import { ScoreBadge } from "@/client/components/table/ScoreBadge";
import { IntentBadge } from "@/client/features/keywords/components";
@@ -22,7 +21,6 @@ import {
formatSavedKeywordDate,
formatSavedKeywordNumber,
} from "./savedKeywordsUtils";
-import { Skeleton } from "@/client/components/ui/skeleton";
const columnHelper = createColumnHelper<SavedKeywordRow>();
@@ -32,16 +30,22 @@ export function SavedKeywordsTable({
sorting,
isLoading,
hasActiveFilters,
+ onClearFilters,
onRowSelectionChange,
onSortingChange,
+ toolbar,
+ footer,
}: {
rows: SavedKeywordRow[];
rowSelection: RowSelectionState;
sorting: SortingState;
isLoading: boolean;
hasActiveFilters: boolean;
+ onClearFilters: () => void;
onRowSelectionChange: OnChangeFn<RowSelectionState>;
onSortingChange: OnChangeFn<SortingState>;
+ toolbar: ReactNode;
+ footer: ReactNode;
}) {
const selectAnchorRef = useSelectionAnchor();
const columns = useMemo<ColumnDef<SavedKeywordRow>[]>(
@@ -110,7 +114,7 @@ export function SavedKeywordsTable({
<SortableHeader column={column} label="Last Fetched" />
),
cell: ({ getValue }) => (
- <span className="text-xs text-base-content/55">
+ <span className="text-xs text-muted-foreground">
{formatSavedKeywordDate(getValue())}
</span>
),
@@ -118,7 +122,7 @@ export function SavedKeywordsTable({
],
[selectAnchorRef],
);
- const table = useAppTable({
+ const table = useDataTable({
data: rows,
columns,
state: { rowSelection, sorting },
@@ -134,12 +138,17 @@ export function SavedKeywordsTable({
});
return (
- <AppDataTable
+ <DataTable
table={table}
- className="table table-sm"
isLoading={isLoading}
- loading={<SavedKeywordsSkeleton />}
- empty={<SavedKeywordsEmptyState hasActiveFilters={hasActiveFilters} />}
+ isFiltered={hasActiveFilters}
+ onClearFilters={onClearFilters}
+ empty={{
+ title: "No saved keywords yet",
+ description: "Use the Keyword Research page to find and save keywords.",
+ }}
+ toolbar={toolbar}
+ footer={footer}
/>
);
}
@@ -159,7 +168,7 @@ function normalizeIntent(value: string | null): KeywordIntent {
function TagList({ tags }: { tags: SavedKeywordRow["tags"] }) {
if (tags.length === 0) {
- return <span className="text-base-content/35">-</span>;
+ return <span className="text-muted-foreground">-</span>;
}
return (
<div className="flex flex-wrap gap-1">
@@ -169,40 +178,3 @@ function TagList({ tags }: { tags: SavedKeywordRow["tags"] }) {
</div>
);
}
-
-function SavedKeywordsSkeleton() {
- return (
- <div className="space-y-3" aria-busy>
- <Skeleton className="h-4 w-48" />
- {Array.from({ length: 8 }).map((_, index) => (
- <div key={index} className="grid grid-cols-9 items-center gap-3">
- <Skeleton className="h-4" />
- <Skeleton className="col-span-2 h-4" />
- <Skeleton className="h-4" />
- <Skeleton className="h-4" />
- <Skeleton className="h-4" />
- <Skeleton className="h-4" />
- <Skeleton className="h-4" />
- <Skeleton className="h-4" />
- </div>
- ))}
- </div>
- );
-}
-
-function SavedKeywordsEmptyState({
- hasActiveFilters,
-}: {
- hasActiveFilters: boolean;
-}) {
- return (
- <div className="py-12 text-center text-sm text-base-content/55">
- <Search className="mx-auto mb-2 size-8 opacity-40" />
- <p>
- {hasActiveFilters
- ? "No saved keywords match the current filters."
- : "No saved keywords yet. Use the Keyword Research page to find and save keywords."}
- </p>
- </div>
- );
-}
diff --git a/src/client/features/search-performance/SearchPerformanceColumns.tsx b/src/client/features/search-performance/SearchPerformanceColumns.tsx
index 30f25aff..caddcbc8 100644
--- a/src/client/features/search-performance/SearchPerformanceColumns.tsx
+++ b/src/client/features/search-performance/SearchPerformanceColumns.tsx
@@ -1,6 +1,6 @@
import { createColumnHelper, type ColumnDef } from "@tanstack/react-table";
import type { MutableRefObject } from "react";
-import { makeSelectionColumn } from "@/client/components/table/AppDataTable";
+import { makeSelectionColumn } from "@/client/components/table/DataTable";
import { SortableHeader } from "@/client/components/table/SortableHeader";
import { safeHttpUrl } from "@/shared/safe-url";
import type { SelectionAnchor } from "@/client/components/table/tableSelection";
diff --git a/src/client/features/search-performance/SearchPerformanceParts.tsx b/src/client/features/search-performance/SearchPerformanceParts.tsx
index 8e38f213..95cab97a 100644
--- a/src/client/features/search-performance/SearchPerformanceParts.tsx
+++ b/src/client/features/search-performance/SearchPerformanceParts.tsx
@@ -2,11 +2,11 @@ import { useMemo, useState } from "react";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { Copy, Loader2, Save } from "lucide-react";
import { toast } from "sonner";
+import { AppDataTable } from "@/client/components/table/AppDataTable";
import {
- AppDataTable,
- useAppTable,
+ useDataTable,
useSelectionAnchor,
-} from "@/client/components/table/AppDataTable";
+} from "@/client/components/table/DataTable";
import {
TableBulkActionBar,
TableBulkActionButton,
@@ -211,7 +211,7 @@ export function DimensionTable({
keyLabel: string;
}) {
const columns = useMemo(() => buildDimensionColumns(keyLabel), [keyLabel]);
- const table = useAppTable({
+ const table = useDataTable({
data: rows,
columns,
withSorting: true,
@@ -242,7 +242,7 @@ export function StrikingDistanceTable({
const anchorRef = useSelectionAnchor();
const [rowSelection, setRowSelection] = useState({});
const columns = useMemo(() => buildStrikingColumns(anchorRef), [anchorRef]);
- const table = useAppTable({
+ const table = useDataTable({
data: rows,
columns,
withSorting: true,
diff --git a/src/routes/_app/p/$projectId/saved.tsx b/src/routes/_app/p/$projectId/saved.tsx
index 8af7b250..0e7abd8b 100644
--- a/src/routes/_app/p/$projectId/saved.tsx
+++ b/src/routes/_app/p/$projectId/saved.tsx
@@ -320,67 +320,62 @@ function SavedKeywordsPage() {
onRefreshMetrics={() => refreshMetricsMutation.mutate()}
/>
- <div className="overflow-hidden rounded-lg border border-base-300 bg-base-100">
- <SavedKeywordsFilters
- filtersForm={filters.filtersForm}
- activeFilterCount={filters.activeFilterCount}
- showFilters={showFilters}
- onToggleFilters={() => setShowFilters((v) => !v)}
- onResetFilters={filters.resetFilters}
- availableTags={availableTags}
- selectedTagIds={selectedTagIds}
- busyTagIds={tagManage.busyTagIds}
- onToggleTagFilter={(tagId) => {
- setSelectedTagIds(
- selectedTagIds.includes(tagId)
- ? selectedTagIds.filter((id) => id !== tagId)
- : [...selectedTagIds, tagId],
- );
- }}
- onClearTagSelection={() => setSelectedTagIds([])}
- onUpdateTag={(input) => void tagManage.updateTag(input)}
- onDeleteTag={(tagId) => void handleDeleteTag(tagId)}
+ {removeError ? (
+ <RemoveSavedKeywordsError message={removeError} />
+ ) : null}
+ {savedKeywordsQuery.isError ? (
+ <QueryError
+ error={savedKeywordsQuery.error}
+ fallback="Failed to load saved keywords."
+ onRetry={() => void savedKeywordsQuery.refetch()}
+ isRetrying={isFetching}
/>
-
- <div className="space-y-3 p-4">
- {removeError ? (
- <RemoveSavedKeywordsError message={removeError} />
- ) : null}
- {savedKeywordsQuery.isError ? (
- <QueryError
- error={savedKeywordsQuery.error}
- fallback="Failed to load saved keywords."
- onRetry={() => void savedKeywordsQuery.refetch()}
- isRetrying={isFetching}
+ ) : null}
+ {/* Without data a failed load has nothing to show; the empty
+ state would claim there are no saved keywords. */}
+ {savedKeywordsQuery.isError && data === undefined ? null : (
+ <SavedKeywordsTable
+ rows={savedKeywords}
+ rowSelection={rowSelection}
+ sorting={sorting}
+ isLoading={isLoading}
+ hasActiveFilters={hasActiveFilters}
+ onClearFilters={() => {
+ filters.resetFilters();
+ setSelectedTagIds([]);
+ }}
+ onRowSelectionChange={setRowSelection}
+ onSortingChange={handleSortingChange}
+ toolbar={
+ <SavedKeywordsFilters
+ filtersForm={filters.filtersForm}
+ activeFilterCount={filters.activeFilterCount}
+ showFilters={showFilters}
+ onToggleFilters={() => setShowFilters((v) => !v)}
+ onResetFilters={filters.resetFilters}
+ availableTags={availableTags}
+ selectedTagIds={selectedTagIds}
+ busyTagIds={tagManage.busyTagIds}
+ onSelectedTagIdsChange={setSelectedTagIds}
+ onUpdateTag={(input) => void tagManage.updateTag(input)}
+ onDeleteTag={(tagId) => void handleDeleteTag(tagId)}
/>
- ) : null}
- {/* Without data a failed load has nothing to show; the empty
- state would claim there are no saved keywords. */}
- {savedKeywordsQuery.isError && data === undefined ? null : (
- <SavedKeywordsTable
- rows={savedKeywords}
- rowSelection={rowSelection}
- sorting={sorting}
- isLoading={isLoading}
- hasActiveFilters={hasActiveFilters}
- onRowSelectionChange={setRowSelection}
- onSortingChange={handleSortingChange}
+ }
+ footer={
+ <TablePagination
+ page={page}
+ pageSize={pageSize}
+ pageSizes={SAVED_KEYWORD_PAGE_SIZES}
+ totalCount={totalCount}
+ isLoading={isFetching}
+ onPageChange={(nextPage) => setSearch({ page: nextPage })}
+ onPageSizeChange={(nextPageSize) =>
+ setSearch({ size: nextPageSize, page: undefined })
+ }
/>
- )}
- </div>
-
- <TablePagination
- page={page}
- pageSize={pageSize}
- pageSizes={SAVED_KEYWORD_PAGE_SIZES}
- totalCount={totalCount}
- isLoading={isFetching}
- onPageChange={(nextPage) => setSearch({ page: nextPage })}
- onPageSizeChange={(nextPageSize) =>
- setSearch({ size: nextPageSize, page: undefined })
}
/>
- </div>
+ )}
<SavedKeywordsBulkActionBar
selectedCount={selectedCount}