Popover

Content that opens beside its trigger and closes when you click away.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/popover

Usage

import { buttonStyle } from "./ui/uicontext/components/Button.ts"import { Popover, PopoverTrigger } from "./ui/uicontext/components/Popover.ts"
const Message = UiSchema.TaggedEnum({ ToggledHelp: { open: Schema.Boolean } })export const Help = (h: Html.H<typeof Message.Type>, open: boolean) => [	PopoverTrigger(h, { target: "help", style: buttonStyle({ emphasis: "ghost" }) }).children("What's a cycle?"),	Popover(h, {		id: "help",		open,		label: "Cycles",		onToggle: (open) => Message.ToggledHelp({ open }),		children: [h.p.children("A cycle is a fixed stretch of time, usually two weeks, that a team plans work into.")],	}),]

Examples

Placements

placement picks the side; when there's no room there, the popover flips to the other side.

API reference

PopoverTriggerView function

Options

PopoverTrigger options
NameTypeDescription
targetrequiredstringThe id of the popover it opens and closes.
styleStyle | Style[]StyleX styles for the button: one style, or a list such as buttonStyle()

PopoverView function

Options

Popover options
NameTypeDefaultDescription
idrequiredstring—The popover's id, which its PopoverTrigger names as target.
openrequiredboolean—Whether it shows. The caller keeps it and follows onToggle.
onTogglerequired(open: boolean) => Message—The browser opened or closed it (its trigger, Escape, a click outside); the Model follows
placement"bottom-start" | "bottom-end" | "top-start" | "right-start"bottom-startWhere it opens beside its trigger; bottom-start by default.
labelstring—The popover's accessible name, when its content has no heading.
childrenrequiredView.Children—What the popover holds.
styleStyle—StyleX styles applied after the popover's own.

Accessibility

  • The trigger is a real button, and the popover is a dialog; give it a label when its content has no heading.
  • Escape, a click outside or another popover opening closes it, and focus goes back to the trigger.

Source