tooltip.tsx 1000 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use client";
  2. import type { ReactNode } from "react";
  3. import { cn } from "@/lib/utils";
  4. interface TooltipProps {
  5. content: ReactNode;
  6. children: ReactNode;
  7. side?: "top" | "bottom";
  8. className?: string;
  9. }
  10. /**
  11. * Minimal CSS-only tooltip: wraps any trigger element and reveals
  12. * `content` on hover or keyboard focus.
  13. */
  14. export function Tooltip({
  15. content,
  16. children,
  17. side = "top",
  18. className,
  19. }: TooltipProps) {
  20. return (
  21. <span className={cn("group/tooltip relative inline-flex", className)}>
  22. {children}
  23. <span
  24. role="tooltip"
  25. className={cn(
  26. "pointer-events-none absolute left-1/2 z-50 -translate-x-1/2 whitespace-nowrap rounded-md border border-border bg-popover px-2 py-1 text-xs text-foreground opacity-0 shadow-lg transition-opacity group-hover/tooltip:opacity-100 group-focus-within/tooltip:opacity-100",
  27. side === "top" ? "bottom-full mb-2" : "top-full mt-2",
  28. )}
  29. >
  30. {content}
  31. </span>
  32. </span>
  33. );
  34. }