mirror of
https://github.com/hamster1963/nezha-dash.git
synced 2025-04-24 21:10:45 +08:00
fix: server name mask
This commit is contained in:
parent
42c7acabb3
commit
8930cea0c4
@ -14,6 +14,7 @@ import { cn, formatBytes, formatNezhaInfo } from "@/lib/utils";
|
|||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
export default function ServerCard({
|
export default function ServerCard({
|
||||||
serverInfo,
|
serverInfo,
|
||||||
@ -26,9 +27,19 @@ export default function ServerCard({
|
|||||||
formatNezhaInfo(serverInfo);
|
formatNezhaInfo(serverInfo);
|
||||||
|
|
||||||
const showFlag = getEnv("NEXT_PUBLIC_ShowFlag") === "true";
|
const showFlag = getEnv("NEXT_PUBLIC_ShowFlag") === "true";
|
||||||
|
|
||||||
const showNetTransfer = getEnv("NEXT_PUBLIC_ShowNetTransfer") === "true";
|
const showNetTransfer = getEnv("NEXT_PUBLIC_ShowNetTransfer") === "true";
|
||||||
|
|
||||||
|
const nameRef = useRef<HTMLParagraphElement | null>(null);
|
||||||
|
const [isNameOverflow, setIsNameOverflow] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (nameRef.current) {
|
||||||
|
setIsNameOverflow(
|
||||||
|
nameRef.current.scrollWidth > nameRef.current.clientWidth,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, [name]);
|
||||||
|
|
||||||
return online ? (
|
return online ? (
|
||||||
<Link href={`/${id}`} prefetch={true}>
|
<Link href={`/${id}`} prefetch={true}>
|
||||||
<Card
|
<Card
|
||||||
@ -55,6 +66,7 @@ export default function ServerCard({
|
|||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<p
|
<p
|
||||||
|
ref={nameRef}
|
||||||
className={cn(
|
className={cn(
|
||||||
"break-all font-bold tracking-tight text-nowrap lg:max-w-[80px] overflow-x-scroll scrollbar-hidden pr-4",
|
"break-all font-bold tracking-tight text-nowrap lg:max-w-[80px] overflow-x-scroll scrollbar-hidden pr-4",
|
||||||
showFlag ? "text-[11px]" : "text-sm",
|
showFlag ? "text-[11px]" : "text-sm",
|
||||||
@ -62,7 +74,9 @@ export default function ServerCard({
|
|||||||
>
|
>
|
||||||
{name}
|
{name}
|
||||||
</p>
|
</p>
|
||||||
<div className="absolute inset-y-0 right-0 w-4 bg-gradient-to-l from-background to-transparent pointer-events-none" />
|
{isNameOverflow && (
|
||||||
|
<div className="absolute inset-y-0 right-0 w-4 bg-gradient-to-l from-background to-transparent pointer-events-none" />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipContent>
|
<TooltipContent>
|
||||||
@ -169,7 +183,9 @@ export default function ServerCard({
|
|||||||
>
|
>
|
||||||
{name}
|
{name}
|
||||||
</p>
|
</p>
|
||||||
<div className="absolute inset-y-0 right-0 w-4 bg-gradient-to-l from-background to-transparent pointer-events-none" />
|
{isNameOverflow && (
|
||||||
|
<div className="absolute inset-y-0 right-0 w-4 bg-gradient-to-l from-background to-transparent pointer-events-none" />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipContent>
|
<TooltipContent>
|
||||||
|
Loading…
Reference in New Issue
Block a user