infoalloggi-monorepo/apps/infoalloggi/src/components/InformationBubble.tsx

90 lines
2.1 KiB
TypeScript
Raw Normal View History

2025-08-28 18:27:07 +02:00
import { ExternalLink } from "lucide-react";
import Link from "next/link";
import type { ReactNode } from "react";
2025-08-04 17:45:44 +02:00
import {
2025-08-28 18:27:07 +02:00
HybridTooltip,
HybridTooltipContent,
HybridTooltipTrigger,
2025-08-04 17:45:44 +02:00
} from "~/components/custom_ui/HybridTooltip";
import { IconMatrix, type IconType } from "~/components/IconComponents";
2025-08-28 18:27:07 +02:00
import { TooltipProvider } from "~/components/ui/tooltip";
import { cn } from "~/lib/utils";
2025-08-04 17:45:44 +02:00
/*
<TouchProvider>
<div className="relative">
<Button onClick={() => console.log("click")}>Azione </Button>
<InformationBubble href="/prezzi" txt="Informazioni sui prezzi" />
</div>
</TouchProvider>
*/
type ChildrenBubbleProps = {
2025-08-28 18:27:07 +02:00
children: ReactNode;
href?: undefined;
txt?: undefined;
target?: undefined;
2025-08-04 17:45:44 +02:00
};
type LinkBubbleProps = {
2025-08-28 18:27:07 +02:00
children?: undefined;
href: string;
txt: string;
target?: "_self" | "_blank" | "_parent" | "_top";
2025-08-04 17:45:44 +02:00
};
type InformationBubbleProps = {
2025-08-28 18:27:07 +02:00
className?: string;
iconClassName?: string;
icon?: IconType;
side?: "top" | "bottom" | "left" | "right";
2025-08-04 17:45:44 +02:00
} & (ChildrenBubbleProps | LinkBubbleProps);
const InformationBubble = ({
2025-08-28 18:27:07 +02:00
className,
icon = "circle-help",
iconClassName,
side,
children,
href,
txt,
target,
2025-08-04 17:45:44 +02:00
}: InformationBubbleProps) => {
2025-08-28 18:27:07 +02:00
return (
<TooltipProvider delayDuration={0}>
<HybridTooltip>
<HybridTooltipTrigger
className={cn(
`absolute -top-2 -right-2 flex size-6 items-center justify-center rounded-full bg-white`,
className,
)}
>
<IconMatrix
className={cn("size-6 text-indigo-500", iconClassName)}
2025-08-29 16:18:32 +02:00
type={icon}
2025-08-28 18:27:07 +02:00
/>
</HybridTooltipTrigger>
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
<HybridTooltipContent
className="border-border -mb-1.5 bg-white shadow-sm [&>span>svg]:invisible"
2025-08-29 16:18:32 +02:00
side={side}
2025-08-28 18:27:07 +02:00
>
{href ? (
<Link
2025-08-29 16:18:32 +02:00
className="flex items-center justify-center text-sm text-blue-500 underline-offset-2 hover:underline"
2025-08-28 18:27:07 +02:00
href={href}
target={target}
>
<ExternalLink className="mr-1 size-4" />
<p>{txt}</p>
</Link>
) : (
<>{children}</>
)}
</HybridTooltipContent>
</HybridTooltip>
</TooltipProvider>
);
2025-08-04 17:45:44 +02:00
};
export default InformationBubble;