mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: add OverflowTip kit component
This commit is contained in:
@ -8,6 +8,7 @@ import { useTagStore } from "@/store/module";
|
|||||||
import { useTranslate } from "@/utils/i18n";
|
import { useTranslate } from "@/utils/i18n";
|
||||||
import { generateDialog } from "./Dialog";
|
import { generateDialog } from "./Dialog";
|
||||||
import Icon from "./Icon";
|
import Icon from "./Icon";
|
||||||
|
import OverflowTip from "./kit/OverflowTip";
|
||||||
|
|
||||||
type Props = DialogProps;
|
type Props = DialogProps;
|
||||||
|
|
||||||
@ -108,13 +109,14 @@ const CreateTagDialog: React.FC<Props> = (props: Props) => {
|
|||||||
{Array.from(tagNameList)
|
{Array.from(tagNameList)
|
||||||
.sort()
|
.sort()
|
||||||
.map((tag) => (
|
.map((tag) => (
|
||||||
<span
|
<OverflowTip
|
||||||
className="max-w-[120px] text-sm mr-2 mt-1 font-mono cursor-pointer truncate dark:text-gray-300 hover:opacity-60 hover:line-through"
|
|
||||||
key={tag}
|
key={tag}
|
||||||
onClick={() => handleDeleteTag(tag)}
|
className="max-w-[120px] text-sm mr-2 mt-1 font-mono cursor-pointer dark:text-gray-300 hover:opacity-60 hover:line-through"
|
||||||
>
|
>
|
||||||
#{tag}
|
<span className="w-full" onClick={() => handleDeleteTag(tag)}>
|
||||||
</span>
|
#{tag}
|
||||||
|
</span>
|
||||||
|
</OverflowTip>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
@ -135,13 +137,14 @@ const CreateTagDialog: React.FC<Props> = (props: Props) => {
|
|||||||
<>
|
<>
|
||||||
<div className="w-full flex flex-row justify-start items-start flex-wrap mb-2">
|
<div className="w-full flex flex-row justify-start items-start flex-wrap mb-2">
|
||||||
{shownSuggestTagNameList.map((tag) => (
|
{shownSuggestTagNameList.map((tag) => (
|
||||||
<span
|
<OverflowTip
|
||||||
className="max-w-[120px] text-sm mr-2 mt-1 font-mono cursor-pointer truncate dark:text-gray-300 hover:opacity-60"
|
|
||||||
key={tag}
|
key={tag}
|
||||||
onClick={() => handleUpsertTag(tag)}
|
className="max-w-[120px] text-sm mr-2 mt-1 font-mono cursor-pointer dark:text-gray-300 hover:opacity-60"
|
||||||
>
|
>
|
||||||
#{tag}
|
<span className="w-full" onClick={() => handleUpsertTag(tag)}>
|
||||||
</span>
|
#{tag}
|
||||||
|
</span>
|
||||||
|
</OverflowTip>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<Button size="sm" variant="outlined" onClick={handleSaveSuggestTagList}>
|
<Button size="sm" variant="outlined" onClick={handleSaveSuggestTagList}>
|
||||||
|
@ -139,7 +139,7 @@ const TagItemContainer: React.FC<TagItemContainerProps> = (props: TagItemContain
|
|||||||
</div>
|
</div>
|
||||||
{hasSubTags ? (
|
{hasSubTags ? (
|
||||||
<div
|
<div
|
||||||
className={`w-full flex flex-col justify-start items-start h-auto ml-5 pl-1 border-l-2 border-l-gray-200 dark:border-l-gray-400 ${
|
className={`w-[calc(100%-1rem)] flex flex-col justify-start items-start h-auto ml-4 pl-1 border-l-2 border-l-gray-200 dark:border-l-gray-400 ${
|
||||||
!showSubTags && "!hidden"
|
!showSubTags && "!hidden"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
|
31
web/src/components/kit/OverflowTip.tsx
Normal file
31
web/src/components/kit/OverflowTip.tsx
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
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;
|
Reference in New Issue
Block a user