eleventy-plugin-popover
v0.9.0
Published
Eleventy plugin that defines a shortcode to create a `<toggle-popover>` custom element. It uses the Popover API declaratively.
Maintainers
Readme
eleventy-plugin-popover
A plugin for Eleventy, that defines a paired shortcode to create a <toggle-popover> custom element. It uses the Popover API declaratively.
eleventy.config.js:
import togglePopoverShortcode from 'eleventy-plugin-popover';
export default async function (eleventyConfig) {
// …
eleventyConfig.addPlugin(togglePopoverShortcode);
// …
}Shortcode Usage
Use the shortcode in your Liquid or Nunjucks template:
{% togglePopover 'Translations' %}
<nav aria-label="Translations">
<ul>
<li><a href="english.html" lang="en">English</a>
<li><a href="francais.html" lang="fr">Français</a>
<li><a href="#…" lang="…">…</a>
</ul>
</nav>
{% endtogglePopover %}Hamburger Popover Shortcode
There is also a hamburgerPopover shortcode:
{% hamburgerPopover 'Toggle menu' %}
<nav>
<ul>
<li><a href="pageOne">Page One</a>
<li><a href="pageTwo">Page Two</a>
<li><a href="pageThree…">Page Three …</a>
</ul>
</nav>
{% endhamburgerPopover %}Used APIs
This server-side JavaScript library builds on the follow Web APIs:
- Autonomous custom elements (Can I use? 96%)
- Declarative shadow DOM (Can I use? 94%)
- Popover API (Can I use? 88%)
- CSS Anchor Positioning (Can I use? 76%)
Why?
- The Popover API provides a way to open and close a popup or menu using declarative HTML attributes. No client-side JavaScript is required.
- Anchor positioning simplifies positioning one element in relation to another.
- Both of the above require uniqueness - unique
IDvalues and unique CSS variables. Declarative shadow DOM can provide uniqueness via encapsulation, without the need for client-side JavaScript.
License
- License: MIT
