Timeline · Use cases
Two synchronized schedules
Two terminals' gates, one date: a shared controlled refDate keeps them on the same day, and flights move between them with externalDrag + externalDrop.
Live demo
Move a flight to Terminal 2 · Page to tomorrow in either one
Fullscreenimport { useState } from "react"
import { ProScheduler, type SchedulerResource } from "@andreisaac/pro-scheduler"
import { flights, terminalOne, terminalTwo } from "./data/planning"
import { useEvents } from "./kit"
export function DualScheduleDemo() {
const today = flights()
const one = useEvents(() => today.filter((f) => String(f.resource).startsWith("a")))
const two = useEvents(() => today.filter((f) => String(f.resource).startsWith("b")))
// One date for both: navigating either moves the other.
const [date, setDate] = useState(() => new Date())
const terminal = (side: typeof one, gates: SchedulerResource[]) => (
<ProScheduler
data={side.events}
resources={gates}
refDate={date}
onSelectedDateChange={setDate}
view={{ timeline: { type: "day", startTime: "05:00", endTime: "16:00" } }}
styleConfig={{ unitWidthPx: 70, fitToWidth: true }}
externalDrag
externalDrop
height={240}
{...side.handlers}
/>
)
return (
<div className="flex flex-col gap-3">
{terminal(one, terminalOne)}
{terminal(two, terminalTwo)}
</div>
)
}// data/planning.ts — sample data, relative to the current week or month.
import type { SchedulerEvent, SchedulerResource } from "@andreisaac/pro-scheduler"
const at = (base: Date, day: number, hour: number, minute = 0) =>
new Date(base.getFullYear(), base.getMonth(), base.getDate() + day, hour, minute)
export const terminalOne: SchedulerResource[] = [
{ id: "a1", name: "Gate A1", color: "#2563eb" },
{ id: "a2", name: "Gate A2", color: "#2563eb" },
{ id: "a3", name: "Gate A3", color: "#2563eb" },
]
export const terminalTwo: SchedulerResource[] = [
{ id: "b1", name: "Gate B1", color: "#059669" },
{ id: "b2", name: "Gate B2", color: "#059669" },
{ id: "b3", name: "Gate B3", color: "#059669" },
]
const flightList: [string, string, number, number, number][] = [
["TP 1234 Lisbon", "a1", 6, 0, 50],
["BA 402 London", "a1", 8, 30, 60],
["LH 1170 Frankfurt", "a2", 7, 15, 55],
["AF 1025 Paris", "a2", 10, 0, 45],
["IB 3102 Madrid", "a3", 9, 10, 50],
["KL 1692 Amsterdam", "a3", 12, 0, 60],
["EK 192 Dubai", "b1", 6, 30, 90],
["QR 344 Doha", "b1", 11, 0, 80],
["UA 65 Newark", "b2", 8, 0, 100],
["AA 237 Miami", "b2", 13, 0, 90],
["SQ 377 Singapore", "b3", 10, 30, 110],
["TK 1760 Istanbul", "b3", 7, 0, 60],
]
/** Today's departures: each at a gate for boarding (minutes). */
export function flights(today = new Date()): SchedulerEvent[] {
return flightList.map(([title, gate, h, m, minutes], i) => {
const start = new Date(today.getFullYear(), today.getMonth(), today.getDate(), h, m)
return {
id: `f${i + 1}`,
title,
start,
end: new Date(start.getTime() + minutes * 60_000),
resource: gate,
color: gate.startsWith("a") ? "#2563eb" : "#059669",
}
})
}About this demo
Two terminals' gates, one date: a shared controlled refDate keeps them on the same day, and flights move between them with externalDrag + externalDrop.
Things to try
- Move a flight to Terminal 2
- Page to tomorrow in either one
The props behind it are explained in Selection, drag and drop, links.