Buff Bar

Active effects on the HUD. Each buff or debuff is a round icon with a countdown ring, a short time label ("4:32", "2h"), a stacks badge and a tooltip with the name, description, source and time left. Debuffs use the danger colour, and under 10 seconds an icon gently blinks. Timers use absolute end times.

View as Markdown

Well fed, a Rainy day debuff, a permanent Festival spirit with 3 stacks and a 12 second Tea break. onExpire removes each buff when its timer ends; the buttons add and refresh. Hover, focus or tap an icon.

Hover or focus an icon for details.

Installation

npx shadcn@latest add @cozy/buff-bar

Usage

import { BuffBar, type Buff } from "@/components/ui/buff-bar"

const buffs: Buff[] = [
  { id: "fed", name: "Well fed", icon: <BowlIcon />, endsAt: Date.now() + 120_000, duration: 120_000, source: "Rice dumplings" },
  { id: "rain", name: "Rainy day", kind: "debuff", endsAt: Date.now() + 45_000, duration: 45_000 },
  { id: "fest", name: "Festival spirit", stacks: 3 },
]

<BuffBar buffs={buffs} onExpire={(b) => removeBuff(b.id)} />

Without duration the ring starts full when the buff is first shown and empties until endsAt.

Tooltips open on hover and keyboard focus; a tap opens and closes them on touch screens. The component has its own TooltipProvider.

Reduced motion stops the blink and the ring transition.

Examples

Sizes, overflow and vertical

size, max with a "+n" chip that lists the rest, orientation="vertical" and sort="none".

API

Everything else is passed through to the underlying element or Radix primitive.

PropTypeDefaultDescription
buffsBuff<T>[]–{ id, name, label?, icon?, description?, kind?, stacks?, endsAt?, duration?, source?, data? }. No endsAt means permanent. `icon` is a React node or an image URL.
onExpire(buff) => void–Called once when a timer reaches 0. Remove the buff from `buffs`; until then it is hidden.
onSelect(buff) => void–Makes the icons buttons.
maxnumberallIcons shown; the rest go into a "+n" chip with a tooltip list.
size"sm" | "md" | "lg""md"40, 52 or 64 px icons.
orientation"horizontal" | "vertical""horizontal"Direction of the row.
sort"time" | "none""time""time": debuffs first, then the soonest to end, permanent last. "none" keeps your order.
emptyTextReactNode–Shown when empty. Without it the component renders nothing.
labelsPartial<BuffBarLabels>Englishbar, timeLeft ("{time} left"), permanent, debuff, source, more ("{count} more effects").