--- layout: default route: index fixed-navbar: false title: Quick-Start subtitle: bulma.io Calendar component with range selection capability --- {% capture component_include_css %} {% endcapture %} {% capture component_include_sass %} @charset "utf-8" // Import Bulma core @import 'bulma.sass' // Import component @import "bulmaCalendar.sass" {% endcapture %} {% capture component_include_es5 %} {% endcapture %} {% capture component_include_es6 %} import bulmaCalendar from '~bulma-calendar/dist/js/bulma-calendar.min.js'; {% endcapture %} {% capture component_example %} {% endcapture %} {% capture component_dataset %} {% endcapture %} {% capture component_init_es5 %} // Initialize all input of type date var calendars = bulmaCalendar.attach('[type="date"]', options); // Loop on each calendar initialized for(var i = 0; i < calendars.length; i++) { // Add listener to date:selected event calendars[i].on('select', date => { console.log(date); }); } // To access to bulmaCalendar instance of an element var element = document.querySelector('#my-element'); if (element) { // bulmaCalendar instance is available as element.bulmaCalendar element.bulmaCalendar.on('select', function(datepicker) { console.log(datepicker.data.value()); }); } {% endcapture %} {% capture component_init_es6 %} // Initialize all input of date type. const calendars = bulmaCalendar.attach('[type="date"]', options); // Loop on each calendar initialized calendars.forEach(calendar => { // Add listener to date:selected event calendar.on('date:selected', date => { console.log(date); }); }); // To access to bulmaCalendar instance of an element const element = document.querySelector('#my-element'); if (element) { // bulmaCalendar instance is available as element.bulmaCalendar element.bulmaCalendar.on('select', datepicker => { console.log(datepicker.data.value()); }); } {% endcapture %} {% capture component_init_vuejs %} // Thanks to @megapctr new Vue({ el: '#app', data() { return { date: new Date(), } }, mounted() { const calendar = bulmaCalendar.attach(this.$refs.calendarTrigger, { startDate: this.date, })[0] calendar.on('date:selected', e => (this.date = e.start || null)) }, computed: { niceDate() { if (this.date) { return this.date.toLocaleDateString() } } } }); // The view is like:
Calendar works fine on any device: desktop, tablet or mobile.
Many options to customize behavior. Use of sass variables to easily customize design.
Pure JavaScript to manage user interaction.
There are several ways to get started with Bulma-extensions. You can either:
Use npm to install and stay up to date in the future
{% highlight shell %}npm install bulma-calendar{% endhighlight %}Use the GitHub repository to get the latest development version
This method requires git installed on your computer.
{% highlight shell %}git clone git://github.com/Wikiki/bulma-calendar.git{% endhighlight %}The component comes with various files:
Depending on your need your can use either pre-compiled files from dist
directory or sources from src
directory.
The best way to start with calendar is to use a simple HTML5 date input:
{% highlight html %}{{ component_example }}{% endhighlight %}You are only at 3 simple steps to work with bulmaCalendar.
The first step is to include the stylesheet into your project. You can use either the minified CSS version or the Sass source to integrate it into a more global project.
{% highlight html %}{{ component_include_css }}{% endhighlight %}
{% highlight html %}{{ component_include_sass }}{% endhighlight %}
Second step is to include the JavaScript part of the component.
{% highlight html %}{{ component_include_es5 }}{% endhighlight %}
{% highlight javascript %}{{ component_include_es6 }}{% endhighlight %}
Now all that remains is to intiate the component to all elements you want to transform into a Calendar / DatePicker
{% highlight javascript %}{{ component_init_es5 }}{% endhighlight %}
{% highlight javascript %}{{ component_init_es6 }}{% endhighlight %}
{% highlight javascript %}{{ component_init_vuejs }}{% endhighlight %}
Calendar component provides some public methods to manually work with it.
{% include methods.html %}Calendar component provides some public Getters to manually access properties.
{% include getters.html %}Calendar component provides some public Setters to manually set properties.
{% include setters.html %}Calendar component comes with Events Management API so you can easily react to its behavior.
{% include events.html %}