Skip to content
Haze UI

Spending Ring

Displays period spending in a centered segmented donut with dynamic active readout and a compact 2-column category legend.

pnpm dlx shadcn@latest add @haze/spending-ring
Open preview in a new tab
Livesmall script

When to use

  • Users inspect how monthly or period spending splits across up to six categories.
  • Highlighting a single category should update the center amount, share, and period-over-period note immediately.

When not to use

  • You need time-series trend lines across many months. Use line-chart or bar-chart instead.
  • More than six spending categories need side-by-side tabular ranking.

Installation

Add the Haze registry to components.json once, then install Spending Ring with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/spending-ring
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
periodstring"October spending"Period heading shown in the top-left of the card.
currencystring"USD"ISO 4217 currency code for formatting totals and category amounts.
categoriesSpendingCategory[]–Spending categories with label, amount, optional comparison note, and theme tone.
defaultActiveIndexnumber0Zero-based index of the initially highlighted category.
headingLevel2 | 3 | 43Heading level for the period title.
classstring–Additional classes on the outer card.

Keyboard interactions

Tab
Move focus across the category buttons and preview each segment in the center readout.
EnterSpace
Select a category and announce its amount, share, and comparison note.

Accessibility

  • Every category button exposes its exact label and rounded amount in text so color is never the sole cue.
  • Hovering, focusing, or clicking a category updates aria-pressed, active ring thickness, and the center readout, announcing clicks in a polite live region.
  • Without JavaScript, the initial active category, total spend, and full category grid remain visible.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Spending Ring" with `npx shadcn@latest add @haze/spending-ring`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import SpendingRing from "@/components/haze/ui/spending-ring.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/spending-ring.md

  • Customize with real content

    Adapt the Haze spending-ring ui for our product. Replace the demo values of these props with our real content: period, currency, categories, defaultActiveIndex, headingLevel, class. Keep the layout, the heading level rules and these accessibility details: Every category button exposes its exact label and rounded amount in text so color is never the sole cue. Hovering, focusing, or clicking a category updates aria-pressed, active ring thickness, and the center readout, announcing clicks in a polite live region. Without JavaScript, the initial active category, total spend, and full category grid remain visible. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using spending-ring, check it fits: use it when users inspect how monthly or period spending splits across up to six categories.; highlighting a single category should update the center amount, share, and period-over-period note immediately.. Avoid it when you need time-series trend lines across many months. use line-chart or bar-chart instead.; more than six spending categories need side-by-side tabular ranking.. Alternatives: @haze/donut-chart, @haze/usage-meter, @haze/split-bar.

Dependencies

  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog