# Alert

A message in the page: a note, a success, a warning or an error.

A message that sits in the page: a note, a success, a warning, an error. A tone icon, a title, a description and optional actions, on the card's box (radius.card, 12px padding). The tones are status-pill's four status tones and their tint pairs: neutral is the card itself (surface on shadow.card); accent, green, orange and red fill with their tint, the icon takes the tone's colour and the text stays ink, so it reads at any length. Static: no engine, no motion.

Kind: component · Category: Feedback · Status: beta · Targets: React, Vue, Svelte

## Add

```bash
npx fndn add alert
```

It writes the folder `alert/` into the project's ui folder (`index.ts`, `alert.tsx`, `Alert.vue`, `Alert.svelte`, `alert.recipe.ts`), and what it is built from: [Button](/components/button.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { Alert } from "@/components/ui/alert";
```

```vue
import { Alert } from "@/components/ui/alert";
```

```svelte
import { Alert } from "$lib/components/ui/alert";
```

## Parts

In the DOM the root carries `data-slot="alert"` and each part `data-slot="alert-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `div` | `alert` |  | role="alert" for orange and red (announced when it appears), role="status" otherwise; the role prop overrides it. A row: the icon, then the content. Radius.card, padding 12px, gap 10px. |
| `icon` | `span` | `alert-icon` | optional | 16px Phosphor glyph (bold) in the tone's colour (ink-3 when neutral), centred on the title's first line; aria-hidden. Default per tone: info (neutral, accent), check-circle (green), warning (orange), warning-circle (red). The icon prop replaces it; icon={false} removes it. |
| `content` | `div` | `alert-content` |  | Takes the free space; holds the title, the description and the actions. min-width 0, so long text wraps inside it. |
| `title` | `div` | `alert-title` | optional | text.sm, weight 500, ink, line-height 20px. Wraps (never cut); author text keeps its own direction. |
| `description` | `div` | `alert-description` | optional | The default slot: text.sm, ink-2, line-height 20px, 2px under the title. Wraps anywhere (an unbreakable address never overflows). |
| `actions` | `div` | `alert-actions` | optional | Buttons (sm) in a wrapping row under the text, inside the content column so they line up with the title; 10px above them. |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `tone` | `"neutral" \| "accent" \| "green" \| "orange" \| "red"` | `"neutral"` | status-pill's status tones. neutral: the card (surface, shadow.card), ink-3 icon. accent / green / orange / red: the tone's tint fill (accent-tint, green-tint, orange-tint, red-tint) and the tone's colour on the icon; text stays ink and ink-2. |
| `title` | `string` |  | The headline. An alert may have only a title, only a description, or both. |
| `icon` | `boolean` | `true` | Show the tone's icon. Your own glyph: a node (React), the icon slot (Vue), a snippet (Svelte). |
| `role` | `"alert" \| "status" \| "none"` |  | Default: alert for orange and red, status for the others. none for an alert that is part of the page from the start and must not be announced. |
| `actions` | `{ label: string; value?: string; variant?: button variant }[]` |  | Buttons under the text (sm; outline unless given). Your own controls instead: the action prop (React, a node; Svelte, a snippet) or the action slot (Vue). |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Events

| Event | Payload |
| --- | --- |
| `action` | (value: string) when an action is pressed |

## Slots

| Slot | Content |
| --- | --- |
| `default` | Description |
| `actions` | Your own controls in place of `actions` (React: the action prop, a node; Vue: the action slot; Svelte: the action snippet) |

## States

`hover`, `press`, `focus-visible`

## Keyboard and accessibility

Role: alert | status.

Notes:

- role="alert" (orange, red) is announced at once when the alert appears; role="status" politely. An alert rendered with the page is read in place; pass role="none" if it must not be announced at all.
- The icon is decorative (aria-hidden): the title says what happened. Colour is never the only signal: the title and the icon carry it too.
- Not focusable itself; its actions are ordinary Buttons in the tab order.

## Motion

- none: an alert is part of the page; a component that shows or hides one decides how

## Tokens

`color.surface`, `color.ink`, `color.ink-2`, `color.ink-3`, `color.accent`, `color.accent-tint`, `color.green`, `color.green-tint`, `color.orange`, `color.orange-tint`, `color.red`, `color.red-tint`, `shadow.card`, `radius.card`, `text.sm`

## Dependencies

- [Button](/components/button.md)

## Examples

### Close to the plan limit

React · `usage-limit.tsx`

```tsx
import { Alert } from "@/components/ui/alert";

export default function UsageLimit() {
  return (
    <Alert className="w-full max-w-[420px]" tone="orange" title="web-app has used 92% of its build minutes">
      Builds pause at 100%. The limit resets on Dec 1.
    </Alert>
  );
}
```

Vue · `usage-limit.vue`

```vue
<script setup lang="ts">
import { Alert } from "@/components/ui/alert";
</script>

<template>
  <Alert class="w-full max-w-[420px]" tone="orange" title="web-app has used 92% of its build minutes">
    Builds pause at 100%. The limit resets on Dec 1.
  </Alert>
</template>
```

Svelte · `usage-limit.svelte`

```svelte
<script lang="ts">
  import { Alert } from "$lib/components/ui/alert";
</script>

<Alert class="w-full max-w-[420px]" tone="orange" title="web-app has used 92% of its build minutes">
  Builds pause at 100%. The limit resets on Dec 1.
</Alert>
```

### Deploy failed, with a way out

React · `deploy-failed.tsx`

```tsx
import { useState } from "react";
import { Alert, type AlertAction } from "@/components/ui/alert";

const actions: AlertAction[] = [
  { label: "Redeploy", value: "redeploy" },
  { label: "Dismiss", value: "dismiss", variant: "ghost" },
];

export default function DeployFailed() {
  const [state, setState] = useState<"failed" | "redeploying" | "dismissed">("failed");
  if (state === "dismissed") return null;
  if (state === "redeploying") {
    return (
      <Alert className="w-full max-w-[420px]" tone="accent" title="Redeploying web-app">
        Started again from commit a1b2c3d on main.
      </Alert>
    );
  }
  return (
    <Alert
      className="w-full max-w-[420px]"
      tone="red"
      title="Deploy to Production failed"
      actions={actions}
      onAction={(value) => setState(value === "redeploy" ? "redeploying" : "dismissed")}
    >
      The build of dpl_7f3a9c exited with code 1. The previous deploy is still live.
    </Alert>
  );
}
```

Vue · `deploy-failed.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Alert, type AlertAction } from "@/components/ui/alert";

const actions: AlertAction[] = [
  { label: "Redeploy", value: "redeploy" },
  { label: "Dismiss", value: "dismiss", variant: "ghost" },
];
const state = ref<"failed" | "redeploying" | "dismissed">("failed");
</script>

<template>
  <Alert v-if="state === 'redeploying'" class="w-full max-w-[420px]" tone="accent" title="Redeploying web-app">
    Started again from commit a1b2c3d on main.
  </Alert>
  <Alert
    v-else-if="state === 'failed'"
    class="w-full max-w-[420px]"
    tone="red"
    title="Deploy to Production failed"
    :actions="actions"
    @action="(value) => (state = value === 'redeploy' ? 'redeploying' : 'dismissed')"
  >
    The build of dpl_7f3a9c exited with code 1. The previous deploy is still live.
  </Alert>
</template>
```

Svelte · `deploy-failed.svelte`

```svelte
<script lang="ts">
  import { Alert, type AlertAction } from "$lib/components/ui/alert";

  const actions: AlertAction[] = [
    { label: "Redeploy", value: "redeploy" },
    { label: "Dismiss", value: "dismiss", variant: "ghost" },
  ];
  let state = $state<"failed" | "redeploying" | "dismissed">("failed");
</script>

{#if state === "redeploying"}
  <Alert class="w-full max-w-[420px]" tone="accent" title="Redeploying web-app">
    Started again from commit a1b2c3d on main.
  </Alert>
{:else if state === "failed"}
  <Alert
    class="w-full max-w-[420px]"
    tone="red"
    title="Deploy to Production failed"
    {actions}
    onaction={(value) => (state = value === "redeploy" ? "redeploying" : "dismissed")}
  >
    The build of dpl_7f3a9c exited with code 1. The previous deploy is still live.
  </Alert>
{/if}
```

### Scheduled maintenance

React · `maintenance.tsx`

```tsx
import { Alert } from "@/components/ui/alert";

/* part of the page from the start: role none, so it is not announced */
export default function Maintenance() {
  return (
    <Alert className="w-full max-w-[420px]" role="none" title="Scheduled maintenance on Nov 21">
      Deploys are paused from 02:00 to 03:00 UTC. Live sites stay up.
    </Alert>
  );
}
```

Vue · `maintenance.vue`

```vue
<script setup lang="ts">
import { Alert } from "@/components/ui/alert";
</script>

<!-- part of the page from the start: role none, so it is not announced -->
<template>
  <Alert class="w-full max-w-[420px]" role="none" title="Scheduled maintenance on Nov 21">
    Deploys are paused from 02:00 to 03:00 UTC. Live sites stay up.
  </Alert>
</template>
```

Svelte · `maintenance.svelte`

```svelte
<script lang="ts">
  import { Alert } from "$lib/components/ui/alert";
</script>

<!-- part of the page from the start: role none, so it is not announced -->
<Alert class="w-full max-w-[420px]" role="none" title="Scheduled maintenance on Nov 21">
  Deploys are paused from 02:00 to 03:00 UTC. Live sites stay up.
</Alert>
```

### Domain verified

React · `domain-verified.tsx`

```tsx
import { Alert } from "@/components/ui/alert";

export default function DomainVerified() {
  return <Alert className="w-full max-w-[420px]" tone="green" title="app.northwind.example is verified and serving web-app" />;
}
```

Vue · `domain-verified.vue`

```vue
<script setup lang="ts">
import { Alert } from "@/components/ui/alert";
</script>

<template>
  <Alert class="w-full max-w-[420px]" tone="green" title="app.northwind.example is verified and serving web-app" />
</template>
```

Svelte · `domain-verified.svelte`

```svelte
<script lang="ts">
  import { Alert } from "$lib/components/ui/alert";
</script>

<Alert class="w-full max-w-[420px]" tone="green" title="app.northwind.example is verified and serving web-app" />
```

### Announcing a feature

React · `new-feature.tsx`

```tsx
import { Sparkle } from "@phosphor-icons/react";
import { Alert } from "@/components/ui/alert";

export default function NewFeature() {
  return (
    <Alert className="w-full max-w-[420px]" tone="accent" icon={<Sparkle data-slot="icon" weight="bold" />} title="New: usage alerts">
      Get an email when a project reaches 80% of its build minutes.
    </Alert>
  );
}
```

Vue · `new-feature.vue`

```vue
<script setup lang="ts">
import { PhSparkle } from "@phosphor-icons/vue";
import { Alert } from "@/components/ui/alert";
</script>

<template>
  <Alert class="w-full max-w-[420px]" tone="accent" title="New: usage alerts">
    <template #icon><PhSparkle data-slot="icon" weight="bold" /></template>
    Get an email when a project reaches 80% of its build minutes.
  </Alert>
</template>
```

Svelte · `new-feature.svelte`

```svelte
<script lang="ts">
  import Sparkle from "phosphor-svelte/lib/SparkleIcon";
  import { Alert } from "$lib/components/ui/alert";
</script>

{#snippet icon()}<Sparkle data-slot="icon" weight="bold" />{/snippet}
<Alert class="w-full max-w-[420px]" tone="accent" {icon} title="New: usage alerts">
  Get an email when a project reaches 80% of its build minutes.
</Alert>
```

## Recipe

`alert.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* alert — a message that sits in the page: icon, title, description, actions. The box is the
 * card's (radius.card, shadow.card on the surface when neutral); the tones are status-pill's four
 * status tones with their tint pairs. On a tint only the icon takes the tone's colour: the title
 * and the description stay ink and ink-2, so a long message reads as well as a short one.
 *
 * The icon sits on the title's first line: its box is one line (20px) high and centres the 16px
 * glyph, so it stays put however many lines the text wraps to. The actions are Buttons (sm) in
 * the content column, under the text, so they line up with the title at any width. Static: no
 * motion, no engine. */

const DIR = "[unicode-bidi:plaintext]";

export const alert = tv({
  slots: {
    base: "flex items-start gap-2.5 min-w-0 p-3 rounded-card text-sm leading-5 text-ink",
    icon: "inline-flex shrink-0 items-center justify-center h-5 text-[16px] [&>[data-slot=icon]]:size-4 [&>svg]:size-4",
    content: "flex flex-col flex-1 min-w-0",
    title: ["font-medium text-ink wrap-anywhere", DIR],
    description: ["text-ink-2 wrap-anywhere [[data-slot=alert-title]+&]:mt-0.5", DIR],
    actions: "flex flex-wrap items-center gap-2 mt-2.5",
  },
  variants: {
    tone: {
      neutral: { base: "bg-surface shadow-card", icon: "text-ink-3" },
      accent: { base: "bg-accent-tint", icon: "text-accent" },
      green: { base: "bg-green-tint", icon: "text-green" },
      orange: { base: "bg-orange-tint", icon: "text-orange" },
      red: { base: "bg-red-tint", icon: "text-red" },
    },
  },
  defaultVariants: { tone: "neutral" },
});

export type AlertRecipeProps = VariantProps<typeof alert>;
```
