# GlassPopover

> A small refractive glass surface that unfolds straight out of its trigger button, holding quick controls, pickers or short details without leaving the page.

```tsx
import { AlarmClock, Moon, Sunrise } from "lucide-react";
import { useState } from "react";

import {
  GlassPopover,
  GlassPopoverClose,
  GlassPopoverContent,
  GlassPopoverDescription,
  GlassPopoverTitle,
  GlassPopoverTrigger,
} from "@vitrumui/react/popover";

const TIMES = [
  { id: "hour", label: "In an hour", icon: AlarmClock },
  { id: "tonight", label: "Tonight at 8", icon: Moon },
  { id: "tomorrow", label: "Tomorrow morning", icon: Sunrise },
] as const;

const COLS = 13;
const ROWS = 7;

const fade = (col: number, row: number) => {
  const distance = Math.hypot(
    (col - (COLS - 1) / 2) / (COLS / 2),
    (row - (ROWS - 1) / 2) / (ROWS / 2),
  );
  return Math.min(1, Math.max(0, (1 - distance) / 0.45));
};

export default function Demo() {
  const [picked, setPicked] = useState<string | null>(null);

  return (
    <div className="relative isolate flex h-96 w-full max-w-xl items-center justify-center">
      <div
        aria-hidden
        className="absolute top-1/2 left-1/2 -z-10 grid -translate-x-1/2 -translate-y-1/2 grid-cols-[repeat(13,40px)]"
      >
        {Array.from({ length: COLS * ROWS }, (_, i) => (
          <span
            key={i}
            className="relative size-10"
            style={{ opacity: fade(i % COLS, Math.floor(i / COLS)) }}
          >
            <span className="absolute inset-x-0 top-0 h-px bg-black/10 dark:bg-white/10" />
            <span className="absolute inset-y-0 left-0 w-px bg-black/10 dark:bg-white/10" />
          </span>
        ))}
      </div>
      <GlassPopover>
        <GlassPopoverTrigger>
          <AlarmClock />
          {TIMES.find((t) => t.id === picked)?.label ?? "Remind me"}
        </GlassPopoverTrigger>
        <GlassPopoverContent>
          <GlassPopoverTitle>Remind me</GlassPopoverTitle>
          <GlassPopoverDescription>
            We will send one notification, then leave you alone.
          </GlassPopoverDescription>
          <div className="flex flex-col gap-1.5">
            {TIMES.map(({ id, label, icon: Icon }) => (
              <GlassPopoverClose
                key={id}
                className="justify-start px-4"
                onClick={() => setPicked(id)}
              >
                <Icon />
                {label}
              </GlassPopoverClose>
            ))}
          </div>
        </GlassPopoverContent>
      </GlassPopover>
    </div>
  );
}
```

**Use it for**

- A compact picker, reminder scheduler, filter panel or detail card anchored to one button.
- Rich interactive content that does not fit a list of menu actions.

**Not for**

- A list of commands with keyboard arrow navigation: use Menu or Dropdown Menu.
- Full-screen forms or blocking confirmations: use a dialog.

```bash
npm install @vitrumui/react
```

> Trigger ARIA attributes, Escape-to-close, click-outside dismissal and positioning come from UI SDK (`@ui-sdk/core` and `@ui-sdk/react`).

## Usage

```tsx
import {
  GlassPopover,
  GlassPopoverContent,
  GlassPopoverTrigger,
} from '@vitrumui/react/popover'

<GlassPopover>
  <GlassPopoverTrigger>Remind me</GlassPopoverTrigger>
  <GlassPopoverContent side="bottom" align="center">
    <p className="font-semibold">Schedule reminder</p>
    <p className="mt-1 text-xs opacity-70">Choose when to be notified.</p>
  </GlassPopoverContent>
</GlassPopover>
```

The trigger wears Button's refractive glass; pressing it unfolds the glass body into a frosted panel right beside it, then pulls back into the button on close. Pass `open` and `onOpenChange` to control it from your own state, or let it manage itself with `defaultOpen`.

## API reference

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `open / defaultOpen / onOpenChange` | `boolean / boolean / (open: boolean) => void` | — | On `GlassPopover`: control open state yourself, or let it keep its own state. |
| `GlassPopoverTrigger asChild` | `boolean` | `false` | Attach the trigger props to its single child element instead of rendering a glass button. |
| `GlassPopoverContent side` | `'top' \| 'right' \| 'bottom' \| 'left'` | `'bottom'` | Which side of the trigger the surface unfolds on. Flips automatically if there is no room. |
| `GlassPopoverContent align` | `'start' \| 'center' \| 'end'` | `'center'` | Alignment along the chosen side. |
| `GlassPopoverContent sideOffset` | `number` | `10` | Gap in px between the trigger and the unfolded glass surface. |
| `GlassPopoverContent className` | `string` | — | Width, padding and corners (`rounded-*`). The glass surface matches the content box. |

## Accessibility

- Trigger carries `aria-expanded` and `aria-haspopup="dialog"` automatically.
- Pressing Escape or clicking outside closes the popover and returns focus to the trigger.
- With reduced motion it opens and closes immediately. Without WebGL2 it renders as a plain frosted panel.

Source: /docs/popover
