Live preview

Interactive example

Loading example…

Usage

Import the component and its manager, then make it your own.

ComponentPopover
Managercreate_popover_manager

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>

API reference

Configure the manager, call its methods, and read its reactive state.

29 entries in configuration

PropertyTypeDefaultDescription
typestring centerSpecifies the popover style. 'dropdown' anchors below an element, 'center' is a modal, 'full' slides up from bottom, 'panel' slides from a side.
popover_typestring autoPopover 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_idstring or null nullID of the DOM element to anchor the popover if type=dropdown. If not provided, popover uses an internally generated anchor.
ptnumber 1Padding top in rem.
pbnumber 1Padding bottom in rem.
plnumber 1Padding left in rem.
prnumber 1Padding right in rem.
min_widthnumber 50Minimum width in px.
min_heightnumber 50Minimum height in px.
target_widthnumber or null 400Intended popover width in px. If screen is smaller, popover might become 'full'.
target_heightnumber or null 400Intended popover height in px. If screen is smaller, might become 'full'.
max_widthnumber or null nullMax width in px. If null, it uses some responsive logic in CSS.
max_heightnumber or null nullMax height in px. If null, uses responsive logic in CSS.
edge_forgivenessnumber 10Margin to keep from the screen edges in px when type=dropdown or similar.
is_disabledboolean falseDisables any user interaction if true (not used in code sample).
is_show_xboolean trueWhether to show an 'X' button in the top-right corner to close the popover.
border_radiusnumber 2Border radius in rem.
background_colorstring (CSS color) var(--bg)Background color of the popover.
border_colorstring (CSS color) var(--shadow5-t)Border color.
contrast_colorstring (CSS color) var(--g14-t)Used for text or stroke color if needed in code (not heavily used in the example).
drop_colorstring (CSS color) var(--shadow8)Used for box-shadow color around the popover.
headerstring or null nullOptional header text displayed at the top of the popover.
header_font_sizenumber 2Header font size in rem.
is_alt_content_shownboolean falseIf true, the content_alt snippet is shown in place of main content. Often used to display success or alternate states.
cornerstring or null nullPositions the popover in a corner if type='center'.
panel_sidestring rightIf type='panel', which side it slides from.
can_swipe_closeboolean falseIf true, allows a user to swipe to close for certain types (like 'full' or 'panel').
on_openfunction —Optional callback invoked when the popover is about to open.
on_closefunction —Optional callback invoked when the popover is about to close.