A stacked bar of figures whose multi-part segment lifts and unfolds a zoomed bar of its parts on hover, focus or tap; labels fit by width.
Click a figure: what it would open shows here.
$ npx shadcn@latest add @highcommand/pop-barCopies the source into your project and pulls in what it needs (4 other items). First time? Add the registry to components.json.
A stacked bar of figures: segments with parts lift out on hover, focus or tap and unfold a zoomed bar of their parts.
segmentsrequiredPopSegment[]—The bar's segments, in order; each is its figure's button.
labelrequiredstring—the bar's accessible name
hintReactNode—the quiet line under the bar at rest, under the hint segment; hidden while a segment is open
hintKeystring—the segment the hint sits under (default: the first one that pops)
caption(seg: PopSegment) => ReactNode—the zoomed bar's caption (default: a swatch, the segment's name, amount and share)
compactboolean—a shorter bar (the account profile)
testidstring—test id prefix: segments `${testid}-${key}`, the zoomed bar `${testid}-${key}-lens`, parts `${testid}-part-${key}`, hint `${testid}-hint`
classNamestring—Extra class on the bar's root.
classAliasstring—extra class prefix put next to every `pop-*` class (`mg-ds` gives `mg-ds-bar`, `mg-ds-seg`...), for selectors that predate PopBar
attrsRecord<string, string | undefined>—attributes for the root (`data-testid`, `data-variant`...)
onSelect(v: SourcedValue) => void—opens a segment's or part's records (default: the page's `CommandActionsProvider`)
usePop(zone: string, sticky?: boolean): { state: PopState; open: boolean; mounted: boolean; show: () => void; hide: () => void; hideSoon: () => void; lastPointer: RefObject<string>; inZone: (el: EventTarget | null) => boolean…Open on hover or focus, close a moment after the pointer leaves (so it can travel from the slice to the parts) or focus leaves, on Escape, and on a tap outside. Closing unmounts at once; what the eye sees leave is a ghost (motion.ts), none with reduced motion.
segmentLabel(s: Named & { share: number; hideName?: boolean | undefined; }, px: number): LabelTextA segment's label: the name with "amount · share", else the short name with them, else "amount · share", else the share, else nothing. `hideName`: the segment never prints its name (something next to the bar names it).
partLabel(p: Named, shareOfTotal: number, px: number): LabelTextA part's label in the zoomed bar. Its share is of the whole bar (as the caption reads), and when even "amount · share" does not fit it falls back to the amount alone (the caption then names the part in full).
spans(segments: readonly { key: string; share: number; }[]): Span[]Where each drawn segment sits along the bar (0..1). Segments with no share are not drawn; the shares are normalised over the drawn ones (so shares of a figure that do not add up to 1, such as costs over revenue when the margin is negative, still fill the bar). The 2 px gaps between segments are small enough to ignore here.
drawnParts<P extends { share: number; }>(segShare: number, parts: readonly P[]): (P & { shareOfTotal: number; })[]The parts drawn in the zoomed bar (those with a share of their segment), each with its share of the whole bar.
popVars(span: Span | undefined): Record<"--fa" | "--fb" | "--fo" | "--fs", string | number>CSS variables for the open (or hint-anchoring) segment: its start, end, centre, and its width as the zoom's starting scale.
pctText(share: number): stringThe share as a percentage: whole points from 10%, one decimal under it.
fits(text: string, px: number): booleanRough width of a label at 12px (Geist and Geist Mono average about 7 px a character), plus the segment's padding.
firstFit(options: string[], px: number): stringThe first option that fits, else nothing.
isPoppable(s: { share: number; parts?: readonly unknown[] | undefined; }): booleanA segment with two or more parts lifts and unfolds them; a segment that is not drawn (no share) never does.
hintSide(span: Span | undefined): "start" | "end"The at-rest hint runs from the segment's start, or ends at its end when the segment sits in the bar's right half.
Install this free piece now; the Pro pieces drop in on top of it, in the same app. Pro is $79 once.