How far a task has got, as a bar or a ring, with a label and its value, or a sweep while the amount is unknown.
Ready to import
Duplicates merge by email address.
import { 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 { formatNumber } from "./ui/uicontext/components/domain/Format.ts"import { Progress } from "./ui/uicontext/components/Progress.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, radius, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ card: { display: "grid", gap: space.xl, inlineSize: "min(100%, 26rem)", padding: space.xl, borderWidth: 1, borderStyle: "solid", borderColor: color.line, borderRadius: radius.lg, backgroundColor: color.panel, }, note: { margin: 0, fontSize: font.sm, color: color.muted }, actions: { display: "flex", gap: space.md },})const TOTAL = 1284const BATCH = 97const Phase = Schema.Literals(["idle", "reading", "importing", "done"])const Message = UiSchema.TaggedEnum({ ClickedImport: {}, CompletedImportBatch: {}, ClickedCancel: {} })// stands in for the server: each call imports one batch of contactsconst ImportBatch = Command.make("Example.ImportBatch", {}, () => Effect.sleep("180 millis").pipe(Effect.as(Message.CompletedImportBatch())))export const ContactImport = Html.component({ name: "ContactImport", // while the file is read the row count isn't known, so the bar has no value yet model: Schema.Struct({ phase: Phase, imported: Schema.Number }), message: Message,}).make({ init: () => ({ phase: "idle", imported: 0 }), update: { ClickedImport: ($) => $.evolve({ phase: "reading", imported: 0 }).run(ImportBatch.make({})), CompletedImportBatch: ($) => { if ($.model.phase === "reading") return $.evolve({ phase: "importing" }).run(ImportBatch.make({})) if ($.model.phase !== "importing") return $.model const imported = Math.min(TOTAL, $.model.imported + BATCH) return imported === TOTAL ? $.evolve({ phase: "done", imported }) : $.evolve({ imported }).run(ImportBatch.make({})) }, ClickedCancel: ($) => $.evolve({ phase: "idle", imported: 0 }), }, view: (h, { phase, imported }) => h.div.attrs(sx(styles.card)).children( Progress(h, { label: phase === "reading" ? "Reading contacts.csv…" : phase === "done" ? "Imported" : phase === "idle" ? "Ready to import" : "Importing contacts", value: phase === "reading" ? null : imported, max: TOTAL, valueText: `${formatNumber(imported)} of ${formatNumber(TOTAL)}`, tone: phase === "done" ? "success" : "accent", }), h.p.attrs({ role: "status", ...sx(styles.note) }).children( phase === "done" ? `${formatNumber(TOTAL)} contacts added to Customers.` : "Duplicates merge by email address.", ), h.div.attrs(sx(styles.actions)).children( phase === "reading" || phase === "importing" ? Button(h).on("click", Message.ClickedCancel()).children("Cancel") : Button(h, { tone: "primary" }).on("click", Message.ClickedImport()).children(phase === "done" ? "Import again" : "Import"), ), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/progressUsage
import { Progress } from "./ui/uicontext/components/Progress.ts"export const UploadProgress = <M>(h: Html.H<M>, sent: number) => Progress(h, { label: "Uploading 3 of 5 files", value: sent })Examples
Limits and tones
The tone says how close a limit is. Words carry the value when a percentage isn't the clearest.
Automation runs
Storage
Seats
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { formatNumber } from "./ui/uicontext/components/domain/Format.ts"import { Progress } from "./ui/uicontext/components/Progress.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ stack: { display: "grid", gap: 20, inlineSize: "min(100%, 26rem)" } })// a plan's limits: quiet while there's room, then a warning, then the limit reachedexport const PlanLimits = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.stack)).children( Progress(h, { key: "runs", label: "Automation runs", value: 4210, max: 10000, valueText: `${formatNumber(4210)} of ${formatNumber(10000)}`, size: "sm" }), Progress(h, { key: "storage", label: "Storage", value: 8.6, max: 10, valueText: "8.6 of 10 GB", tone: "warning", size: "sm" }), Progress(h, { key: "seats", label: "Seats", value: 25, max: 25, valueText: "25 of 25", tone: "danger", size: "sm" }), )Progress circle
A ring for cards and rows. A small one keeps its label for screen readers only.
Workspace setup
Syncing calendar
Indexing the repository
Uploading roadmap.pdf
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { ProgressCircle } from "./ui/uicontext/components/Progress.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ row: { display: "flex", flexWrap: "wrap", alignItems: "center", gap: 28 } })export const Rings = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.row)).children( ProgressCircle(h, { key: "setup", label: "Workspace setup", value: 3, max: 5, valueText: "3 of 5 steps", size: "lg", tone: "success" }), ProgressCircle(h, { key: "sync", label: "Syncing calendar", value: 42 }), ProgressCircle(h, { key: "index", label: "Indexing the repository", value: null }), // small enough for a row of text: the label stays, for a screen reader ProgressCircle(h, { key: "upload", label: "Uploading roadmap.pdf", value: 71, size: "sm", showLabel: false }), )API reference
ProgressView function
Options
| Name | Type | Default | Description |
|---|---|---|---|
key | string | — | Names the bar among others in the same view; needed for more than one |
valuerequired | number | null | — | How far along, from min to max, or null while the amount is unknown. |
min | number | 0 | 0 by default. |
max | number | 100 | 100 by default. |
labelrequired | string | — | What's in progress: "Uploading 3 of 5 files". Shown above the bar, and its name. |
hideLabel | boolean | — | Hide the label but keep it as the bar's name, for a bar whose meaning is plain from where it sits. |
valueText | string | — | The value as words, when a percentage isn't the clearest: "8 of 10 GB". |
showValue | boolean | true | Show the value beside the label; true by default. |
size | "sm" | "md" | "lg" | md | The bar's thickness; md by default. |
tone | "accent" | "success" | "warning" | "danger" | "info" | accent | Its color, by what it means; accent by default. Use danger for a quota nearly used up. |
style | Style | — | StyleX styles applied after the bar's own. |
ProgressCircleView function
Options
| Name | Type | Default | Description |
|---|---|---|---|
size | "sm" | "md" | "lg" | md | sm (20px) sits in a row of text, md (40px) in a card, lg (64px) leads a panel; md by default. |
showLabel | boolean | true | Show the label and the value beside the ring; true by default. Without it the label still names the ring for a screen reader. |