Files
nanobot/webui/src/components/ConnectionBadge.tsx
T
chengyongru 30e43aec82 refactor(webui): separate presentation views and expand component gallery (#6179)
* refactor(webui): organize shared components with an internal gallery

* refactor(webui): decouple views and expand component gallery

* fix(docker): include channel sources in WebUI build

* refactor(webui): cover all channel interfaces in gallery

* docs(webui): remove manual paragraph wrapping
2026-10-14 00:11:00 +08:00

55 lines
1.5 KiB
TypeScript

import { useTranslation } from "react-i18next";
import { cn } from "@/lib/utils";
import type { ConnectionStatus } from "@/lib/types";
const COPY: Record<ConnectionStatus, { color: string }> = {
idle: { color: "text-muted-foreground" },
connecting: {
color: "text-amber-700 dark:text-amber-300",
},
open: {
color: "text-emerald-700 dark:text-emerald-400",
},
reconnecting: {
color: "text-amber-700 dark:text-amber-300",
},
closed: {
color: "text-muted-foreground",
},
error: {
color: "text-destructive",
},
};
export function ConnectionBadge({ status }: { status: ConnectionStatus }) {
const { t } = useTranslation();
const meta = COPY[status];
const pulsing =
status === "connecting" ||
status === "reconnecting" ||
status === "error";
const label = t(`connection.${status}`);
return (
<span
className={cn(
"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition-colors",
"text-muted-foreground/70 hover:bg-sidebar-accent/65",
meta.color,
)}
aria-live="polite"
role="status"
title={label}
>
<span className="relative flex h-2 w-2" aria-hidden>
{pulsing && (
<span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-current opacity-75" />
)}
<span className="relative inline-flex h-2 w-2 rounded-full bg-current" />
</span>
<span className="sr-only">{label}</span>
</span>
);
}