You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
memos/web/src/components/kit/OverflowTip.tsx

32 lines
813 B
TypeScript

import { Tooltip } from "@mui/joy";
import classNames from "classnames";
import { useRef, useState, useEffect } from "react";
interface Props {
children: React.ReactNode;
className?: string;
}
const OverflowTip = ({ children, className }: Props) => {
const [isOverflowed, setIsOverflow] = useState(false);
const textElementRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!textElementRef.current) {
return;
}
setIsOverflow(textElementRef.current.scrollWidth > textElementRef.current.clientWidth);
}, []);
return (
<Tooltip title={children} placement="top" arrow disableHoverListener={!isOverflowed}>
<div ref={textElementRef} className={classNames("truncate", className)}>
{children}
</div>
</Tooltip>
);
};
export default OverflowTip;