What a view shows when it's empty, after a failure, or when access is refused, for a whole page or inside a table or list.
- 4.7 kB JS 3.7 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left
- 8 tests
No runs yet
Runs show here once Invoice sync is triggered. Run it now to see one.
This example also uses Segmented Control and Skeleton. Install them too:
npx shadcn@latest add checkfu/uicontext/segmented-control checkfu/uicontext/skeletonimport { Command, UiSchema } from "effect/ui"import { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Effect, Schema } from "effect"import { Button } from "./ui/uicontext/components/Button.ts"import { EmptyState, ErrorBanner } from "./ui/uicontext/components/States.ts"import { SkeletonList } from "./ui/uicontext/components/Skeleton.ts"import { SegmentedControl } from "./ui/uicontext/components/SegmentedControl.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, corner, font, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ stack: { display: "grid", gap: space.lg, inlineSize: "min(100%, 34rem)" }, note: { margin: 0, minBlockSize: "1.4em", fontSize: font.sm, color: color.muted }, panel: { minBlockSize: 200, padding: space.lg, borderRadius: corner.card, backgroundColor: color.panel, boxShadow: `inset 0 0 0 1px ${color.line}`, },})const Shown = Schema.Literals(["loading", "empty", "failed", "refused"])const Message = UiSchema.TaggedEnum({ PickedState: { state: Shown }, ClickedRetry: {}, CompletedRetry: {}, ClickedCreate: {}, ClickedRequestAccess: {},})// stands in for the app's request: it fails again, so the banner stays to showconst Retry = Command.make("Example.RetryRuns", {}, () => Effect.sleep("900 millis").pipe(Effect.as(Message.CompletedRetry())))// the app's words for each rejection its services can returnconst copy = { Unreachable: { sentence: "Couldn't load this workflow's runs.", nextStep: "Check your connection, then try again.", action: "Try again" }, NotAMember: { sentence: "You don't have access to Invoice sync.", nextStep: "Ask Maya Chen, its owner, to add you.", action: "Request access", tone: "neutral" as const, },}export const RunStates = Html.component({ name: "RunStates", model: Schema.Struct({ state: Shown, retrying: Schema.Boolean, note: Schema.String }), message: Message,}).make({ init: () => ({ state: "empty", retrying: false, note: "" }), update: { PickedState: ($, { state }) => $.evolve({ state, retrying: false, note: "" }), ClickedRetry: ($) => ($.model.retrying ? $.model : $.evolve({ state: "loading", retrying: true }).run(Retry.make())), CompletedRetry: ($) => ($.model.retrying ? $.evolve({ state: "failed", retrying: false }) : $.model), ClickedCreate: ($) => $.evolve({ note: "The app would start a run." }), ClickedRequestAccess: ($) => $.evolve({ note: "Request sent. Maya Chen will get an email." }), }, view: (h, { state, note }) => h.div.attrs(sx(styles.stack)).children( SegmentedControl(h, { label: "State", size: "sm", value: state, options: [ { value: "loading", label: "Loading" }, { value: "empty", label: "Empty" }, { value: "failed", label: "Failed" }, { value: "refused", label: "No access" }, ], onChange: (value) => Message.PickedState({ state: value === "loading" || value === "failed" || value === "refused" ? value : "empty" }), }), h.div.attrs({ "aria-live": "polite", ...sx(styles.panel) }).children( state === "loading" ? SkeletonList(h, { label: "Loading runs", shape: "rows", count: 4 }) : state === "empty" ? EmptyState(h, { icon: "↻", title: "No runs yet", hint: "Runs show here once Invoice sync is triggered. Run it now to see one.", actions: [Button(h, { tone: "primary" }).on("click", Message.ClickedCreate()).children("Run now")], }) : ErrorBanner(h, { props: { agentId: "runs-error", rejection: state === "failed" ? "Unreachable" : "NotAMember", copy, urgent: state === "failed" }, onEmit: { RequestedAction: ({ rejection }) => (rejection === "Unreachable" ? Message.ClickedRetry() : Message.ClickedRequestAccess()), RequestedDismiss: () => undefined, }, }), ), h.p.attrs({ role: "status", ...sx(styles.note) }).children(note), ),})When to use
What a view shows when it's empty, after a failure, or when access is refused, for a whole page or inside a table or list. Use Skeleton instead when the content is on its way, not missing.
Usage
import { EmptyState } from "./ui/uicontext/components/States.ts"export const IssuesBody = <M>(h: Html.H<M>, issues: ReadonlyArray<string>) => issues.length === 0 ? EmptyState(h, { title: "No open issues", hint: "Issues you're assigned show here." }) : h.ul.children(issues.map((title) => h.li.key(title).children(title)))API reference
ErrorBannerComponent
Props
| Name | Type | Description |
|---|---|---|
agentId | string | This banner's id for agents, unique on the page: "spend-limit-error" |
rejectionrequired | string | null | The rejection's _tag, or null for no banner |
copyrequired | Record<string, RejectionCopy> | The app's table: one entry per rejection tag |
fallback | RejectionCopy | For a tag the table lacks; a generic "That didn't work" by default |
dismissible | boolean | Shows a dismiss button that emits RequestedDismiss |
urgent | boolean | Announce at once (a failed action) or politely (a state the page is in) |
Events
| Event | Payload | Description |
|---|---|---|
RequestedAction | { rejection: string } | The person asked for the next step of this rejection |
RequestedDismiss | { rejection: string } | The person dismissed the banner; stop passing this rejection |
Agent actions
| Action | Description |
|---|---|
ClickedAction | Take the banner's next step (its action) |
ClickedDismiss | Dismiss the banner |
EmptyStateView function
Options
| Name | Type | Default | Description |
|---|---|---|---|
titlerequired | string | — | What isn't here, plainly: "No connectors yet" |
hint | string | — | Why, or what will appear here: "Connected apps show here. Agents use only the ones you connect." |
icon | string | — | One character or symbol, decorative |
actions | View.Children | — | The one thing to do about it: usually a single Button |
heading | "h2" | "h3" | "p" | — | A heading level for the title when the empty state stands for a whole page |
variant | "page" | "compact" | page | page for a whole page or section; compact inside a table, a list or a panel; page by default |
style | Style | — | StyleX styles applied after the empty state's own. |
Keyboard and accessibility
- An empty state's title can be an
h2orh3when it stands for a whole page. - An error banner is an
alert, or a politestatuswithurgent: false; its next step is a real button or link and its dismiss button is labelled. - Agents read the banner's sentence, next step and action, and can take the next step or dismiss it, as a person would.
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/empty-state