A vanilla JavaScript remake of bootstrap-datepicker for Bulma and other CSS frameworks
This package is written from scratch as ECMAScript modules/Sass stylesheets to reproduce similar usability to bootstrap-datepicker.
It can work either standalone or with CSS framework (e.g. Bootstrap, Foundation), but works best with Bulma as it's developed primarily for Bulma.
The package also includes pre-built js/css files for those who like to use it directly on browser.
Install the package using npm.
npm install --save-dev vanillajs-datepicker
– Input picker
<input type="text" name="foo">
Datepicker
module.import Datepicker from 'path/to/node_modules/vanillajs-datepicker/js/Datepicker.js';
Or if you use a bundler that supports pkg.module (e.g. Rollup with node-resolve plugin, webpack)
import { Datepicker } from 'vanillajs-datepicker';
_Or if your bundler supports package entry points (e.g. Rollup with node-resolve plugin v8.4+, webpack v5+), you can also do this._
import Datepicker from 'vanillajs-datepicker/Datepicker';
Datepicker
constructor with the input element and, optionally, config options.const elem = document.querySelector('input[name="foo"]');
const datepicker = new Datepicker(elem, {
// ...options
});
– Inline picker
<div id="foo" data-date="01/25/2020"></div>
import the Datepicker
module in the same way as Input picker.
call Datepicker
constructor with the block element and, optionally, config options.
const elem = document.getElementById('foo');
const datepicker = new Datepicker(elem, {
// ...options
});
<div id="foo">
<input type="text" name="start">
<span>to</span>
<input type="text" name="end">
</div>
DateRangePicker
module.import DateRangePicker from 'path/to/node_modules/vanillajs-datepicker/js/DateRangePicker.js';
Or if you use a bundler that supports pkg.module (e.g. Rollup with node-resolve plugin, webpack)
import { DateRangePicker } from 'vanillajs-datepicker';
_Or if your bundler supports package entry points (e.g. Rollup with node-resolve plugin v8.4+, webpack v5+), you can also do this._
import DateRangePicker from 'vanillajs-datepicker/DateRangePicker';
DateRangePicker
constructor with the block element and, optionally, config options.const elem = document.getElementById('foo');
const rangepicker = new DateRangePicker(elem, {
// ...options
});
@import 'path/to/node_modules/vanillajs-datepicker/sass/datepicker';
@import 'path/to/node_modules/vanillajs-datepicker/sass/datepicker-bulma';
buttonClass: 'btn'
option to call Datepicker
/DateRangePicker
constructor.const datepicker = new Datepicker(elem, {
buttonClass: 'btn',
});
@import 'path/to/node_modules/vanillajs-datepicker/sass/datepicker-bs4';
@import 'path/to/node_modules/vanillajs-datepicker/sass/datepicker-foundation';
buttonClass
option to call Datepicker
/DateRangePicker
constructor.const datepicker = new Datepicker(elem, {
buttonClass: 'uk-button',
});
/***
Copy the datepicker variables (the ones with `dp-` prefix and `!default` flag)
from `sass/Datepicker.scss` to here
Then, edit them using your framework's variables/values
e.g.:
$dp-background-color: $background !default;
$dp-border-color: $border !default;
...
***/
@import '../node_modules/vanillajs-datepicker/sass/mixins';
@mixin dp-button {
.button {
/***
Place style adjustment for date picker's buttons here, if needed
***/
.datepicker-header & {
@include dp-header-button-common;
/***
Place style adjustment specific to the header buttons here, if needed
***/
}
.datepicker-footer & {
@include dp-footer-button-common;
/***
Place style adjustment specific to the footer buttons here, if needed
***/
}
}
}
@import '../node_modules/vanillajs-datepicker/sass/datepicker';
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.1.4/dist/css/datepicker.min.css">
...
<script src="https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.1.4/dist/js/datepicker-full.min.js"></script>
If you use Bulma, Bootstrap or Foundation, you can use the css for your framework instead.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.1.4/dist/css/datepicker-bulma.min.css">
<!-- or -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.1.4/dist/css/datepicker-bs4.min.css">
<!-- or -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.1.4/dist/css/datepicker-foundation.min.css">
And if don't need date range, you can use the datepicker-only version of js file.
<script src="https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.1.4/dist/js/datepicker.min.js"></script>
Datepicker
/DateRangePicker
constructor in the same way as explained above. (The classes are exposed to global scope.)const elem = document.querySelector('input[name="foo"]');
const datepicker = new Datepicker(elem, {
// ...options
});