Minimal Inline Calendar Date Picker In Vanilla JavaScript

Category: Date & Time , Javascript | October 9, 2018
Author: chrisssycollins
Views Total: 5,205
Official Page: Go to website
Last Update: October 9, 2018
License: MIT

Preview:

Minimal Inline Calendar Date Picker In Vanilla JavaScript

Description:

A vanilla JavaScript library which enables the user to select a date from a minimal clean inline calendar view.

How to use it:

Load the style sheet ‘vanillacalendar.css’ in the header, and the JavaScript file ‘vanillacalendar.js’ at the end of the document.

<link href="vanillacalendar.css" rel="stylesheet">
<script src="vanillacalendar.js"></script>

Create the HTML for the inline calendar.

<div class="cal">
  <div class="cal__header">
    <button class="btn btn-action btn-link btn-lg" data-calendar-toggle="previous"><svg height="24" version="1.1" viewbox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
    <path d="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z"></path></svg></button>
    <div class="cal__header__label" data-calendar-label="month">
      March 2017
    </div><button class="btn btn-action btn-link btn-lg" data-calendar-toggle="next"> <svg height="24" version="1.1" viewbox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
    <path d="M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z"></path></svg></button>
  </div>
  <div class="cal__week">
    <span>Mon</span> <span>Tue</span><span>Wed</span> <span>Thu</span> <span>Fri</span> <span>Sat</span> <span>Sun</span>
  </div>
  <div class="cal__body" data-calendar-area="month"></div>
</div>

Create a container to place the date picked by your users.

Date picked: <span data-calendar-label="picked"></span>

Initialize the inline calendar on page load.

window.addEventListener('load', function () {
  vanillacalendar.init();
})

Changelog:

v0.0.3 (10/09/2018)

  • added disablePastDays parameter.

You Might Be Interested In:

One thought on “Minimal Inline Calendar Date Picker In Vanilla JavaScript

  1. avishay.c

    Not Realy Working… in console “Uncaught TypeError: Cannot read property ‘appendChild’ of undefined”

    Reply

Leave a Reply