# Popover — SvelteKit UI

Package: sveltekit-ui 1.1.94

Page: https://www.sveltekit-ui.com/components/popover

Category: Foundations

Displays content in a floating panel, either as a dropdown anchored to an element or a modal (center, panel, or full screen).

Public component import: `Popover`

Public manager import: `create_popover_manager`

## Usage

```svelte
<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { Popover, create_popover_manager, Button, create_button_manager } from "sveltekit-ui"

  const manager = create_popover_manager({
    header: "Project details",
    type: "center",
    target_width: 420,
    target_height: 260,
  })

  const open_button = create_button_manager({
    text: "View project details",
    popover_target: () => "popover_" + manager.id,
  })
  const close_button = create_button_manager({
    text: "Done",
    on_click: () => manager.close(),
  })
</script>

<Button manager={open_button} />
<Popover {manager}>
  {#snippet content()}<p>The website is ready for review.</p>{/snippet}
  {#snippet footer()}<Button manager={close_button} />{/snippet}
</Popover>
```

## Configuration

### `type`

- type: string
- default: center
- allowed_values:
  - dropdown
  - center
  - full
  - panel
- description: Specifies the popover style. 'dropdown' anchors below an element, 'center' is a modal, 'full' slides up from bottom, 'panel' slides from a side.

### `popover_type`

- type: string
- default: auto
- allowed_values:
  - auto
  - manual
- description: Popover usage approach. If 'auto', uses the new HTML <dialog popover> attribute. If 'manual', you handle your own toggling. Not fully implemented in code example (it currently expects 'auto').

### `anchor_id`

- type: string or null
- default: null
- description: ID of the DOM element to anchor the popover if type=dropdown. If not provided, popover uses an internally generated anchor.

### `pt`

- type: number
- default: 1
- description: Padding top in rem.

### `pb`

- type: number
- default: 1
- description: Padding bottom in rem.

### `pl`

- type: number
- default: 1
- description: Padding left in rem.

### `pr`

- type: number
- default: 1
- description: Padding right in rem.

### `min_width`

- type: number
- default: 50
- description: Minimum width in px.

### `min_height`

- type: number
- default: 50
- description: Minimum height in px.

### `target_width`

- type: number or null
- default: 400
- description: Intended popover width in px. If screen is smaller, popover might become 'full'.

### `target_height`

- type: number or null
- default: 400
- description: Intended popover height in px. If screen is smaller, might become 'full'.

### `max_width`

- type: number or null
- default: null
- description: Max width in px. If null, it uses some responsive logic in CSS.

### `max_height`

- type: number or null
- default: null
- description: Max height in px. If null, uses responsive logic in CSS.

### `edge_forgiveness`

- type: number
- default: 10
- description: Margin to keep from the screen edges in px when type=dropdown or similar.

### `is_disabled`

- type: boolean
- default: false
- description: Disables any user interaction if true (not used in code sample).

### `is_show_x`

- type: boolean
- default: true
- description: Whether to show an 'X' button in the top-right corner to close the popover.

### `border_radius`

- type: number
- default: 2
- description: Border radius in rem.

### `background_color`

- type: string (CSS color)
- default: var(--bg)
- description: Background color of the popover.

### `border_color`

- type: string (CSS color)
- default: var(--shadow5-t)
- description: Border color.

### `contrast_color`

- type: string (CSS color)
- default: var(--g14-t)
- description: Used for text or stroke color if needed in code (not heavily used in the example).

### `drop_color`

- type: string (CSS color)
- default: var(--shadow8)
- description: Used for box-shadow color around the popover.

### `header`

- type: string or null
- default: null
- description: Optional header text displayed at the top of the popover.

### `header_font_size`

- type: number
- default: 2
- description: Header font size in rem.

### `is_alt_content_shown`

- type: boolean
- default: false
- description: If true, the content_alt snippet is shown in place of main content. Often used to display success or alternate states.

### `corner`

- type: string or null
- allowed_values:
  - tl
  - tr
  - bl
  - br
- default: null
- description: Positions the popover in a corner if type='center'.

### `panel_side`

- type: string
- default: right
- allowed_values:
  - right
  - left
- description: If type='panel', which side it slides from.

### `can_swipe_close`

- type: boolean
- default: false
- description: If true, allows a user to swipe to close for certain types (like 'full' or 'panel').

### `on_open`

- type: function
- description: Optional callback invoked when the popover is about to open.

### `on_close`

- type: function
- description: Optional callback invoked when the popover is about to close.

## Methods

### `open()`

- description: Opens the popover element (via showPopover).

### `close()`

- description: Closes the popover element (via hidePopover).

### `toggle()`

- description: Toggles the popover element (show/hide).

### `handle_before_toggle()`

- description: Internal method triggered by onbeforetoggle event. Tracks open/close state, calls on_open/on_close.

### `show_temp_message()`

- description: Displays a temporary success/error message overlay, optionally closing the popover afterward.
- parameters:
  - message: string to display
  - icon: string (optional icon, e.g. 'success', 'error')
  - ms: number (time in ms to keep message visible)
  - is_close_on_end: boolean (whether to close the popover at the end)
  - on_finish: callback function

## Returned state

### `id`

- type: string
- description: Unique ID for the popover.

### `is_show`

- type: boolean
- description: Tracks whether the popover is currently shown.

### `x_button_manager`

- type: object
- description: Button manager for the 'X' button in the top-right corner if is_show_x=true.

### `temp_message`

- type: object or null
- description: Used for ephemeral messaging overlay (like a success check).

### `positioning`

- type: object or null
- description: Used internally to store layout calculations, e.g. (popover_left_pos, popover_top_pos).

### `handle_screen_change`

- description: Function to recalc positions if screen size changes. Currently triggers on window scroll & resize.
