eventProjection
Drives external drag-in. You feed the calendar a pointer position and a proposed event; the renderer resolves the pointer to a snapped calendar position, mutates the descriptor's event in place with the calculated start, end, and any resource/unit fields, and draws a lightweight marker where the event would land.
Usage
eventProjection?: EventProjection | null;
type EventProjection = {
htmlEvent: { clientX: number; clientY: number } | null;
event: Partial<CalendarEvent>;
};
| Field | Type | Description |
|---|---|---|
htmlEvent | { clientX: number; clientY: number } | null | Current pointer coordinates. Replace it on each dragover; null shows no marker. |
event | Partial<CalendarEvent> | Proposed event. The renderer writes the resolved start, end, and resource/unit fields back onto it. |
The default is undefined. Because the renderer enriches event in place, keep the same nested object across the drag and read its resolved start/end on drop.
Example
import { useRef, useState } from "react";
import { Calendar } from "@svar-ui/react-calendar";
function App() {
const api = useRef(null);
const [eventProjection, setEventProjection] = useState(null);
const task = { text: "New task", duration: 60 };
return (
<div
onDragStart={() => setEventProjection({ htmlEvent: null, event: { ...task } })}
onDragOver={e => {
setEventProjection(prev => ({ ...prev, htmlEvent: e }));
e.preventDefault();
}}
onDrop={e => {
if (eventProjection?.event.start && eventProjection.event.end) {
e.preventDefault();
api.current.exec("add-event", { event: eventProjection.event });
}
setEventProjection(null);
}}
>
<Calendar ref={api} events={events} eventProjection={eventProjection} />
</div>
);
}
Related articles
- External Drag and Drop — full walkthrough of dragging items into the calendar.