Popover
A small panel that opens next to a button, for extra details or a quick form. Same markup and props in every style: switch the style in the header to see it change.
Basic
Text and a link. In HTML it's the browser's popover: button popovertarget opens it, Escape and a click outside close it.
Team plan
Up to 10 people share one theme and one set of components. Compare plans
<button type="button" class="vin-btn vin-btn--outline" popovertarget="pop-about">About this plan</button>
<div class="vin-popover" id="pop-about" popover role="dialog" aria-labelledby="pop-about-title" data-vin-popover>
<p class="vin-popover__title" id="pop-about-title">Team plan</p>
<p class="vin-popover__description">Up to 10 people share one theme and one set of components. <a class="vin-link" href="#">Compare plans</a></p>
</div>Team plan
Up to 10 people share one theme and one set of components. Compare plans
import { Popover } from "@/components/vin/popover";
import { Button } from "@/components/vin/button";
import { Link } from "@/components/vin/typography";
export function PopoverBasic() {
return (
<Popover
trigger={<Button variant="outline">About this plan</Button>}
title="Team plan"
description={<>Up to 10 people share one theme and one set of components. <Link href="#">Compare plans</Link></>}
/>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Popover from "@/components/vin/popover.vue";
import Button from "@/components/vin/button.vue";
import { Link } from "@/components/vin/typography.vue";
</script>
<template>
<Popover title="Team plan">
<template #trigger><Button variant="outline">About this plan</Button></template>
<template #description>Up to 10 people share one theme and one set of components. <Link href="#">Compare plans</Link></template>
</Popover>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Popover from "$lib/components/vin/popover.svelte";
import Button from "$lib/components/vin/button.svelte";
import Link from "$lib/components/vin/typography-link.svelte";
</script>
<Popover title="Team plan">
{#snippet trigger(props)}<Button variant="outline" {...props}>About this plan</Button>{/snippet}
{#snippet description()}Up to 10 people share one theme and one set of components. <Link href="#plans">Compare plans</Link>{/snippet}
</Popover>With a form
A few fields that apply at once.
Dimensions
Set the size of the layer.
<button type="button" class="vin-btn vin-btn--outline" popovertarget="pop-size">Dimensions</button>
<div class="vin-popover" id="pop-size" popover role="dialog" aria-labelledby="pop-size-title" data-vin-popover style="width: 260px">
<p class="vin-popover__title" id="pop-size-title">Dimensions</p>
<p class="vin-popover__description">Set the size of the layer.</p>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px">
<div class="vin-field">
<label class="vin-label" for="pop-w">Width</label>
<input id="pop-w" class="vin-input vin-input--sm" value="1200">
</div>
<div class="vin-field">
<label class="vin-label" for="pop-h">Height</label>
<input id="pop-h" class="vin-input vin-input--sm" value="800">
</div>
</div>
</div>Dimensions
Set the size of the layer.
import { Popover } from "@/components/vin/popover";
import { Button } from "@/components/vin/button";
import { Field } from "@/components/vin/input";
export function PopoverForm() {
return (
<Popover trigger={<Button variant="outline">Dimensions</Button>} title="Dimensions" description="Set the size of the layer." style={{ width: 260 }}>
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 10 }}>
<Field label="Width" size="sm" defaultValue="1200" />
<Field label="Height" size="sm" defaultValue="800" />
</div>
</Popover>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Popover from "@/components/vin/popover.vue";
import Button from "@/components/vin/button.vue";
import Field from "@/components/vin/input.vue";
</script>
<template>
<Popover title="Dimensions" description="Set the size of the layer." style="width: 260px">
<template #trigger><Button variant="outline">Dimensions</Button></template>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px">
<Field label="Width" size="sm" default-value="1200" />
<Field label="Height" size="sm" default-value="800" />
</div>
</Popover>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Popover from "$lib/components/vin/popover.svelte";
import Button from "$lib/components/vin/button.svelte";
import Field from "$lib/components/vin/input-field.svelte";
</script>
<Popover title="Dimensions" description="Set the size of the layer." style="width: 260px">
{#snippet trigger(props)}<Button variant="outline" {...props}>Dimensions</Button>{/snippet}
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px">
<Field label="Width" size="sm" value="1200" />
<Field label="Height" size="sm" value="800" />
</div>
</Popover>Share
A link to copy, lined up with the end of the button.
Installation
React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:
npx @vinish/ui add popoverimport { Popover } from "@/components/vin/popover";import Popover from "@/components/vin/popover.vue";import Popover from "$lib/components/vin/popover.svelte";The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.
Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.
API
From spec/popover.json, which every framework version is tested against.
| Prop | Values | Default | In HTML |
|---|---|---|---|
triggerThe button that opens it. | ReactElement | — | button[popovertarget="id"] |
title / description | ReactNode | — | .vin-popover__title, .vin-popover__description |
open / defaultOpenUse onOpenChange to hear about changes. | boolean | — | — |
side | toprightbottomleft | bottom | data-side on .vin-popover |
align | startcenterend | start | data-align on .vin-popover |
Parts
| React, Vue, Svelte | HTML classes |
|---|---|
<Popover> | .vin-popover.vin-popover__title.vin-popover__description |
Accessibility
- The panel is a dialog named by its title (aria-labelledby). The trigger says whether it is expanded.
- Escape closes it, as does a click outside; focus goes back to the trigger.
- Tab moves from the trigger into the panel, because it sits right after the trigger in the reading order.
- It isn't modal: the rest of the page still works. Use a Dialog when the user must answer first.
Customize
Saved in this browser. Style and accent are in the header.