Popover

A panel that floats beside the button that opens it, below it by default, for content that belongs next to it, here a PopoverHeader with its title and description.

import { Button } from "@produkto/ui/Button";
import {
  Popover,
  PopoverContent,
  PopoverDescription,
  PopoverHeader,
  PopoverTitle,
  PopoverTrigger,
} from "@produkto/ui/Popover";

const Example = () => (
  <Popover>
    <PopoverTrigger asChild>
      <Button>Button</Button>
    </PopoverTrigger>
    <PopoverContent>
      <PopoverHeader>
        <PopoverTitle>Title</PopoverTitle>
        <PopoverDescription>Description</PopoverDescription>
      </PopoverHeader>
    </PopoverContent>
  </Popover>
);

export default Example;

Usage

import { Button } from "@produkto/ui/Button";
import {
  Popover,
  PopoverContent,
  PopoverDescription,
  PopoverHeader,
  PopoverTitle,
  PopoverTrigger,
} from "@produkto/ui/Popover";
<Popover>
  <PopoverTrigger asChild>
    <Button>Button</Button>
  </PopoverTrigger>
  <PopoverContent>
    <PopoverHeader>
      <PopoverTitle>Title</PopoverTitle>
      <PopoverDescription>Description</PopoverDescription>
    </PopoverHeader>
  </PopoverContent>
</Popover>

Examples

Sizes

size sets the padding and the words at the same width: sm 6px in around 12px words, base 8px around 14px words (the default) or lg 12px around 16px words, the title and the description stepping with them; each button opens its own popover.

import { Button } from "@produkto/ui/Button";
import {
  Popover,
  PopoverContent,
  PopoverDescription,
  PopoverHeader,
  PopoverTitle,
  PopoverTrigger,
  type PopoverSize,
} from "@produkto/ui/Popover";

const sizes: { size: PopoverSize; label: string }[] = [
  { size: "sm", label: "Small" },
  { size: "base", label: "Base" },
  { size: "lg", label: "Large" },
];

const Example = () => (
  <div className="flex flex-wrap items-center gap-2">
    {sizes.map((item) => (
      <Popover key={item.size}>
        <PopoverTrigger asChild>
          <Button>{item.label}</Button>
        </PopoverTrigger>
        <PopoverContent size={item.size}>
          <PopoverHeader>
            <PopoverTitle>Title</PopoverTitle>
            <PopoverDescription>Description</PopoverDescription>
          </PopoverHeader>
          Content goes here.
        </PopoverContent>
      </Popover>
    ))}
  </div>
);

export default Example;

Border radius

borderRadius sets the panel's corners on the kit's one scale: none, xs 4px, sm 6px, base 8px, lg 12px (the default) or xl 16px; each button opens its own popover.

import { Button } from "@produkto/ui/Button";
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
  type PopoverBorderRadius,
} from "@produkto/ui/Popover";

const radii: PopoverBorderRadius[] = ["none", "xs", "sm", "base", "lg", "xl"];

const Example = () => (
  <div className="flex flex-wrap items-center gap-2">
    {radii.map((borderRadius) => (
      <Popover key={borderRadius}>
        <PopoverTrigger asChild>
          <Button>{borderRadius}</Button>
        </PopoverTrigger>
        <PopoverContent borderRadius={borderRadius}>
          Content goes here.
        </PopoverContent>
      </Popover>
    ))}
  </div>
);

export default Example;

Side

side opens the panel above, to the right of, below (the default) or to the left of its trigger, and it flips to the opposite side when there is no room.

import { Button } from "@produkto/ui/Button";
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
  type PopoverContentProps,
} from "@produkto/ui/Popover";

const sides: {
  side: NonNullable<PopoverContentProps["side"]>;
  label: string;
}[] = [
  { side: "top", label: "Top" },
  { side: "right", label: "Right" },
  { side: "bottom", label: "Bottom" },
  { side: "left", label: "Left" },
];

const Example = () => (
  <div className="flex flex-wrap items-center gap-2">
    {sides.map((item) => (
      <Popover key={item.side}>
        <PopoverTrigger asChild>
          <Button>{item.label}</Button>
        </PopoverTrigger>
        <PopoverContent side={item.side}>Content goes here.</PopoverContent>
      </Popover>
    ))}
  </div>
);

export default Example;

Align

align lines the panel up with the start, the centre or the end of its trigger; by default it takes the start or the end, after the half of the page the trigger sits in.

import { Button } from "@produkto/ui/Button";
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
  type PopoverContentProps,
} from "@produkto/ui/Popover";

const alignments: {
  align: NonNullable<PopoverContentProps["align"]>;
  label: string;
}[] = [
  { align: "start", label: "Start" },
  { align: "center", label: "Center" },
  { align: "end", label: "End" },
];

const Example = () => (
  <div className="flex flex-wrap items-center gap-2">
    {alignments.map((item) => (
      <Popover key={item.align}>
        <PopoverTrigger asChild>
          <Button>{item.label}</Button>
        </PopoverTrigger>
        <PopoverContent align={item.align}>Content goes here.</PopoverContent>
      </Popover>
    ))}
  </div>
);

export default Example;

Anchor

PopoverAnchor places the panel against another element, here the row that holds the trigger, rather than against the trigger itself.

import { Button } from "@produkto/ui/Button";
import {
  Popover,
  PopoverAnchor,
  PopoverContent,
  PopoverTrigger,
} from "@produkto/ui/Popover";

const Example = () => (
  <Popover>
    <PopoverAnchor className="flex w-full max-w-sm items-center justify-between gap-2">
      <span>Content goes here.</span>
      <PopoverTrigger asChild>
        <Button>Button</Button>
      </PopoverTrigger>
    </PopoverAnchor>
    <PopoverContent>Content goes here.</PopoverContent>
  </Popover>
);

export default Example;

API Reference

It takes the props of Radix Popover.Root.

PopoverTrigger

PopoverTriggerProps · takes the props of Radix Popover.Trigger

PopoverAnchor

PopoverAnchorProps · takes the props of Radix Popover.Anchor

PopoverContent

PopoverContentProps · also takes the props of Radix Popover.Content
PropTypeDefault
sizePopoverSize"sm" | "base" | "lg""base"
borderRadiusPopoverBorderRadius"none" | "xs" | "sm" | "base" | "lg" | "xl""lg"
scrollablebooleantrue
sideOffsetnumber8

PopoverHeader

PopoverHeaderProps · also takes the props of <div>
PropTypeDefault
borderedbooleanfalse

PopoverTitle

PopoverTitleProps · takes the props of <div>

PopoverDescription

PopoverDescriptionProps · takes the props of <p>