mirror of
https://github.com/hunvreus/basecoat.git
synced 2026-11-14 14:08:18 +00:00
168 lines
6.3 KiB
Plaintext
168 lines
6.3 KiB
Plaintext
---
|
|
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"}
|
|
) %}
|
|
<div class="grid gap-4">
|
|
<header class="grid gap-1.5">
|
|
<h4 class="leading-none font-medium">Dimensions</h4>
|
|
<p class="text-muted-foreground text-sm">Set the dimensions for the layer.</p>
|
|
</header>
|
|
<form class="form grid gap-2">
|
|
<div class="grid grid-cols-3 items-center gap-4">
|
|
<label for="demo-popover-width">Width</label>
|
|
<input type="text" id="demo-popover-width" value="100%" class="col-span-2 h-8"/>
|
|
</div>
|
|
<div class="grid grid-cols-3 items-center gap-4">
|
|
<label for="demo-popover-max-width">Max. width</label>
|
|
<input type="text" id="demo-popover-max-width" value="300px" class="col-span-2 h-8"/>
|
|
</div>
|
|
<div class="grid grid-cols-3 items-center gap-4">
|
|
<label for="demo-popover-height">Height</label>
|
|
<input type="text" id="demo-popover-height" value="25px" class="col-span-2 h-8"/>
|
|
</div>
|
|
<div class="grid grid-cols-3 items-center gap-4">
|
|
<label for="demo-popover-max-height">Max. height</label>
|
|
<input type="text" id="demo-popover-max-height" value="none" class="col-span-2 h-8"/>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
{% endcall %}
|
|
{% endset %}
|
|
|
|
{% set code_script %}
|
|
{# <script>
|
|
{% fetchCode "src/js/popover.js" %}
|
|
|
|
document.addEventListener('alpine:init', () => {
|
|
window.basecoat.registerPopover(Alpine);
|
|
});
|
|
</script> #}
|
|
{% endset %}
|
|
|
|
{{ code_preview("popover", code_script | prettyHtml ~ code_html | prettyHtml) }}
|
|
|
|
<h2 id="usage"><a href="#usage">Usage</a></h2>
|
|
|
|
<h3 id="usage-default"><a href="#usage-default">HTML + Javascript</a></h3>
|
|
|
|
<div class="alert my-6">
|
|
{% lucide "circle-alert" %}
|
|
<h2>This component requires Javascript.</h2>
|
|
</div>
|
|
|
|
<section class="prose">
|
|
<p>The component is structured as such:</p>
|
|
|
|
<ul>
|
|
<li>A <code><div class="popover"></code> which wraps around the entire component and holds it state (e.g. open/close).</li>
|
|
<li>A <code><button></code> that acts as the trigger to open or close the popover.</li>
|
|
<li>A <code><div data-popover></code> that holds the content of the popover.</li>
|
|
</ul>
|
|
|
|
<p>You can set up a few additional options on the <code><div data-popover></code> element:</p>
|
|
|
|
<ul>
|
|
<li><code>data-side</code> can be set to <code>top</code>, <code>bottom</code>, <code>left</code>, or <code>right</code> to change the side of the popover.</li>
|
|
<li><code>data-align</code> can be set to <code>start</code>, <code>center</code>, or <code>end</code> to change the alignment of the popover.</li>
|
|
</ul>
|
|
|
|
<p>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. <code class="text-xs">x-bind</code>, <code class="text-xs">x-data</code>, <code class="text-xs">@click</code>).</p>
|
|
</section>
|
|
|
|
<div class="flex flex-wrap gap-2 my-6">
|
|
<a class="badge-outline" href="/installation/#install-js">
|
|
Components with Javascript
|
|
{% lucide "arrow-right" %}
|
|
</a>
|
|
<a class="badge-outline" href="/installation/#install-cli">
|
|
Use the CLI
|
|
{% lucide "arrow-right" %}
|
|
</a>
|
|
<a class="badge-outline" href="https://github.com/hunvreus/basecoat/blob/main/src/js/popover.js" target="_blank">
|
|
Individual JS file (popover.js)
|
|
{% lucide "arrow-right" %}
|
|
</a>
|
|
</div>
|
|
|
|
{% 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) }}
|
|
|
|
<h3 id="usage-macro"><a href="#usage-macro">Jinja and Nunjucks</a></h3>
|
|
|
|
<div class="prose">
|
|
<p>You can use the <code class="relative rounded bg-muted px-[0.3rem] py-[0.2rem] font-mono text-xs">popover()</code> Nunjucks or Jinja macro for this component.</p>
|
|
</div>
|
|
|
|
<div class="flex flex-wrap gap-2 my-6">
|
|
<a class="badge-outline" href="/installation/#install-macros" target="_blank">
|
|
Use Nunjucks or Jinja macros
|
|
{% lucide "arrow-right" %}
|
|
</a>
|
|
<a class="badge-outline" href="https://github.com/hunvreus/basecoat/blob/main/src/jinja/popover.html.jinja" target="_blank">
|
|
Jinja macro
|
|
{% lucide "arrow-right" %}
|
|
</a>
|
|
<a class="badge-outline" href="https://github.com/hunvreus/basecoat/blob/main/src/nunjucks/popover.njk" target="_blank">
|
|
Nunjucks macro
|
|
{% lucide "arrow-right" %}
|
|
</a>
|
|
</div>
|
|
|
|
{% 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"]
|
|
) %}
|
|
<div class="grid gap-4">
|
|
<header class="grid gap-1.5">
|
|
<h4 class="leading-none font-medium">Dimensions</h4>
|
|
<p class="text-muted-foreground text-sm">Set the dimensions for the layer.</p>
|
|
</header>
|
|
<form class="form grid gap-2">
|
|
<div class="grid grid-cols-3 items-center gap-4">
|
|
<label for="demo-popover-width">Width</label>
|
|
<input type="text" id="demo-popover-width" value="100%" class="col-span-2 h-8"/>
|
|
</div>
|
|
<div class="grid grid-cols-3 items-center gap-4">
|
|
<label for="demo-popover-max-width">Max. width</label>
|
|
<input type="text" id="demo-popover-max-width" value="300px" class="col-span-2 h-8"/>
|
|
</div>
|
|
<div class="grid grid-cols-3 items-center gap-4">
|
|
<label for="demo-popover-height">Height</label>
|
|
<input type="text" id="demo-popover-height" value="25px" class="col-span-2 h-8"/>
|
|
</div>
|
|
<div class="grid grid-cols-3 items-center gap-4">
|
|
<label for="demo-popover-max-height">Max. height</label>
|
|
<input type="text" id="demo-popover-max-height" value="none" class="col-span-2 h-8"/>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
{% endcall %}{% endraw %}{% endset %}
|
|
{{ code_block(raw_code, "jinja") }} |