g1t/apps/web/app/components/ui/tooltip.tsx
| 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. Each tooltip carries its |
| 7 | // own provider, so one can be dropped in anywhere without setup. |
| 8 | |
| 9 | export function TooltipProvider({ delayDuration = 200, ...props }: ComponentProps<typeof Primitive.Provider>) { |
| 10 | return <Primitive.Provider delayDuration={delayDuration} {...props} />; |
| 11 | } |
| 12 | |
| 13 | export function Tooltip(props: ComponentProps<typeof Primitive.Root>) { |
| 14 | return ( |
| 15 | <TooltipProvider> |
| 16 | <Primitive.Root {...props} /> |
| 17 | </TooltipProvider> |
| 18 | ); |
| 19 | } |
| 20 | |
| 21 | export const TooltipTrigger = Primitive.Trigger; |
| 22 | |
| 23 | export function TooltipContent({ |
| 24 | className, |
| 25 | sideOffset = 6, |
| 26 | children, |
| 27 | ...props |
| 28 | }: ComponentProps<typeof Primitive.Content>) { |
| 29 | return ( |
| 30 | <Primitive.Portal> |
| 31 | <Primitive.Content |
| 32 | sideOffset={sideOffset} |
| 33 | className={cn( |
| 34 | "z-50 max-w-xs rounded-md border border-line-strong bg-raised px-2.5 py-1.5 text-xs text-fg shadow-lg shadow-black/40", |
| 35 | "origin-(--radix-tooltip-content-transform-origin) animate-pop-in data-[state=closed]:animate-pop-out motion-reduce:animate-none", |
| 36 | className, |
| 37 | )} |
| 38 | {...props} |
| 39 | > |
| 40 | {children} |
| 41 | <Primitive.Arrow className="fill-raised" width={10} height={5} /> |
| 42 | </Primitive.Content> |
| 43 | </Primitive.Portal> |
| 44 | ); |
| 45 | } |