import React, { PropsWithChildren, useState } from "react"; import UnfoldMoreIcon from "@mui/icons-material/UnfoldMore"; import { Box, ButtonBase, Popover, Stack, TableCell, TableCellProps, Typography, TypographyProps, } from "@mui/material"; export interface TableHeadingProps extends PropsWithChildren { typographyProps?: TypographyProps; popover?: React.ReactNode; popoverLabel?: React.ReactNode; } export const TableHeading: React.FC = ({ children, typographyProps, popover, popoverLabel, ...props }) => { const [anchorEl, setAnchorEl] = useState(null); const headingText = ( {children} ); return ( {popover != null ? ( <> theme.transitions.create("opacity", { duration: theme.transitions.duration.shortest, }), zIndex: -1, pointerEvents: "none", }, "&:hover::before, &:focus-visible::before": { opacity: 1 }, "&:hover .popover-label, &:focus-visible .popover-label": { backgroundColor: "transparent", }, }} onClick={(e) => setAnchorEl(e.currentTarget)} > {headingText} {popoverLabel != null ? ( {popoverLabel} ) : null} setAnchorEl(null)} > {popover} ) : ( headingText )} ); }; export default TableHeading;