# Empty Note

> The one line a panel section shows when it has nothing to list, with one action to fix it.

Page: https://uicontext.com/docs/components/empty-note

Group: Primitives.

## When to use

The one line a panel section shows when it has nothing to list, with one action to fix it. Use [Empty State](https://uicontext.com/docs/components/empty-state.md) instead when the whole view or table is empty, not one section.

## Usage

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

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

export const NoTasks = (h: Html.H<typeof Message.Type>) =>
	EmptyNote(h, { text: "No tasks due this week.", action: { label: "Add a task", onPress: Message.AddedTask() } })
```

## Examples

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

### Empty sections of a panel

The example the page opens with: Empty Note in “Empty sections of a panel”.

```ts title="src/demo.ts" source="www/src/examples/empty-note/demo.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { EmptyNote } from "./ui/uicontext/components/EmptyNote.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({
	panel: { display: "grid", inlineSize: "min(100%, 24rem)", borderWidth: stroke.hairline, borderStyle: "solid", borderColor: color.line, borderRadius: corner.card, backgroundColor: color.panel },
	section: { borderBlockStartWidth: stroke.hairline, borderBlockStartStyle: "solid", borderBlockStartColor: color.line },
	first: { borderBlockStartWidth: 0 },
	title: { margin: 0, paddingBlockStart: space.md, paddingInline: space.md, fontSize: font.xs, fontWeight: 600, color: color.muted },
	deal: { margin: 0, paddingBlock: space.md, paddingInline: space.md, fontSize: font.sm },
})

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

// a company's side panel in a CRM: deals, tickets and notes, two of them empty
export const AccountPanel = Html.component({
	name: "AccountPanel",
	model: Schema.Struct({ deals: Schema.Array(Schema.String) }),
	message: Message,
}).make({
	init: () => ({ deals: [] }),
	update: { AddedDeal: ($) => $.evolve({ deals: (d) => [...d, `Renewal ${2027 + d.length} · $48,000`] }) },
	view: (h, model) =>
		h.div.attrs(sx(styles.panel)).children(
			h.section.attrs(sx(styles.section, styles.first)).children(
				h.h3.attrs(sx(styles.title)).children("Deals"),
				model.deals.length === 0
					? EmptyNote(h, { text: "No open deals with Northwind.", action: { label: "Add a deal", onPress: Message.AddedDeal() } })
					: h.div.children(model.deals.map((d) => h.p.key(d).attrs(sx(styles.deal)).children(d))),
			),
			h.section.attrs(sx(styles.section)).children(h.h3.attrs(sx(styles.title)).children("Open tickets"), EmptyNote(h, { text: "Nothing open. The last ticket closed on 2 December." })),
			h.section.attrs(sx(styles.section)).children(h.h3.attrs(sx(styles.title)).children("Notes"), EmptyNote(h, { text: "No notes yet.", action: { label: "Write one", href: "#notes" } })),
		),
})
```

### Framed

`framed` draws a dashed outline and centers the note, for a slot waiting to be filled.

```ts title="src/framed.ts" source="www/src/examples/empty-note/framed.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { EmptyNote } from "./ui/uicontext/components/EmptyNote.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { space } from "./ui/uicontext/components/tokens.stylex.ts"

const styles = stylex.create({ wrap: { display: "grid", gap: space.md, inlineSize: "min(100%, 26rem)" } })

const Pin = <M>(h: Html.H<M>) =>
	h.svg.attrs({ width: "16", height: "16", viewBox: "0 0 16 16", fill: "none" }).children(
		h.path.attrs({ d: "M6 2h4l-.5 4 2.5 2v1.5H4V8l2.5-2L6 2zM8 9.5V14", stroke: "currentColor", "stroke-width": "1.5", "stroke-linejoin": "round" }),
	)

// slots waiting to be filled: a channel's pinned messages and a dashboard's empty widget
export const WaitingSlots = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.wrap)).children(
		EmptyNote(h, { text: "No pinned messages. Pin one from its menu to keep it here.", icon: Pin(h), framed: true }),
		EmptyNote(h, { text: "No data for the last 7 days.", action: { label: "Show 30 days", href: "#range-30" }, framed: true }),
	)
```

## API reference

**Options**

| Name | Type | Description |
| --- | --- | --- |
| `text` (required) | `string` | What isn't there, as a sentence: "No open tickets for this customer." |
| `action` | `EmptyNoteAction<Message>` | The one thing to do about it. |
| `icon` | `View.Content` | A small icon before the text. |
| `framed` | `boolean` | A dashed outline around it, centered: for a slot that's waiting to be filled. |
| `style` | `Style` | — |

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/empty-note
```

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

It writes these files:

- `src/ui/uicontext/components/EmptyNote.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/EmptyNote.ts](https://github.com/checkfu/uicontext/blob/main/src/EmptyNote.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.
