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
Fullscreenimport { 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>
)
}// data/shifts.ts — sample data, relative to the current week or month.
import type { SchedulerEvent, SchedulerResource } from "@andreisaac/pro-scheduler"
import { weekStart } from "./studio"
export type Shift = "Morning" | "Evening" | "Night"
export type ShiftEvent = SchedulerEvent & {
id: string
start: Date
end: Date
resource: string
shift: Shift
}
export const shiftTimes: Record<Shift, { from: number; hours: number; color: string }> = {
Morning: { from: 6, hours: 8, color: "#0ea5e9" },
Evening: { from: 14, hours: 8, color: "#f59e0b" },
Night: { from: 22, hours: 8, color: "#6366f1" },
}
export const crew: SchedulerResource[] = [
{ id: "c1", name: "Aiko Tanaka", role: "Supervisor", color: "#0ea5e9" },
{ id: "c2", name: "Bruno Costa", role: "Forklift", color: "#10b981" },
{ id: "c3", name: "Clara Weiss", role: "Picker", color: "#f59e0b" },
{ id: "c4", name: "Diego Ramos", role: "Picker", color: "#ef4444" },
{ id: "c5", name: "Emma Lund", role: "Loader", color: "#8b5cf6" },
{ id: "c6", name: "Femi Adeyemi", role: "Loader", color: "#ec4899" },
{ id: "c7", name: "Grace Kim", role: "Forklift", color: "#14b8a6" },
{ id: "c8", name: "Hugo Laurent", role: "Supervisor", color: "#64748b" },
]
const rotation: Shift[] = ["Morning", "Evening", "Night"]
/** Five shifts a week each, rotating so every shift is always covered. */
export function crewShifts(base = weekStart()): ShiftEvent[] {
const events: ShiftEvent[] = []
crew.forEach((person, p) => {
for (let day = 0; day < 7; day++) {
if ((day + p) % 7 >= 5) continue // two days off, staggered
const shift = rotation[(p + Math.floor(day / 2)) % 3]
const { from, hours } = shiftTimes[shift]
const start = new Date(base.getFullYear(), base.getMonth(), base.getDate() + day, from)
events.push({
id: `shift-${person.id}-${day}`,
title: `${shift} shift`,
start,
end: new Date(start.getFullYear(), start.getMonth(), start.getDate(), from + hours),
resource: String(person.id),
shift,
color: shiftTimes[shift].color,
})
}
})
return events
}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.