Code Monkey home page Code Monkey logo

vanilla-material-datepicker's Introduction

Vanilla Material Datepicker

Vanilla JS material design-influenced date picker widget based on Moment.js

Installation

Current:

Clone the repo and build the files, or use the already-built files in ./dist. To build, you should use the following command:

> npm install && npm run dist

Future:

> npm install vanilla-material-datepicker

Usage

Reference the files in your HTML:

<link rel="stylesheet" href="path/to/vanilla-material-datepicker/datepicker.css">
<script src="path/to/moment/moment.js"></script>
<script src="path/to/vanilla-material-datepicker/datepicker.js"></script>

Initialize the widget:

document.addEventListener('DOMContentLoaded', function(event) {
  var input = document.querySelector('.with_input [name=date_field]');
  var display = document.querySelector('.with_button .display');
  var button = document.querySelector('.with_button .opener');
  var min = moment().subtract(1, 'year');
  var max = moment().add(1, 'year');
  var filter = function(moment) { ... };
  var openCallback = function() { ... };
  var closeCallback = function() { ... };
  var selectDateCallback = function(moment) { ... };

  var datepicker = new Datepicker(input, { // All members of this object are optional
    display: display,
    button: button,
    min: min,
    max: max,
    filter: filter,
    onOpen: openCallback,
    onClose: closeCallback,
    onSelectDate: selectDateCallback
  });
});

If you do anything wrong, it should tell you.

How do I know whether this date picker widget is for me?

This date picker widget has the following qualities:

  • Only dependency is moment.js
  • Intended to integrate into any JS app in any framework with minimal quirks or side-effects
  • Size and positioning are entirely dictated by CSS
  • Opens on input focus or optional display/button element click
  • The button option can be any element, not just a button
  • Weekday labels are displayed at the top of the container
  • Calendar display starts at the first week of the month of the selected date
  • Displays 6-7 weeks in a vertically scrollable panel
  • Scrolls through months and years infinitely into both the past and future, unless min and/or max are set
  • Filters dates based on a user-provided filter function option
  • Accepts optional callback functions for onOpen, onClose, and onSelectDate
  • Container is appended to the input/display element's parent element if a parent element option is not specified

License

vanilla-material-datepicker is freely distributable under the terms of the MIT license.

vanilla-material-datepicker's People

Contributors

phobetron avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.