Hover Card
Installation
npx shadcn@latest add https://uibrik.com/r/hover-card.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/hover-card/hover-card.tsx"use client"; // A preview card that opens while you rest on a link (a person, a repo, a // page) and stays while you move into it, so its own links can be used. It // waits before opening and before closing, so passing over a link does // nothing. Keyboard focus opens it too. import { AnimatePresence, motion } from "motion/react"; import { useEffect, useRef, useState, type ReactNode } from "react"; import { cn } from "@/lib/utils"; import { EASE_OUT, Portal, SURFACE, originFor, triggerBox, useAnchoredPosition, useDismiss, useLayer, type Align, type Side } from "../_overlay/overlay"; export type HoverCardProps = { /** The link or element that shows the card. */ children: ReactNode; content: ReactNode; side?: Side; align?: Align; /** Gap between trigger and card in px. */ offset?: number; /** Milliseconds of hover before it opens. */ openDelay?: number; /** Milliseconds after leaving before it closes. */ closeDelay?: number;
Adds the files to
components/uibrik/hover-card and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/hover-card.Props
HoverCard- side
- Type "bottom" | "top" | "right" | "left"
- "bottom"
- Preferred side. Flips when there isn't room.
- align
- Type "start" | "center" | "end"
- "center"
- Which part of the link the card lines up with.
- openDelay
- Type number
- 450
- Hover time before it opens.
- closeDelay
- Type number
- 200
- Time after leaving before it closes.
- childrenrequired
- Type ReactNode
- –
- The link or element that shows the card.
- contentrequired
- Type ReactNode
- –
- The card's contents.
- className
- Type string
- –
- Classes for the card.