shadimage
oui
uioui-alertsource: ok · hit

Alert

A shadcn Alert for a form displaying form action result.

npx shadcn add "https://oui.mw10013.workers.dev/r/oui-alert.json"
free

No selection tags yet — empty means no evidence, not lack of support.

Dependencies

Bundle weight · light
react-aria-components

Registry dependencies

alert

Files1 · source cached 10/8/2026, 3:40:34 PM

registry/default/ui/oui-alert.tsx
import {
  Alert,
  AlertDescription,
  AlertTitle,
} from "@/registry/default/ui/alert";
import * as Rac from "react-aria-components";

export interface AlertFormActionResult {
  success: boolean;
  message?: string;
  details?: string | string[];
  validationErrors?: Rac.FormProps["validationErrors"];
}

/**
 * A shadcn Alert for a form displaying form action result.
 * @param props - Component props including success, message, details.
 */
export function AlertForm({
  success,
  message,
  details,
  className,
  ...props
}: React.ComponentProps<typeof Alert> &
  Partial<Pick<AlertFormActionResult, "success" | "message" | "details">>) {
  const detailsArray = Array.isArray(details)
    ? details
    : details
      ? [details]
      : [];
  if (success === undefined) return null;
  if (!message && detailsArray.length === 0) return null;

  return (
    <Alert
      data-slot="alert-form"
      variant={success ? "default" : "destructive"}
      className={className}
      {...props}
    >
      {message && <AlertTitle>{message}</AlertTitle>}
      {detailsArray.length > 0 && (
        <AlertDescription>
          {detailsArray.map((detail, i) => (
            <div key={i}>{detail}</div>
          ))}
        </AlertDescription>
      )}
    </Alert>
  );
}

More from oui

Browse all components in this library →