---
title: "Popover · Base UI — StyleX Blocks"
description: "Anchored panels with header, body, and footer slots in four padding sizes."
url: "https://stylexblocks.com/components/base-ui/popover/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Popover

Anchored panels with header, body, and footer slots in four padding sizes.

- Behavior engine: Base UI
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/popover.md), [UI SDK](https://stylexblocks.com/components/ui-sdk/popover.md)
- Category: Display
- Sizes: xs, sm, md, lg
- HTML page: https://stylexblocks.com/components/base-ui/popover/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style base-ui
```

Then add the item as source you own:

```sh
npx stylexblocks add popover
```

Equivalent: `npx shadcn add @stylexblocks/popover`. Registry item JSON: https://stylexblocks.com/r/base-ui/popover.json

## Usage

```tsx
import { Popover } from "#components/ui/base-ui/popover.tsx";
import { Button } from "#components/ui/base-ui/button.tsx";

export function Example() {
  return (
    // size resolves once on Root; parts inherit it via context. Portal →
    // Positioner → Popup is Base UI's real overlay chain.
    <Popover.Root size="md">
      <Popover.Trigger render={<Button variant="surface" />}>
        Share settings
      </Popover.Trigger>
      <Popover.Portal>
        <Popover.Positioner sideOffset={8}>
          <Popover.Popup>
            <Popover.Title>Share this block</Popover.Title>
            <Popover.Description>
              Anyone with the link can view this block.
            </Popover.Description>
            <Popover.Footer>
              <Button variant="solid" size="sm">Copy link</Button>
            </Popover.Footer>
          </Popover.Popup>
        </Popover.Positioner>
      </Popover.Portal>
    </Popover.Root>
  );
}
```

## Source

`components/ui/base-ui/popover.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { Popover as BasePopover } from "@base-ui/react/popover";
import { createSlotRecipeContext } from "#lib/base-ui/create-slot-recipe-context.tsx";
import { defineSlotRecipe, resolveSlotStyles } from "#lib/recipe-props.ts";
import { semanticShadows } from "@stylexblocks/ui/semantic-tokens/shadows.stylex.ts";
import { durations } from '@stylexblocks/ui/tokens/durations.stylex.ts'
import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'
import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'
import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'
import { zIndices } from '@stylexblocks/ui/tokens/z-indices.stylex.ts'

const popoverContent = stylex.create({
  base: {
    position: 'relative',
    display: 'flex',
    flexDirection: 'column',
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    '--popover-bg': semanticColors.bgPanel,
    backgroundColor: 'var(--popover-bg)',
    '--popover-size': sizes.xs,
    '--popover-mobile-size': 'calc(100dvw - 1rem)',
    '--popover-z-index': zIndices.layer2,
    zIndex: 'calc(var(--popover-z-index) + var(--layer-index, 0))',
    outline: 'none',
    '--popover-radius': semanticRadii.panel,
    '--popover-concentric-radius':
      'max(0px, calc(var(--popover-radius) - var(--popover-padding)))',
    transformOrigin: 'var(--transform-origin)',
    animationName: {
      default: null,
      ':is([data-open], [data-state="open"])': 'scale-in, fade-in',
      ':is([data-closed], [data-state="closed"])': 'scale-out, fade-out',
    },
    animationDuration: {
      default: null,
      ':is([data-open], [data-state="open"])': durations.fast,
      ':is([data-closed], [data-state="closed"])': durations.faster,
    },
  },
})

const popoverContentSizes = stylex.create({
  xs: {
    '--popover-padding': spacing._3,
  },
  sm: {
    '--popover-padding': spacing._4,
  },
  md: {
    '--popover-padding': spacing._5,
  },
  lg: {
    '--popover-padding': spacing._6,
  },
})

const popoverHeader = stylex.create({
  base: {
    paddingInline: 'var(--popover-padding)',
    paddingTop: 'var(--popover-padding)',
  },
})

const popoverBody = stylex.create({
  base: {
    padding: 'var(--popover-padding)',
    flex: 1,
  },
})

const popoverFooter = stylex.create({
  base: {
    display: 'flex',
    alignItems: 'center',
    paddingInline: 'var(--popover-padding)',
    paddingBottom: 'var(--popover-padding)',
  },
})

const popoverArrow = stylex.create({
  base: {
    '--arrow-size': sizes._3,
    '--arrow-background': 'var(--popover-bg)',
  },
})

const popoverArrowTip = stylex.create({
  base: {
    borderTopWidth: '1px',
    borderInlineStartWidth: '1px',
  },
})

export type PopoverSize = keyof typeof popoverContentSizes

// defineSlotRecipe validates the shape at compile time: default values must
// exist in the axis maps, and slot keys must be `styles` or a declared axis
const popoverRecipe = defineSlotRecipe({
  slots: {
    content: { styles: popoverContent, sizes: popoverContentSizes },
    header: { styles: popoverHeader },
    body: { styles: popoverBody },
    footer: { styles: popoverFooter },
    arrow: { styles: popoverArrow },
    arrowTip: { styles: popoverArrowTip },
  },
  defaultVariants: { size: "md" },
});

// Local chrome the recipe leaves to the composition layer: the panel surface
// and a z-index that clears sticky page chrome — the generated `layer2` (10)
// would sit beneath a `z-index: 50` site header.
const chrome = stylex.create({
  content: {
    "--popover-z-index": zIndices.popover,
    width: "var(--popover-size)",
    maxWidth: "var(--popover-mobile-size)",
    borderRadius: "var(--popover-radius)",
    boxShadow: semanticShadows.overlay,
  },
});

const { withRootProvider, withContext } = createSlotRecipeContext(popoverRecipe);

/**
 * Popover — Base UI's popover machine wearing the popover slot recipe: real
 * portal (via `Popover.Portal`), anchor positioning, focus management, and
 * dismiss behavior all come from the engine's Portal → Positioner → Popup
 * chain. `<Popover.Root size>` resolves the recipe once; every part inherits
 * it through context and composes via `render`. Portal and Positioner stay
 * unstyled engine parts.
 */
export const Popover = {
  Root: withRootProvider(BasePopover.Root, "PopoverRoot"),
  Trigger: BasePopover.Trigger,
  Portal: BasePopover.Portal,
  Positioner: BasePopover.Positioner,
  Popup: withContext(
    BasePopover.Popup,
    (v) => [...resolveSlotStyles(popoverRecipe.slots.content, v), chrome.content],
    "PopoverPopup",
  ),
  Header: withContext("div", "header", "PopoverHeader"),
  Body: withContext("div", "body", "PopoverBody"),
  Footer: withContext("div", "footer", "PopoverFooter"),
  Title: withContext(BasePopover.Title, "header", "PopoverTitle"),
  Description: withContext(BasePopover.Description, "body", "PopoverDescription"),
  Close: BasePopover.Close,
  Arrow: withContext(BasePopover.Arrow, "arrow", "PopoverArrow"),
};
```
