ProSchedulerSign in

Agenda · Displaying events

External navigation

Jump the list from your own sidebar through ref.navigate, and keep the sidebar in step with onSelectedDateChange.

Live demo

Jump two weeks ahead · Use the header arrows and watch the sidebar

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

const weekLinks: [number, string][] = [
  [-2, "Two weeks ago"],
  [-1, "Last week"],
  [0, "This week"],
  [1, "Next week"],
  [2, "In two weeks"],
]

export function AgendaNavigationDemo() {
  const { events, handlers } = useEvents(studioSessions)
  const scheduler = useRef<ProSchedulerInstance>(null)
  const [week, setWeek] = useState(() => weekStart())

  const go = (date: Date) => {
    setWeek(weekStart(date))
    scheduler.current?.navigate(date)
  }

  return (
    <div className="demo-split">
      <aside className="demo-side">
        <p className="demo-muted">Jump to a week</p>
        <ul>
          {weekLinks.map(([offset, label]) => {
            const now = weekStart()
            const monday = new Date(now.getFullYear(), now.getMonth(), now.getDate() + offset * 7)
            return (
              <li key={offset}>
                <button
                  type="button"
                  aria-pressed={monday.getTime() === week.getTime()}
                  onClick={() => go(monday)}
                >
                  <strong>{label}</strong>
                  <span>from {monday.toLocaleDateString()}</span>
                </button>
              </li>
            )
          })}
        </ul>
      </aside>
      <ProScheduler
        ref={scheduler}
        data={events}
        resources={studioResources}
        view={{ agenda: { type: "week" } }}
        onSelectedDateChange={(date) => setWeek(weekStart(date))}
        height={520}
        {...handlers}
      />
    </div>
  )
}

About this demo

Jump the list from your own sidebar through ref.navigate, and keep the sidebar in step with onSelectedDateChange.

Things to try

  • Jump two weeks ahead
  • Use the header arrows and watch the sidebar

The props behind it are explained in API reference.

Use ProScheduler in your project