All files / src/app/admin/components/_components InfoPopover.tsx

50% Statements 5/10
33.33% Branches 2/6
25% Functions 1/4
55.55% Lines 5/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 682x               202x 202x   202x   202x                                                                                                            
"use client";
 
import { COMPONENT_INFO, type ComponentMeta } from "@/lib/edc/component-info";
import { useState } from "react";
import { Info, X } from "lucide-react";
import { useT } from "@/lib/i18n/translate";
 
export function InfoPopover({ name }: { name: string }) {
  const t = useT("admin");
  const [open, setOpen] = useState(false);
  const meta: ComponentMeta | undefined = COMPONENT_INFO[name];
  Iif (!meta) return null;
 
  return (
    <span className="relative inline-block">
      <button
        onClick={(e) => {
          e.stopPropagation();
          setOpen(!open);
        }}
        className="text-(--text-secondary) hover:text-teal-800 dark:hover:text-teal-300 transition-colors p-0.5"
        title={t("Info: {name}", { name })}
      >
        <Info size={13} />
      </button>
      {open && (
        <>
          {/* Backdrop */}
          <div className="fixed inset-0 z-30" onClick={() => setOpen(false)} />
          {/* Popover */}
          <div className="absolute z-40 left-6 top-0 w-80 bg-(--surface-2) border border-(--border-ui) rounded-xl shadow-2xl p-4 text-xs space-y-2">
            <div className="flex items-center justify-between mb-1">
              <span className="font-semibold text-sm text-(--text-primary)">
                {name}
              </span>
              <button
                onClick={() => setOpen(false)}
                className="text-(--text-secondary) hover:text-(--text-primary)"
              >
                <X size={14} />
              </button>
            </div>
            <p className="text-(--text-secondary) leading-relaxed">
              {meta.description}
            </p>
            <div className="grid grid-cols-[80px_1fr] gap-y-1.5 gap-x-2 pt-1 border-t border-(--border)">
              <span className="text-(--text-secondary)">{t("Protocol")}</span>
              <span className="text-(--text-primary)">{meta.protocol}</span>
              <span className="text-(--text-secondary)">{t("Ports")}</span>
              <span className="text-(--text-primary) font-mono text-[11px]">
                {meta.ports}
              </span>
              <span className="text-(--text-secondary)">{t("Depends on")}</span>
              <span className="text-(--text-primary)">
                {meta.dependsOn.length > 0
                  ? meta.dependsOn.join(", ")
                  : t("None")}
              </span>
              <span className="text-(--text-secondary)">{t("Health")}</span>
              <span className="text-(--text-primary)">{meta.healthSource}</span>
            </div>
          </div>
        </>
      )}
    </span>
  );
}