# Inline Notice

> One line under a form or a list that says what just happened, such as Saved or Couldn't save, read aloud when it changes.

Page: https://uicontext.com/docs/components/inline-notice

Group: Primitives.

## When to use

One line under a form or a list that says what just happened, such as Saved or Couldn't save, read aloud when it changes. Use [Toast](https://uicontext.com/docs/components/toast.md) instead when the message isn't tied to one form or list.

## Usage

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

export const Saved = <M>(h: Html.H<M>, savedAt: string | null) =>
	InlineNotice(h, { tone: "success", text: savedAt === null ? "" : `Saved at ${savedAt}` })
```

## Examples

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

### Under a field

The example the page opens with: Inline Notice in “Under a field”.

```ts title="src/demo.ts" source="www/src/examples/inline-notice/demo.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { InlineNotice } from "./ui/uicontext/components/InlineNotice.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, corner, density, font, motion, space, stroke } from "./ui/uicontext/components/tokens.stylex.ts"

const styles = stylex.create({
	form: { display: "grid", gap: space.sm, inlineSize: "min(100%, 24rem)" },
	label: { fontSize: font.sm, fontWeight: 500 },
	input: {
		minBlockSize: density.control,
		paddingInline: space.md,
		borderWidth: stroke.control,
		borderStyle: "solid",
		borderColor: color.controlLine,
		borderRadius: corner.control,
		backgroundColor: color.panel,
		color: color.fg,
		fontFamily: "inherit",
		fontSize: { default: font.sm, "@media (pointer: coarse)": "1rem" },
		outline: { default: "none", ":focus-visible": `2px solid ${color.focusRing}` },
	},
	actions: { display: "flex", flexWrap: "wrap", gap: space.sm },
	button: {
		minBlockSize: density.control,
		paddingInline: space.md,
		borderWidth: stroke.control,
		borderStyle: "solid",
		borderColor: color.controlLine,
		borderRadius: corner.control,
		backgroundColor: { default: color.panel, ":hover": { default: null, "@media (hover: hover) and (pointer: fine)": color.hover } },
		color: color.fg,
		fontFamily: "inherit",
		fontSize: font.sm,
		fontWeight: 500,
		cursor: "pointer",
		outline: { default: "none", ":focus-visible": `2px solid ${color.focusRing}` },
		outlineOffset: 2,
		transform: { default: "none", ":active": `scale(${motion.press})` },
		transitionProperty: "background-color, transform",
		transitionDuration: motion.fast,
	},
})

const Message = UiSchema.TaggedEnum({ Saved: {}, Failed: {} })

// a settings field: the notice under it says how the last save went, and a screen reader hears it
export const WorkspaceName = Html.component({
	name: "WorkspaceName",
	model: Schema.Struct({ result: Schema.Literals(["none", "saved", "failed"]) }),
	message: Message,
}).make({
	init: () => ({ result: "none" as const }),
	update: { Saved: ($) => $.evolve({ result: () => "saved" as const }), Failed: ($) => $.evolve({ result: () => "failed" as const }) },
	view: (h, model) =>
		h.div.attrs(sx(styles.form)).children(
			h.label.attrs({ for: "workspace-name", ...sx(styles.label) }).children("Workspace name"),
			h.input.attrs({ id: "workspace-name", value: "Harborview Support", "aria-describedby": "workspace-name-notice", ...sx(styles.input) }),
			InlineNotice(h, {
				id: "workspace-name-notice",
				tone: model.result === "failed" ? "danger" : "success",
				text: model.result === "saved" ? "Saved. Everyone sees the new name." : model.result === "failed" ? "Couldn't save. Check your connection and try again." : "",
			}),
			h.div.attrs(sx(styles.actions)).children(
				h.button.attrs({ type: "button", ...sx(styles.button) }).on("click", Message.Saved()).children("Save"),
				h.button.attrs({ type: "button", ...sx(styles.button) }).on("click", Message.Failed()).children("Save while offline"),
			),
		),
})
```

### Tones

Plain for status, then info, success, warning and danger. `danger` is announced at once; the rest wait for a pause.

```ts title="src/tones.ts" source="www/src/examples/inline-notice/tones.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { InlineNotice } from "./ui/uicontext/components/InlineNotice.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"
import { touchArea } from "./ui/uicontext/components/touch.stylex.ts"

const styles = stylex.create({
	stack: { display: "grid", gap: space.md, inlineSize: "min(100%, 30rem)" },
	// a finger gets 44px around the short link
	link: { position: "relative", "::after": { content: touchArea.content, position: "absolute", insetInline: touchArea.reach, insetBlock: touchArea.reach }, color: color.accent, fontSize: font.sm, fontWeight: 500, textDecoration: { default: "none", ":hover": { default: null, "@media (hover: hover) and (pointer: fine)": "underline" } } },
})

// what an import, a sync and a deploy say about themselves, one line each
export const ImportResults = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.stack)).children(
		InlineNotice(h, { text: "Last synced 2 minutes ago" }),
		InlineNotice(h, { tone: "info", text: "Imports over 10,000 rows run in the background; we'll email you when it's done." }),
		InlineNotice(h, { tone: "success", text: "Imported 1,208 contacts." }),
		InlineNotice(h, { tone: "warning", text: "14 rows skipped: no email address.", action: h.a.attrs({ href: "#skipped", ...sx(styles.link) }).children("See rows") }),
		InlineNotice(h, { tone: "danger", size: "sm", text: "Deploy failed at step 3 of 5: the build ran out of memory." }),
	)
```

## API reference

**Options**

| Name | Type | Description |
| --- | --- | --- |
| `text` (required) | `string` | What happened or what's wrong. Empty draws only the live region, so the next text is heard. |
| `tone` | `"neutral" \| "info" \| "success" \| "warning" \| "danger"` | `danger` is announced at once; the others wait for a pause. |
| `action` | `View.Content` | Something to do about it, after the text: a Retry button, a link. |
| `size` | `"sm" \| "md"` | — |
| `id` | `string` | An id, for the field whose `aria-describedby` points here. |
| `style` | `Style` | — |

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/inline-notice
```

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

It writes these files:

- `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/InlineNotice.ts](https://github.com/checkfu/uicontext/blob/main/src/InlineNotice.ts)
- [src/touch.stylex.ts](https://github.com/checkfu/uicontext/blob/main/src/touch.stylex.ts)

## Used in

- [SaaS dashboard](https://uicontext.com/blocks/saas-dashboard.md)
- [Workflow builder](https://uicontext.com/blocks/automation-builder.md)
- [Team chat](https://uicontext.com/blocks/team-chat.md)
- [Whiteboard](https://uicontext.com/blocks/whiteboard.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.
