Tooltip
NewInstallation
npx shadcn@latest add https://uibrik.com/r/tooltip.jsonInstall the packages
npm install motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/tooltip/tooltip.tsx"use client"; // A small label for icon buttons and toolbars. The first tooltip waits a // moment before it shows; once one is open, moving to a neighbour inside the // same <TooltipGroup> swaps instantly with no animation, so scanning a // toolbar feels immediate. It flips to the other side when there's no room // and stays inside the viewport. import { AnimatePresence, motion, useReducedMotion } from "motion/react"; import { createContext, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, type ReactNode, } from "react"; import { createPortal } from "react-dom"; import { cn } from "@/lib/utils"; const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1];
Adds the files to
components/uibrik/tooltip and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/tooltip.Props
Tooltip- side
- Type "top" | "bottom" | "left" | "right"
- "top"
- Preferred side. Flips when there isn't room.
- offset
- Type number
- 8
- Gap between trigger and tooltip.
- delay
- Type number
- 250
- Hover time before the first tooltip shows. Set on TooltipGroup when grouped.
- childrenrequired
- Type ReactElement
- –
- The trigger, usually a button.
- contentrequired
- Type ReactNode
- –
- What the tooltip says.
- shortcut
- Type string
- –
- A keyboard shortcut shown after the content, e.g. ⌘B.
- className
- Type string
- –
- Classes for the tooltip.
- <TooltipGroup delay skipDelay>
- Type component
- –
- Wrap a toolbar so that once one tooltip is open, neighbours open instantly. skipDelay (default 300ms) is how long that lasts after one closes.