-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e80c7ef
commit 724e9b5
Showing
60 changed files
with
1,666 additions
and
1,436 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { TooltipProps } from "@mui/material"; | ||
import { Tooltip, Typography, type TypographyProps } from "@mui/material"; | ||
import type { FC, ReactChild } from "react"; | ||
import { useEffect, useRef, useState } from "react"; | ||
|
||
export interface OverflowTypograpyProps extends TypographyProps { | ||
children: ReactChild; | ||
tooltipProps?: Omit<TooltipProps, "title" | "children">; | ||
} | ||
|
||
export const OverflowTypograpy: FC<OverflowTypograpyProps> = ({ | ||
children, | ||
tooltipProps, | ||
...props | ||
}) => { | ||
const ref = useRef<HTMLSpanElement>(null); | ||
const [tooltipEnabled, setTooltipEnabled] = useState(false); | ||
|
||
useEffect(() => { | ||
const compareSize = () => { | ||
if (ref.current) { | ||
const compare = ref.current.scrollWidth > ref.current.clientWidth; | ||
|
||
setTooltipEnabled(compare); | ||
} | ||
}; | ||
compareSize(); | ||
window.addEventListener("resize", compareSize); | ||
return () => window.removeEventListener("resize", compareSize); | ||
}, []); | ||
|
||
return ( | ||
<Tooltip | ||
title={children} | ||
disableHoverListener={!tooltipEnabled} | ||
{...tooltipProps} | ||
> | ||
<Typography | ||
ref={ref} | ||
noWrap | ||
overflow="hidden" | ||
textOverflow="ellipsis" | ||
{...props} | ||
> | ||
{children} | ||
</Typography> | ||
</Tooltip> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.