diff --git a/src/components/ui/DataTable.tsx b/src/components/ui/DataTable.tsx index ab60d48d..f638d1a9 100644 --- a/src/components/ui/DataTable.tsx +++ b/src/components/ui/DataTable.tsx @@ -4,6 +4,7 @@ import { Box, Card, Pagination, + Stack, Table, TableBody, TableCell, @@ -11,6 +12,8 @@ import { TableHead, TableRow, Typography, + useMediaQuery, + useTheme, } from "@mui/material"; import { ReactNode } from "react"; import { usePathname, useRouter, useSearchParams } from "next/navigation"; @@ -35,6 +38,8 @@ type DataTableProps = { page: number; perPage: number; }; + /** If provided, renders this instead of the table on xs/sm screens */ + mobileCard?: (row: T) => ReactNode; }; function PaginationBar({ page, perPage, total }: { page: number; perPage: number; total: number }) { @@ -72,7 +77,34 @@ export function DataTable({ loading = false, onRowClick, pagination, + mobileCard, }: DataTableProps) { + const theme = useTheme(); + const isMobile = useMediaQuery(theme.breakpoints.down("md")); + + const isEmpty = data.length === 0 && !loading; + + if (isMobile && mobileCard) { + return ( + + {isEmpty ? ( + + {emptyMessage} + + ) : ( + + {data.map((row) => ( + onRowClick(row) : undefined} sx={onRowClick ? { cursor: "pointer" } : undefined}> + {mobileCard(row)} + + ))} + + )} + {pagination && } + + ); + } + return ( @@ -91,7 +123,7 @@ export function DataTable({ - {data.length === 0 && !loading ? ( + {isEmpty ? ( {emptyMessage}