# Alert

A compact banner-style message with optional icon, action, and dismissal controls.

A compact banner-style message with optional icon, action, and dismissal controls.

```tsx
import { Alert, Stack } from "@zentara-co/zenos-ui";

const alertExampleTitle = "Lorem ipsum here";

const alertExampleDescription = "Content text here zipzipzipzipzipzipblebleblebleblebleble";

function AlertPreviewExample() {
  return (
    <Stack gap="3" className="w-full">
      {(["info", "success", "warning"] as const).map((variant) => (
        <Alert.Root key={variant} variant={variant}>
          <Alert.Content>
            <Alert.Icon />
            <Alert.Body>
              <Alert.Title>{alertExampleTitle}</Alert.Title>
              <Alert.Description>{alertExampleDescription}</Alert.Description>
            </Alert.Body>
          </Alert.Content>
        </Alert.Root>
      ))}
    </Stack>
  );
}
```

## Import

```tsx
import { Alert } from "@zentara-co/zenos-ui";
```

## Custom icons

Pass a custom icon on `Alert.Root` for a shared leading icon, or on `Alert.Icon` with the `icon` prop (or children) to override it locally. Set `showDefault={false}` on `Alert.Icon` to omit the variant default on status alerts. Built-in status icons are exported as `AlertInfoIcon`, `AlertCheckCircleIcon`, `AlertWarningIcon`, and `AlertErrorIcon`.

```tsx
import { Alert, Stack } from "@zentara-co/zenos-ui";

function AlertCustomIconExample() {
  const SparkIcon = () => (
    <svg aria-hidden="true" className="size-5" viewBox="0 0 20 20" fill="currentColor">
      <path d="M10 2.5 11.4 8.6 17.5 10l-6.1 1.4L10 17.5 8.6 11.4 2.5 10l6.1-1.4L10 2.5Z" />
    </svg>
  );

  return (
    <Stack gap="3" className="w-full">
      <Alert.Root variant="default" icon={<SparkIcon />}>
        <Alert.Content>
          <Alert.Icon />
          <Alert.Body>
            <Alert.Title>Scheduled maintenance</Alert.Title>
            <Alert.Description>Workspace sync pauses tonight from 11 PM to 1 AM.</Alert.Description>
          </Alert.Body>
        </Alert.Content>
      </Alert.Root>
      <Alert.Root variant="announcement">
        <Alert.Content>
          <Alert.Icon icon={<SparkIcon />} />
          <Alert.Body>
            <Alert.Title>Product launch week</Alert.Title>
            <Alert.Description>Pin the launch checklist to your team home page.</Alert.Description>
          </Alert.Body>
        </Alert.Content>
      </Alert.Root>
    </Stack>
  );
}
```

## Actions and dismissal

`Alert.Title` and `Alert.Description` use body medium and body regular at the `body-m` scale. Long copy truncates with an ellipsis. `Alert.Action` adds a related action. `Alert.Close` provides the dismiss control while the consumer remains responsible for removing the static alert. Both controls automatically match the semantic color of `Alert.Root`.

```tsx
import { Alert, Button } from "@zentara-co/zenos-ui";
import { useState } from "react";

function AlertActionsExample() {
  const [visible, setVisible] = useState(true);

  if (!visible) {
    return (
      <Button variant="primary" onClick={() => setVisible(true)}>
        Show alert
      </Button>
    );
  }

  return (
    <Alert.Root variant="info" className="w-full">
      <Alert.Content>
        <Alert.Icon />
        <Alert.Body>
          <Alert.Title>Import running</Alert.Title>
          <Alert.Description>Your workspace data is still being processed.</Alert.Description>
        </Alert.Body>
        <Alert.Action onClick={() => undefined}>Details</Alert.Action>
        <Alert.Close onClick={() => setVisible(false)} />
      </Alert.Content>
    </Alert.Root>
  );
}
```

## Variants

Neutral variants suit general and inverse announcements. Status variants use information and accent subtle banner surfaces for success, info, warning, and error. Leading icons appear on status variants only. Action and close controls inherit the alert tone.

```tsx
import { Alert, Stack, Text } from "@zentara-co/zenos-ui";

type CatalogVariantProps = { limit?: number };

const limited = <T,>(items: readonly T[], limit?: number) =>
  limit === undefined ? items : items.slice(0, limit);

const alertVariantGroups = [
  { label: "Neutral", variants: ["default", "announcement"] },
  { label: "Status", variants: ["info", "success", "warning", "error"] },
] as const;

const alertVariants = alertVariantGroups.flatMap((group) => group.variants);

const alertShowsDefaultIcon = (variant: (typeof alertVariants)[number]) =>
  variant === "info" || variant === "success" || variant === "warning" || variant === "error";

const alertExampleTitle = "Lorem ipsum here";

const alertExampleDescription = "Content text here zipzipzipzipzipzipblebleblebleblebleble";

function AlertVariantsExample({ limit }: CatalogVariantProps = {}) {
  if (limit !== undefined) {
    return (
      <Stack gap="3" className="w-full">
        {limited(alertVariants, limit).map((variant) => (
          <Alert.Root key={variant} variant={variant}>
            <Alert.Content>
              {alertShowsDefaultIcon(variant) ? <Alert.Icon /> : null}
              <Alert.Body>
                <Alert.Title>{alertExampleTitle}</Alert.Title>
                <Alert.Description>{alertExampleDescription}</Alert.Description>
              </Alert.Body>
              <Alert.Action>Button</Alert.Action>
              <Alert.Close />
            </Alert.Content>
          </Alert.Root>
        ))}
      </Stack>
    );
  }

  return (
    <Stack gap="5" className="w-full">
      {alertVariantGroups.map((group) => (
        <Stack key={group.label} gap="2">
          <Text as="h3" type="emphasis" size="s" color="subtle">
            {group.label}
          </Text>
          <Stack gap="3">
            {group.variants.map((variant) => (
              <Alert.Root key={variant} variant={variant}>
                <Alert.Content>
                  {alertShowsDefaultIcon(variant) ? <Alert.Icon /> : null}
                  <Alert.Body>
                    <Alert.Title>{alertExampleTitle}</Alert.Title>
                    <Alert.Description>{alertExampleDescription}</Alert.Description>
                  </Alert.Body>
                  <Alert.Action>Button</Alert.Action>
                  <Alert.Close />
                </Alert.Content>
              </Alert.Root>
            ))}
          </Stack>
        </Stack>
      ))}
    </Stack>
  );
}
```

## Anatomy

```text
Alert.Root
Alert.Content
Alert.Icon
Alert.Body
Alert.Title
Alert.Description
Alert.Action
Alert.Close
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| Root.variant | AlertVariant | default | Semantic visual tone; error also defaults to role=alert. |
| Root.icon | ReactNode | — | Custom leading icon for Alert.Icon when it has no local override. |
| Icon.icon | ReactNode | — | Custom icon node; overrides Root.icon and the variant default. |
| Icon.showDefault | boolean | true | Renders the variant default when no custom icon is provided. |
| Action.variant | ButtonVariant | ghost | Button treatment; its color follows Root.variant. |
| Close.label | string | Dismiss | Accessible name for the dismiss control. |
| role | AriaRole | — | Overrides the status or alert role. |
| native props | React.HTMLAttributes<HTMLDivElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Alert uses `role="status"` by default and `role="alert"` for the error variant. Use concise titles, keep action labels meaningful, and avoid placing essential information only in the icon or color.

Source: https://zenos-ui.pages.dev/components/alert/