add optional tooltip

This commit is contained in:
Alex Holliday committed 2025-08-28 12:21:23 -07:00
1 parent 0ad759a384
commit bda48e07f1
1 file changed
+48 -16
+48 -16
View File
@@ -7,6 +7,7 @@ import {
TableHead, TableHead,
TableRow, TableRow,
} from "@mui/material"; } from "@mui/material";
import Tooltip from "@mui/material/Tooltip";
import SkeletonLayout from "./skeleton"; import SkeletonLayout from "./skeleton";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
@@ -41,6 +42,7 @@ const DataTable = ({
data = [], data = [],
config = { config = {
emptyView: "No data", emptyView: "No data",
tooltipContent: null,
onRowClick: () => {}, onRowClick: () => {},
}, },
}) => { }) => {
@@ -101,24 +103,54 @@ const DataTable = ({
data.map((row) => { data.map((row) => {
const key = row.id || row._id || Math.random(); const key = row.id || row._id || Math.random();
return ( return (
<TableRow <Tooltip
key={key} key={key}
sx={config?.rowSX ?? {}} followCursor
onClick={config?.onRowClick ? () => config.onRowClick(row) : null} enterDelay={500}
enterNextDelay={500}
title={
typeof config.tooltipContent === "function"
? config.tooltipContent(row)
: config.tooltipContent
}
slotProps={{
tooltip: {
sx: {
background: "unset",
},
},
popper: {
modifiers: [
{
name: "offset",
options: {
offset: ({ popper }) => {
return [popper.width / 2 + 20, -popper.height / 8];
},
},
},
],
},
}}
> >
{headers.map((header, index) => { <TableRow
return ( sx={config?.rowSX ?? {}}
<TableCell onClick={config?.onRowClick ? () => config.onRowClick(row) : null}
align={index === 0 ? "left" : "center"} >
key={header.id} {headers.map((header, index) => {
onClick={header.onClick ? (e) => header.onClick(e, row) : null} return (
sx={header.getCellSx ? header.getCellSx(row) : {}} <TableCell
> align={index === 0 ? "left" : "center"}
{header.render(row)} key={header.id}
</TableCell> onClick={header.onClick ? (e) => header.onClick(e, row) : null}
); sx={header.getCellSx ? header.getCellSx(row) : {}}
})} >
</TableRow> {header.render(row)}
</TableCell>
);
})}
</TableRow>
</Tooltip>
); );
}) })
)} )}