Components / Foundations
Popover
Component + managerDisplays content in a floating panel, either as a dropdown anchored to an element or a modal (center, panel, or full screen).
Live preview
Interactive exampleUsage
Import the component and its manager, then make it your own.
Component
PopoverManager
create_popover_manager<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
| Property | Type | Default | Description |
|---|---|---|---|
type | string | center | 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 | string | auto | 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 | string or null | null | ID of the DOM element to anchor the popover if type=dropdown. If not provided, popover uses an internally generated anchor. |
pt | number | 1 | Padding top in rem. |
pb | number | 1 | Padding bottom in rem. |
pl | number | 1 | Padding left in rem. |
pr | number | 1 | Padding right in rem. |
min_width | number | 50 | Minimum width in px. |
min_height | number | 50 | Minimum height in px. |
target_width | number or null | 400 | Intended popover width in px. If screen is smaller, popover might become 'full'. |
target_height | number or null | 400 | Intended popover height in px. If screen is smaller, might become 'full'. |
max_width | number or null | null | Max width in px. If null, it uses some responsive logic in CSS. |
max_height | number or null | null | Max height in px. If null, uses responsive logic in CSS. |
edge_forgiveness | number | 10 | Margin to keep from the screen edges in px when type=dropdown or similar. |
is_disabled | boolean | false | Disables any user interaction if true (not used in code sample). |
is_show_x | boolean | true | Whether to show an 'X' button in the top-right corner to close the popover. |
border_radius | number | 2 | Border radius in rem. |
background_color | string (CSS color) | var(--bg) | Background color of the popover. |
border_color | string (CSS color) | var(--shadow5-t) | Border color. |
contrast_color | string (CSS color) | var(--g14-t) | Used for text or stroke color if needed in code (not heavily used in the example). |
drop_color | string (CSS color) | var(--shadow8) | Used for box-shadow color around the popover. |
header | string or null | null | Optional header text displayed at the top of the popover. |
header_font_size | number | 2 | Header font size in rem. |
is_alt_content_shown | boolean | false | If true, the content_alt snippet is shown in place of main content. Often used to display success or alternate states. |
corner | string or null | null | Positions the popover in a corner if type='center'. |
panel_side | string | right | If type='panel', which side it slides from. |
can_swipe_close | boolean | false | If true, allows a user to swipe to close for certain types (like 'full' or 'panel'). |
on_open | function | — | Optional callback invoked when the popover is about to open. |
on_close | function | — | Optional callback invoked when the popover is about to close. |