ProSchedulerSign in

Timeline · Use cases

Employee shift scheduling

A week of rotating shifts at hour resolution, colour-coded by shift. Night shifts run straight through midnight.

Live demo

Scroll to a night shift · Swap a shift to another person

Fullscreen
import { ProScheduler } from "@andreisaac/pro-scheduler"
import { crew, crewShifts, shiftTimes, type Shift } from "./data/shifts"
import { useEvents } from "./kit"

const hhmm = (d: Date) => d.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })

export function EmployeeShiftsDemo() {
  const { events, handlers } = useEvents(crewShifts)

  return (
    <div className="docs-demo__stack">
      <div className="demo-legend">
        {(Object.keys(shiftTimes) as Shift[]).map((shift) => (
          <span key={shift}>
            <i style={{ background: shiftTimes[shift].color }} />
            {shift} {shiftTimes[shift].from}:00–{(shiftTimes[shift].from + shiftTimes[shift].hours) % 24}:00
          </span>
        ))}
      </div>
      <ProScheduler
        data={events}
        resources={crew}
        // A week at hour resolution: narrow hour columns, scroll sideways.
        view={{ timeline: { type: "week", resolutionHorizontal: "hour", dragTimeStep: 60 } }}
        styleConfig={{ unitWidthPx: 18, fitToWidth: false, laneHeight: 34 }}
        renderResource={(person) => (
          <div className="min-w-0">
            <div className="truncate text-sm font-medium">{person.name}</div>
            <div className="truncate text-xs text-muted-foreground">{String(person.role)}</div>
          </div>
        )}
        renderEventContent={({ original, start, end }) => (
          <span className="truncate">
            {String(original.shift)} · {hhmm(start)}–{hhmm(end)}
          </span>
        )}
        height={520}
        {...handlers}
      />
    </div>
  )
}

About this demo

A week of rotating shifts at hour resolution, colour-coded by shift. Night shifts run straight through midnight.

Things to try

  • Scroll to a night shift
  • Swap a shift to another person

The props behind it are explained in Resources.

Use ProScheduler in your project