React Alert Component
A glass React alert component for inline messages, with four tones, an optional action and a dismiss button, announced by screen readers.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/alert.jsonSaving your draft
Syncing 3 changes to the cloud.
Four tones
Each tone has its own icon and tint. The words always say what happened.
A new version is available
Reload the page to get the latest features.
Changes saved
Your profile is up to date.
Storage almost full
You have used 92% of your plan.
Payment failed
Your card was declined. Update it to keep your plan.
import { Alert } from "@/components/sheenui/alert/alert";
// Package build (after the first npm release, or a packed tarball): import { Alert } from "@sheenui/theme";
export function Example() {
return (
<div className="flex w-full max-w-xl flex-col gap-3">
<Alert tone="info" title="A new version is available">Reload the page to get the latest features.</Alert>
<Alert tone="success" title="Changes saved">Your profile is up to date.</Alert>
<Alert tone="warning" title="Storage almost full">You have used 92% of your plan.</Alert>
<Alert tone="danger" title="Payment failed">Your card was declined. Update it to keep your plan.</Alert>
</div>
);
}Files to copy
6 folders · 7 files · 4 packages
- From
theme/src/ components/alert/components/status-icons/hooks/{use-controllable.ts, use-media-query.ts, use-preferences.ts}motion/tokens.tslib/{cn.ts, motion-props.ts, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/alert.jsonRegistry item: alert. The styles need the Tailwind v4 glass UI setup.- The examples also use
components/button/components/spinner/hooks/{use-latest.ts, use-magnetic.ts}motion/gate.tslib/{form.ts, state-light.tsx}
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Action and dismiss
Put a real button or link in action. dismissible adds a close button; open and onOpenChange let you control it.
Your trial ends in 3 days
Add a payment method to keep your projects.
import { useState } from "react";
import { Alert } from "@/components/sheenui/alert/alert";
import { Button } from "@/components/sheenui/button/button";
// Package build (after the first npm release, or a packed tarball): import { Alert, Button } from "@sheenui/theme";
// This example also uses button: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json
export function Example() {
const [open, setOpen] = useState(true);
return (
<div className="flex w-full max-w-xl flex-col gap-3">
<Alert
tone="warning"
title="Your trial ends in 3 days"
action={<Button size="sm" variant="glass">Upgrade</Button>}
dismissible
open={open}
onOpenChange={setOpen}
>
Add a payment method to keep your projects.
</Alert>
{!open && (
<Button size="sm" variant="ghost" className="self-start" onClick={() => setOpen(true)}>
Show the alert again
</Button>
)}
</div>
);
}Props
AlertLabels keys and English defaults (1)
Keyboard
Accessibility
- Warning and danger use role="alert" (announced at once); info and success use role="status" (announced politely). Pass role="none" for a message that is already on screen at page load: the live demos on this page do, so navigating here does not read out five alerts (the code samples show normal use).
- The tone icon is decorative. The title and message carry the meaning, color is only a hint.
- The dismiss button is named by labels.dismiss, is 44px on touch screens, and has a visible focus ring.
- Text sits on a near-opaque tinted surface, so it keeps 4.5:1 over glass, photos and blobs in light and dark. Forced colors draw a CanvasText border.
When to use Alert
- Use Alert as an inline message in React for a form-level error above a checkout form, such as a declined card, where the message must stay on screen next to the fields the person has to fix.
- Use it for a plan-limit banner at the top of a settings page, with an action button like Upgrade placed at the end of the row and a close button for people who have seen it.
- Use the success tone for a saved confirmation that should remain readable until the next navigation, instead of vanishing the way a toast does after a few seconds.
- Skip it when the message should disappear by itself after a short moment or must block the page until answered. Use Toast for the first case and Dialog or AlertDialog for the second.
- Pair it with Button for the action slot, Field or Input for the form it explains, and Toast for the lighter follow-up feedback once the problem is fixed.
Frequently asked questions
Related pages
67 components pages in all: browse them on All components.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .