A schedule

The week by the hour, or one day, moved between weeks, an event opening in a card beside it

8 min readWritten for your agentMarkdown

Copy the file below whole (src/screens/schedule.tsx) beside frame.tsx (docs/screen-frame.md), whose rail holds /calendar (the frame block's row; node goop/agent/start.mjs schedule keeps it), and swap the sample events for yours; keep the parts and their props. Use it for timed events by day and hour (visits, shifts, bookings, a person's own week); people or rooms down the side, the days across, is WeekBoard's job instead. This is the reference's own main screen, the week: one page beside the rail, the calendar's bar over the calendar, the calendar to the page's foot.

The bar (WeekCalendarToolbar) draws, from the start: the frame's navigation button (below the breakpoint), the trail (Calendar, the month, the week's number), then at its end Today (shown only away from the week that holds today), the previous and next arrows (a week at a time, or a day in the day view), the Week and Day choice (a SegmentedControl: the arrows move it) and the New event button. The calendar (WeekCalendar) scrolls its hours inside itself, the all-day row over them, today's heading and the time now marked. An event moves by drag (a quarter hour a step) or by the keys (Enter picks it up, the arrows move it, Enter drops it, Escape puts it back), its edges resize it; a drag across empty time (or Tab to the empty slot and Enter) makes one in place. A press on an event (the pointer's: the keys move it) opens it in a card beside it (RecordPeek): its done box, its day and time, its place, Delete; the card's arrows step through the events shown; Escape or the close puts it away. New event opens the CreateDialog: a name, a place, the day, its start and length; the calendar moves to the day it lands on. Light, dark, phone (the hours scroll sideways under their headings) and desktop are the parts' own: add no class for them.

Show the code346 lines
TSX
// src/screens/schedule.tsx: the week (or a day) by the hour, an event opening in a card beside it
import { type CSSProperties, useLayoutEffect, useRef, useState } from 'react';
import { AppFramePanel, AppFrameTrigger } from '@/components/goop/patterns/app-frame';
import { CreateDialog } from '@/components/goop/patterns/create-dialog';
import { PageBody } from '@/components/goop/patterns/page-body';
import {
  RecordPeek,
  RecordPeekBody,
  RecordPeekGroup,
  RecordPeekHeader,
  RecordPeekItem,
  RecordPeekPanel,
} from '@/components/goop/patterns/record-peek';
import {
  Breadcrumb,
  BreadcrumbItem,
  BreadcrumbLink,
  BreadcrumbList,
  BreadcrumbPage,
} from '@/components/ui/goop/breadcrumb';
import { Button, ButtonIcon } from '@/components/ui/goop/button';
import { Checkbox } from '@/components/ui/goop/checkbox';
import { IconButton, IconButtonIcon } from '@/components/ui/goop/icon-button';
import { SegmentedControl, SegmentedControlItem } from '@/components/ui/goop/segmented-control';
import {
  WeekCalendar,
  type WeekCalendarDay,
  type WeekCalendarEvent,
  WeekCalendarToolbar,
} from '@/components/ui/goop/week-calendar';
import { ScreenFrame } from './frame';
import { hrefOf } from './router';

// ---- the sample data: swap it for yours
/** Today, as the sample's week holds it: `new Date().toISOString().slice(0, 10)` for the real day. */
const TODAY = '2026-11-25';
/** The time now, the red line on today's column: yours from the clock. */
const NOW = { day: TODAY, at: 15 * 60 + 1, label: '3:01 pm' };
/** An event: the calendar's own fields (its day, `start` and `end` in minutes from midnight) and where it is. */
interface Event extends WeekCalendarEvent {
  place: string;
}
const EVENTS: Event[] = [
  { id: 'ev-1', day: '2026-11-23', start: 600, end: 660, title: 'Planting plan', tone: 'blue', place: 'Barn office' },
  {
    id: 'ev-2',
    day: '2026-11-24',
    start: 540,
    end: 600,
    title: 'Soil sample walk',
    tone: 'green',
    place: 'Lower beds',
  },
  { id: 'ev-3', day: '2026-11-25', start: 660, end: 750, title: 'Growers call', tone: 'amber', place: 'Video call' },
  {
    id: 'ev-4',
    day: '2026-11-26',
    start: 840,
    end: 900,
    title: 'Crew debrief',
    tone: 'indigo',
    place: 'Barn office',
  },
  { id: 'ev-5', day: '2026-11-27', start: 1020, end: 1080, title: 'Vet visit', tone: 'pink', place: 'North field' },
  {
    id: 'ev-6',
    day: '2026-11-25',
    start: 0,
    end: 1440,
    allDay: true,
    flag: true,
    title: 'Seed order due',
    tone: 'cyan',
    place: '',
  },
  {
    id: 'ev-7',
    day: '2026-12-01',
    start: 600,
    end: 720,
    title: 'Hedge planting',
    tone: 'green',
    place: 'North field',
  },
];
/** A new event's start times (minutes from midnight) and lengths (minutes), as the create dialog offers them. */
const STARTS = [480, 540, 600, 660, 720, 780, 840, 900, 960, 1020];
const LENGTHS = [30, 60, 90, 120];

// ---- the days: arithmetic on `YYYY-MM-DD`, no date library
const DAY_MS = 86_400_000;
const dateOf = (day: string) => new Date(`${day}T00:00:00Z`);
const plusDays = (day: string, days: number) =>
  new Date(dateOf(day).getTime() + days * DAY_MS).toISOString().slice(0, 10);
/** The Monday of the week a day is in. */
const mondayOf = (day: string) => plusDays(day, -((dateOf(day).getUTCDay() + 6) % 7));
const wordsOf = (day: string, options: Intl.DateTimeFormatOptions) =>
  dateOf(day).toLocaleDateString('en-GB', { ...options, timeZone: 'UTC' });
/** The week a day is in, Monday to Sunday, as the calendar heads its columns. */
const weekOf = (day: string): WeekCalendarDay[] =>
  Array.from({ length: 7 }, (_, index) => {
    const id = plusDays(mondayOf(day), index);
    return {
      id,
      name: wordsOf(id, { weekday: 'short' }),
      date: wordsOf(id, { day: 'numeric' }),
      label: wordsOf(id, { weekday: 'long', day: 'numeric', month: 'long' }),
      today: id === TODAY,
      weekend: index > 4,
    };
  });
/** The week's number in its year (the week holding the year's first Thursday is 1). */
function weekNumber(day: string): number {
  const thursday = plusDays(mondayOf(day), 3);
  const first = dateOf(`${thursday.slice(0, 4)}-01-01`);
  return 1 + Math.floor((dateOf(thursday).getTime() - first.getTime()) / (7 * DAY_MS));
}
/** A time of day in words (`9:30 am`), from minutes since midnight. */
function clock(minutes: number): string {
  const hour = Math.floor(minutes / 60);
  return `${hour % 12 || 12}:${String(minutes % 60).padStart(2, '0')} ${hour < 12 ? 'am' : 'pm'}`;
}
const lengthWords = (minutes: number) =>
  minutes < 60 ? `${minutes} minutes` : `${minutes / 60} ${minutes === 60 ? 'hour' : 'hours'}`;
/** The next free id (`ev-8`). */
const nextId = (all: readonly Event[]) =>
  `ev-${1 + Math.max(0, ...all.map((event) => Number(event.id.replace(/\D/g, '')) || 0))}`;

type View = 'week' | 'day';

export default function ScheduleScreen() {
  const [events, setEvents] = useState(EVENTS);
  const [view, setView] = useState<View>('week');
  // the day shown: its week in the week view, the day itself in the day view
  const [day, setDay] = useState(TODAY);
  const [openId, setOpenId] = useState<string | null>(null);
  const [creating, setCreating] = useState(false);
  const days = weekOf(day);
  const shownDays = view === 'week' ? days.map((one) => one.id) : [day];
  // the card steps through the timed events shown, in time order
  const records = events
    .filter((event) => !event.allDay && shownDays.includes(event.day))
    .sort((a, b) => a.day.localeCompare(b.day) || a.start - b.start)
    .map((event) => event.id);
  const open = events.find((event) => event.id === openId);
  const change = (id: string, next: Partial<Event>) =>
    setEvents((all) => all.map((event) => (event.id === id ? { ...event, ...next } : event)));
  /** Moves the calendar to a day, putting an open card away. */
  const show = (next: string) => {
    setOpenId(null);
    setDay(next);
  };
  const step = view === 'week' ? 7 : 1;

  // the card hangs from the open event: a box laid over the event's own card on the week, measured as it opens
  const peek = useRef<HTMLDivElement>(null);
  const [anchor, setAnchor] = useState<CSSProperties | null>(null);
  useLayoutEffect(() => {
    const root = peek.current;
    const card = openId && root ? root.querySelector(`[data-event-id="${openId}"]`) : null;
    if (!root || !card) {
      setAnchor(null);
      return;
    }
    const from = root.getBoundingClientRect();
    const at = card.getBoundingClientRect();
    setAnchor({ top: at.top - from.top, left: at.left - from.left, width: at.width, height: at.height });
  }, [openId]);

  return (
    <ScreenFrame current="/calendar" scroll="panel">
      <AppFramePanel
        aria-label="Calendar"
        header={
          <WeekCalendarToolbar
            start={
              <>
                <AppFrameTrigger />
                <Breadcrumb>
                  <BreadcrumbList>
                    <BreadcrumbItem>
                      <BreadcrumbLink href={hrefOf('/calendar')} onClick={() => show(TODAY)}>
                        Calendar
                      </BreadcrumbLink>
                    </BreadcrumbItem>
                    <BreadcrumbItem>
                      <BreadcrumbLink asChild>
                        <button type="button" onClick={() => show(`${mondayOf(day).slice(0, 8)}01`)}>
                          {wordsOf(mondayOf(day), { month: 'short', year: 'numeric' })}
                        </button>
                      </BreadcrumbLink>
                    </BreadcrumbItem>
                    <BreadcrumbItem>
                      <BreadcrumbPage>
                        {view === 'week' ? `W${weekNumber(day)}` : wordsOf(day, { weekday: 'short', day: 'numeric' })}
                      </BreadcrumbPage>
                    </BreadcrumbItem>
                  </BreadcrumbList>
                </Breadcrumb>
              </>
            }
            end={
              <>
                {/* shown away from today alone, as the reference's */}
                {shownDays.includes(TODAY) ? null : (
                  <Button variant="ghost" onClick={() => show(TODAY)}>
                    Today
                  </Button>
                )}
                <IconButton aria-label={`Previous ${view}`} onClick={() => show(plusDays(day, -step))}>
                  <IconButtonIcon icon="chevron-left" />
                </IconButton>
                <IconButton aria-label={`Next ${view}`} onClick={() => show(plusDays(day, step))}>
                  <IconButtonIcon icon="chevron-right" />
                </IconButton>
                <SegmentedControl
                  aria-label="View"
                  fit
                  value={view}
                  onValueChange={(next) => {
                    setOpenId(null);
                    setView(next as View);
                  }}
                >
                  <SegmentedControlItem value="week">Week</SegmentedControlItem>
                  <SegmentedControlItem value="day">Day</SegmentedControlItem>
                </SegmentedControl>
                <Button onClick={() => setCreating(true)}>
                  <ButtonIcon icon="plus" />
                  New event
                </Button>
              </>
            }
          />
        }
      >
        <PageBody>
          <RecordPeek
            ref={peek}
            className="grow"
            open={open !== undefined}
            onOpenChange={(next) => next || setOpenId(null)}
            records={records}
            value={openId}
            onValueChange={setOpenId}
          >
            <WeekCalendar
              aria-label="Fieldwork calendar"
              days={days}
              view={view}
              date={day}
              events={events}
              now={NOW}
              defaultAllDayOpen
              onEventSelect={(event) => setOpenId(event.id)}
              onEventChange={(event, next) => change(event.id, next)}
              onEventCreate={(event) =>
                setEvents((all) => [...all, { ...event, id: nextId(all), place: '' }])
              }
            />
            {open && anchor ? (
              <RecordPeekItem value={open.id} asChild>
                <span aria-hidden="true" className="pointer-events-none absolute" style={anchor} />
              </RecordPeekItem>
            ) : null}
            <RecordPeekPanel>
              <RecordPeekHeader
                title={open?.title ?? ''}
                description={open ? wordsOf(open.day, { weekday: 'long', day: 'numeric', month: 'long' }) : null}
                media={
                  <Checkbox
                    aria-label="Done"
                    checked={open?.done === true}
                    onCheckedChange={(done) => open && change(open.id, { done })}
                  />
                }
                actions={
                  <IconButton
                    aria-label="Delete event"
                    onClick={() => {
                      setEvents((all) => all.filter((event) => event.id !== openId));
                      setOpenId(null);
                    }}
                  >
                    <IconButtonIcon icon="trash" />
                  </IconButton>
                }
              />
              {open ? (
                <RecordPeekBody>
                  <RecordPeekGroup icon="tabler-outline:clock">
                    {open.allDay ? 'All day' : `${clock(open.start)} to ${clock(open.end)}`}
                  </RecordPeekGroup>
                  {open.place ? <RecordPeekGroup icon="map-2">{open.place}</RecordPeekGroup> : null}
                </RecordPeekBody>
              ) : null}
            </RecordPeekPanel>
          </RecordPeek>
        </PageBody>
      </AppFramePanel>
      <CreateDialog
        open={creating}
        onOpenChange={setCreating}
        heading="New event"
        titleLabel="Event name"
        titlePlaceholder="Event name"
        summaryPlaceholder="Place"
        submitLabel="Create event"
        properties={[
          { kind: 'date', name: 'day', label: 'Day', today: new Date(`${TODAY}T12:00`) },
          {
            name: 'start',
            label: 'Starts',
            icon: 'tabler-outline:clock',
            options: STARTS.map((at) => ({ value: String(at), label: clock(at) })),
          },
          {
            name: 'length',
            label: 'Length',
            icon: 'clock',
            options: LENGTHS.map((minutes) => ({ value: String(minutes), label: lengthWords(minutes) })),
          },
        ]}
        defaultValues={{
          properties: { day: shownDays.includes(TODAY) ? TODAY : (shownDays[0] ?? day), start: '540', length: '60' },
        }}
        onCreate={(values) => {
          const start = Number(values.properties.start || 540);
          const on = values.properties.day || day;
          setEvents((all) => [
            ...all,
            {
              id: nextId(all),
              day: on,
              start,
              end: start + Number(values.properties.length || 60),
              title: values.title,
              place: values.summary,
            },
          ]);
          show(on);
        }}
      />
    </ScreenFrame>
  );
}

`tsx frame { words: 'Calendar', path: '/calendar', icon: 'calendar' },

Code

Where would you like to start?

Free · now

The Goop plugin

A design system for your AI coding agent, so screen ten matches screen one.

/plugin marketplace add goop-so/skillsthen /plugin install goop@goopCodex, Cursor, ChatGPT, the Claude app and more: Connect Goop
FreePro

The components

Every part live, with its props, its keys and what an agent sees. Whole page and app templates, working with sample data.