Counts per day or week as word-sized columns, the latest in full color.
- 2.0 kB JS 5.3 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left
- 10 tests
| Service | Last 14 days | Deploys | Failed |
|---|---|---|---|
| api-gateway | 41 | 1 | |
| billing-worker | 6 | 0 | |
| search-indexer | 42 | 3 |
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { SparkBars } from "./ui/uicontext/components/charts/SparkBars.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space, stroke } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ table: { inlineSize: "min(100%, 34rem)", borderCollapse: "collapse", fontSize: font.sm }, th: { paddingBlock: space.sm, paddingInline: space.sm, textAlign: "start", fontSize: font.xs, fontWeight: 500, color: color.muted, borderBlockEndWidth: stroke.hairline, borderBlockEndStyle: "solid", borderBlockEndColor: color.line }, td: { paddingBlock: space.sm, paddingInline: space.sm, textAlign: "start", borderBlockEndWidth: stroke.hairline, borderBlockEndStyle: "solid", borderBlockEndColor: color.line }, num: { textAlign: "end", fontVariantNumeric: "tabular-nums" }, failed: { color: color.danger },})const services = [ { name: "api-gateway", deploys: [3, 5, 2, 0, 0, 4, 6, 3, 7, 2, 0, 0, 5, 4], failed: 1 }, { name: "billing-worker", deploys: [1, 0, 0, 1, 0, 0, 0, 2, 0, 1, 0, 0, 0, 1], failed: 0 }, { name: "search-indexer", deploys: [0, 2, 4, 3, 0, 0, 1, 9, 12, 6, 0, 0, 3, 2], failed: 3 },]// deploys a day for two weeks, one row per service; today's column is the dark oneexport const DeployTable = <M>(h: Html.H<M>) => h.table.attrs(sx(styles.table)).children( h.thead.children( h.tr.children( h.th.attrs({ scope: "col", ...sx(styles.th) }).children("Service"), h.th.attrs({ scope: "col", ...sx(styles.th) }).children("Last 14 days"), h.th.attrs({ scope: "col", ...sx(styles.th, styles.num) }).children("Deploys"), h.th.attrs({ scope: "col", ...sx(styles.th, styles.num) }).children("Failed"), ), ), h.tbody.children( services.map((s) => h.tr.key(s.name).children( h.th.attrs({ scope: "row", ...sx(styles.td) }).children(s.name), h.td.attrs(sx(styles.td)).children(SparkBars(h, { label: `${s.name} deploys a day, last 14 days`, values: s.deploys })), h.td.attrs(sx(styles.td, styles.num)).children(String(s.deploys.reduce((a, b) => a + b, 0))), h.td.attrs(sx(styles.td, styles.num, s.failed > 0 && styles.failed)).children(String(s.failed)), )), ), )When to use
Counts per day or week as word-sized columns, the latest in full color. Use Bar Chart instead when the values need axes and labels.
Usage
import { SparkBars } from "./ui/uicontext/components/charts/SparkBars.ts"export const Deploys = <M>(h: Html.H<M>) => SparkBars(h, { label: "Deploys, last 14 days", values: [3, 5, 2, 0, 0, 4, 6, 3, 7, 2, 0, 0, 5, 4] })Examples
Across a stat card
width: "fill" takes the card's width; hours still to come are null. highlight picks out the busiest.
Signups today
427
Busiest at 13:00 · 51 signups
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { SparkBars } from "./ui/uicontext/components/charts/SparkBars.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({ card: { display: "grid", gap: space.sm, inlineSize: "min(100%, 20rem)", padding: space.lg, borderWidth: stroke.hairline, borderStyle: "solid", borderColor: color.line, borderRadius: corner.card, backgroundColor: color.panel }, label: { margin: 0, fontSize: font.sm, color: color.muted }, value: { margin: 0, fontSize: font.xl, fontWeight: 600, fontVariantNumeric: "tabular-nums" }, hint: { margin: 0, fontSize: font.xs, color: color.muted },})// signups an hour since midnight, filling the card's width; the busiest hour is the one picked outconst hours = [2, 1, 0, 0, 1, 3, 9, 18, 31, 42, 38, 35, 44, 51, 47, 40, 36, 29, null, null, null, null, null, null]const busiest = hours.indexOf(Math.max(...hours.map((v) => v ?? 0)))export const SignupsToday = <M>(h: Html.H<M>) => h.section.attrs(sx(styles.card)).children( h.p.attrs(sx(styles.label)).children("Signups today"), h.p.attrs(sx(styles.value)).children("427"), SparkBars(h, { label: "Signups an hour, today", values: hours, width: "fill", height: 40, highlight: busiest, color: 3 }), h.p.attrs(sx(styles.hint)).children("Busiest at 13:00 · 51 signups"), )API reference
Options
| Name | Type | Default | Description |
|---|---|---|---|
valuesrequired | ReadonlyArray<number | null> | — | One number per period, oldest first; null for a period with no data. |
labelrequired | string | — | What it shows, for its accessible name: "Deploys, last 14 days". |
format | ChartFormat | — | — |
width | number | "fill" | 96 | Pixels, or "fill" to take its container's width. 96 by default. |
height | number | 24 | Pixels; 24 by default. |
highlight | number | — | The column in full color; the last by default, -1 for all of them. |
color | ChartColor | — | — |
locale | string | — | — |
style | Style | — | — |
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/spark-bars