For the complete documentation index, see llms.txt. Markdown variants are available by appending .md to documentation URLs. Homepage markdown is available at /llms.md/content.md. An agent skill is available at /.well-known/agent-skills/site-skill.md.

Alert

The Alert component from this design system, built on Base UI.

Installation

$ pnpm dlx shadcn@latest add @cobalt/alert

Source

import { cva } from "class-variance-authority";
import type { VariantProps } from "class-variance-authority";
import { cn } from "cn";
import * as React from "react";

const alertVariants = cva(
  "group/alert relative grid w-full gap-y-1 overflow-hidden rounded-[16px] border border-[var(--border-subtle,var(--border))] p-4 text-left text-sm leading-5 shadow-[shadow:var(--shadow-dropdown,0_1px_1px_0_rgb(0_0_0/0.04),0_4px_4px_0_rgb(0_0_0/0.02))] has-data-[slot=alert-action]:pe-11 has-[>svg]:grid-cols-[40px_minmax(0,1fr)] has-[>svg]:gap-x-3 *:[svg]:row-span-2 *:[svg]:rounded-full *:[svg]:p-2.5 *:[svg:not([class*='size-'])]:size-10",
  {
    defaultVariants: {
      variant: "default",
    },
    variants: {
      variant: {
        default:
          "bg-[var(--surface-raised,var(--card))] text-card-foreground *:[svg]:bg-[var(--surface-strong,var(--muted))] *:[svg]:text-muted-foreground dark:*:[svg]:bg-[var(--surface-sunken,var(--muted))]",
        destructive:
          "bg-[var(--surface-raised,var(--card))] text-card-foreground not-has-[>svg]:text-destructive not-has-[>svg]:*:data-[slot=alert-description]:text-destructive *:[svg]:bg-[var(--notification-error-background,var(--muted))] *:[svg]:text-[color:var(--notification-error-foreground,var(--destructive))]",
        info: "bg-[var(--surface-raised,var(--card))] text-card-foreground *:[svg]:bg-[var(--notification-information-background,var(--muted))] *:[svg]:text-[color:var(--notification-information-foreground,var(--primary))]",
        success:
          "bg-[var(--surface-raised,var(--card))] text-card-foreground *:[svg]:bg-[var(--notification-success-background,var(--muted))] *:[svg]:text-[color:var(--alert-success-foreground,var(--primary))]",
      },
    },
  }
);

function Alert({
  className,
  variant,
  ...props
}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
  return (
    <div
      data-slot="alert"
      role="alert"
      className={cn(alertVariants({ variant }), className)}
      {...props}
    />
  );
}

function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="alert-title"
      className={cn(
        "font-medium group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground",
        className
      )}
      {...props}
    />
  );
}

function AlertDescription({
  className,
  ...props
}: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="alert-description"
      className={cn(
        "text-sm leading-5 text-muted-foreground [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_p:not(:last-child)]:mb-4",
        className
      )}
      {...props}
    />
  );
}

function AlertAction({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="alert-action"
      className={cn("absolute top-3 end-3", className)}
      {...props}
    />
  );
}

export { Alert, AlertTitle, AlertDescription, AlertAction };