--- 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"] ) %}
Set the dimensions for the layer.
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:
<div class="popover"> which wraps around the entire component and holds it state (e.g. open/close).<button> that acts as the trigger to open or close the popover.<div data-popover> that holds the content of the popover.You can set up a few additional options on the <div data-popover> element:
data-side can be set to top, bottom, left, or right to change the side of the popover.data-align can be set to start, center, or end to change the alignment of the popover.If you use Jinja (or Nunjucks), you can use the popover() macro directly. Read more about using Basecoat with Jinja and Nunjucks.
Set the dimensions for the layer.