The line that splits a feed by day, such as Today or Yesterday, and a helper that groups items by day.
- 1.2 kB JS 2.5 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left
- 10 tests
- Lena Fischer10:02
Happy new year in advance, everyone.
- Wei Chen09:15
Q4 targets are in the planning doc.
- Priya Raman14:40
Northwind signed the renewal.
- Tomás García15:05
Nice. I'll send the onboarding plan.
- Ada Okafor08:50
Exports are failing for a few customers; looking now.
- Ada Okafor09:12
Fixed: a timeout on the ledger API. Exports are back.
- Priya Raman09:20
Thank you! Telling the customers now.
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { DateDivider, groupByDay } from "./ui/uicontext/components/DateDivider.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({ feed: { inlineSize: "min(100%, 30rem)", blockSize: 380, overflowY: "auto", overscrollBehavior: "contain", paddingInline: space.md, borderWidth: stroke.hairline, borderStyle: "solid", borderColor: color.line, borderRadius: corner.card, backgroundColor: color.panel }, day: { margin: 0, padding: 0, listStyle: "none" }, message: { display: "grid", gap: 2, paddingBlock: space.sm }, top: { display: "flex", gap: space.sm, alignItems: "baseline", fontSize: font.sm }, name: { fontWeight: 600 }, time: { fontSize: font.xs, color: color.muted, fontVariantNumeric: "tabular-nums" }, text: { margin: 0, fontSize: font.sm, lineHeight: 1.5 },})// the instant the demo pretends it is, so the labels don't change from day to dayconst now = "2026-12-04T16:30:00Z"const timeZone = "Europe/London"const clock = new Intl.DateTimeFormat("en-GB", { timeZone, hour: "2-digit", minute: "2-digit" })const messages = [ { id: "1", from: "Lena Fischer", at: "2025-12-29T10:02:00Z", text: "Happy new year in advance, everyone." }, { id: "2", from: "Wei Chen", at: "2026-11-20T09:15:00Z", text: "Q4 targets are in the planning doc." }, { id: "3", from: "Priya Raman", at: "2026-12-01T14:40:00Z", text: "Northwind signed the renewal." }, { id: "4", from: "Tomás García", at: "2026-12-01T15:05:00Z", text: "Nice. I'll send the onboarding plan." }, { id: "5", from: "Ada Okafor", at: "2026-12-03T08:50:00Z", text: "Exports are failing for a few customers; looking now." }, { id: "6", from: "Ada Okafor", at: "2026-12-04T09:12:00Z", text: "Fixed: a timeout on the ledger API. Exports are back." }, { id: "7", from: "Priya Raman", at: "2026-12-04T09:20:00Z", text: "Thank you! Telling the customers now." },]// a team channel: a sticky day stays on top while its messages scroll under itexport const Channel = <M>(h: Html.H<M>) => h.div.attrs({ tabindex: "0", "aria-label": "#support messages", ...sx(styles.feed) }).children( groupByDay(messages, (m) => m.at, { now, timeZone, locale: "en-GB" }).map((day) => h.section.key(day.key).children( DateDivider(h, { label: day.label, sticky: true }), h.ul.attrs(sx(styles.day)).children( day.items.map((m) => h.li.key(m.id).attrs(sx(styles.message)).children( h.div.attrs(sx(styles.top)).children(h.span.attrs(sx(styles.name)).children(m.from), h.span.attrs(sx(styles.time)).children(clock.format(new Date(m.at)))), h.p.attrs({ dir: "auto", ...sx(styles.text) }).children(m.text), )), ), )), )When to use
The line that splits a feed by day, such as Today or Yesterday, and a helper that groups items by day. Use Group Header instead when rows are grouped by something other than the day.
Usage
import { DateDivider, groupByDay } from "./ui/uicontext/components/DateDivider.ts"export const Feed = <M>(h: Html.H<M>, messages: ReadonlyArray<{ readonly id: string; readonly sentAt: string; readonly text: string }>, now: string) => groupByDay(messages, (m) => m.sentAt, { now }).map(({ label, items }) => [DateDivider(h, { label }), ...items.map((m) => h.p.key(m.id).children(m.text))])Examples
Activity, in the reader's time zone
align: "start" puts the day at the line's start. timeZone decides which day an instant falls on.
- Ada Okafor closed the issue10:10 AM
- Deploy 3f9a2c reached production8:00 PM
- Tomás García linked a pull request9:30 AM
- Priya Raman set priority to High11:00 AM
- Wei Chen opened the issue8:20 AM
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { DateDivider, groupByDay } from "./ui/uicontext/components/DateDivider.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ wrap: { inlineSize: "min(100%, 28rem)" }, list: { display: "grid", gap: space.xs, margin: 0, padding: 0, listStyle: "none", paddingBlockEnd: space.sm }, row: { display: "flex", justifyContent: "space-between", gap: space.md, fontSize: font.sm }, time: { flexShrink: 0, fontSize: font.xs, color: color.muted, fontVariantNumeric: "tabular-nums" },})const now = "2026-12-04T16:30:00Z"const timeZone = "America/New_York"const clock = new Intl.DateTimeFormat("en-US", { timeZone, hour: "numeric", minute: "2-digit" })// what happened to an issue, newest first, in New York time: 01:00 UTC on the 4th is still the 3rd thereconst events = [ { id: "e1", at: "2026-12-04T15:10:00Z", text: "Ada Okafor closed the issue" }, { id: "e2", at: "2026-12-04T01:00:00Z", text: "Deploy 3f9a2c reached production" }, { id: "e3", at: "2026-12-03T14:30:00Z", text: "Tomás García linked a pull request" }, { id: "e4", at: "2026-11-30T16:00:00Z", text: "Priya Raman set priority to High" }, { id: "e5", at: "2026-11-18T13:20:00Z", text: "Wei Chen opened the issue" },]export const IssueActivity = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.wrap)).children( groupByDay(events, (e) => e.at, { now, timeZone, locale: "en-US" }).map((day) => h.section.key(day.key).children( DateDivider(h, { label: day.label, align: "start" }), h.ul.attrs(sx(styles.list)).children( day.items.map((e) => h.li.key(e.id).attrs(sx(styles.row)).children(h.span.children(e.text), h.span.attrs(sx(styles.time)).children(clock.format(new Date(e.at)))))), )), )API reference
DateDividerView function
Options
| Name | Type | Description |
|---|---|---|
labelrequired | string | The day: from dayLabel, or any words. |
align | "center" | "start" | The label at the start of the line rather than in the middle. |
sticky | boolean | Sticks to the top of its scrolling feed, on a pill, while the day's items pass under it. |
style | Style | — |
DayView function
Options
| Name | Type | Description |
|---|---|---|
nowrequired | string | The instant it is now, ISO: days are counted back from its day. |
timeZone | string | The reader's IANA time zone, such as "Europe/London": it decides which day an instant falls on. |
locale | string | Writes weekdays and dates in this language. |
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/date-divider