ProSchedulerSign in

Scheduler · Resources

Resource filtering in the header

Checkboxes in a custom header choose which people get a column.

Live demo

Add Ben · Remove everyone but one

Fullscreen
import { useState } from "react"
import { CalendarNav, CalendarNext, CalendarPrev, CalendarToday, ProScheduler } from "@andreisaac/pro-scheduler"
import { studioResources, studioSessions } from "./data/studio"
import { useEvents } from "./kit"

export function ResourceFilterDemo() {
  const { events, handlers } = useEvents(studioSessions)
  const [shown, setShown] = useState<string[]>(["ada", "chloe", "farah"])
  const toggle = (id: string) =>
    setShown((list) => (list.includes(id) ? list.filter((x) => x !== id) : [...list, id]))

  return (
    <ProScheduler
      data={events}
      resources={studioResources.filter((r) => shown.includes(r.id))}
      view={{ scheduler: { type: "day", resources: true, startTime: "07:00", endTime: "20:00" } }}
      // The filter lives in the header, next to the navigation.
      renderHeader={() => (
        <div className="flex flex-wrap items-center gap-2 border-b border-border px-3 py-2">
          <CalendarPrev />
          <CalendarToday />
          <CalendarNext />
          <CalendarNav className="mr-2" />
          {studioResources.map((r) => (
            <label key={r.id} className="flex items-center gap-1.5 text-xs">
              <input type="checkbox" checked={shown.includes(r.id)} onChange={() => toggle(r.id)} />
              <span className="size-2 rounded-full" style={{ background: r.color }} />
              {r.name.split(" ")[0]}
            </label>
          ))}
        </div>
      )}
      height={600}
      {...handlers}
    />
  )
}

About this demo

Checkboxes in a custom header choose which people get a column.

Things to try

  • Add Ben
  • Remove everyone but one

The props behind it are explained in Resources.

Use ProScheduler in your project