ProSchedulerSign in

Timeline · Configuring the view

Custom range

type: "custom" shows any window: hours for three days, days for ten, weeks for six. The arrows page by the range's length.

Live demo

Switch between the ranges · Page forward

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

const today = () => {
  const d = new Date()
  return new Date(d.getFullYear(), d.getMonth(), d.getDate())
}

const ranges = [
  { label: "3 days", days: 3 },
  { label: "10 days", days: 10 },
  { label: "6 weeks", days: 42 },
]

export function TimelineCustomRangeDemo() {
  const { events, handlers } = useEvents(() => studioAssignments())
  const [pick, setPick] = useState(1)
  const { days } = ranges[pick]
  const range = useMemo(() => {
    const start = today()
    return { start, end: new Date(start.getFullYear(), start.getMonth(), start.getDate() + days) }
  }, [days])
  return (
    <>
      <Toolbar label="Range">
        {ranges.map((r, i) => (
          <Choice key={r.label} active={pick === i} onClick={() => setPick(i)}>
            {r.label}
          </Choice>
        ))}
      </Toolbar>
      <ProScheduler
        data={events}
        resources={studioResources}
        view={{
          timeline: {
            type: "custom",
            range,
            // hours for a short range, weeks for a long one
            resolutionHorizontal: days <= 3 ? "hour" : days > 31 ? "week" : "day",
            unitWidthPx: days <= 3 ? 28 : days > 31 ? 140 : 80,
          },
        }}
        styleConfig={{ fitToWidth: true }}
        height={520}
        {...handlers}
      />
    </>
  )
}

About this demo

type: "custom" shows any window: hours for three days, days for ten, weeks for six. The arrows page by the range's length.

Things to try

  • Switch between the ranges
  • Page forward

The props behind it are explained in Scales, ranges and zoom.

Use ProScheduler in your project