ProSchedulerSign in

Scheduler · Templating

Custom date header

renderDay replaces each column heading. This one adds the hours booked that day, in red past twelve.

Live demo

Move a long event to another day and watch both totals change

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

export function DateHeaderDemo() {
  const { events, handlers } = useEvents(studioSessions)

  const hoursByDay = useMemo(() => {
    const totals = new Map<string, number>()
    for (const e of events) {
      const key = new Date(e.start).toDateString()
      const hours = (new Date(e.end!).getTime() - new Date(e.start).getTime()) / 3_600_000
      totals.set(key, (totals.get(key) ?? 0) + hours)
    }
    return totals
  }, [events])

  return (
    <ProScheduler
      data={events}
      resources={studioResources}
      view={{ scheduler: { type: "week", startTime: "07:00", endTime: "20:00" } }}
      styleConfig={{ headerHeight: 64 }}
      renderDay={({ date }) => {
        const hours = hoursByDay.get(date.toDateString()) ?? 0
        return (
          <div className="grid justify-items-center gap-0.5 text-xs">
            <span className="uppercase text-muted-foreground">
              {date.toLocaleDateString([], { weekday: "short" })}
            </span>
            <span className="text-base font-semibold">{date.getDate()}</span>
            <span className={hours > 12 ? "text-destructive" : "text-muted-foreground"}>{hours}h booked</span>
          </div>
        )
      }}
      height={620}
      {...handlers}
    />
  )
}

About this demo

renderDay replaces each column heading. This one adds the hours booked that day, in red past twelve.

Things to try

  • Move a long event to another day and watch both totals change

The props behind it are explained in Custom rendering.

Use ProScheduler in your project