Popover
A popup with arbitrary content; menus are built from it.
Compose Popover.Trigger with a single trigger element (usually a Button) and Popover.Content. Put Popover.Item elements inside to get a menu — it closes itself after an item is chosen — or any other markup. placement sets the side and alignment (bottom-start by default, bottom-end, top, etc.); when space runs out the popup flips and shifts so it stays on screen. Control visibility with open and onOpenChange, move the popup to the end of body with portal, and add a search field with search on Popover.Content. When the trigger is a Button without its own rightIcon, Popover.Trigger adds a chevron on the right; turn this off with icon={false}.
Live example
Example controls
Usage
import { UserCircleIcon } from '@heroicons/react/24/outline';
import { Badge, Button, Popover } from '@prosazhin/pbcomponents';
<Popover placement='bottom-end'>
<Popover.Trigger>
<Button>Open menu</Button>
</Popover.Trigger>
<Popover.Content>
<Popover.Item
leftIcon={UserCircleIcon}
badge={<Badge color='secondary'>2</Badge>}
>
My orders
</Popover.Item>
<Popover.Item>Profile settings</Popover.Item>
<Popover.Item borderTop>Sign out</Popover.Item>
</Popover.Content>
</Popover>;Component API
Compound parts: Popover.Trigger, Popover.Content, Popover.Item.
| Prop | Type / variants | Purpose | Default |
|---|---|---|---|
children | ReactNode | Popover.Trigger with the trigger element and Popover.Content with the content. | — |
open | boolean | Controlled open state. | — |
defaultOpen | boolean | Initial open state when uncontrolled. | false |
onOpenChange | (open: boolean) => void | Called when the popup opens or closes. | — |
placement | PopoverPlacementtop · top-start · top-end · bottom · bottom-start · bottom-end · left · left-start · left-end · right · right-start · right-end | Side and alignment relative to the trigger: top, bottom-start, right-end, etc. The popup flips and shifts when space runs out. | bottom-start |
portal | boolean | Renders the popup into a portal at the end of body. | false |
Popover.Trigger.icon | boolean | Adds a chevron on the right of a Button trigger that has no rightIcon of its own. false keeps the button as is. | true |
Popover.Content.search | { value, onChange, placeholder? } | Search field above the content. | — |
Popover.Content.contentClassName | string | Class of the scrollable content area. | — |
Popover.Content.className | string | Class of the popup panel. | — |
Native HTML attributes are accepted where the component renders the corresponding element. className props only affect styling.