npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svelte-fullcalendar

v3.0.0

Published

A Svelte component wrapper around FullCalendar

Downloads

2,096

Readme

Known Vulnerabilities install size npm package version Contributor Covenant PRs Welcome Gitpod ready-to-code

svelte-fullcalendar

A Svelte 3 component-wrapper for FullCalendar

Please @mention me for any issue (I'm unwatching for renovate reasons)

FullCalendar (almost) seamlessly integrates with the Svelte JavaScript compiler and the SvelteKit JavaScript framework. It provides a component that matches the functionality of FullCalendar's standard API.

This guide does not go into depth about initializing a Svelte/SvelteKit project. Please consult the example for that.

First steps

The first step is to install the FullCalendar-related dependencies. You'll need the Svelte adapter and some plugins to handle the styles.

npm install @fullcalendar/core @fullcalendar/common
npm install --save-dev svelte-preprocess svelte-fullcalendar

Then install any additional plugins you plan to use:

npm install @fullcalendar/daygrid

After that you should update your svelte.config.js:

import adapter from '@sveltejs/adapter-auto';
import preprocess from 'svelte-preprocess';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	// Consult https://github.com/sveltejs/svelte-preprocess
	// for more information about preprocessors
	preprocess: preprocess(),

	kit: {
		adapter: adapter(),
+++		vite: {
+++			resolve: {
+++				dedupe: ['@fullcalendar/common'],
+++			},
+++			optimizeDeps: {
+++				include: ['@fullcalendar/common'],
+++			},
		},
	},
};

export default config;
  • This is crutial for the component to work with SvelteKit.

You may then begin to write a parent component that leverages the <FullCalendar> component:

<script lang="ts">
	import type { CalendarOptions } from 'svelte-fullcalendar';
	import FullCalendar from 'svelte-fullcalendar';
	import daygridPlugin from '@fullcalendar/daygrid';

	let options: CalendarOptions = {
		initialView: 'dayGridMonth',
		plugins: [daygridPlugin],
	};
</script>

<FullCalendar {options} />
  • You must initialized your calendar with at least one plugin that provides a view!

Example

Here you can find a working example.

Props and Emitted Events

For the FullCalendar connector, there is no distinction between props and events. Everything is passed into the master options object as key-value pairs. Here is an example that demonstrates passing in an events array and a dateClick handler:

<script>
	let options = {
		dateClick: (event) => alert('date click! ' + event.dateStr),
		events: [
			{ title: 'event 1', date: '2019-04-01' },
			{ title: 'event 2', date: '2019-04-02' },
		],
		initialView: dayGridMonth,
		plugins: [...],
	};
</script>

<FullCalendar {options} />

Modifying Options

You can modify your calendar’s options after initialization by reassigning them within the options object and reassign the options object. This is an example of changing the weekends options:

<script>
	import FullCalendar from 'svelte-fullcalendar';

	let options = {
		initialView: dayGridMonth,
		plugins: [...],
		weekends: false,
	};

	function toggleWeekends() {
		options = {
				...options,
				weekends: !options.weekends
		};
	}
</script>

<button on:click="{toggleWeekends}">toggle weekends</button>
<FullCalendar {options} />

Calendar API

Hopefully you won’t need to do it often, but sometimes it’s useful to access the underlying Calendar object for raw data and methods.

This is especially useful for controlling the current date. The initialDate prop will set the initial date of the calendar, but to change it after that, you’ll need to rely on the date navigation methods.

To do something like this, you’ll need to get ahold of the component’s ref (short for “reference”). In the template:

<FullCalendar bind:this="{calendarRef}" {options} />

Once you have the ref, you can get the underlying Calendar object via the getApi method:

<script>
	let calendarRef;

	function next() {
		const calendarApi = calendarRef.getAPI();
		calendarApi.next();
	}
</script>

Scheduler

How do you use FullCalendar Scheduler's premium plugins with Svelte? They are no different than any other plugin. Just follow the same instructions as you did dayGridPlugin in the above example. Also, make sure to include your schedulerLicenseKey:

<script>
	import FullCalendar from 'svelte-fullcalendar';

	let options = {
		plugins: [(await import('@fullcalendar/resource-timeline')).default],
		schedulerLicenseKey: 'your-license-key',
	};
</script>

<FullCalendar {options} />

Draggable external events

You'll need to install the interactionPlugin:

npm install @fullcalendar/interaction

See the official docs for all available props.

Here is a simple usage example:

<script>
	import FullCalendar, { Draggable } from 'svelte-fullcalendar';
	import resourceTimelinePlugin from '@fullcalendar/resource-timeline';
	import interactionPlugin from '@fullcalendar/interaction';

	let options = {
		schedulerLicenseKey: "XXX",
		plugins: [resourceTimelinePlugin, interactionPlugin],
		droppable: true
	};
</script>

<Draggable eventData={{ title: 'my event', duration: '02:00' }}>
	Drag me!
</Draggable>

<FullCalendar {options}/>

License

This component is released under the MIT license, same as the FullCalendar library.