Svelte Event Calendar: Load, Filter and Edit Events in Svelte 5
By SimpleCalendarJS Team
For a Svelte event calendar, keep your events in `$state`, build the visible list with `$derived`, and mount a framework-agnostic calendar such as SimpleCalendarJS in a `{@attach}` attachment that calls `refresh()` whenever that list changes. If you need resource or timeline views, use @event-calendar/core instead.
A Svelte event calendar has to do more than draw a grid. It has to show events from your state, filter them, open an editor when someone clicks a slot, and save drag & drop changes without falling out of sync with your data. This guide builds that in Svelte 5 with runes and attachments, then covers loading the same events from an API and running it in SvelteKit.
If you only need the basic setup (installing a calendar and mounting it), start with How to Add a Calendar to a Svelte App. This post continues from there and covers the event workflow.
Svelte Event Calendar Options in 2026
You have three realistic routes. Which one fits depends on the views you need.
| Library | How it works with Svelte | License | Views | Notes |
|---|---|---|---|---|
| @event-calendar/core (vkurko) | Native Svelte 5 component, options passed as $state | MIT | day grid, time grid, list, resource time grid, resource timeline | README says 39 kB Brotli-compressed, zero dependencies in the standalone bundle |
SVAR Svelte Calendar (@svar-ui/svelte-calendar) | Svelte 5 component with TypeScript support | MIT core, commercial PRO | Day, Week, Month (PRO adds Agenda, Year, Resources, Timeline) | PRO also adds recurring events, timezone switching and export |
| SimpleCalendarJS | Framework-agnostic class mounted in an attachment or action | Free for personal, educational and open source use; commercial license for commercial use | month, week, day, list, plus date and range picker modes | ~14 KB gzipped JS, zero dependencies |
The trade-offs are clear:
- If you need resources or a timeline (rooms, staff, equipment rows), choose @event-calendar/core. SimpleCalendarJS has no resource or timeline views.
- If you want a Svelte-native component with TypeScript types and an upgrade path to recurring events and timezones, look at SVAR.
- If you want a small calendar with month, week, day and list views that you can reuse across non-Svelte projects too, a vanilla component mounted in an attachment works well. That's the approach below.
For a wider comparison, see Svelte Scheduler Components in 2026.
How the Pieces Fit: State, Derived, Attachment, Refresh
A vanilla calendar doesn't know about Svelte's reactivity, so you have to connect the two yourself. The pattern has four parts:
$stateholds the source of truth. An array of your event objects with your own fields (category,ownerId, whatever you need).$derivedbuilds what the calendar shows. Filtering and color mapping happen here, so the calendar always gets plain objects in the shape it expects.- An attachment creates the calendar once. In Svelte 5.29 and newer, the Svelte docs recommend attachments (
{@attach}) overuse:actions for new code. An attachment runs when the element mounts, and the function it returns runs when the element is removed, which is where you calldestroy(). - An
$effectcallsrefresh(). When the derived list changes, the effect tells the calendar to clear its cache and callfetchEventsagain.
One detail matters here. Attachments run inside an effect and re-run whenever state read inside them changes. If the calendar's constructor reads your event list synchronously (for its first fetchEvents call), the attachment would track that list. Then every edit would destroy and rebuild the whole calendar. Wrapping the constructor in untrack() prevents that. The Svelte docs describe it this way: inside an effect, "any state read inside fn will not be treated as a dependency."
The result is one long-lived calendar instance, and a single place (refresh()) where Svelte state reaches it.
Need a calendar in your app?
SimpleCalendarJS: ~14 KB gzipped, zero dependencies, works in any framework. Free for personal use.
Building the Svelte Event Calendar With SimpleCalendarJS
Install the package:
npm install simple-calendar-js
Here's the complete component. It includes a category filter, a create/edit form, and drag & drop that updates your state. The click and drop handlers are plain functions declared in the script and passed to the calendar by reference. Save it as src/lib/EventCalendar.svelte:
<script> import { untrack } from 'svelte'; import SimpleCalendarJs from 'simple-calendar-js'; import 'simple-calendar-js/dist/simple-calendar-js.min.css'; const COLORS = { work: '#4f46e5', personal: '#059669', travel: '#d97706' }; let events = $state([ { id: 1, title: 'Sprint planning', category: 'work', start: new Date(2026, 10, 30, 9, 0), end: new Date(2026, 10, 30, 10, 30) }, { id: 2, title: 'Dentist', category: 'personal', start: new Date(2026, 11, 2, 14, 0), end: new Date(2026, 11, 2, 15, 0) }, { id: 3, title: 'Flight to Lisbon', category: 'travel', start: new Date(2026, 11, 3, 7, 15), end: new Date(2026, 11, 3, 9, 40) } ]); let filter = $state('all'); let draft = $state(null); let calendar = null; // Plain copies for the calendar. The spread reads every field, // so editing any property of any event re-runs this derivation. let calendarEvents = $derived( events .filter((e) => filter === 'all' || e.category === filter) .map((e) => ({ ...e, color: COLORS[e.category] })) ); function toInputValue(date) { const d = new Date(date); const pad = (n) => String(n).padStart(2, '0'); return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`; } // Calendar callbacks: declared here, passed by reference below function handleEventClick(event) { draft = { id: event.id, title: event.title, category: event.category ?? 'work', start: toInputValue(event.start), end: toInputValue(event.end) }; } function handleSlotClick(date) { const end = new Date(date.getTime() + 60 * 60 * 1000); draft = { id: null, title: '', category: 'work', start: toInputValue(date), end: toInputValue(end) }; } function handleEventDrop(event, oldStart, oldEnd, newStart, newEnd) { const target = events.find((e) => e.id === event.id); if (target) { target.start = newStart; target.end = newEnd; } } function calendarAttachment(node) { untrack(() => { calendar = new SimpleCalendarJs(node, { defaultView: 'week', enabledViews: ['month', 'week', 'day', 'list'], weekStartsOn: 1, use24Hour: true, enableDragDrop: true, enableResize: true, fetchEvents: async () => calendarEvents, onEventClick: handleEventClick, onSlotClick: handleSlotClick, onEventDrop: handleEventDrop }); }); return () => { calendar.destroy(); calendar = null; }; } // Push every change in calendarEvents to the calendar $effect(() => { void calendarEvents; calendar?.refresh(); }); function saveDraft(e) { e.preventDefault(); const start = new Date(draft.start); // local date-time string, read as local time const end = new Date(draft.end); if (!(end > start)) return; const data = { title: draft.title, category: draft.category, start, end }; if (draft.id == null) { events.push({ id: crypto.randomUUID(), ...data }); } else { Object.assign(events.find((ev) => ev.id === draft.id), data); } draft = null; } function deleteDraft() { events = events.filter((ev) => ev.id !== draft.id); draft = null; } </script> <label> Show <select bind:value={filter}> <option value="all">All events</option> <option value="work">Work</option> <option value="personal">Personal</option> <option value="travel">Travel</option> </select> </label> <div {@attach calendarAttachment} style="height: 650px"></div> {#if draft} <form class="editor" onsubmit={saveDraft}> <input bind:value={draft.title} placeholder="Event title" required /> <select bind:value={draft.category}> <option value="work">Work</option> <option value="personal">Personal</option> <option value="travel">Travel</option> </select> <input type="datetime-local" bind:value={draft.start} required /> <input type="datetime-local" bind:value={draft.end} required /> <button type="submit">Save</button> {#if draft.id != null} <button type="button" onclick={deleteDraft}>Delete</button> {/if} <button type="button" onclick={() => (draft = null)}>Cancel</button> </form> {/if} <style> .editor { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; } </style>
Use it from any page with <EventCalendar />. A few points are worth explaining.
Why the derived list makes copies
{ ...e } does two things. It hands the calendar plain objects instead of Svelte proxies, so the library never holds a reference into your reactive state. And because spreading reads every property, the derivation depends on every field of every event. Renaming an event in the form re-runs calendarEvents, which re-runs the effect, which calls refresh(). Without the spread, $derived would only track the array itself and would miss in-place edits.
Svelte's $state only proxies plain objects and arrays, so the Date values pass through as real Date objects. That's what the calendar expects for start and end.
Why the effect is separate from the attachment
The attachment's job is to create and destroy the calendar. The $effect handles keeping it up to date. Keeping them separate means a filter change costs one refresh() call, not a full teardown and rebuild of the calendar's DOM. On mount, the effect may run before or after the attachment. If it runs first, calendar?.refresh() does nothing. If it runs after, it triggers one extra fetch from local state. Either way the result is correct.
Why the inline height
SimpleCalendarJS only treats an inline height as a fixed height. With style="height: 650px", month view shows "+N more" on busy days. A height from the <style> block or a utility class counts as no height, so month view expands to fit every event.
Adding and Editing Events From Calendar Clicks
SimpleCalendarJS has no built-in event form. That's a deliberate gap: you wire onSlotClick and onEventClick to your own UI. In Svelte, this is just a draft state object:
onSlotClick(date)gets the clicked day or time slot as aDate.handleSlotClickturns it into a one-hour draft withid: null, which marks it as new.onEventClick(event)gets the event object back, including your extra fields.categoryis not a calendar field, but it's kept and passed back, sohandleEventClickcan pre-select it in the form.- Saving either pushes a new object or uses
Object.assignon the existing proxy. Both are state mutations that Svelte tracks, so you never callrefresh()from the form. The effect does it.
The datetime-local inputs work with strings like 2026-12-02T14:00. Parsing them with new Date() treats them as local time, which is what you want here. Avoid date-only strings like '2026-12-02': they parse as UTC midnight and land on the previous day for anyone west of UTC.
For a real app, replace the inline form with a modal or side panel. The state flow stays the same.
Saving Drag and Drop Changes to a Server
enableDragDrop and enableResize let users move and stretch events with a mouse or touch. After either action, onEventDrop(event, oldStart, oldEnd, newStart, newEnd) reports the change. Every event needs a unique id for this to work.
The handleEventDrop function above only updates local state. To save the change, replace it with a version that updates the state optimistically and rolls back if the request fails:
async function handleEventDrop(event, oldStart, oldEnd, newStart, newEnd) { const target = events.find((e) => e.id === event.id); if (!target) return; const previous = { start: target.start, end: target.end }; target.start = newStart; target.end = newEnd; try { const res = await fetch(`/api/events/${event.id}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ start: newStart.toISOString(), end: newEnd.toISOString() }) }); if (!res.ok) throw new Error(`HTTP ${res.status}`); } catch (err) { Object.assign(target, previous); // the effect refreshes the calendar back console.error('Could not save the move', err); } }
Because the rollback is just another state change, the event jumps back to its original slot without any extra calendar code. For validation, such as blocking drops onto weekends or overlapping bookings, see Drag and Drop Calendar in JavaScript.
Loading Events From an API Instead of Local State
The local-state version works when the full event list is small and already in the page, for example from a SvelteKit load function. Once you have thousands of events, let the calendar ask for only the range it's showing. fetchEvents(start, end) is called with the visible date range, and the results are cached per month grid.
Swap the derived list for a loader function that requests the visible range:
const COLORS = { work: '#4f46e5', personal: '#059669', travel: '#d97706' }; let filter = $state('all'); let calendar = null; async function loadEvents(start, end) { const params = new URLSearchParams({ start: start.toISOString(), end: end.toISOString() }); if (filter !== 'all') params.set('category', filter); const res = await fetch(`/api/events?${params}`); if (!res.ok) return []; const rows = await res.json(); return rows.map((row) => ({ ...row, color: COLORS[row.category] })); } function calendarAttachment(node) { untrack(() => { calendar = new SimpleCalendarJs(node, { defaultView: 'week', enabledViews: ['month', 'week', 'day', 'list'], fetchEvents: loadEvents }); }); return () => calendar.destroy(); } // The cache doesn't know about the filter, so clear it when the filter changes $effect(() => { void filter; calendar?.refresh(); });
After a create, update or delete, await the request and then call calendar.refresh() yourself, because there's no local state for the effect to track. If an event has no valid start and end, it isn't shown, so check your API's date format first when something is missing. How to Load Calendar Events From a REST API covers the server side of this pattern.
Running It in SvelteKit
Attachments and actions don't run during server-side rendering, so the calendar is never created on the server. To keep the browser-only library out of the server render completely, render the component only in the browser:
<script> import { browser } from '$app/environment'; import EventCalendar from '$lib/EventCalendar.svelte'; </script> {#if browser} <EventCalendar /> {/if}
How to Add a Calendar to a SvelteKit Site covers the SSR details, including loading initial events from +page.server.js.
Where SimpleCalendarJS Fits (and Where It Doesn't)
SimpleCalendarJS fits a Svelte event calendar that needs month, week, day and list views, drag & drop, tooltips, locale-aware formatting and CSS-variable theming, in about 14 KB gzipped. Because it's a plain class, the same calendar code works in a SvelteKit app, a marketing site and a legacy page with a script tag. In Svelte, it adds one attachment and one effect.
It's not the right choice for every project:
- No resource or timeline views. For a room-booking grid or staff timeline, use @event-calendar/core's
resourceTimeGrid/resourceTimelineor SVAR PRO. - No recurring events. Expand series into individual events before returning them.
- No timezone option. Dates display in the browser's local time.
- No TypeScript types and no Svelte-native props. You configure it with an options object, not component props.
- License: free for personal, educational and open source projects. Commercial use (client sites, SaaS, internal tools) needs a paid license.
Try the options in the sandbox or read the full API in the docs before you commit.
Need a calendar in your app?
SimpleCalendarJS: ~14 KB gzipped, zero dependencies, works in any framework. Free for personal use.
Sources & Further Reading
- use: (actions) — Svelte docs
- {@attach ...} — Svelte docs
- svelte (untrack) — Svelte docs
- $derived — Svelte docs
- vkurko/calendar: Event Calendar — GitHub
- SVAR Svelte Calendar — SVAR
Image Credits
- Cover: An open planner on a laptop — Pexels
Image free to use under the Pexels License.
Frequently Asked Questions
Does SimpleCalendarJS support recurring events in a Svelte app?
No. SimpleCalendarJS has no RRULE or recurrence support. Expand the recurring series into individual occurrences yourself, for example in a `$derived` value or inside `fetchEvents(start, end)` for the visible range, and return those concrete events. A library such as rrule.js can generate the dates for you.
How do I switch the calendar to dark mode in Svelte?
Add the `uc-dark` class to the calendar container or any parent element, for example `class:uc-dark={dark}` on a wrapper div. It doesn't follow the system setting by itself, so if you want that, set `dark` from `matchMedia('(prefers-color-scheme: dark)')` and listen for its `change` event.
Why does month view keep growing instead of showing "+N more"?
SimpleCalendarJS only treats an inline height as a fixed height. Put `style="height: 650px"` directly on the container element. A height from a stylesheet, a Svelte `<style>` block or a utility class like Tailwind's `h-[650px]` counts as no height, so month view expands to fit every event.
Can I use this approach in Svelte 4?
Yes, but swap the attachment for a classic action. Svelte 4 has no runes or `{@attach}`. Create the calendar in a `use:` action, return an object with a `destroy()` method that calls `calendar.destroy()`, and call `calendar.refresh()` from a reactive `$:` statement after your events change.
Does simple-calendar-js ship TypeScript types for a Svelte TS project?
No, the package has no TypeScript type definitions. In a `lang="ts"` Svelte project, add a `.d.ts` file containing `declare module 'simple-calendar-js';` so the import compiles. The calendar instance is then typed as `any`, so check the options table in the docs as you go.
How do I show events in a specific timezone?
SimpleCalendarJS has no timezone option and shows dates in the browser's local time. If your events need to appear in another zone, convert the start and end times before you return them from `fetchEvents`, using `Intl.DateTimeFormat` with a `timeZone` or a date library that handles zones.
Add a calendar to your app today
Free for personal projects. $49/year or $199 lifetime per commercial project.



