Author: | uvarov-frontend |
---|---|
Views Total: | 0 views |
Official Page: | Go to website |
Last Update: | May 14, 2022 |
License: | MIT |
Preview:

Description:
A tiny clean calendar in Vanilla JavaScript. Create a beautiful customizable calendar for your website, using the ISO 8601 standard. No dependencies, no jQuery, and no frameworks.
Key features include custom holidays, multiple date selection, inbuilt language support, and minified size of only 9kb.
The code is easy to understand and is a good starting point if you want to display events and schedules on the page.
How to use it:
1. Install and import the VanillaCalendar component.
# NPM $ npm i @uvarov.frontend/vanilla-calendar
import VanillaCalendar from '@uvarov.frontend/vanilla-calendar';
2. Or load the JavaScript library directly in the document.
<link rel="stylesheet" href="vanilla-calendar.css" /> <script>var exports = {};</script> <script src="vanilla-calendar.js"></script>
3. Add the CSS class ‘vanilla-calendar’ to the target container where the library generates the calendar.
<div class="vanilla-calendar"> </div>
4. Generate a basic calendar.
const calendar = new VanillaCalendar({ HTMLElement: document.querySelector('.vanilla-calendar'), }); calendar.init();
5. Set today’s date.
const calendar = new VanillaCalendar({ HTMLElement: document.querySelector('.vanilla-calendar'), date: new Date('2022-01-01'), });
6. Determine whether to use ISO 8601 format. (Default: true,)
const calendar = new VanillaCalendar({ HTMLElement: document.querySelector('.vanilla-calendar'), settings: { iso8601: false, }, }); calendar.init();
7. Disable date selection.
const calendar = new VanillaCalendar({ HTMLElement: document.querySelector('.vanilla-calendar'), settings: { selecting: false, }, }); calendar.init();
8. Set the date range.
const calendar = new VanillaCalendar({ HTMLElement: document.querySelector('.vanilla-calendar'), settings: { range: { min: '2022-05-01', max: '2022-05-13', values: ['2022-05-16', '2022-05-17'], }, }, }); calendar.init();
9. Specify the selected dates.
const calendar = new VanillaCalendar({ HTMLElement: document.querySelector('.vanilla-calendar'), settings: { selected: { date: '2022-05-14', month: 5, year: 2022, holidays: ['2022-05-01', '2022-05-02', '2022-05-03', '2022-05-04'], }, }, }); calendar.init();
10. Set the visibility of the component.
const calendar = new VanillaCalendar({ HTMLElement: document.querySelector('.vanilla-calendar'), settings: { isibility: { // hightlights weekends weekend: true, // highlights today today: true, // shows months months: false, // shows years year: true, // shows navigation buttons arrows: { prev: true, next: true, }, }, }, }); calendar.init();
11. Localize the calendar.
calendar.name.months.custom = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; calendar.name.week.custom = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; calendar.name.arrow.prev.custom = 'Prev'; calendar.name.arrow.next.custom = 'Next'; calendar.settings.lang = 'custom'; calendar.init();