Skip to content
37 linesCodeBlameRaw
1import { HoverCard as Primitive } from "radix-ui";
2import type { ComponentProps } from "react";
3
4import { cn } from "../../lib/cn";
5
6// shadcn/ui's hover card, styled with g1t's tokens. It opens on hover and
7// keyboard focus, never on touch: a tap on its trigger does what the
8// trigger does. Hover hints (a label, nothing more) use the Tooltip.
9
10export function HoverCard({ openDelay = 450, closeDelay = 150, ...props }: ComponentProps<typeof Primitive.Root>) {
11 return <Primitive.Root openDelay={openDelay} closeDelay={closeDelay} {...props} />;
12}
13
14export const HoverCardTrigger = Primitive.Trigger;
15
16export function HoverCardContent({
17 className,
18 align = "start",
19 sideOffset = 6,
20 ...props
21}: ComponentProps<typeof Primitive.Content>) {
22 return (
23 <Primitive.Portal>
24 <Primitive.Content
25 align={align}
26 sideOffset={sideOffset}
27 collisionPadding={12}
28 className={cn(
29 "z-50 w-80 max-w-[calc(100vw-2rem)] rounded-xl border border-line-strong bg-raised p-4 text-sm text-fg shadow-xl shadow-black/40 outline-none",
30 "origin-(--radix-hover-card-content-transform-origin) data-[state=open]:animate-pop-in data-[state=closed]:animate-pop-out motion-reduce:animate-none",
31 className,
32 )}
33 {...props}
34 />
35 </Primitive.Portal>
36 );
37}