Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

lightpick

wakirin16.7kMITdeprecated1.6.2TypeScript support: definitely-typed

Unmaintained in favor of Litepicker. Please use https://github.com/wakirin/Litepicker

Javascript date range picker - lightweight, no jQuery - (Unmaintained)

datepicker, date, daterange, date, picker, range

readme

npm version license

Lightpick

WARNING: Unmaintained in favor of Litepicker

Javascript date range picker - lightweight, no jQuery

Demo & Docs


Dependencies

Installation


npm install lightpick

or you can download and include Moment.js and Lightpick files manually.

Usage


Lightpick can be bound to an input field:

<input type="text" id="datepicker"/>

Include Lightpick script to the end of your document:

<link rel="stylesheet" type="text/css" href="css/lightpick.css">  
...  
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script src="lightpick.js"></script>  
<script>  
var picker = new Lightpick({ field: document.getElementById('datepicker') });  
</script>

Configuration


field

  • Type: Element
  • Default: null

Bind the datepicker to a form field

secondField

  • Type: Element
  • Default: null

If exists then end of date range will set here.

firstDay

  • Type: Number
  • Default: 1

ISO day of the week (1: Monday, ..., 7: Sunday).

parentEl

  • Type: String | Element
  • Default: body

Selector of the parent element that the date range picker will be added to, if not provided this will be 'body'.

lang

  • Type: String
  • Default: auto

Language code for names of days, months by Date.prototype.toLocaleString(). 'auto' will try detect user browser language.

format

  • Type: String
  • Default: DD/MM/YYYY

The default output format.

separator

  • Type: String
  • Default: -

Separator between dates when one field.

numberOfMonths

  • Type: Number
  • Default: 1

Number of visible months.

numberOfColumns

  • Type: Number
  • Default: 2

Number of columns months.

singleDate

  • Type: Boolean
  • Default: true

Choose a single date instead of a date range.

autoclose

  • Type: Boolean
  • Default: true

Close calendar when picked date/range.

hideOnBodyClick

  • Type: Boolean
  • Default: true

Close calendar when clicked outside the elements specified in field or parentEl. Recommended use when autoclose is set to false.

repick

  • Type: Boolean
  • Default: false

Repick start/end instead of new range. This option working only when exists secondField.

minDate

  • Type: moment|String|Number|Date
  • Default: null

The minimum/earliest date that can be selected. Any format: moment() or '2018-06-01' or 1527811200000, new Date()

maxDate

  • Type: moment|String|Number|Date
  • Default: null

The maximum/latest date that can be selected. Any format: moment() or '2018-06-01' or 1527811200000, new Date()

disableDates

  • Type: Array
  • Default: null

Array of disabled dates. Array can contains ranges, allowed the same format as in options minDate, maxDate. Eg.: \[moment().startOf('month'), \['2018-06-23', '2018-06-30'\]\]

selectForward

  • Type: Boolean
  • Default: false

Select second date after the first selected date.

selectBackward

  • Type: Boolean
  • Default: false

Select second date before the first selected date.

minDays

  • Type: Number
  • Default: null

The minimum days of the selected range.

maxDays

  • Type: Number
  • Default: null

The maximum days of the selected range.

hoveringTooltip

  • Type: Boolean
  • Default: true

Show tooltip.

  • Type: Boolean|String
  • Default: false

Footer calendar, if set to true will use default footer (Reset/Apply buttons) or custom string (html).

disabledDatesInRange

  • Type: Boolean
  • Default: true

If set to false then will reset selected range when disabled dates exists in selected range.

tooltipNights

  • Type: Boolean
  • Default: false

Calc date range in nights. (For hotels when last date doesn't include to range)

orientation

  • Type: String
  • Default: auto

A space-separated string consisting of one or two of “left” or “right”, “top” or “bottom”, and “auto” (may be omitted); for example, “top left”, “bottom” (horizontal orientation will default to “auto”), “right” (vertical orientation will default to “auto”), “auto top”.

disableWeekends

  • Type: Boolean
  • Default: false

Disable Saturday and Sunday.

inline

  • Type: Boolean
  • Default: false

Show calendar inline. If true and parentEl is not provided then will use parentNode of field.

weekdayStyle

  • Type: String
  • Default: short

Determines the weekday display style. Possible values are: long (e.g., Thursday), short (e.g., Thu), narrow (e.g., T). Two weekdays may have the same narrow style for some locales (e.g. Tuesday's narrow style is also T).

  • Type: Object|Boolean
  • Default:
    { 
      years: { 
          min: 1900, 
          max: null, 
      }, 
      months: true, 
    }
    Dropdown selections for years, months. Can be false for disable both dropdowns.
    years (Object|Boolean) - Object must contains min and max range of years or can be false for disable dropdown of years.
    months (Boolean) - true/false for enable/disable dropdown of months.

locale

  • Type: Object
  • Default:

    { 
      buttons: { 
          prev: '&leftarrow;', 
          next: '&rightarrow;', 
          close: '&times;', 
          reset: 'Reset', 
          apply: 'Apply'
      }, 
      tooltip: { 
          one: 'day',  
          other: 'days'
      },
      tooltipOnDisabled: null,
      pluralize: function(i, locale){
          if (typeof i === "string") i = parseInt(i, 10);
    
          if (i === 1 && 'one' in locale) return locale.one;
          if ('other' in locale) return locale.other;
    
          return '';
      }
    }

    buttons - Text for buttons
    tooltip - Text for tooltip (one, few, many, other)
    tooltipOnDisabled (String) - Show tooltip text on disabled dates. (Eg. «Already booked»)
    pluralize (function) - Function for calc plural text. More examples for another locales on betsol/numerous

onSelect

  • Type: Function
  • Default: null

Callback function for when a date is selected. Will return the start date (when singleDate=true or not set), or both the start and end dates (when singleDate=false). This will be called every time setDate() or setDateRange() is used unless the third boolean argument on those functions is set to true.

onSelectStart

  • Type: Function
  • Default: null

Callback function for when a start date is selected (only when singleDate=false). Will return the start date only.

onSelectEnd

  • Type: Function
  • Default: null

Callback function for when a end date is selected (only when singleDate=false). Will return the end date only.

onOpen

  • Type: Function
  • Default: null

Callback function for when the picker becomes visible.

onClose

  • Type: Function
  • Default: null

Callback function for when the picker is hidden.

onError

  • Type: Function
  • Default: null

Working when disabledDatesInRange: false Callback function for when user has select date range with disabled dates.

onMonthsChange

  • Type: Function
  • Default: null

Callback function for when the months select is changed.

onYearsChange

  • Type: Function
  • Default: null

Callback function for when the years select is changed.

Methods


picker.setDate(date, preventOnSelect)

Set date when singleDate is true. date can be moment, string, number, date.
Optional argument preventOnSelect (boolean) is set to false by default. Setting it to true will prevent the picker from calling it's onSelect function. Eg. picker.setDate(new Date());

picker.setDateRange(start, end, preventOnSelect)

Set date range. start, end can be moment, string, number, date. Optional argument preventOnSelect (boolean) is set to false by default. Setting it to true will prevent the picker from calling it's onSelect function. Eg. picker.setDateRange(new Date(), moment().add(7, 'day'));

picker.setDisableDates(array)

array of disabled dates. Array can contains ranges, allowed moment, string, number, date. Eg. picker.setDisableDates([ moment().startOf('month'), ['2018-06-23', '2018-06-30'] ]);

picker.getDate()

Return current date as moment object.

picker.getStartDate()

Return current start of date range as moment object.

picker.getEndDate()

Return current start of date range as moment object.

picker.toString('YYYY-MM-DD')

Returns the date in a string format.

picker.reloadOptions({})

Update picker options.

picker.show()

Make the picker visible.

picker.hide()

Hide the picker.

picker.destroy()

Hide the picker and remove all event listeners.

changelog

Changelog

All notable changes to this project will be documented in this file.

[1.6.0] - 2020-01-23

  • Change month title bar tag header to div

[1.5.0] - 2019-11-12

  • All getX methods returns clone dates now - PR #75 - Thanks @StevenGastroSophy

[1.4.5] - 2019-11-03

  • Added onSelectStart and onSelectEnd helper functions - PR #61 - Thanks @scssyworks

[1.4.4] - 2019-11-03

  • Fix autoclose refresh date issue - #74

[1.4.3] - 2019-11-01

  • Fix reload options for dropdowns and locale objects

[1.4.2] - 2019-11-01

  • SCSS file added - PR #72 - Thanks @tomvanenckevort

[1.4.1] - 2019-10-23

  • Fix iOS daylight savings time weekdayName issue - PR #85 - Thanks @EionRobb

[1.4.0] - 2019-10-22

  • Fix minDate, maxDate, disableDates and value (gotoDate) of input now respects format parameter.

[1.3.6] - 2019-10-22

  • New options onMonthsChange and onYearsChange - Events fire when months or years select changed. onMonthsChange throws zero based number of month. Ex: January = 0 onYearsChange throws year. Ex: 2019 Implementation of #59

[1.3.5] - 2019-10-22

  • New option weekdayStyle - Weekday display style added. Possible values are 'long', 'short' or 'narrow'. Implementation of #91

[1.3.4] - 2019-03-30

  • fixed bug #51

[1.3.2] - 2019-03-25

  • New option: dropdowns

[1.3.1] - 2019-03-22

  • New option: inline (default is false)

[1.3.0] - 2019-03-22

  • Dropdown list months, years

[1.2.11] - 2019-02-13

  • Improve sync values with fields

[1.2.10] - 2019-02-12

  • fixed bug #36

[1.2.9] - 2019-01-15

  • fixed bugs #28, #29, #30

[1.2.8] - 2018-12-18

  • improved option orientation (checking available space on top when value is auto)

[1.2.7] - 2018-12-10

  • fix bug when used both options repick and minDays (on repick date minDays was ignored)

[1.2.6] - 2018-11-08

  • new option: orientation
  • new option: disableWeekends
  • fixed bug #23

[1.2.5] - 2018-09-06

  • Improve pluralize. Now as function.

[1.2.4] - 2018-08-26

  • Tooltip on disabled days.

[1.2.3] - 2018-08-24

  • Removed extra div days in next month.

[1.2.2] - 2018-08-24

  • new callback: onError Calling when disabledDatesInRange is set to false and user is select range includes disabled dates.
  • minor bug fixes

[1.2.0] - 2018-08-23

  • new option: disabledDatesInRange
  • new option: tooltipNights

[1.1.2] - 2018-08-22

  • new option: footer

[1.1.1] - 2018-08-16

  • fixed bug #15

[1.1.0] - 2018-07-20

  • drop support IE
  • now header (month name) is clickable for fast change month

[1.0.9] - 2018-07-19

  • fixed bug #9

[1.0.8] - 2018-07-12

  • new option hideOnBodyClick (by ninty9notout)
  • fixed bug #7

[1.0.6] - 2018-07-12

  • Improves styling (by bartvandebiezen)

[1.0.5] - 2018-07-12

  • new method reloadOptions (by Codetaal)
  • fixed bug #5

[1.0.4] - 2018-07-12

  • Improves CSS (by bartvandebiezen)

[1.0.3] - 2018-07-09

  • fixed bug #1: preventing pick a one-day-range when minDays option

[1.0.2] - 2018-06-20

  • Added method toString

[1.0.0] - 2018-06-20

  • Constructor name to begin with a capital letter: lightPick to Lightpick

[0.0.6] - 2018-06-20

  • Added option repick

[0.0.4] - 2018-06-18

  • Added tooltip
  • Option buttons moved to locale

[0.0.2] - 2018-06-16

  • Added polyfill (Object.assign)
  • flexbox fallback for IE
  • Update docs

[0.0.1] - 2018-06-15

  • Published on Github