Components

Popover component

The kit:popover component displays contextual content above an activator. It is useful for providing additional information, options or secondary actions without overloading the main interface.

Popovers open dynamically from an activator and can be positioned in several directions: top, bottom, left or right. It is bindable and customizable in terms of theme, density, color, etc.

popover.svelte
<script lang="ts">
	import type { ModelPopoverProps } from 'lapikit/components';
</script>

<kit:popover>
	{#snippet activator({ toggle }: ModelPopoverProps)}
		<kit:btn variant="outline" onclick={(e: MouseEvent) => toggle(e.currentTarget as HTMLElement)}>
			Open popover
		</kit:btn>
	{/snippet}

	<div style="min-width: 14rem;">
		<p style="margin: 0 0 0.375rem; font-weight: 600;">Popover title</p>
		<p style="margin: 0; opacity: 0.7; font-size: 0.875rem;">
			Rich content can go here — links, buttons, or any component. Closes on click outside.
		</p>
	</div>
</kit:popover>

kit:popover renders the activator snippet inline and the panel in a fixed-position <div> when open. The panel position is computed from the activator’s bounding rect and updates on scroll and resize. Scrolling the page while a popover is open closes it automatically.

The activator snippet receives one argument:

activator(model: ModelPopoverProps)
  • model.toggle: (element: HTMLElement) => void

Examples of popover

position

  • position: 'top' | 'bottom' | 'left' | 'right' = 'bottom'
popover.svelte
<script lang="ts">
	import type { ModelPopoverProps } from 'lapikit/components';

	const positions = ['top', 'bottom', 'left', 'right'] as const;
</script>

<div style="display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center; padding: 3rem 0;">
	{#each positions as position (position)}
		<kit:popover {position}>
			{#snippet activator({ toggle }: ModelPopoverProps)}
				<kit:btn
					variant="outline"
					onclick={(e: MouseEvent) => toggle(e.currentTarget as HTMLElement)}>{position}</kit:btn
				>
			{/snippet}
			<p style="margin: 0;">Position: <strong>{position}</strong></p>
		</kit:popover>
	{/each}
</div>

The popover is displayed in the top layer of the page (Popover API): it is never cut by an overflow: hidden parent nor hidden behind a modal. It follows its activator when the page or a parent scrolls, flips to the opposite side when there is not enough space, and stays in the viewport.

Without preprocess Lapikit

If you aren’t using the Lapikit preprocessor in svelte.config.js, import the components directly:

import { Popover } from 'lapikit/components';

API Reference

kit:popover

propstypedescriptiondefault
ref $bindableHTMLElementBindable reference to the rendered DOM element.null
classstring | array | objectClasses of the popover, with the rules of Svelte (clsx).
stylestringInline style of the popover.
s-classstring | array | objectClasses of the popover, merged with class.
s-styleobjectInline style as an object of property / value pairs.
open $bindablebooleanControls visibility. Bindable.false
positionenum'top''bottom''left''right'Preferred position relative to the activator.'bottom'
roundedenum0'xs''sm''md''lg''xl''full'Border radius.'md'
colorstring | false | { base?, active? }Background color, the text follows its on- color or a contrasted color.
activatorSnippet<[model]>Trigger element. Receives model with toggle.
childrenSnippetFloating panel content.
elevationElevationStateenum'0''1''2''3''4''5'Add shadow effect.'2'
densityenum'dense''compact''default''comfortable''spacious'Padding, from -4px to +4px.'default'

ModelPopoverProps

The ModelPopoverProps interface provides the properties passed to the activator slot. It allows you to access the Popover’s current state (open), manipulate it dynamically (state) and retrieve the trigger element or linked event (element).

You can use it to create fully customized activators that finely control Popover opening/closing.

propstypedescription
openbooleanWhether the popover is currently open.
toggle(element: HTMLElement) => voidFunction to toggle the popover visibility. Call it with the trigger element to open/close the popover. The element is used for positioning the popover panel.

kit:popover are the ideal complement to Dialogs or Buttons in modern interfaces.