# Alert

> A short message beside the content it's about, in any tone, with an optional next step: a paused workflow, a refusal, a failed sync.

Page: https://uicontext.com/docs/components/alert

Group: Primitives.

## When to use

A short message beside the content it's about, in any tone, with an optional next step: a paused workflow, a refusal, a failed sync. Use [Banner](https://uicontext.com/docs/components/banner.md) instead when the message is about the whole product, not the content beside it.

## Usage

```ts
import { Callout } from "./ui/uicontext/components/Callout.ts"

export const ScheduleNote = <M>(h: Html.H<M>) =>
	Callout(h, { title: "Runs every weekday" }, "It starts at 9:00 in the workspace's time zone.")
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### Information and a failure

The example the page opens with: Alert in “Information and a failure”.

```ts title="src/demo.ts" source="www/src/examples/alert/demo.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Callout } from "./ui/uicontext/components/Callout.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const styles = stylex.create({ stack: { display: "grid", gap: 12, inlineSize: "min(100%, 30rem)" } })

// a neutral callout is a quiet status; a danger one is an alert, announced at once
export const ConnectionNotes = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.stack)).children(
		Callout(h, { title: "Invoices sync every hour" }, "Changes in Northwind Freight's ledger show here within the hour."),
		Callout(h, { tone: "danger", title: "Couldn't reach the ledger" }, "The API key was revoked. Paste a new one in Settings, then sync again."),
	)
```

### Tones and a next step

Alert in “Tones and a next step”.

```ts title="src/tones.ts" source="www/src/examples/alert/tones.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Callout } from "./ui/uicontext/components/Callout.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const styles = stylex.create({ stack: { display: "grid", gap: 12, inlineSize: "min(100%, 30rem)" } })

// the tone shows in the dot; a link after the message is the next step
export const WorkflowNotices = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.stack)).children(
		Callout(h, { tone: "warning", href: "#resume", linkLabel: "Resume" }, "Invoice sync is paused."),
		Callout(h, { tone: "danger" }, "Only admins can change spend limits."),
		Callout(h, { tone: "info" }, "Runs every weekday at 9:00."),
		Callout(h, { tone: "success" }, "Reconnected. Replay the run to try the step again."),
	)
```

## API reference

**Options**

| Name | Type | Description |
| --- | --- | --- |
| `title` | `string` | A few words above the message, in bold: "Couldn't reach the ledger". |
| `tone` | `"neutral" \| "accent" \| "danger" \| "warning" \| "success" \| "info"` | What it means: the dot's color, and `danger` makes it an alert; `neutral`, with no dot, by default. |
| `href` | `string` | A page or setting that helps, linked after the message. |
| `linkLabel` | `string` | The link's words; "Learn more" by default. |
| `style` | `Style` | StyleX styles applied after the callout's own. |

## Keyboard and accessibility

- A danger callout is an `alert`, announced when it appears; any other is a polite `status`. The tone's dot is hidden from screen readers.
- The words must carry the meaning; the tone only colors it.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/alert
```

With npm: `npx shadcn@latest add checkfu/uicontext/alert`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/alert`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/alert`.

It writes these files:

- `src/ui/uicontext/components/Callout.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/variants.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/Callout.ts](https://github.com/checkfu/uicontext/blob/main/src/Callout.ts)

## Used in

- [Workflow builder](https://uicontext.com/blocks/automation-builder.md)
- [CRM](https://uicontext.com/blocks/crm.md)

## Related

- [Button](https://uicontext.com/docs/components/button.md) (`button`): A button, and a link that looks like one, in every tone and three sizes.
- [Toggle](https://uicontext.com/docs/components/toggle.md) (`toggle`): A button that stays pressed, such as Bold or Pin.
- [Toggle Group](https://uicontext.com/docs/components/toggle-group.md) (`toggle-group`): Buttons that stay pressed and share one value, such as text styles.
- [Input](https://uicontext.com/docs/components/input.md) (`input`): Text inputs, selects and textareas in a labeled field with a hint and an error, and their styles for controls you lay out yourself.
- [Status](https://uicontext.com/docs/components/status.md) (`status`): Status badges and tags for runs and records.
- [Glyphs](https://uicontext.com/docs/components/glyphs.md) (`glyphs`): Small marks for status, priority, color and people.
