Hover Card
A floating card that appears on element hover.
Installation
"use client";

import { forwardRef } from "react";
import { HoverCard as HoverCardPrimitives, Portal } from "@ark-ui/react";

const HoverCard = HoverCardPrimitives.Root;

const HoverCardTrigger = HoverCardPrimitives.Trigger;

const HoverCardContent = forwardRef<
  React.ElementRef<typeof HoverCardPrimitives.Content>,
  React.ComponentPropsWithoutRef<typeof HoverCardPrimitives.Content>
>(({ className, ...props }, ref) => (
  <Portal>
    <HoverCardPrimitives.Positioner>
      <HoverCardPrimitives.Content
        ref={ref}
        className={
          "border-base-100 bg-base-0 text-base-800 z-50 block w-max rounded-sm border p-4 shadow-md outline-none transition-all duration-200 data-[state=open]:visible data-[state=closed]:invisible data-[state=closed]:scale-95 data-[state=open]:scale-100 data-[state=closed]:opacity-0 data-[state=open]:opacity-100 " +
          className
        }
        {...props}
      />
    </HoverCardPrimitives.Positioner>
  </Portal>
));
HoverCardContent.displayName = HoverCardPrimitives.Content.displayName;

export { HoverCard, HoverCardTrigger, HoverCardContent };
Example
import {
  HoverCard,
  HoverCardContent,
  HoverCardTrigger,
} from "../core/hover-card";
import { Button } from "../core/button";
import { Avatar, AvatarFallback, AvatarImage } from "../core/avatar";

export const HoverCardExample = () => {
  return (
    <HoverCard>
      <HoverCardTrigger asChild>
        <Button variant="ghost">@nextjs</Button>
      </HoverCardTrigger>
      <HoverCardContent>
        <div className="flex w-80 justify-between space-x-4">
          <Avatar>
            <AvatarImage src="https://github.com/vercel.png" />
            <AvatarFallback>VC</AvatarFallback>
          </Avatar>
          <div className="space-y-1">
            <h4 className="text-sm font-semibold">@nextjs</h4>
            <p className="text-sm">
              The React Framework – created and maintained by @vercel.
            </p>
            <div className="flex items-center pt-2">
              <span className="text-muted-foreground text-xs">
                Joined December 2021
              </span>
            </div>
          </div>
        </div>
      </HoverCardContent>
    </HoverCard>
  );
};