The one line a panel section shows when it has nothing to list, with one action to fix it.
- 1.0 kB JS 2.9 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left
- 9 tests
Deals
No open deals with Northwind.
Open tickets
Nothing open. The last ticket closed on 2 December.
Notes
No notes yet.Write one
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 emptyexport 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" } })), ),})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 instead when the whole view or table is empty, not one section.
Usage
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
Framed
framed draws a dashed outline and centers the note, for a slot waiting to be filled.
No pinned messages. Pin one from its menu to keep it here.
No data for the last 7 days.Show 30 days
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 widgetexport 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 |
|---|---|---|
textrequired | 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
pnpm dlx shadcn@latest add checkfu/uicontext/empty-note