Spend alert
Budget threshold card with live spend/forecast bar, range slider, Email/Slack/PagerDuty/Hard-stop toggles and live Slack alert preview.
pnpm dlx shadcn@latest add @haze/spend-alert---
import { BellRing, Check, Hash, ShieldAlert } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Props {
id?: string;
currentSpend?: number;
forecastSpend?: number;
initialThreshold?: number;
maxBudget?: number;
class?: string;
}
const {
id = "haze-spend-alert",
currentSpend = 420,
forecastSpend = 580,
initialThreshold = 500,
maxBudget = 1000,
class: className,
} = Astro.props;
const curPct = Math.round((currentSpend / maxBudget) * 100);
const forePct = Math.round((forecastSpend / maxBudget) * 100);
const thrPct = Math.round((initialThreshold / maxBudget) * 100);
---
<section aria-labelledby={`${id}-title`} data-haze-spend-alert data-max={maxBudget} class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
<div class="mx-auto max-w-2xl rounded-2xl border border-border bg-card p-5 sm:p-6">
<header class="flex flex-wrap items-center justify-between gap-2 border-b border-border pb-4">
<div class="flex items-center gap-2.5">
<span class="grid size-8 place-items-center rounded-lg border border-frame bg-muted text-muted-foreground" aria-hidden="true">
<BellRing class="size-4" />
</span>
<div>
<h2 id={`${id}-title`} class="text-base/6 font-semibold tracking-tight text-foreground">Budget & spend alert</h2>
<p class="text-xs/5 text-muted-foreground">Notify your team or pause metered calls at a monthly threshold.</p>
</div>
</div>
<span data-sa-val class="rounded-lg border border-frame bg-muted px-2.5 py-1 font-mono text-xs font-semibold text-foreground tabular-nums">${initialThreshold} / mo</span>
</header>
<div class="mt-5 space-y-3">
<div class="flex flex-wrap items-center justify-between gap-2 text-xs text-muted-foreground tabular-nums">
<span>Current: <strong class="text-foreground">${currentSpend}</strong></span>
<span>Forecast: <strong class="text-warning">${forecastSpend}</strong></span>
<span>Scale max: ${maxBudget}</span>
</div>
<div class="relative h-3 w-full overflow-hidden rounded-full bg-muted">
<div class="absolute inset-y-0 left-0 rounded-full bg-warning/35" style={`width: ${forePct}%`}></div>
<div class="absolute inset-y-0 left-0 rounded-full bg-primary" style={`width: ${curPct}%`}></div>
<div data-sa-marker class="absolute inset-y-0 w-0.5 bg-foreground" style={`left: ${thrPct}%`}></div>
</div>
<div class="grid gap-1.5">
<label for={`${id}-range`} class="text-xs font-medium text-foreground">Alert threshold ($100 – ${maxBudget})</label>
<input id={`${id}-range`} data-sa-range type="range" min="100" max={maxBudget} step="25" value={initialThreshold} class="w-full accent-ring" />
</div>
</div>
<div class="mt-5 grid gap-2 sm:grid-cols-2">
<label class="flex cursor-pointer items-center justify-between gap-2 rounded-xl border border-border bg-muted/40 px-3.5 py-2.5 text-xs text-foreground">
<span>Email finance admins</span>
<span class="relative inline-grid size-4 shrink-0 place-items-center"><input type="checkbox" checked class="peer col-start-1 row-start-1 size-4 shrink-0 cursor-pointer appearance-none rounded-sm border border-border-strong bg-field transition-[background-color,border-color,scale] duration-150 ease-snappy hover:border-foreground active:scale-90 checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring forced-colors:appearance-auto" /><Check class="pointer-events-none col-start-1 row-start-1 size-3 scale-50 text-primary-foreground opacity-0 transition-[opacity,scale] duration-200 ease-spring peer-checked:scale-100 peer-checked:opacity-100 forced-colors:hidden" stroke-width={3} aria-hidden="true" /></span>
</label>
<label class="flex cursor-pointer items-center justify-between gap-2 rounded-xl border border-border bg-muted/40 px-3.5 py-2.5 text-xs text-foreground">
<span>Slack #billing-alerts</span>
<span class="relative inline-grid size-4 shrink-0 place-items-center"><input type="checkbox" checked class="peer col-start-1 row-start-1 size-4 shrink-0 cursor-pointer appearance-none rounded-sm border border-border-strong bg-field transition-[background-color,border-color,scale] duration-150 ease-snappy hover:border-foreground active:scale-90 checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring forced-colors:appearance-auto" /><Check class="pointer-events-none col-start-1 row-start-1 size-3 scale-50 text-primary-foreground opacity-0 transition-[opacity,scale] duration-200 ease-spring peer-checked:scale-100 peer-checked:opacity-100 forced-colors:hidden" stroke-width={3} aria-hidden="true" /></span>
</label>
<label class="flex cursor-pointer items-center justify-between gap-2 rounded-xl border border-border bg-muted/40 px-3.5 py-2.5 text-xs text-foreground">
<span>PagerDuty on-call</span>
<span class="relative inline-grid size-4 shrink-0 place-items-center"><input type="checkbox" class="peer col-start-1 row-start-1 size-4 shrink-0 cursor-pointer appearance-none rounded-sm border border-border-strong bg-field transition-[background-color,border-color,scale] duration-150 ease-snappy hover:border-foreground active:scale-90 checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring forced-colors:appearance-auto" /><Check class="pointer-events-none col-start-1 row-start-1 size-3 scale-50 text-primary-foreground opacity-0 transition-[opacity,scale] duration-200 ease-spring peer-checked:scale-100 peer-checked:opacity-100 forced-colors:hidden" stroke-width={3} aria-hidden="true" /></span>
</label>
<label class="flex cursor-pointer items-center justify-between gap-2 rounded-xl border border-frame bg-muted/40 px-3.5 py-2.5 text-xs text-foreground">
<span class="inline-flex items-center gap-1.5"><ShieldAlert class="size-3.5 text-muted-foreground" aria-hidden="true" />Hard stop at threshold</span>
<span class="relative inline-grid size-4 shrink-0 place-items-center"><input type="checkbox" data-sa-hard class="peer col-start-1 row-start-1 size-4 shrink-0 cursor-pointer appearance-none rounded-sm border border-border-strong bg-field transition-[background-color,border-color,scale] duration-150 ease-snappy hover:border-foreground active:scale-90 checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring forced-colors:appearance-auto" /><Check class="pointer-events-none col-start-1 row-start-1 size-3 scale-50 text-primary-foreground opacity-0 transition-[opacity,scale] duration-200 ease-spring peer-checked:scale-100 peer-checked:opacity-100 forced-colors:hidden" stroke-width={3} aria-hidden="true" /></span>
</label>
</div>
<div class="mt-5 rounded-xl border border-border bg-muted/40 p-4">
<p class="inline-flex items-center gap-1 text-[0.6875rem] font-medium tracking-wider text-muted-foreground uppercase">
<Hash class="size-3 text-muted-foreground" aria-hidden="true" />
Live Slack preview · #billing-alerts
</p>
<p data-sa-preview class="mt-2 border-l-2 border-border-strong pl-3 text-xs/5 text-pretty text-foreground">
Spend alert: Workspace crossed <strong>${initialThreshold}</strong> (forecast ${forecastSpend}). Soft alert only — requests remain active.
</p>
</div>
<p data-sa-status role="status" class="mt-3 min-h-4 text-xs/4 text-muted-foreground"></p>
</div>
</section>
<script>
function initSpendAlerts() {
document.querySelectorAll<HTMLElement>("[data-haze-spend-alert]").forEach((root) => {
if (root.hasAttribute("data-enhanced")) return;
root.setAttribute("data-enhanced", "");
const max = Number(root.dataset.max ?? 1000);
const range = root.querySelector<HTMLInputElement>("[data-sa-range]");
const hard = root.querySelector<HTMLInputElement>("[data-sa-hard]");
const val = root.querySelector<HTMLElement>("[data-sa-val]");
const marker = root.querySelector<HTMLElement>("[data-sa-marker]");
const preview = root.querySelector<HTMLElement>("[data-sa-preview]");
const status = root.querySelector<HTMLElement>("[data-sa-status]");
const sync = () => {
const n = Number(range?.value ?? 500);
const pct = Math.min(100, Math.round((n / max) * 100));
if (val) val.textContent = `$${n} / mo`;
if (marker) marker.style.left = `${pct}%`;
if (preview) {
preview.innerHTML = hard?.checked
? `Hard stop triggered: Workspace reached <strong>$${n}</strong>. Metered requests are paused until an admin raises the cap.`
: `Spend alert: Workspace crossed <strong>$${n}</strong>. Soft alert only — requests remain active.`;
}
if (status) status.textContent = `Threshold set to $${n}/mo (${hard?.checked ? "hard stop" : "soft alert"}).`;
};
range?.addEventListener("input", sync);
hard?.addEventListener("change", sync);
});
}
initSpendAlerts();
document.addEventListener("astro:page-load", initSpendAlerts);
</script>When to use
- Configuring monthly spend alert thresholds with immediate visual context against current and projected spend
- Previewing the exact Slack alert message for soft notifications versus hard-stop caps
When not to use
- Displaying multiple resource usage meters and past spend history; use usage-billing
Installation
Add the Haze registry to components.json once, then install Spend alert with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/spend-alertnpx shadcn@latest add @haze/spend-alertyarn dlx shadcn@latest add @haze/spend-alertbunx --bun shadcn@latest add @haze/spend-alertFirst 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
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | "haze-spend-alert" | Unique prefix for slider label and heading IDs. |
| currentSpend | number | 420 | Accrued spend in dollars. |
| forecastSpend | number | 580 | Forecasted end-of-month spend in dollars. |
| initialThreshold | number | 500 | Starting alert threshold in dollars. |
| maxBudget | number | 1000 | Upper bound of the slider scale. |
| class | string | – | Extra classes on the outer section. |
Keyboard interactions
- ArrowLeftArrowRight
- Adjust the monthly spend threshold slider in $25 steps
- TabSpace
- Toggle Email, Slack, PagerDuty or Hard-stop checkboxes
Accessibility
- The threshold control uses a native range input with an explicit label and announces updated dollar amounts via role="status".
- Channel and Hard-stop toggles use native checkboxes and immediately update the live Slack preview text.
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 block "Spend alert" with `npx shadcn@latest add @haze/spend-alert`. 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 SpendAlert from "@/components/haze/blocks/spend-alert.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/blocks/spend-alert.md
Customize with real content
Adapt the Haze spend-alert block for our product. Replace the demo values of these props with our real content: id, currentSpend, forecastSpend, initialThreshold, maxBudget, class. Keep the layout, the heading level rules and these accessibility details: The threshold control uses a native range input with an explicit label and announces updated dollar amounts via role="status". Channel and Hard-stop toggles use native checkboxes and immediately update the live Slack preview text. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using spend-alert, check it fits: use it when configuring monthly spend alert thresholds with immediate visual context against current and projected spend; previewing the exact slack alert message for soft notifications versus hard-stop caps. Avoid it when displaying multiple resource usage meters and past spend history; use usage-billing. Alternatives: @haze/usage-billing, @haze/slider.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.