ProSchedulerSign in

Timeline · Templating

Custom resource column

renderResource and renderResourceHeader fill the left column: avatar, role and days booked this month.

Live demo

Move a bar and watch both people's totals

Fullscreen
import { useMemo } from "react"
import { ProScheduler } from "@andreisaac/pro-scheduler"
import { studioAssignments, studioResources } from "./data/studio"
import { useEvents } from "./kit"

export function ResourceColumnDemo() {
  const { events, handlers } = useEvents(studioAssignments)

  const booked = useMemo(() => {
    const days = new Map<string, number>()
    for (const e of events) {
      const d = (new Date(e.end!).getTime() - new Date(e.start).getTime()) / 86_400_000
      days.set(String(e.resource), (days.get(String(e.resource)) ?? 0) + d)
    }
    return days
  }, [events])

  return (
    <ProScheduler
      data={events}
      resources={studioResources}
      view={{ timeline: { type: "month" } }}
      styleConfig={{ resourceColWidth: 240, minRowHeight: 60 }}
      renderResourceHeader={() => <span>Crew · booked days</span>}
      renderResource={(resource) => {
        const days = Math.round(booked.get(String(resource.id)) ?? 0)
        return (
          <div className="flex w-full items-center gap-2.5">
            <span
              className="flex size-8 shrink-0 items-center justify-center rounded-full text-[11px] font-semibold text-white"
              style={{ background: String(resource.color) }}
            >
              {resource.name
                .split(" ")
                .map((part) => part[0])
                .join("")}
            </span>
            <div className="min-w-0 flex-1">
              <div className="truncate text-sm font-medium">{resource.name}</div>
              <div className="truncate text-xs text-muted-foreground">{String(resource.role)}</div>
            </div>
            <span className="text-xs tabular-nums text-muted-foreground">{days}d</span>
          </div>
        )
      }}
      height={600}
      {...handlers}
    />
  )
}

About this demo

renderResource and renderResourceHeader fill the left column: avatar, role and days booked this month.

Things to try

  • Move a bar and watch both people's totals

The props behind it are explained in Resources.

Use ProScheduler in your project