--- layout: layouts/component.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 or Nunjucks id: usage-jinja --- {% from "macros/code_preview.njk" import code_preview %} {% from "macros/code_block.njk" import code_block %} {% from "components/popover.njk" import popover %} {% set code_html %} {% 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 %} {% endset %} {% set code_script %} {% include "components/popover-script.njk" %} {% endset %} {{ code_preview("combobox", code_script | prettyHtml ~ code_html | prettyHtml) }}

Usage

HTML + Javascript

{% lucide "circle-alert" %}

This component requires Javascript.

You will need to include the Javascript (Alpine.js) code provided below before the HTML code for this component. As with all interactive components, you will need to add some Alpine.js properties to certain elements (e.g. x-bind, x-data, @click).

The component is structured as such:

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

{% from "components/tabs.njk" import tabs %} {% set tabsets = [ { tab: "HTML", panel: code_block(code_html | prettyHtml) }, { tab: "Javascipt (Alpine.js)", panel: code_block(code_script | prettyHtml) } ] %} {{ tabs(id="popover", tabsets=tabsets) }}

Jinja or Nunjucks

If you use Jinja (or Nunjucks), you can use the popover() macro directly. Read more about using Basecoat with Jinja and Nunjucks.

{% 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") }}