Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
add-to-calendar-button
Advanced tools
A convenient JavaScript snippet, which lets you create beautiful buttons, where people can add events to their calendars.
The convenient JavaScript snippet, which lets you reliably create beautiful buttons, where people can add events to their calendars.
For everybody, who wants to include a button at their website or app, which enables users to easily add a specific event to their calendars. It's main goal is to keep this process as easy as possible at maximum compatibility. Simply define your button configuration and everything else is automatically generated by the script. Supporting calendars at Apple, Google, Microsoft (365, Outlook, Teams), Yahoo, and generic iCal.
The script integrates easily with any usual HTML webpage (VanillaJS way) as well as popular JavaScript frameworks and libraries like Angular, React, Vue, Svelte, and more.
In terms of system support, all modern browsers (Chrome, Edge, Firefox, Safari) on Windows, Mac, Android, and iOS as well as rather restricted webview environments like the Instagram in-app browser are supported.
See add-to-calendar-button.com for a live demo.
And remember to ⭐ star this repository in order to stay up-to-date and save it for later! 🤗
Simple and convenient integration of 1 or many buttons, configurable directly within the HTML code.
You can use the jsDeliver CDN and load the respective ressources into your web project.
Put the css (use atcb-3d for an alternative style) into the <head>
:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/add-to-calendar-button@1/assets/css/atcb.min.css">
... and the javascript into the <body>
footer:
<script src="https://cdn.jsdelivr.net/npm/add-to-calendar-button@1" async defer></script>
Mind that this always pulls the latest release of v1! You can pin a more specific version by adding the exact version number after the "@" - see jsDeliver.com for details. If you want to rather host it yourself, you could also download the source files or clone the repository (mind to take the original one at github.com/add2cal/add-to-calendar-button) and maintain/update it manually.
Import the package using the following npm command:
npm install add-to-calendar-button
Import the module into your project/component. For example with Angular/React:
import { atcb_action, atcb_init } from 'add-to-calendar-button';
Either use atcb_action
with your own buttons/forms/etc, or run atcb_init
after the DOM has been loaded. To determine the right moment to execute the atcb_init
, ...
ngAfterViewInit()
with atcb_init();
(mind that, depending on your app, other hooks might be better);DOMContentLoaded
or use a hook in a functional component like useEffect(() => atcb_init());
.Include the css. For example with Angular or React, add @import 'add-to-calendar-button/assets/css/atcb.css'
to some other css file - or include it in other more direct ways (like adding import 'add-to-calendar-button/assets/css/atcb.css';
to the respective component) (use atcb-3d for an alternative style).
A button can be easily created by placing a respective placeholder, wherever you want the button to appear.
(The style="display:none;"
theoretically is not necessary, but should be used for better compatibility.)
<div class="atcb" style="display:none;">(...)</div>
Within this placeholder, you can easily configure the button, by placing a respective JSON structure.
Mind that with Angular, you might need to escape the { with {{ '{' }}
and } with {{ '}' }}
; with React it would be { '{' }
and { '}' }
.
If there is no endDate set, the script assumes that it is the same as startDate.
Mind that for auto-generating rich snippets, a location would be mandatory as well. Even a timezone is not required, but recommended - if not given, the script will assume UTC.
<div class="atcb" style="display:none;">
{
"name":"Add the title of your event",
"startDate":"2022-02-21",
"options":[
"Google"
]
}
</div>
<div class="atcb" style="display:none;">
{
"name":"Add the title of your event",
"description":"A nice description does not hurt",
"startDate":"2022-02-21",
"endDate":"2022-03-24",
"startTime":"10:13",
"endTime":"17:57",
"location":"Somewhere over the rainbow",
"label":"Add to Calendar",
"options":[
"Apple",
"Google",
"iCal",
"Microsoft365",
"MicrosoftTeams",
"Outlook.com",
"Yahoo"
],
"timeZone":"Europe/Berlin",
"trigger":"click",
"inline":true,
"listStyle":"modal",
"iCalFileName":"Reminder-Event"
}
</div>
If you can't or don't want to use atcb_init
, you can use the atcb_action
import with your own buttons or other elements/components.
This may work better with React and other frontend frameworks, but it misses the Schema.org and button specific functionalities.
import React from 'react';
import { atcb_action } from 'add-to-calendar-button';
const MyComponent = () => {
const [name, setName] = React.useState("Some event");
const changeName = e => {
setName(e.target.value);
};
return (
<form onSubmit={e => {
e.preventDefault();
atcb_action({
name: name,
startDate: "2022-10-14",
endDate: "2022-10-18",
options: ['Apple', 'Google', 'iCal', 'Microsoft365', 'Outlook.com', 'Yahoo'],
timeZone: "Europe/Berlin",
iCalFileName: "Reminder-Event",
});
}}>
<input value={name} onChange={changeName} />
<input type="submit" value="save" />
</form>
);
}
Alternatively, you could use atcb_init
with a useEffect
hook:
import React from "react";
import { atcb_init } from "add-to-calendar-button";
import 'add-to-calendar-button/assets/css/atcb.css';
const MyComponent = () => {
React.useEffect( () => { atcb_init() }, []);
return (
<div className="atcb">
{ '{' }
"name":"Add the title of your event",
"description":"A nice description does not hurt",
"startDate":"2022-02-21",
"endDate":"2022-03-24",
"startTime":"10:13",
"endTime":"17:57",
"location":"Somewhere over the rainbow",
"label":"Add to Calendar",
"options":[
"Apple",
"Google",
"iCal",
"Microsoft365",
"Outlook.com",
"Yahoo"
],
"timeZone":"Europe/Berlin",
"iCalFileName":"Reminder-Event"
{ '}' }
</div>
);
}
By the way: Both functions return an array, holding the IDs of the generated buttons!
Find all information about the available options and how to configure specific features at the DOCS.md.
Find all changes in the dedicated file at CHANGELOG.md.
Anyone is welcome to contribute, but mind the guidelines:
IMPORTANT NOTE: Run npm install
, npm run format
, and npm run build
to auto-lint and create the minified js, css, as well as its sourcemap files!
Copyright (c) Jens Kuerschner.
Licensed under Apache-2.0 (with “Commons Clause” License Condition v1.0).
uxwing.com as well as all contributors:
FAQs
A convenient JavaScript snippet, which lets you create beautiful buttons, where people can add events to their calendars.
The npm package add-to-calendar-button receives a total of 22,789 weekly downloads. As such, add-to-calendar-button popularity was classified as popular.
We found that add-to-calendar-button demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.