A day, three days or a week of hours: overlapping events side by side, drag to add, move and resize, the keyboard, time zones and working hours.
December 2026
EST
All day
Tuesday, December 8, 2026
All day
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { addDays } from "./ui/uicontext/components/dates/DateMath.ts"import { Outcome } from "./ui/uicontext/components/domain/Outcome.ts"import { eventOf, expandEvents, moveOccurrence, removeOccurrence, ScheduleEvent } from "./ui/uicontext/components/schedule/Events.ts"import { TimeGrid, TimeGridView } from "./ui/uicontext/components/schedule/TimeGrid.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"import { now, teamEvents, today, zone } from "./schedule.ts"// A team's week. Drag on empty hours to add an event, drag one to move it, or drag its edges. Undo// puts the last change back, from its button or Ctrl+Z (⌘Z on a Mac). From the keyboard, tab into// the hours, move with the arrow keys and press Enter. Sofía's retro is hers, so it stays put.const styles = stylex.create({ frame: { display: "flex", flexDirection: "column", blockSize: 640, inlineSize: "100%" }, undo: { display: "flex", alignItems: "center", gap: space.md, minBlockSize: 32, paddingInline: space.lg, fontSize: font.sm, color: color.muted }, undoButton: { borderWidth: 0, padding: 0, backgroundColor: "transparent", color: color.fg, fontFamily: "inherit", fontSize: font.sm, fontWeight: 600, cursor: "pointer", textDecoration: "underline", textUnderlineOffset: 3, },})const Message = UiSchema.TaggedEnum({ RequestedDateGrid: { date: Schema.String }, RequestedViewGrid: { view: TimeGridView }, RequestedCreateGrid: { start: Schema.String, end: Schema.String, allDay: Schema.Boolean }, RequestedChangeGrid: { request: Schema.String, occurrence: Schema.String, start: Schema.String, end: Schema.String, previous: Schema.Struct({ start: Schema.String, end: Schema.String }) }, RequestedDeleteGrid: { occurrence: Schema.String }, RequestedOpenGrid: { occurrence: Schema.String }, ClickedUndo: {}, PressedUndoKey: {},})const Change = Schema.Struct({ title: Schema.String, occurrence: Schema.String, start: Schema.String, end: Schema.String })const TeamWeekModel = Schema.Struct({ date: Schema.String, view: TimeGridView, events: Schema.Array(ScheduleEvent), outcomes: Schema.Array(Outcome), /** each change's times before it, newest last */ undo: Schema.Array(Change), next: Schema.Number, selected: Schema.NullOr(Schema.String),})const undone = (events: ReadonlyArray<ScheduleEvent>, change: typeof Change.Type | undefined) => change === undefined ? events : moveOccurrence(events, change.occurrence, change.start, change.end)export const TeamWeek = Html.component({ name: "TeamWeek", model: TeamWeekModel, message: Message }).make({ init: () => ({ date: today, view: "week", events: teamEvents, outcomes: [], undo: [], next: 1, selected: null }), update: { RequestedDateGrid: ($, { date }) => $.evolve({ date }), RequestedViewGrid: ($, { view }) => $.evolve({ view }), RequestedCreateGrid: ($, { start, end, allDay }) => $.evolve({ next: (n) => n + 1, events: (events) => [...events, { id: `new-${$.model.next}`, title: "New event", start, end, timeZone: zone, color: "blue", ...(allDay ? { allDay } : {}) }], }), RequestedChangeGrid: ($, { request, occurrence, start, end, previous }) => $.evolve({ events: (events) => moveOccurrence(events, occurrence, start, end), outcomes: (o) => [...o.slice(-20), { _tag: "Accepted", request }], undo: (u) => [...u.slice(-20), { occurrence, title: eventOf($.model.events, occurrence)?.title ?? "event", ...previous }], }), RequestedDeleteGrid: ($, { occurrence }) => $.evolve({ events: (events) => removeOccurrence(events, occurrence) }), RequestedOpenGrid: ($, { occurrence }) => $.evolve({ selected: $.model.selected === occurrence ? null : occurrence }), ClickedUndo: ($) => $.evolve({ events: (events) => undone(events, $.model.undo.at(-1)), undo: (u) => u.slice(0, -1) }), PressedUndoKey: ($) => $.evolve({ events: (events) => undone(events, $.model.undo.at(-1)), undo: (u) => u.slice(0, -1) }), }, view: (h, model) => h.div.attrs(sx(styles.frame)) .on("keydown", ({ key, ctrl, meta, shift, editable }) => (key.toLowerCase() === "z" && (ctrl || meta) && !shift && !editable && model.undo.length > 0 ? Message.PressedUndoKey() : undefined), { preventDefault: true }) .children( TimeGrid(h, { props: { label: "Team calendar", occurrences: expandEvents(model.events, `${addDays(model.date, -8)}T00:00:00Z`, `${addDays(model.date, 9)}T00:00:00Z`), date: model.date, view: model.view, timeZone: zone, now, weekStart: 1, locale: "en-US", outcomes: model.outcomes, selected: model.selected, agentId: "time-grid-team", }, onEmit: { RequestedDate: ({ date }) => Message.RequestedDateGrid({ date }), RequestedView: ({ view }) => Message.RequestedViewGrid({ view }), RequestedCreate: (create) => Message.RequestedCreateGrid(create), RequestedChange: (change) => Message.RequestedChangeGrid(change), RequestedDelete: ({ occurrence }) => Message.RequestedDeleteGrid({ occurrence }), RequestedOpen: ({ occurrence }) => Message.RequestedOpenGrid({ occurrence }), }, }), h.div.attrs({ "aria-live": "polite", ...sx(styles.undo) }).children( model.undo.length > 0 && [ h.span.key("t").children(`Changed “${model.undo.at(-1)!.title}”`), h.button.key("b").attrs({ type: "button", "aria-keyshortcuts": "Control+Z Meta+Z", ...sx(styles.undoButton) }).on("click", Message.ClickedUndo()).children("Undo"), ], ), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/time-gridUsage
import { expandEvents, type ScheduleEvent } from "./ui/uicontext/components/schedule/Events.ts"import { TimeGrid } from "./ui/uicontext/components/schedule/TimeGrid.ts"const Message = UiSchema.TaggedEnum({ RequestedDateCalendar: { date: Schema.String }, RequestedNewEvent: { start: Schema.String, end: Schema.String }, RequestedMoveEvent: { occurrence: Schema.String, start: Schema.String, end: Schema.String },})export const Week = (h: Html.H<typeof Message.Type>, events: ReadonlyArray<ScheduleEvent>, date: string, now: string) => TimeGrid(h, { props: { label: "Calendar", // repeats become one occurrence per day; give the grid the weeks around the one shown occurrences: expandEvents(events, "2026-12-01T00:00:00Z", "2026-12-20T00:00:00Z"), date, view: "week", timeZone: "America/New_York", now, }, onEmit: { RequestedDate: ({ date }) => Message.RequestedDateCalendar({ date }), RequestedCreate: ({ start, end }) => Message.RequestedNewEvent({ start, end }), // move it at once with moveOccurrence; keep `previous` for an Undo RequestedChange: ({ occurrence, start, end }) => Message.RequestedMoveEvent({ occurrence, start, end }), RequestedOpen: () => undefined, RequestedDelete: () => undefined, RequestedView: () => undefined, }, })Examples
Two time zones, read-only
New York's hours with London's beside them, lunch shaded from the working hours, and nothing to drag.
December 2026
GMTEST
All day
Tuesday, December 8, 2026
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { expandEvents } from "./ui/uicontext/components/schedule/Events.ts"import { TimeGrid, TimeGridView } from "./ui/uicontext/components/schedule/TimeGrid.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { hours, now, teamEvents, today, zone } from "./schedule.ts"// Three days in New York with London's hours beside them, for a team split across the Atlantic.// The working hours come from the same weekly hours a booking page uses, so lunch is shaded too.const styles = stylex.create({ frame: { display: "flex", flexDirection: "column", blockSize: 600, inlineSize: "100%" } })const Message = UiSchema.TaggedEnum({ RequestedDateGrid: { date: Schema.String }, RequestedViewGrid: { view: TimeGridView },})export const TwoZones = Html.component({ name: "TwoZones", model: Schema.Struct({ date: Schema.String, view: TimeGridView }), message: Message,}).make({ init: () => ({ date: today, view: "3day" }), update: { RequestedDateGrid: ($, { date }) => $.evolve({ date }), RequestedViewGrid: ($, { view }) => $.evolve({ view }), }, view: (h, { date, view }) => h.div.attrs(sx(styles.frame)).children(TimeGrid(h, { props: { label: "Calendar with London", occurrences: expandEvents(teamEvents, "2026-11-25T00:00:00Z", "2026-12-25T00:00:00Z"), date, view, timeZone: zone, secondZone: "Europe/London", now, workingHours: hours.weekly, readOnly: "This calendar is read-only here", locale: "en-US", agentId: "time-grid-two-zones", }, onEmit: { RequestedDate: ({ date: d }) => Message.RequestedDateGrid({ date: d }), RequestedView: ({ view: v }) => Message.RequestedViewGrid({ view: v }), RequestedCreate: () => undefined, RequestedChange: () => undefined, RequestedDelete: () => undefined, RequestedOpen: () => undefined, }, })),})Thirty events in a day
Clashes three deep, long titles and calls that overlap the next: the worst a day should look.
EST
All day
All day
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { expandEvents, moveOccurrence, ScheduleEvent } from "./ui/uicontext/components/schedule/Events.ts"import { TimeGrid } from "./ui/uicontext/components/schedule/TimeGrid.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { busyDay, now, today, zone } from "./schedule.ts"// The most a day should hold: thirty calls, three at a time, some long enough to overlap the next// three, and titles that need several lines. Columns share the width and each block keeps its title// readable for as long as its height allows.const styles = stylex.create({ frame: { display: "flex", flexDirection: "column", blockSize: 640, inlineSize: "100%" } })const Message = UiSchema.TaggedEnum({ RequestedChangeGrid: { occurrence: Schema.String, start: Schema.String, end: Schema.String },})export const BusiestDay = Html.component({ name: "BusiestDay", model: Schema.Struct({ events: Schema.Array(ScheduleEvent) }), message: Message,}).make({ init: () => ({ events: busyDay }), update: { RequestedChangeGrid: ($, { occurrence, start, end }) => $.evolve({ events: (events) => moveOccurrence(events, occurrence, start, end) }), }, view: (h, { events }) => h.div.attrs(sx(styles.frame)).children(TimeGrid(h, { props: { label: "A crowded day", occurrences: expandEvents(events, "2026-12-07T00:00:00Z", "2026-12-10T00:00:00Z"), date: today, view: "day", timeZone: zone, now, scrollTo: 7 * 60, locale: "en-US", controls: false, agentId: "time-grid-busiest", }, onEmit: { RequestedDate: () => undefined, RequestedView: () => undefined, RequestedCreate: () => undefined, RequestedChange: ({ occurrence, start, end }) => Message.RequestedChangeGrid({ occurrence, start, end }), RequestedDelete: () => undefined, RequestedOpen: () => undefined, }, })),})API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
labelrequired | string | — | What the grid shows: "Team calendar" |
occurrencesrequired | Occurrence[] | — | The occurrences to draw (see expandEvents); the grid picks the ones on its days |
daterequired | IsoDate | — | A day in the period shown |
viewrequired | TimeGridView | — | — |
timeZonerequired | TimeZoneId | — | The zone times are drawn in |
secondZone | TimeZoneId | — | A second zone, its hours beside the first |
nowrequired | string | — | The app's current instant (ISO): today and the line across it |
weekStart | number | — | The first day of the week, 0 (Sunday) to 6; the locale's by default |
step | Int | 15 | Minutes a drag or an arrow key snaps to; 15 by default |
defaultDuration | Int | 30 | Minutes a click or Enter makes; 30 by default |
workingHours | HoursRange[][] | — | Working hours per weekday, Sunday first, in timeZone; the rest is shaded |
selected | string | null | — | The occurrence whose details are open: it's marked, and an EventPopover anchors to it |
readOnly | string | — | Why nothing can be changed here: "You can view this calendar, not edit it" |
outcomes | Outcome[] | — | The answers to its requests |
controls | boolean | true | Draw the title, Today, Previous, Next and the view switch; true by default |
locale | string | — | — |
hour12 | boolean | — | — |
scrollTo | Int | — | The minute to scroll to as it opens; an hour before working hours by default |
agentId | string | — | — |
Events
| Event | Payload | Description |
|---|---|---|
RequestedDate | { date: IsoDate } | Show another period: a day in it |
RequestedView | { view: TimeGridView } | — |
RequestedOpen | { occurrence: string } | Open an occurrence's details |
RequestedCreate | { start: string; end: string; allDay: boolean } | A new event over these times (ISO instants), or these days when allDay |
RequestedChange | { request: string; occurrence: string; start: string; end: string; previous: { start, end } } | New times for an occurrence; previous are the times it had, for an Undo. Answer through outcomes |
RequestedDelete | { occurrence: string } | — |
Agent actions
| Action | Description |
|---|---|
ChoseDate | Show the period around a day, "YYYY-MM-DD" |
PickedView | Show a day, 3 days, the work week or the week |
ClickedEvent | Open an event's details by its id |
RequestedCreateEvent | Make an event over two ISO instants; the app asks for its title |
RequestedMoveEvent | Give an event new times: its id and two ISO instants |