Quota Warning Banner
Dismissible quota warning alert with upgrade actions above per-resource usage meters.
"use client"
import { useState } from "react"
import { WarningIcon, XIcon } from "@phosphor-icons/react"
import { cn } from "cn"
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { Button, buttonVariants } from "@/components/ui/button"
import { Progress } from "@/components/ui/progress"
const COPY = {
title: "You have used 92% of your monthly seats and storage",
body: "At 100% new invites and uploads pause until the next billing date on Dec 1.",
upgrade: "Upgrade plan",
manage: "Manage usage",
dismiss: "Dismiss warning",
restored: "Warning hidden until usage changes.",
undo: "Show again",
} as const
const METERS = [
{ label: "Seats", used: 23, total: 25, unit: "" },
{ label: "Storage", used: 46, total: 50, unit: " GB" },
{ label: "API calls", used: 612, total: 1000, unit: "k" },
] as const
/** Quota warning banner with per-resource meters, upgrade action and dismiss. */
export default function AlertQuotaWarning01() {
const [open, setOpen] = useState(true)
return (
<div className="mx-auto flex w-full max-w-2xl flex-col gap-4">
{open ? (
<Alert className="pr-12">
<WarningIcon aria-hidden="true" />
<AlertTitle>{COPY.title}</AlertTitle>
<AlertDescription>{COPY.body}</AlertDescription>
<div className="col-start-2 mt-3 flex gap-2">
<a
href="#"
data-slot="button"
className={buttonVariants({ size: "sm" })}
>
{COPY.upgrade}
</a>
<a
href="#"
data-slot="button"
className={cn(buttonVariants({ size: "sm", variant: "outline" }))}
>
{COPY.manage}
</a>
</div>
<Button
size="icon-xs"
variant="ghost"
className="absolute top-2.5 right-3"
aria-label={COPY.dismiss}
onClick={() => setOpen(false)}
>
<XIcon />
</Button>
</Alert>
) : (
<p className="flex items-center justify-between rounded-2xl border border-dashed px-4 py-3 text-sm text-muted-foreground">
{COPY.restored}
<Button size="xs" variant="ghost" onClick={() => setOpen(true)}>
{COPY.undo}
</Button>
</p>
)}
<div className="grid gap-4 rounded-2xl border bg-card p-5">
{METERS.map((m) => {
const pct = Math.round((m.used / m.total) * 100)
return (
<Progress key={m.label} value={pct} className="gap-2">
<div className="flex w-full justify-between text-sm">
<span className="font-medium">{m.label}</span>
<span className="text-muted-foreground tabular-nums">
{m.used}
{m.unit} of {m.total}
{m.unit}
</span>
</div>
</Progress>
)
})}
</div>
</div>
)
}
Installation
pnpm dlx shadcn@latest add @01orbital/quota-warning-01npx shadcn@latest add @01orbital/quota-warning-01yarn dlx shadcn@latest add @01orbital/quota-warning-01bunx --bun shadcn@latest add @01orbital/quota-warning-01Make it yours
- Its words are in
COPYat the top ofcomponents/blocks/alert/quota-warning-01/index.tsx: change them there, not in the markup. METERS, also at the top of the file, holds its lists and settings.
Built from
npm: @phosphor-icons/react, cn. The CLI installs them for you.
Built from these parts. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:
The shadcn parts here are their Base UI versions, and this piece uses Base UI's API. A Radix version you already have won't work with it.
Last updated on