popover-panel
A button that opens a small panel beside it: filters, a share menu, a colour picker, a few settings. On the native popover: a click outside or Escape closes it and focus returns to the button. It's placed below the button by CSS anchor positioning (flipping above when there's no room), or by script where that isn't supported. align is start or end. open is two-way.
Try it: events appear here (openchange).
Source: popover-panel.zb, and its registry item.
Install
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/popover-panel.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/popover-panel.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/popover-panel.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/popover-panel.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/popover-panel.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/popover-panel.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/popover-panel.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/popover-panel.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/popover-panel.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/popover-panel.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/popover-panel.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/popover-panel.json
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/popover-panel.js"></script>The compiled install writes src/components/zubra/popover-panel.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.
Usage
<popover-panel label="Share">
<p><strong>Share this recipe</strong></p>
<p><a href="#copy">Copy link</a></p>
<p><a href="#email">Email it</a></p>
</popover-panel>
<script type="module">
import './components/zubra/popover-panel.js';
const element = document.querySelector('popover-panel');
element.addEventListener('openchange', (event) => console.log('openchange', event.detail));
</script>import './components/zubra/popover-panel.js';
export function PopoverPanelExample() {
return (
<popover-panel
label="Share"
onopenchange={(event) => console.log('openchange', event.detail)}
>
<p><strong>Share this recipe</strong></p>
<p><a href="#copy">Copy link</a></p>
<p><a href="#email">Email it</a></p>
</popover-panel>
);
}<script setup>
import './components/zubra/popover-panel.js';
const onOpenchange = (event) => console.log('openchange', event.detail);
</script>
<template>
<popover-panel label="Share" @openchange="onOpenchange">
<p><strong>Share this recipe</strong></p>
<p><a href="#copy">Copy link</a></p>
<p><a href="#email">Email it</a></p>
</popover-panel>
</template>
<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) --><script>
import './components/zubra/popover-panel.js';
</script>
<popover-panel
label="Share"
onopenchange={(event) => console.log('openchange', event.detail)}
>
<p><strong>Share this recipe</strong></p>
<p><a href="#copy">Copy link</a></p>
<p><a href="#email">Email it</a></p>
</popover-panel>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/popover-panel.js';
@Component({
selector: 'app-popover-panel-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<popover-panel label="Share" (openchange)="onOpenchange($event)">
<p><strong>Share this recipe</strong></p>
<p><a href="#copy">Copy link</a></p>
<p><a href="#email">Email it</a></p>
</popover-panel>
`,
})
export class PopoverPanelExample {
onOpenchange(event: Event) {
console.log('openchange', (event as CustomEvent).detail);
}
}API
| Property | Type | Default |
|---|---|---|
open | boolean | false |
label | string | "Options" |
align | "start" | "end" | "start" |
| Event | When |
|---|---|
openchange | open changed; detail is the new value. |
| Slot | For |
|---|---|
(default) | The panel's content. |
Size
1.6 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 18.3 KB.