# Banner

> A band across the top about the whole product, such as a trial ending, with one action.

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

Group: Primitives.

## When to use

A band across the top about the whole product, such as a trial ending, with one action. Use [Alert](https://uicontext.com/docs/components/alert.md) instead when the message is about one part of the page.

## Usage

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

const Message = UiSchema.TaggedEnum({ DismissedNews: {} })

export const News = (h: Html.H<typeof Message.Type>) =>
	Banner(h, { tone: "info", title: "Exports now include comments.", action: { label: "See what's new", href: "/changelog" }, onDismiss: Message.DismissedNews() })
```

## Examples

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

### Maintenance, trial and payment

The example the page opens with: Banner in “Maintenance, trial and payment”.

```ts title="src/demo.ts" source="www/src/examples/banner/demo.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { Banner } from "./ui/uicontext/components/Banner.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { space } from "./ui/uicontext/components/tokens.stylex.ts"

const styles = stylex.create({ stack: { display: "grid", alignContent: "start", gap: space.md, inlineSize: "100%" } })

const Message = UiSchema.TaggedEnum({ Dismissed: { id: Schema.String }, ClickedRetry: {} })

// the bands an app shows across its top: news you can dismiss, and states that stay until they're fixed
export const AppBanners = Html.component({
	name: "AppBanners",
	model: Schema.Struct({ dismissed: Schema.Array(Schema.String), retried: Schema.Boolean }),
	message: Message,
}).make({
	init: () => ({ dismissed: [], retried: false }),
	update: {
		Dismissed: ($, { id }) => $.evolve({ dismissed: (d) => [...d, id] }),
		ClickedRetry: ($) => $.evolve({ retried: true }),
	},
	view: (h, model) =>
		h.div.attrs(sx(styles.stack)).children(
			model.dismissed.includes("maintenance")
				? null
				: Banner(h, {
						tone: "info",
						inset: true,
						title: "Scheduled maintenance Sunday, 02:00–03:00 UTC.",
						body: "Sync pauses for up to 20 minutes. Nothing is lost.",
						onDismiss: Message.Dismissed({ id: "maintenance" }),
					}),
			Banner(h, { tone: "warning", inset: true, title: "Your trial ends in 3 days.", action: { label: "Choose a plan", href: "#billing" } }),
			Banner(h, {
				tone: "danger",
				inset: true,
				title: model.retried ? "Trying the card again…" : "Your last payment failed.",
				body: "Update the card ending 4242 to keep your workspace active.",
				action: { label: "Retry payment", onClick: Message.ClickedRetry() },
			}),
		),
})
```

### Across the top of an app

Without `inset` it's a band, edge to edge. A state that still holds has no dismiss.

```ts title="src/app-top.ts" source="www/src/examples/banner/app-top.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Banner } from "./ui/uicontext/components/Banner.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, corner, font, space, stroke } from "./ui/uicontext/components/tokens.stylex.ts"

const styles = stylex.create({
	app: { inlineSize: "100%", overflow: "hidden", borderWidth: stroke.hairline, borderStyle: "solid", borderColor: color.line, borderRadius: corner.card, backgroundColor: color.panel },
	bar: { display: "flex", alignItems: "center", gap: space.md, blockSize: 44, paddingInline: space.lg, borderBlockEndWidth: stroke.hairline, borderBlockEndStyle: "solid", borderBlockEndColor: color.line, fontSize: font.sm, fontWeight: 600, color: color.fg },
	page: { padding: space.xl, fontSize: font.sm, color: color.muted },
})

// read-only mode during an incident: the band sits above the app's own header, edge to edge
export const IncidentBanner = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.app)).children(
		Banner(h, {
			tone: "warning",
			label: "Service status",
			title: "Editing is paused while we fix a database issue.",
			body: "You can still read everything.",
			action: { label: "Status page", href: "#status" },
		}),
		h.div.attrs(sx(styles.bar)).children("Northwind · Docs"),
		h.div.attrs(sx(styles.page)).children("Q3 launch plan"),
	)
```

## API reference

**Options**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `tone` | `"neutral" \| "info" \| "warning" \| "danger"` | `Neutral` | Neutral by default; danger for something broken that needs action now |
| `title` (required) | `string` | — | What's happening, in one short sentence: "Your trial ends in 3 days." |
| `body` | `string \| View.Content` | — | More, when it helps: "Scheduled maintenance Sunday 02:00–03:00 UTC." |
| `action` | `BannerAction<Message>` | — | — |
| `onDismiss` | `Message` | — | Leave it out while the state still holds (a failed payment); give it for news. |
| `inset` | `boolean` | — | A card inside a page instead of a band across the top. |
| `label` | `string` | `"Announcement"` | The landmark's name; "Announcement" by default. |
| `style` | `Style` | — | — |

## Installation

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

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

It writes these files:

- `src/ui/uicontext/components/Banner.ts`
- `src/ui/uicontext/components/IconStroke.ts`
- `src/ui/uicontext/components/InlineNotice.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/touch.stylex.ts`

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

## Source

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

## 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.
