Popover
Display rich contextual content in an anchored floating panel. Popovers are ideal for previews, additional information, actions, and custom interactive content.
Quick Start
Use Popover to display floating content anchored to a trigger element.
1import { 2 Popover, 3 PopoverTrigger, 4 PopoverContent, 5} from "@ecos/ui"; 6 7<Popover> 8 <PopoverTrigger asChild> 9 <Button>Open Popover</Button> 10 </PopoverTrigger> 11 12 <PopoverContent>Additional information appears here.</PopoverContent> 13</Popover>
Basic Popover
Display simple contextual content when a trigger is activated.
1<Popover> 2 <PopoverTrigger asChild> 3 <Button>Product Details</Button> 4 </PopoverTrigger> 5 6 <PopoverContent>View additional product information.</PopoverContent> 7</Popover>
Rich Content
Popover content can contain any React elements including text, links, forms, and custom components.
1<Popover> 2<PopoverTrigger asChild> 3 <Button>Order Summary</Button> 4</PopoverTrigger> 5 6<PopoverContent> 7 <div className="space-y-2"> 8 <TypographyH4 className="font-medium">Order #12345</TypographyH4> 9 10 <TypographyP>Gold Sheet x2</TypographyP> 11 <TypographyP>Total: £250.00</TypographyP> 12 </div> 13</PopoverContent> 14</Popover>
Controlled Usage
Control the open state externally when integrating with application state.
1const [open, setOpen] = React.useState(false); 2 3<Popover 4 open={open} 5 onOpenChange={setOpen} 6> 7 <PopoverTrigger asChild> 8 <Button> 9 Toggle 10 </Button> 11 </PopoverTrigger> 12 13 <PopoverContent> 14 Controlled popover content. 15 </PopoverContent> 16</Popover>
Positioning
Control the placement and alignment of the popover relative to its trigger.
1<Popover> 2 <PopoverTrigger asChild> 3 <Button>Positioned Popover</Button> 4 </PopoverTrigger> 5 6 <PopoverContent 7 side="right" 8 align="start" 9 sideOffset={8} 10 > 11 Positioned content 12 </PopoverContent> 13</Popover>
Custom Width
Override the default width when displaying larger amounts of content.
1<Popover> 2 <PopoverTrigger asChild> 3 <Button> 4 Large Content 5 </Button> 6 </PopoverTrigger> 7 8 <PopoverContent className="w-96"> 9 Extended content area. 10 </PopoverContent> 11</Popover>
Anchored Popovers
Use PopoverAnchor when the positioning element is different from the trigger.
1<Popover> 2 <PopoverAnchor /> 3 4 <PopoverTrigger asChild> 5 <Button> 6 Open 7 </Button> 8 </PopoverTrigger> 9 10 <PopoverContent> 11 Anchored content. 12 </PopoverContent> 13</Popover>
Advanced Usage
Popovers can contain complex layouts, forms, cards, and interactive experiences.
1<Popover> 2 <PopoverTrigger asChild> 3 <Button>Profile</Button> 4 </PopoverTrigger> 5 6 <PopoverContent> 7 <Card> 8 <CardContent className="space-y-3 p-4"> 9 <Avatar> 10 ... 11 </Avatar> 12 13 <div> 14 <TypographyP className="font-medium"> 15 John Smith 16 </TypographyP> 17 18 <TypographyP> 19 john@example.com 20 </TypographyP> 21 </div> 22 23 <Button size="small">View Profile</Button> 24 </CardContent> 25 </Card> 26 </PopoverContent> 27</Popover>
API Reference
Popover
Property | Type | Default | Description |
|---|---|---|---|
| open | boolean | - | Controlled open state of the popover. |
| defaultOpen | boolean | false | Initial open state when uncontrolled. |
| onOpenChange | (open: boolean) => void | - | Called when the open state changes. |
| modal | boolean | false | Whether interaction outside the popover is disabled. |
PopoverTrigger
Property | Type | Default | Description |
|---|---|---|---|
| asChild | boolean | false | Merges trigger behaviour into a custom element. |
| children | ReactNode | - | Element used to open the popover. |
PopoverContent
Property | Type | Default | Description |
|---|---|---|---|
| align | "start" | "center" | "end" | "center" | Alignment relative to the trigger. |
| side | "top" | "right" | "bottom" | "left" | "bottom" | Preferred placement of the popover. |
| sideOffset | number | 4 | Distance between trigger and content. |
| avoidCollisions | boolean | true | Adjusts placement to remain visible within the viewport. |
| className | string | - | Additional classes applied to the content container. |
PopoverAnchor
Property | Type | Default | Description |
|---|---|---|---|
| asChild | boolean | false | Merges anchor behaviour into a custom element. |
| children | ReactNode | - | Custom anchor element used for positioning. |
Visual Reference
Variant | Preview |
|---|---|
| Basic | |
| Form | |
| Product Details | |
| Custom Width |