| 1 | import { Tooltip as Primitive } from "radix-ui"; |
| 2 | import type { ComponentProps } from "react"; |
| 3 | |
| 4 | import { cn } from "../../lib/cn"; |
| 5 | |
| 6 | // shadcn/ui's tooltip, styled with g1t's tokens: the inverted bubble, the |
| 7 | // page's foreground behind the page's background colour, so it reads at a |
| 8 | // glance in either theme. Each tooltip carries its own provider, so one |
| 9 | // can be dropped in anywhere without setup. |
| 10 | |
| 11 | export function TooltipProvider({ delayDuration = 200, ...props }: ComponentProps<typeof Primitive.Provider>) { |
| 12 | return <Primitive.Provider delayDuration={delayDuration} {...props} />; |
| 13 | } |
| 14 | |
| 15 | export function Tooltip(props: ComponentProps<typeof Primitive.Root>) { |
| 16 | return ( |
| 17 | <TooltipProvider> |
| 18 | <Primitive.Root {...props} /> |
| 19 | </TooltipProvider> |
| 20 | ); |
| 21 | } |
| 22 | |
| 23 | export const TooltipTrigger = Primitive.Trigger; |
| 24 | |
| 25 | export function TooltipContent({ |
| 26 | className, |
| 27 | sideOffset = 6, |
| 28 | children, |
| 29 | ...props |
| 30 | }: ComponentProps<typeof Primitive.Content>) { |
| 31 | return ( |
| 32 | <Primitive.Portal> |
| 33 | <Primitive.Content |
| 34 | sideOffset={sideOffset} |
| 35 | className={cn( |
| 36 | "z-50 max-w-xs rounded-md bg-fg px-3 py-1.5 text-xs font-medium text-bg shadow-md text-balance", |
| 37 | "origin-(--radix-tooltip-content-transform-origin) animate-pop-in data-[state=closed]:animate-pop-out motion-reduce:animate-none", |
| 38 | className, |
| 39 | )} |
| 40 | {...props} |
| 41 | > |
| 42 | {children} |
| 43 | <Primitive.Arrow className="fill-fg" width={10} height={5} /> |
| 44 | </Primitive.Content> |
| 45 | </Primitive.Portal> |
| 46 | ); |
| 47 | } |