JavaScript calendar

A lightweight responsive JavaScript calendar, date and date-time picker web component plugin. It brings a great user experience across different devices.

  • React, Angular, Vue compatible;
  • Mobile friendly;
  • Date picker;
  • Time picker;
  • Year-month picker;
  • Several events and easy integration;
  • JS plugin or web component;

Examples


Webcomponent date picker

How to embed a simple webcomponent calendar input in your application.



<html>
<script src="https://jsuites.net/v4/jsuites.js"></script>
<script src="https://jsuites.net/v4/jsuites.webcomponents.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v4/jsuites.css" type="text/css" />

<jsuites-calendar value="2020-01-20"></jsuites-calendar>

<script>
document.querySelector('jsuites-calendar').addEventListener('onchange', function(e) {
    console.log('New value: ' + e.target.value);
});
document.querySelector('jsuites-calendar').addEventListener('onclose', function(e) {
    console.log('Calendar is closed');
});
</script>
</html>


Basic date input

Create a basic date and time input using pure JavaScript.



<html>
<script src="https://jsuites.net/v4/jsuites.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v4/jsuites.css" type="text/css" />

<input id='calendar' />

<script>
jSuites.calendar(document.getElementById('calendar'),{
    format: 'DD/MM/YYYY HH:MM',
    time: true,
});
</script>
</html>


React integration

Using the JavaScript calendar via NPM.

Install

%npm install jsuites

Component

import jSuites from "jsuites";

import { useRef, useEffect } from "react";
import jSuites from "jsuites";

import "jsuites/dist/jsuites.css";

export default function Calendar({ options }) {
  const calendarRef = useRef(null);

  useEffect(() => {
    jSuites.calendar(calendarRef.current, options);
  }, [options]);

  return <input ref={calendarRef} />;
}


Documentation

Methods

Method Description
calendar.open();Open the javascript calendar picker
calendar.close(ignoreEvents);Close the calendar
@param int ignoreEvents - Do no execute onclose event
calendar.getValue();Get the current selected date
calendar.setValue(newValue);Set a new value for the javascript calendar and time picker
@param mixed newValue - New date should be set as YYYY-MM-DD HH:MM:SS
calendar.reset();Reset the input value
calendar.next();Go to the next month
calendar.prev();Go to the previous month


Events

Method Description
onchangeTrigger a method when value is changed.
onupdateTrigger a method when any information change in the calendar picker.
oncloseTrigger a method when the calendar is closed.
onopenTrigger a method when the calendar is closed.


Initial settings

Property Description
type: stringPicker type: default | year-month-picker. Default: default
validRange: [ date, date ]Date selection would be disabled out of this range. Default: null
startingDay: numberStarting weekday - 0 for sunday, 6 for saturday. Default: 0 (Sunday)
format: stringDate format. Default: YYYY-MM-DD
readonly: booleanInput will be disabled for manual changes.
today: booleanIf no value is default, open teh calendar on today as default. Default: false
time: booleanInclude a time picker on the calendar. Default: false
resetButton: booleanShow reset button. Default: true
placeholder: stringPlaceholder instructions
months: arrayMonth short names.
Default: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
monthsFull: arrayMonth short names.
Default: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
weekdays: arrayWeekday names.
Default: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
weekdays_short: arrayWeekday short names.
Default: ['S', 'M', 'T', 'W', 'T', 'F', 'S']
value: stringDefault date.
fullscreen: booleanRender in fullscreen. Default: true for screenWidth: 800px
opened: booleanCalendar starts opened. Default: false.
textDone: stringText of the 'Done' button
textReset: stringText of the 'textReset' button
textUpdate: stringText of the 'Update' button


More examples using the calendar plugin