Examples
Feedback variants
Each semantic variant combines a readable message with the matching status color and announcement role.
New report available
The monthly report is ready to review.
Changes saved
Workspace settings were updated.
Review required
Two members still need to accept their invitations.
Import failed
Check the file format and try the import again.
Info, success, warning, and danger alerts
import { Alert } from "@phuctech/ui/components/alert";
export function Example() {
return (
<div className="grid w-full gap-3">
<Alert variant="info" heading="New report available" description="The monthly report is ready to review." />
<Alert variant="success" heading="Changes saved" description="Workspace settings were updated." />
<Alert variant="warning" heading="Review required" description="Two members still need to accept their invitations." />
<Alert variant="danger" heading="Import failed" description="Check the file format and try the import again." />
</div>
);
}
Dismissible feedback
Dismissal is a local presentation behavior. A controlled parent can keep or remove the alert through open and onOpenChange.
Invitation prepared
The invitation is ready to send.
Dismissible success alert
"use client";
import { Alert } from "@phuctech/ui/components/alert";
export function Example() {
return (
<Alert
variant="success"
heading="Invitation prepared"
description="The invitation is ready to send."
dismissible
/>
);
}
Try the props
Compare semantic meaning and optional dismissal using the same values in the preview and copied code.
Review required
Check the pending items before continuing.
Alert property playground
import { Alert } from "@phuctech/ui/components/alert";
export function Example() {
return <Alert variant="warning" heading="Review required" description="Check the pending items before continuing." dismissible />;
}When to use
Use Alert for feedback that must remain visible in the current page or form section. Use Toast for brief, non-blocking feedback that should not take space in the content flow.
Usage
import { Alert } from "@phuctech/ui/components/alert";
<Alert variant="danger" heading="Import failed" description="Check the file format and try again." />Variant is one of info, success, warning, and danger. The component performs no data requests and does not decide whether a business operation succeeded.
API
Tokens
Accessibility
- The default live-region role is
statusfor info, success, and warning, andalertfor danger. Pass a native role when the surrounding interaction needs a different announcement contract. - The status icon is decorative; the words carry the meaning. The dismiss control has a configurable accessible name.
- Do not rely on color alone, and keep dismissal keyboard-operable through the shared Button behavior.
Do and don’t
Explain what happened and give a recovery step for a blocking issue.
Use Alert as a replacement for form validation or a temporary Toast message.