Skip to contentVibraUI
Utilities

Popover

A floating panel anchored to a trigger, for a small form or detail.

Vibra draws the panel as the kit's elev-1 floating layer — popover plane, hairline ring, --shadow-float — and fades it in over --duration-base without shadcn's zoom, sliding 4px from its side rather than 8. PopoverHeader, PopoverTitle and PopoverDescription name it: the panel is a dialog, labelled by its title and described by its description. It opens on a click, a tap or Enter and stays until it is dismissed, so it is where information goes that a reader on a phone needs — a tooltip never opens under a finger. Escape and a click outside close it, and the focus returns to its trigger.

Install

npx shadcn@latest add @vibra/popover

Needs the @vibra registry in your components.json — set it up once.

Examples

Notifications

The bell's name carries the unread count, not only its dot; unread rows say so in words, and marking them read is announced.

Share

A report's link with a button that copies it, and who can open it, said right beside the link.

Explains a term

A definition that opens on a tap, a click or Enter and stays — the touch-proof twin of a tooltip — named by its title and described by the sentence.

A filter

An orders table's Amount chip: the chip says what is applied, a minimum above the maximum is refused in the panel, and Apply returns the focus to the chip.

A tour in steps

Three tips in one panel: each is read out as it replaces the last, Next keeps the focus, and Done closes the tour.

Props

PropTypeDefaultDescription
open / onOpenChangeboolean / (open: boolean) => void—Control it to close it from inside — an Apply that validates first, a tour's last step.
PopoverContent.initialFocusReact.RefObject<HTMLElement>—Where the focus goes as it opens — the first control by default; a tour's Next, not its disabled Back.
PopoverContent.side / align"top" | "bottom" | "inline-start" | "inline-end" | … / "start" | "center" | "end""bottom" / "center"Where it opens against the trigger; Base UI flips it when there is no room.

Dependencies

Source

components/ui/popover.tsx
"use client"

import * as React from "react"
import { Popover as PopoverPrimitive } from "@base-ui/react/popover"
import { cn } from "@/lib/utils"

function Popover({ ...props }: PopoverPrimitive.Root.Props) {
  return <PopoverPrimitive.Root data-slot="popover" {...props} />
}

function PopoverTrigger({ ...props }: PopoverPrimitive.Trigger.Props) {
  return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />
}

function PopoverContent({
  className,
  align = "center",
  alignOffset = 0,
  side = "bottom",
  sideOffset = 4,
  ...props
}: PopoverPrimitive.Popup.Props &
  Pick<
    PopoverPrimitive.Positioner.Props,
    "align" | "alignOffset" | "side" | "sideOffset"
  >) {
  return (
    <PopoverPrimitive.Portal>
      <PopoverPrimitive.Positioner
        align={align}
        alignOffset={alignOffset}
        side={side}
        sideOffset={sideOffset}
        className="isolate z-50"
      >
        <PopoverPrimitive.Popup
          data-slot="popover-content"
          className={cn(
            "z-50 flex w-72 origin-(--transform-origin) flex-col gap-2.5 elev-1 p-2.5 text-sm text-popover-foreground outline-hidden data-[side=bottom]:slide-in-from-top-1 data-[side=inline-end]:slide-in-from-left-1 data-[side=inline-start]:slide-in-from-right-1 data-[side=left]:slide-in-from-right-1 data-[side=right]:slide-in-from-left-1 data-[side=top]:slide-in-from-bottom-1 data-open:animate-in data-open:fade-in-0 data-open:duration-(--duration-base) data-open:ease-(--ease-standard) data-closed:animate-out data-closed:fade-out-0 data-closed:duration-(--duration-fast) data-closed:ease-(--ease-exit)",
            className
          )}
          {...props}
        />
      </PopoverPrimitive.Positioner>
    </PopoverPrimitive.Portal>
  )
}

function PopoverHeader({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="popover-header"
      className={cn("flex flex-col gap-0.5 text-sm", className)}
      {...props}
    />
  )
}

function PopoverTitle({ className, ...props }: PopoverPrimitive.Title.Props) {
  return (
    <PopoverPrimitive.Title
      data-slot="popover-title"
      className={cn("font-medium", className)}
      {...props}
    />
  )
}

function PopoverDescription({
  className,
  ...props
}: PopoverPrimitive.Description.Props) {
  return (
    <PopoverPrimitive.Description
      data-slot="popover-description"
      className={cn("text-muted-foreground", className)}
      {...props}
    />
  )
}

export {
  Popover,
  PopoverContent,
  PopoverDescription,
  PopoverHeader,
  PopoverTitle,
  PopoverTrigger,
}