--- layout: layouts/page.njk title: Popover description: Displays rich content in a portal, triggered by a button. toc: - label: Usage id: usage children: - label: HTML + Javascript id: usage-default - label: Jinja and Nunjucks id: usage-macro --- {% from "macros/code_preview.njk" import code_preview %} {% from "macros/code_block.njk" import code_block %} {% from "popover.njk" import popover %} {% set code_html %} {% call popover( id="demo-popover", trigger="Open popover", trigger_attrs={"class": "btn-outline"}, popover_attrs={"class": "w-80"} ) %}

Dimensions

Set the dimensions for the layer.

{% endcall %} {% endset %} {% set code_script %} {# #} {% endset %} {{ code_preview("popover", code_script | prettyHtml ~ code_html | prettyHtml) }}

Usage

HTML + Javascript

{% lucide "circle-alert" %}

This component requires Javascript.

The component is structured as such:

You can set up a few additional options on the <div data-popover> element:

You can include the Javascript code provided below, load it as an individual file or use the CLI. Some Alpine.js properties are also required on certain elements (e.g. x-bind, x-data, @click).

Components with Javascript {% lucide "arrow-right" %} Use the CLI {% lucide "arrow-right" %} Individual JS file (popover.js) {% lucide "arrow-right" %}
{% from "tabs.njk" import tabs %} {% set tabsets = [ { tab: "HTML", panel: code_block(code_html | prettyHtml, class="") }, { tab: "Javascipt (Alpine.js)", panel: code_block(code_script | prettyHtml, class="") } ] %} {{ tabs(id="popover", tabsets=tabsets) }}

Jinja and Nunjucks

You can use the popover() Nunjucks or Jinja macro for this component.

Use Nunjucks or Jinja macros {% lucide "arrow-right" %} Jinja macro {% lucide "arrow-right" %} Nunjucks macro {% lucide "arrow-right" %}
{% set raw_code %}{% raw %}{% call popover( id="demo-popover", trigger="Open popover", trigger_attrs={"class": "btn-outline"}, content_attrs={"class": "w-80 p-4"}, register_on=["alpine:init", "htmx:afterSwap"] ) %}

Dimensions

Set the dimensions for the layer.

{% endcall %}{% endraw %}{% endset %} {{ code_block(raw_code, "jinja") }}