Timeline · Use cases
Shifts and tasks
Each person is a group with a shifts row and a tasks row; with groupSummary the person's row shows both at a glance.
Live demo
Collapse a person · Move a task within its shift
Fullscreenimport { useMemo } from "react"
import { ProScheduler, type SchedulerEvent, type SchedulerResource } from "@andreisaac/pro-scheduler"
import { crew, crewShifts } from "./data/shifts"
import { useEvents } from "./kit"
export function ShiftsAndTasksDemo() {
// Each person is a group with two rows: their shifts and their tasks.
const people = crew.slice(0, 4)
const resources = useMemo<SchedulerResource[]>(
() =>
people.map((p) => ({
id: p.id,
name: p.name,
color: p.color,
eventCreation: false,
children: [
{ id: `${p.id}-shifts`, name: "Shifts", color: p.color },
{ id: `${p.id}-tasks`, name: "Tasks", color: "#64748b" },
],
})),
// people is a fixed slice
// eslint-disable-next-line react-hooks/exhaustive-deps
[]
)
const { events, handlers } = useEvents<SchedulerEvent>(() => {
const shifts = crewShifts()
.filter((s) => people.some((p) => p.id === s.resource))
.map((s) => ({ ...s, resource: `${s.resource}-shifts` }))
const tasks = shifts.map((s, i) => {
const start = new Date(new Date(s.start).getTime() + 2 * 3_600_000)
return {
id: `task-${i}`,
title: ["Pick order", "Cycle count", "Load truck", "Inventory"][i % 4],
start,
end: new Date(start.getTime() + (2 + (i % 3)) * 3_600_000),
resource: String(s.resource).replace("-shifts", "-tasks"),
}
})
return [...shifts, ...tasks]
})
return (
<ProScheduler
data={events}
resources={resources}
view={{ timeline: { type: "week", resolutionHorizontal: "hour", groupSummary: true } }}
styleConfig={{ unitWidthPx: 18, fitToWidth: false, laneHeight: 28, minRowHeight: 40 }}
height={560}
{...handlers}
/>
)
}// 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
Each person is a group with a shifts row and a tasks row; with groupSummary the person's row shows both at a glance.
Things to try
- Collapse a person
- Move a task within its shift
The props behind it are explained in Resources.