feat(mui): add DataTable rowSx per-row style escape hatch

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
BOHA
2026-06-07 00:31:28 +02:00
parent 3d1bd49ad6
commit 9ab2bd7ef2

View File

@@ -1,4 +1,5 @@
import type { ReactNode } from "react"; import type { ReactNode } from "react";
import type { SxProps, Theme } from "@mui/material/styles";
import Table from "@mui/material/Table"; import Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody"; import TableBody from "@mui/material/TableBody";
import TableCell from "@mui/material/TableCell"; import TableCell from "@mui/material/TableCell";
@@ -36,6 +37,8 @@ export interface DataTableProps<T> {
onRowClick?: (row: T) => void; onRowClick?: (row: T) => void;
/** When it returns true, the row is tinted with the error palette (danger highlight). */ /** When it returns true, the row is tinted with the error palette (danger highlight). */
rowDanger?: (row: T) => boolean; rowDanger?: (row: T) => boolean;
/** Per-row style escape hatch (merged last) for arbitrary status tints. */
rowSx?: (row: T) => SxProps<Theme>;
empty?: ReactNode; empty?: ReactNode;
/** Server-sort wiring: active key (matches a column's sortKey), direction, handler. */ /** Server-sort wiring: active key (matches a column's sortKey), direction, handler. */
sortBy?: string; sortBy?: string;
@@ -51,6 +54,7 @@ export default function DataTable<T>({
rowInactive, rowInactive,
onRowClick, onRowClick,
rowDanger, rowDanger,
rowSx,
empty, empty,
sortBy, sortBy,
sortDir, sortDir,
@@ -117,7 +121,9 @@ export default function DataTable<T>({
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
{rows.map((row) => ( {rows.map((row) => {
const extra = rowSx?.(row);
return (
<TableRow <TableRow
key={rowKey(row)} key={rowKey(row)}
hover hover
@@ -135,6 +141,7 @@ export default function DataTable<T>({
} }
: {}, : {},
rowInactive?.(row) ? { opacity: 0.55 } : {}, rowInactive?.(row) ? { opacity: 0.55 } : {},
...(Array.isArray(extra) ? extra : extra ? [extra] : []),
]} ]}
> >
{columns.map((c) => ( {columns.map((c) => (
@@ -160,7 +167,8 @@ export default function DataTable<T>({
</TableCell> </TableCell>
))} ))}
</TableRow> </TableRow>
))} );
})}
</TableBody> </TableBody>
</Table> </Table>
</TableContainer> </TableContainer>