Bluepicker
A beautiful VanillaJS date or datetime picker that also supports local or UTC input.
Why ?
It is nearly impossible to find a date(time) picker that simultaneously brings:
- Only has the awesome momentjs as dependency
- Local CSS styles (avoids conflicts with the surrounding application)
- Can be either an efficient Date picker or a Datetime one
- Supports UTC or local time input
- Low complexity: less than 500 SLOC.
- Is beautiful and easy to use enough (not 5 dropdowns)
Sample code
Simply require it and use it !
<div id="picker_id">
<input type="text"></input>
</div>
import bluepicker from 'bluepicker'
import 'bluepicker/dist/bundle.css' # hashed CSS classes for the picker
bluepicker.init('picker_id')
Configuration
Almost everything is configurable.
bluepicker.init('picker_id', {
callback: null,
locale: 'cn',
format: 'lll',
mode: 'hours',
utcMode: true,
padToBoundary: false,
nowButtonText: 'Now'
}, initValue)
Events
Upon changes (either by direct modification in the input field, or a click
in the picker buttons) a DOM event is fired and the callback is called,
if provided.
bluepicker.init('picker_id', {callback: onPickerChange})
document.addEventListener('bluepicker:update', (e) => onPickerChange(e.detail))
function onPickerChange ({id, format, value, utcMode}) {
}
License
MIT