ProSchedulerSign in

Scheduler · Setting up

Responsive day and week

The host measures its container and passes a day view when it is narrow, the whole week when there is room. The scheduler itself needs no special mode.

Live demo

Narrow the browser window below the breakpoint · Widen it again

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

export function ResponsiveDemo() {
  const { events, handlers } = useEvents(studioSessions)
  const box = useRef<HTMLDivElement>(null)
  const [narrow, setNarrow] = useState(false)

  // One day on a narrow container, the whole week when there is room.
  useEffect(() => {
    const el = box.current
    if (!el) return
    const observer = new ResizeObserver(() => setNarrow(el.clientWidth < 640))
    observer.observe(el)
    return () => observer.disconnect()
  }, [])

  return (
    <div ref={box}>
      <ProScheduler
        key={narrow ? "day" : "week"}
        data={events}
        resources={studioResources}
        view={{ scheduler: { type: narrow ? "day" : "week", startTime: "07:00", endTime: "20:00" } }}
        height={600}
        {...handlers}
      />
    </div>
  )
}

About this demo

The host measures its container and passes a day view when it is narrow, the whole week when there is room. The scheduler itself needs no special mode.

Things to try

  • Narrow the browser window below the breakpoint
  • Widen it again

The props behind it are explained in Views.

Use ProScheduler in your project