``` ____ __ __ /\ _`\ /\ \__ __ /\ \ \ \ \/\ \ __ \ \ ,_\ __ _____ /\_\ ___\ \ \/'\ __ _ __ \ \ \ \ \ /'__`\\ \ \/ /'__`\/\ '__`\/\ \ /'___\ \ , < /'__`\/\`'__\ \ \ \_\ \/\ \L\.\\ \ \_/\ __/\ \ \L\ \ \ \/\ \__/\ \ \\`\ /\ __/\ \ \/ \ \____/\ \__/.\_\ \__\ \____\\ \ ,__/\ \_\ \____\\ \_\ \_\ \____\\ \_\ \/___/ \/__/\/_/\/__/\/____/ \ \ \/ \/_/\/____/ \/_/\/_/\/____/ \/_/ \ \_\ \/_/ By: The Qodesmith ``` # Datepicker.js · [](https://badge.fury.io/js/js-datepicker) Get a date with JavaScript! Or a daterange, but that's not a good pun. Datepicker has **no dependencies** and weighs in at **5.9kb gzipped**! Datepicker is simple to use and looks sexy on the screen. A calendar pops up and you pick a date. #Boom.  ### Table of Contents * [Installation](#installation) * [Basic Usage](#basic-usage) * [Custom Elements / Shadow DOM Usage](#custom-elements--shadow-dom-usage) * [Manual Year & Month Navigation](#manual-year--month-navigation) * [Using As A Daterange Picker](#using-as-a-daterange-picker) * [Calendar Examples](#examples) * [Sizing The Calendar](#sizing-the-calendar) * [Properties & Values](#properties--values) #### Event Callbacks * [onSelect](#onselect) * [onShow](#onshow) * [onHide](#onhide) * [onMonthChange](#onmonthchange) #### Customizations * [formatter](#formatter) * [position](#position) * [startDay](#startday) * [customDays](#customdays) * [customMonths](#custommonths) * [customOverlayMonths](#customoverlaymonths) * [defaultView](#defaultView) * [overlayButton](#overlaybutton) * [overlayPlaceholder](#overlayplaceholder) * [events](#events) #### Settings * [alwaysShow](#alwaysshow) * [dateSelected](#dateselected) * [maxDate](#maxdate) * [minDate](#mindate) * [startDate](#startdate) * [showAllDates](#showalldates) * [respectDisabledReadOnly](#respectdisabledreadonly) #### Disabling Things * [noWeekends](#noweekends) * [disabler](#disabler) * [disabledDates](#disableddates) * [disableMobile](#disablemobile) * [disableYearOverlay](#disableyearoverlay) * [disabled](#disabled) #### ID - Daterange * [id](#id) #### Instance Methods * [navigate](#navigate) * [remove](#remove) * [setDate](#setdate) * [setMin](#setmin) * [setMax](#setmax) * [show](#show) * [hide](#hide) * [Show / Hide "Gotcha"](#show--hide-gotcha) * [toggleOverlay](#toggleOverlay) * [getRange](#getrange) _(daterange only)_ See the [examples](#examples) below. ## Installation #### Manually Simply include `datepicker.min.css` in the `
`... ```html ... ``` and include `datepicker.min.js` just above your closing `` tag... ```html ... ``` If you downloaded the package via zip file from Github, these files are located in the `dist` folder. Otherwise, you can use the Unpkg CDN as shown in the examples above. #### Via NPM ``` npm install js-datepicker ``` Files & locations: | File | Folder | Description | | ------------------ | ------------------------------- | --------------------------------------- | | datepicker.min.js | node_modules/js-datepicker/dist | production build - (ES5, 5.9kb gzipped) | | datepicker.min.css | node_modules/js-datepicker/dist | production stylesheet | | datepicker.scss | node_modules/js-datepicker/src | Scss file. Use it in your own builds. | ## Basic Usage Importing the library if you're using it in Node: ```javascript import datepicker from 'js-datepicker' // or const datepicker = require('js-datepicker') ``` Using it in your code: ```javascript const picker = datepicker(selector, options) ``` Importing the styles into your project using Node: ```javascript // From within a scss file, // import datepickers scss file... @import '~js-datepicker/src/datepicker'; // or import datepickers css file. @import '~js-datepicker/dist/datepicker.min.css'; ``` Datepicker takes 2 arguments: 1. `selector` - two possibilities: 1. `string` - a CSS selector, such as `'.my-class'`, `'#my-id'`, or `'div'`. 2. `DOM node` - provide a DOM node, such as `document.querySelector('#my-id')`. 2. (optional) An object full of [options](#options). The return value of the `datepicker` function is the datepicker instance. See the methods and properties below. You can use Datepicker with any type of element you want. If used with an `` element (the common use case), then the ``'s value will automatically be set when selecting a date. _NOTE: Datepicker will not change the value of input fields with a type of_ `date` - ``. _This is because those input's already have a built in calendar and can cause problems. Use_ `` _instead._ ### Manual Year & Month Navigation By clicking on the year or month an overlay will show revealing an input field and a list of months. You can either enter a year in the input, click a month, or both:  ### Using As A Daterange Picker Want 2 calendars linked together to form ~~Voltron~~ a daterange picker? It's as simple as giving them both the same [id](#id)! By using the [id](#id) option, Datepicker handles all the logic to keep both calendars in sync.  The 1st calendar will serve as the minimum date and the 2nd calendar as the maximum. Dates will be enabled / disabled on each calendar automatically when the user selects a date on either. The [getRange](#getrange) method will conveniently give you an object with the `start` and `end` date selections. It's as simple as creating 2 instances with the same `id` to form a daterange picker: ```javascript const start = datepicker('.start', { id: 1 }) const end = datepicker('.end', { id: 1 }) ``` And when you want to get your start and end values, simply call [getRange](#getrange) on _either_ instance: ```javascript start.getRange() // { start: