ProSchedulerSign in

Scheduler · Drag & drop

External drag and drop

A backlog of unscheduled tasks. Wrap each in ExternalDraggable with the event it becomes (duration in minutes); externalDrop lets the scheduler take it, with a preview of where it lands.

Live demo

Drag “Fix login redirect” onto Tuesday morning · Drop one onto lunch — it's refused if it clashes

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

/** A card in a side list. */
function Card({ color, title, meta }: { color?: string; title: string; meta?: string }) {
  return (
    <div className="flex items-center gap-2 rounded-md border border-border bg-card px-2.5 py-2 text-sm shadow-xs">
      <span className="size-2.5 shrink-0 rounded-full" style={{ backgroundColor: color ?? "var(--primary)" }} />
      <span className="min-w-0 flex-1 truncate font-medium">{title}</span>
      {meta && <span className="shrink-0 text-xs text-muted-foreground">{meta}</span>}
    </div>
  )
}

const minutes = (n = 60) => (n >= 60 ? `${n / 60} h` : `${n} min`)

export function ExternalDropDemo() {
  const { events, setEvents } = useEvents(() => studioSessions())
  const [tasks, setTasks] = useState(backlog)
  return (
    <div className="grid gap-3 md:grid-cols-[220px_1fr]">
      <div className="flex flex-col gap-2">
        <p className="text-xs font-medium text-muted-foreground">Backlog — drag onto the calendar</p>
        {tasks.map((task) => (
          <ExternalDraggable key={task.id} event={task}>
            <Card color={task.color} title={task.title} meta={minutes(task.duration)} />
          </ExternalDraggable>
        ))}
        {tasks.length === 0 && <p className="text-sm text-muted-foreground">All scheduled.</p>}
      </div>
      <ProScheduler
        data={events}
        resources={studioResources}
        view={{ scheduler: { type: "week", startTime: "08:00", endTime: "19:00" } }}
        externalDrop
        height={600}
        onEventCreated={(event) => {
          // A dropped task keeps its id; it leaves the backlog.
          setEvents((list) => [...list, { ...event, id: String(event.id ?? `new-${Date.now()}`) } as (typeof list)[number]])
          setTasks((list) => list.filter((t) => t.id !== event.id))
        }}
        onEventUpdated={(event) => setEvents((list) => list.map((e) => (e.id === event.id ? (event as typeof e) : e)))}
        onEventDeleted={(event) => setEvents((list) => list.filter((e) => e.id !== event.id))}
      />
    </div>
  )
}

About this demo

A backlog of unscheduled tasks. Wrap each in ExternalDraggable with the event it becomes (duration in minutes); externalDrop lets the scheduler take it, with a preview of where it lands.

Drops go through the usual create path — rules, onEventCreate (with draft.external) and onEventCreated.

Things to try

  • Drag “Fix login redirect” onto Tuesday morning
  • Drop one onto lunch — it's refused if it clashes

The props behind it are explained in Selection, drag and drop, links.

Use ProScheduler in your project