# Popover

A small panel that opens next to what people clicked.

```tsx
import { Popover } from '@halo-ds/react';
```

## When to use it
Use a popover for extra information or a quick task that belongs to one thing on the page, like sharing a link or changing a filter. It opens on click, points at its trigger with an arrow, and closes when people press Escape or click outside it.

## Do
- Open on click, not on hover.
- Keep the content short enough to fit without scrolling.
- Move focus into the popover when it opens.
- Pick the side with the most room, and flip near the edge of the screen.

## Don't
- Put a popover inside another popover.
- Use it for errors or for a decision that blocks the page; use a Modal.
- Hide important actions in a popover people may not open.
- Cover the trigger with the popover.

## Popover, Tooltip or Modal?
All three float above the page. Pick by what people need to do.
- **Popover**: Opens on click and stays open until closed. Can hold links, forms and Buttons. The page behind stays usable.
- **Tooltip or Modal**: Tooltip: a short label on hover or focus, with nothing to click. Modal: a bigger task or a decision that needs full attention. Modal blocks the page behind with an Overlay.

## Props
### Popover props
| Prop | Type | What it does |
| --- | --- | --- |
| `trigger` (required) | `ReactElement<unknown, string \| JSXElementConstructor<any>>` | The element that opens the popover, like a Button. |
| `side` | `Side \| undefined` | Which side of the trigger it opens on. Flips when there is no room. Figma: Placement. |
| `align` | `Align \| undefined` | How it lines up with the trigger along that side. |
| `arrow` | `boolean \| undefined` | Shows the arrow pointing at the trigger. Figma: Placement=None hides it. |
| `title` | `ReactNode` | Figma: Title. |
| `description` | `ReactNode` | Figma: Description. |
| `showClose` | `boolean \| undefined` | Shows a close button. Figma: Close. |
| `actions` | `ReactNode` | Buttons at the bottom right. Figma: Actions. |
| `open` | `boolean \| undefined` |  |
| `defaultOpen` | `boolean \| undefined` |  |
| `onOpenChange` | `((open: boolean) => void) \| undefined` |  |
| `children` | `ReactNode` | The body. Figma: Content slot. |
| `className` | `string \| undefined` |  |
| `classNames` | `Partial<Record<PopoverPart, string>> \| undefined` | Extra class names for the parts inside the component, by part name, like `{ header: 'my-header' }`. |
| `styles` | `Partial<Record<PopoverPart, CSSProperties>> \| undefined` | Inline styles for the parts inside the component, by part name, like `{ footer: { gap: 4 } }`. |
It also takes the usual HTML attributes for its element.

## Examples
### Overview
```tsx
import { Button, InputField, Popover } from '@halo-ds/react';

export default function Example() {
  return (
    <Popover
      trigger={<Button variant="secondary">Share</Button>}
      title="Share this file"
      description="Anyone with the link can view it."
      showClose
    >
      <InputField label="Invite by email" placeholder="name@company.com" />
    </Popover>
  );
}
```

### With actions
Buttons at the bottom right for a quick decision.
```tsx
import { Button, Popover } from '@halo-ds/react';

export default function Demo() {
  return (
    <Popover
      trigger={<Button variant="secondary">Archive</Button>}
      title="Archive this project?"
      description="You can bring it back from the archive at any time."
      actions={
        <>
          <Button variant="secondary" size="sm">Cancel</Button>
          <Button size="sm">Archive</Button>
        </>
      }
    />
  );
}
```

### Plain
No arrow and no close button, just content.
```tsx
import { Button, Popover } from '@halo-ds/react';

export default function Demo() {
  return (
    <Popover trigger={<Button variant="secondary">Details</Button>} arrow={false} showClose={false}>
      Last edited 2 hours ago by the design team.
    </Popover>
  );
}
```

More: https://halodesignsystem.dev/components/popover
