Command Palette

Search for a command...

Alert

Display important messages to users.

Heads up!
Hey there! This is a simple alert.
import { LuTerminal } from "react-icons/lu";
import {
  Alert,
  AlertContent,
  AlertDescription,
  AlertIcon,
  AlertTitle,
} from "@/components/ui/alert";

export default function AlertDemo() {
  return (
    <Alert css={{ w: "2/3" }}>
      <AlertIcon>
        <LuTerminal />
      </AlertIcon>
      <AlertContent>
        <AlertTitle>Heads up!</AlertTitle>
        <AlertDescription>Hey there! This is a simple alert.</AlertDescription>
      </AlertContent>
    </Alert>
  );
}

Installation

npx nore-ui-cli@latest add alert

Usage

import {
  Alert,
  AlertContent,
  AlertDescription,
  AlertIcon,
  AlertTitle,
} from "@/components/ui/alert";
<Alert variant="info">
  <AlertIcon>
    <LuInfo />
  </AlertIcon>
  <AlertContent>
    <AlertTitle>Info</AlertTitle>
    <AlertDescription>This is an info alert.</AlertDescription>
  </AlertContent>
</Alert>

Examples

Variant

Info
This is an info message.
Success!
Your changes have been saved successfully.
Warning
Your subscription will expire in 7 days.
Error
Failed to save changes. Please try again.
import { LuCircleCheckBig, LuCircleX, LuInfo, LuTriangleAlert } from "react-icons/lu";
import { styled } from "styled-system/jsx";
import {
  Alert,
  AlertContent,
  AlertDescription,
  AlertIcon,
  AlertTitle,
} from "@/components/ui/alert";

export default function AlertVariant() {
  return (
    <styled.div css={{ w: "2/3", spaceY: "4" }}>
      {/* Info variant */}
      <Alert variant="info">
        <AlertIcon>
          <LuInfo />
        </AlertIcon>
        <AlertContent>
          <AlertTitle>Info</AlertTitle>
          <AlertDescription>This is an info message.</AlertDescription>
        </AlertContent>
      </Alert>

      {/* Success variant */}
      <Alert variant="success">
        <AlertIcon>
          <LuCircleCheckBig />
        </AlertIcon>
        <AlertContent>
          <AlertTitle>Success!</AlertTitle>
          <AlertDescription>Your changes have been saved successfully.</AlertDescription>
        </AlertContent>
      </Alert>

      {/* Warning variant */}
      <Alert variant="warning">
        <AlertIcon>
          <LuTriangleAlert />
        </AlertIcon>
        <AlertContent>
          <AlertTitle>Warning</AlertTitle>
          <AlertDescription>Your subscription will expire in 7 days.</AlertDescription>
        </AlertContent>
      </Alert>

      {/* Danger variant */}
      <Alert variant="danger">
        <AlertIcon>
          <LuCircleX />
        </AlertIcon>
        <AlertContent>
          <AlertTitle>Error</AlertTitle>
          <AlertDescription>Failed to save changes. Please try again.</AlertDescription>
        </AlertContent>
      </Alert>
    </styled.div>
  );
}

Without Icon

Info only
This alert doesn't have an icon.
import { Alert, AlertContent, AlertDescription, AlertTitle } from "@/components/ui/alert";

export default function AlertWithoutIcon() {
  return (
    <Alert variant="info" css={{ w: "2/3" }}>
      <AlertContent>
        <AlertTitle>Info only</AlertTitle>
        <AlertDescription>This alert doesn&apos;t have an icon.</AlertDescription>
      </AlertContent>
    </Alert>
  );
}

Without Title

This alert doesn't have a title.
import { LuCircleCheckBig } from "react-icons/lu";
import { Alert, AlertContent, AlertDescription, AlertIcon } from "@/components/ui/alert";

export default function AlertWithoutTitle() {
  return (
    <Alert variant="success" css={{ w: "2/3" }}>
      <AlertIcon>
        <LuCircleCheckBig />
      </AlertIcon>
      <AlertContent>
        <AlertDescription>This alert doesn&apos;t have a title.</AlertDescription>
      </AlertContent>
    </Alert>
  );
}

Only Description

This is a minimal alert with just description.
import { Alert, AlertDescription } from "@/components/ui/alert";

export default function AlertOnlyDescription() {
  return (
    <Alert variant="warning" css={{ w: "2/3" }}>
      <AlertDescription>This is a minimal alert with just description.</AlertDescription>
    </Alert>
  );
}

Custom

Custom Styled Alert
With custom border styling.
import { LuCircleX } from "react-icons/lu";
import {
  Alert,
  AlertContent,
  AlertDescription,
  AlertIcon,
  AlertTitle,
} from "@/components/ui/alert";

export default function AlertCustom() {
  return (
    <Alert
      css={{
        w: "2/3",
        borderStartWidth: "4px",
        borderStartColor: { base: "border.600", _dark: "red.500" },
      }}
    >
      <AlertIcon>
        <LuCircleX />
      </AlertIcon>
      <AlertContent>
        <AlertTitle css={{ textStyle: "lg" }}>Custom Styled Alert</AlertTitle>
        <AlertDescription>With custom border styling.</AlertDescription>
      </AlertContent>
    </Alert>
  );
}