The line over a group of rows with its count, sticky while they scroll, folding the group.
- 1.7 kB JS 3.1 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left
- 9 tests
- Send the Q4 renewal quote to Northwind28 Nov
- Review the security questionnaire1 Dec
- Call back Harborview Supply about seats2 Dec
- Prep the pricing review deck4 Dec
- Reply to Priya on the SSO question4 Dec
- Update the Billing migration status4 Dec
- Book the offsite venue4 Dec
- Interview: senior designer5 Dec
- 1:1 with Tomás6 Dec
- Close out November expenses7 Dec
- Ship the onboarding checklist3 Dec
- Merge the invoice PDF fix3 Dec
- Archive the old help center2 Dec
- Sign the Halvorsen & Co order form1 Dec
- Draft the hiring plan30 Nov
import { UiSchema } from "effect/ui"import { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { GroupHeader } from "./ui/uicontext/components/GroupHeader.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, corner, density, font, space, stroke } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ box: { inlineSize: "min(100%, 30rem)", blockSize: 320, overflowY: "auto", overscrollBehavior: "contain", borderWidth: stroke.hairline, borderStyle: "solid", borderColor: color.line, borderRadius: corner.card, backgroundColor: color.app }, rows: { margin: 0, padding: 0, listStyle: "none" }, row: { display: "flex", alignItems: "baseline", gap: space.md, paddingBlock: space.sm, paddingInline: space.md, fontSize: font.sm, borderBlockEndWidth: stroke.hairline, borderBlockEndStyle: "solid", borderBlockEndColor: color.line }, title: { flexGrow: 1, minInlineSize: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, due: { flexShrink: 0, fontSize: font.xs, color: color.muted, fontVariantNumeric: "tabular-nums" }, done: { color: color.muted, textDecorationLine: "line-through" }, add: { paddingInline: space.sm, minBlockSize: density.control, minInlineSize: { default: 0, "@media (pointer: coarse)": density.control }, borderWidth: 0, borderRadius: corner.tag, backgroundColor: "transparent", color: color.muted, fontFamily: "inherit", fontSize: font.xs, cursor: "pointer" },})const groups = [ { id: "overdue", title: "Overdue", tone: "danger" as const, tasks: [["Send the Q4 renewal quote to Northwind", "28 Nov"], ["Review the security questionnaire", "1 Dec"], ["Call back Harborview Supply about seats", "2 Dec"]] }, { id: "today", title: "Today", tasks: [["Prep the pricing review deck", "4 Dec"], ["Reply to Priya on the SSO question", "4 Dec"], ["Update the Billing migration status", "4 Dec"], ["Book the offsite venue", "4 Dec"]] }, { id: "week", title: "This week", tasks: [["Interview: senior designer", "5 Dec"], ["1:1 with Tomás", "6 Dec"], ["Close out November expenses", "7 Dec"]] }, { id: "done", title: "Done", tasks: [["Ship the onboarding checklist", "3 Dec"], ["Merge the invoice PDF fix", "3 Dec"], ["Archive the old help center", "2 Dec"], ["Sign the Halvorsen & Co order form", "1 Dec"], ["Draft the hiring plan", "30 Nov"]] },] as constconst Message = UiSchema.TaggedEnum({ Toggled: { id: Schema.String } })// a task list: each group's header sticks while its rows scroll under it, and folds the groupexport const TaskGroups = Html.component({ name: "TaskGroups", model: Schema.Struct({ closed: Schema.Array(Schema.String) }), message: Message,}).make({ init: () => ({ closed: ["done"] }), update: { Toggled: ($, { id }) => $.evolve({ closed: (list) => (list.includes(id) ? list.filter((x) => x !== id) : [...list, id]) }) }, view: (h, model) => h.div.attrs(sx(styles.box)).children( groups.map((g) => { const open = !model.closed.includes(g.id) return h.section.key(g.id).children( GroupHeader(h, { title: g.title, count: g.tasks.length, ...("tone" in g ? { tone: g.tone } : {}), sticky: true, open, onToggle: Message.Toggled({ id: g.id }), controls: `tasks-${g.id}`, end: h.button.attrs({ type: "button", "aria-label": `Add a task to ${g.title}`, ...sx(styles.add) }).children("Add"), }), h.ul.attrs({ id: `tasks-${g.id}`, hidden: open ? undefined : "", ...sx(styles.rows) }).children( g.tasks.map(([title, due]) => h.li.key(title).attrs(sx(styles.row)).children( h.span.attrs({ dir: "auto", ...sx(styles.title, g.id === "done" && styles.done) }).children(title), h.span.attrs(sx(styles.due)).children(due), )), ), ) }), ),})When to use
The line over a group of rows with its count, sticky while they scroll, folding the group. Use Accordion instead when the sections are content, not groups of rows.
Usage
import { GroupHeader } from "./ui/uicontext/components/GroupHeader.ts"const Message = UiSchema.TaggedEnum({ ToggledDone: {} })export const DoneHeader = (h: Html.H<typeof Message.Type>, open: boolean) => GroupHeader(h, { title: "Done", count: 12, sticky: true, open, onToggle: Message.ToggledDone(), controls: "done-rows" })Examples
Plain headings
Without onToggle it's a heading and a count; level places it among the page's headings.
Needs your review2
- Dark mode for settings
- Retry failed webhooks
Waiting on others3
- Rate-limit the export API
- New invoice template
- Search by customer email
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { GroupHeader } from "./ui/uicontext/components/GroupHeader.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({ wrap: { inlineSize: "min(100%, 26rem)" }, rows: { margin: 0, marginBlockEnd: space.md, padding: 0, listStyle: "none" }, row: { paddingBlock: space.sm, paddingInline: space.sm, fontSize: font.sm, borderBlockEndWidth: stroke.hairline, borderBlockEndStyle: "solid", borderBlockEndColor: color.line },})const lanes = [ { title: "Needs your review", tone: "accent" as const, rows: ["Dark mode for settings", "Retry failed webhooks"] }, { title: "Waiting on others", rows: ["Rate-limit the export API", "New invoice template", "Search by customer email"] },]// pull requests grouped by what they wait on: headings without a toggle, one in the accentexport const ReviewLanes = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.wrap)).children( lanes.map((lane) => h.section.key(lane.title).children( GroupHeader(h, { title: lane.title, count: lane.rows.length, ...(lane.tone === undefined ? {} : { tone: lane.tone }), level: 2 }), h.ul.attrs(sx(styles.rows)).children(lane.rows.map((r) => h.li.key(r).attrs(sx(styles.row)).children(r))), )), )API reference
Options
| Name | Type | Default | Description |
|---|---|---|---|
titlerequired | string | — | — |
count | number | — | How many rows the group holds, shown after the title. |
tone | "danger" | "accent" | — | Colors the title: danger for overdue, accent for what needs you. |
sticky | boolean | — | Sticks to the top of its scrolling list while its rows pass under it. |
level | 2 | 3 | 4 | 3 | The heading level, so the groups show in a screen reader's list of headings. 3 by default. |
open | boolean | — | Whether the group is open; with onToggle, the header folds it. |
onToggle | Message | — | — |
controls | string | — | The id of the element holding the group's rows, which the toggle opens and closes. |
end | View.Content | — | Things at the end: an "Add" button, a menu. |
locale | string | — | — |
style | Style | — | — |
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/group-header