AI
NUI logov3.1.0

Alert

A flexible and accessible alert component for displaying contextual messages, notifications, or warnings. Supports multiple variants (info, success, warning, error), optional closable behavior, and clear accessibility cues.

tsx
import { Alert } from '@nofinite/nui';

Interactive Preview

Loading preview...

Usage

Basic Alert

tsx
import { Alert } from '@nofinite/nui';

<Alert>This is an informational message.</Alert>;

Alert with a title

tsx
<Alert title="Network Error">
  Unable to connect to the server. Please try again.
</Alert>

Variants

tsx
<Alert variant="success" title="Success">
  Your data has been saved successfully.
</Alert>

<Alert variant="warning" title="Warning">
  Your subscription will expire in 3 days.
</Alert>

<Alert variant="error" title="Error">
  Failed to process your request.
</Alert>

Closable Alert

tsx
<Alert
  variant="info"
  title="Reminder"
  closable
  onClose={() => console.log('Alert closed')}
>
  Don’t forget to check your inbox.
</Alert>

Variants

VariantBackgroundBorderText ColorDescription
infovar(--brand-50)var(--brand-100)var(--color-primary-hover)Informational message
success#f0fdf4#dcfce7var(--color-success)Positive feedback / success message
warning#fffbeb#fef3c7#b45309Warning or caution
error#fef2f2#fee2e2var(--color-danger)Error / critical alert

Colors can be overridden with design tokens for theming.


Accessibility

  • Uses semantic roles:

    • role="alert" for error and warning (automatically announced by screen readers)
    • role="status" for info and success
  • Headers are optional but recommended.

  • Close button is keyboard accessible (Enter / Space triggers onClose).

  • Focus styles visible via :focus-visible on the close button.


Behavior

  • Alerts are controlled/uncontrolled: content always renders; visibility is handled via parent component logic.
  • closable triggers onClose callback but does not remove alert automatically — parent should handle removal.
  • Alerts are visually distinct per variant for immediate recognition.
  • Close button shows hover and focus states for better UX.

Best Practices

Do

  • Provide a title for clarity, especially for error or warning alerts.
  • Keep messages concise.
  • Use closable for temporary notifications.

Don’t

  • Overload with too much text — keep alerts scannable.
  • Use only color to convey status; combine with icons or text.
  • Nest alerts inside other alerts — avoid confusion.

API Reference

PropTypeDefaultDescription
variantenuminfo—
titleReactNode——
closablebooleanfalseDetermines if the close icon button is rendered
onClose(() => void)—Callback fired when the close button is clicked. Note: The component is controlled; it does not unmount itself.
classNamestring——
asChildboolean—Renders the component using its child element