Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Alert

FreeNew

An inline message in five tones, each with its own icon, with optional actions and a dismiss button.

Installation

pnpm dlx shadcn@latest add @viewport/alert

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above.

alert-demo.tsx
"use client";

import { useState } from "react";
import { Alert } from "@/components/viewport/alert";
import { Button } from "@/components/viewport/button";

export default function AlertDemo() {
  const [trial, setTrial] = useState(true);
  return (
    <div className="flex w-full max-w-md flex-col gap-3">
      {trial ? (
        <Alert
          tone="warning"
          title="Your trial ends in 3 days"
          onDismiss={() => setTrial(false)}
          action={
            <>
              <Button size="sm">Choose a plan</Button>
              <Button size="sm" variant="ghost">
                Compare plans
              </Button>
            </>
          }
        >
          After that, automations pause and new contacts cannot be added.
        </Alert>
      ) : (
        <Button variant="outline" size="sm" className="self-start" onClick={() => setTrial(true)}>
          Show the trial notice again
        </Button>
      )}
      <Alert tone="success" title="Import finished">
        1,284 contacts were added and 16 duplicates were merged.
      </Alert>
      <Alert tone="danger" title="We could not charge the card ending in 4242" />
      <Alert tone="neutral" title="Exports include archived deals">
        Turn this off under Settings, then Data.
      </Alert>
    </div>
  );
}

Props

PropTypeDefault
tonekeyof typeof tones

The kind of message. Each tone has its own icon, so color is not the only signal.

"info"
title*React.ReactNode

The message in a few words.

—
actionReact.ReactNode

Buttons or links placed under the text.

—
onDismiss() => void

Adds a close button.

—
announceboolean

Announce the alert when it appears. Use for messages that arrive after an action; leave off for alerts that are part of the page from the start.

false

Accessibility

  • Announced as an alert or a status only when you ask for it, so page-load notices stay quiet.
  • Icon and text carry the meaning; color only supports them.
  • The dismiss button has a name and a visible focus ring.