Alert

A banner that sits in the page with a title, a line of text and room for one action, marked and faintly tinted for success, a warning, an error or plain news. The cross dismisses it.

Payment received

Invoice 1042 is paid. Your receipt is on its way.

Your trial ends in 3 days

Add a card to keep your projects.

Add a card
A new version is ready

Reload the page to get it.

Reload

Options

Screen
Colour

Code

import { useState } from "react";
import "./alert.css";

/* An inline banner. kind is "good", "warn", "bad" or "info". Give it an action
   to show a small button, and onDismiss to show the cross.

   <Alert kind="warn" title="Your trial ends in 3 days" action="Add a card" href="/billing" onDismiss={hide}>Add a card to keep your projects.</Alert> */
export function Alert({ kind = "info", title, action, href = "#", onDismiss, children }) {
  return (
    <div className="dh-alert" data-kind={kind} role={kind === "bad" ? "alert" : "status"}>
      <div>
        <strong>{title}</strong>
        <p>{children}</p>
      </div>
      {action && <a href={href}>{action}</a>}
      {onDismiss && (
        <button type="button" aria-label="Dismiss" onClick={onDismiss}>
          <svg viewBox="0 0 12 12" aria-hidden="true">
            <path d="M3 3l6 6M9 3l-6 6" />
          </svg>
        </button>
      )}
    </div>
  );
}

export function Example() {
  const [hidden, setHidden] = useState([]);
  const hide = (name) => () => setHidden((list) => [...list, name]);
  const shown = (name) => !hidden.includes(name);

  return (
    <div className="dh-alert-stack">
      {shown("paid") && (
        <Alert kind="good" title="Payment received" onDismiss={hide("paid")}>
          Invoice 1042 is paid. Your receipt is on its way.
        </Alert>
      )}
      {shown("trial") && (
        <Alert kind="warn" title="Your trial ends in 3 days" action="Add a card" onDismiss={hide("trial")}>
          Add a card to keep your projects.
        </Alert>
      )}
      <Alert kind="bad" title="We could not reach your domain" action="Try again">
        Check the DNS records for example.com.
      </Alert>
      {shown("version") && (
        <Alert kind="info" title="A new version is ready" action="Reload" onDismiss={hide("version")}>
          Reload the page to get it.
        </Alert>
      )}
    </div>
  );
}
Payment received

Invoice 1042 is paid. Your receipt is on its way.

Your trial ends in 3 days

Add a card to keep your projects.

Add a card
A new version is ready

Reload the page to get it.

Reload