Skip to content

Alert

Feedback

Persistent contextual feedback with five semantic appearances.

InfoSuccessWarningDestructive
Open preview

Responsive viewport — resize the window to explore. Direction and density apply only to this preview. Theme applies to the docs too.

Usage

Compose AlertTitle and AlertDescription inside Alert. Use variant to indicate context. For urgent newly occurring errors, explicitly pass role=alert; visual severity does not automatically interrupt assistive technology.

Import
import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert";

Shipped as editable source in src/components/ui/alert.tsx in both apps. Copy the implementation below when moving it to another project. Copy the complete example from Source code for all imports and state. Add "use client" when using hooks or event handlers. See installation and theming for project setup.

Component source

The complete implementation is included in both apps. It uses the React, Radix, Lucide, and shared-core dependencies already installed in Apex. Keep your project’s semantic theme tokens when reusing it.

src/components/ui/alert.tsx
import type { ComponentProps } from "react";
import { cn } from "@dashboardpack/core/lib/utils";
const variants = {
  default: "border-border bg-card text-card-foreground",
  info: "border-primary/30 bg-primary/5 text-foreground",
  success: "border-success/30 bg-success/5 text-foreground",
  warning: "border-warning/40 bg-warning/10 text-foreground",
  destructive: "border-destructive/30 bg-destructive/5 text-foreground",
};
export function Alert({
  className,
  variant = "default",
  ...props
}: ComponentProps<"div"> & { variant?: keyof typeof variants }) {
  return (
    <div
      role="status"
      className={cn(
        "relative rounded-xl border p-4 text-sm [&>svg]:mb-2 [&>svg]:size-5",
        variants[variant],
        className,
      )}
      {...props}
    />
  );
}
export function AlertTitle({ className, ...props }: ComponentProps<"h3">) {
  return (
    <h3
      className={cn("mb-1 font-semibold tracking-tight", className)}
      {...props}
    />
  );
}
export function AlertDescription({
  className,
  ...props
}: ComponentProps<"div">) {
  return (
    <div
      className={cn(
        "text-sm leading-relaxed text-muted-foreground [&_a]:underline",
        className,
      )}
      {...props}
    />
  );
}

API reference

Common props and defaults. Slot-specific props are named below; native elements also accept their standard HTML attributes. The component TypeScript definitions are the complete type reference.

Alert props
PropType / DefaultDescription
variantdefault | info | success | warning | destructive

Default: default

Border and surface appearance.
roleHTML ARIA role

Default: status

Use alert only for urgent announcements.
childrenReactNode

Default: —

Icon, title, description, and optional actions.
classNamestring

Default: —

Extend the outer container.

Build with these too