made PulseBox forwar a ref so it can be used with Tooltip

This commit is contained in:
Carter 2025-03-31 16:05:10 -06:00
parent fedb930e79
commit ca6f2ac400
2 changed files with 26 additions and 18 deletions

View file

@ -1,7 +1,7 @@
import { Box, BoxProps, Theme } from "@mui/material"; import { Box, BoxProps, Theme } from "@mui/material";
import { makeStyles } from "@mui/styles"; import { makeStyles } from "@mui/styles";
import classNames from "classnames"; import classNames from "classnames";
import { ReactNode } from "react"; import { forwardRef, ReactNode } from "react";
const useStyles = makeStyles((_theme: Theme) => ({ const useStyles = makeStyles((_theme: Theme) => ({
pulseWrapper: { pulseWrapper: {
@ -41,12 +41,13 @@ interface Props extends BoxProps {
className?: string; className?: string;
} }
export default function PulseBox(props: Props) { const PulseBox = forwardRef<HTMLDivElement, Props>((props, ref) => {
const { color, children, className, ...boxProps } = props; const { color, children, className, ...boxProps } = props;
const classes = useStyles() const classes = useStyles()
return ( return (
<Box <Box
ref={ref}
{...boxProps} {...boxProps}
className={classNames([classes.pulseWrapper, className])} className={classNames([classes.pulseWrapper, className])}
style={{ '--pulse-color': color } as React.CSSProperties} style={{ '--pulse-color': color } as React.CSSProperties}
@ -54,4 +55,9 @@ export default function PulseBox(props: Props) {
{children} {children}
</Box> </Box>
); );
}; });
// Optional: Add a display name for better debugging
PulseBox.displayName = "PulseBox";
export default PulseBox;

View file

@ -1,4 +1,4 @@
import { Grid2, Theme, Typography } from "@mui/material"; import { Grid2, Theme, Tooltip, Typography } from "@mui/material";
import { blue, orange } from "@mui/material/colors"; import { blue, orange } from "@mui/material/colors";
import { makeStyles } from "@mui/styles"; import { makeStyles } from "@mui/styles";
import { Device } from "models"; import { Device } from "models";
@ -16,7 +16,7 @@ const useStyles = makeStyles((theme: Theme) => {
box: { box: {
display: "inline-block", display: "inline-block",
borderRadius: "6px", borderRadius: "6px",
backgroundColor: lightMode ? "rgb(155, 155, 155)" : "rgb(34, 34, 34)", backgroundColor: lightMode ? "rgb(210, 210, 210)" : "rgb(50, 50, 50)",
padding: theme.spacing(0.75), padding: theme.spacing(0.75),
marginRight: "auto", marginRight: "auto",
margin: theme.spacing(1), margin: theme.spacing(1),
@ -47,10 +47,11 @@ export default function StatusPlenum(props: Props) {
}, []); }, []);
return ( return (
<Tooltip title={"Hello :)"}>
<PulseBox color={color} className={classes.box} > <PulseBox color={color} className={classes.box} >
<Grid2 container direction="column" > <Grid2 container direction="column" >
<Grid2> <Grid2>
<Typography variant="body2" style={{ color: orange[400]}}> <Typography variant="body2" style={{ color: orange[700]}}>
{device.status.plenum?.temperature.toFixed(1)}°C {device.status.plenum?.temperature.toFixed(1)}°C
</Typography> </Typography>
</Grid2> </Grid2>
@ -61,5 +62,6 @@ export default function StatusPlenum(props: Props) {
</Grid2> </Grid2>
</Grid2> </Grid2>
</PulseBox> </PulseBox>
</Tooltip>
) )
} }