Calendar widget for use either on its own or a mix with another component. When a date is chosen, data attributes on the base elements are updated, and a change
event is fired which also contains this data.
Standard calendar.
Mon | Tue | Wed | Thu | Fri | Sat | Sun |
---|
A calendar with extra fields to specify a time.
Mon | Tue | Wed | Thu | Fri | Sat | Sun |
---|
A list of modifiers for the calendar component, allowing you to change its appearance to fit a variety of roles and scenarios.
Modifiers can typically be combined to achieve the desired appearance, unless stated otherwise.
This modifier makes some of the calendar elements smaller. Use to keep everything in proportion when the calendar itself is small.
Mon | Tue | Wed | Thu | Fri | Sat | Sun |
---|
This modifier makes some of the calendar elements larger. Use to keep everything in proportion when the calendar itself is large.
Mon | Tue | Wed | Thu | Fri | Sat | Sun |
---|
This component has methods which allow you to programatically trigger actions. You can trigger these using the evo()
selector.
See JavaScript API for more information and a list of shared, global methods.
You can programatically change the calendar date using the setDate
method. The minimum data required is year
, so you don't have to pass a month
or day
value unless you need to.
// Would set the calendar's date to 30/09/2021 04:30
evo('.js-my-calendar-class').calendar('setDate', {
day: 30,
month: 9,
year: 2021,
hour: 4,
minute: 30
})
// Would set the calendar's date to 30/09/2021
evo('.js-my-calendar-class').calendar('setDate', {
day: 30,
month: 9,
year: 2021
})
// Would set the calendar's date to 01/09/2021
evo('.js-my-calendar-class').calendar('setDate', {
month: 9,
year: 2021,
})
// Would set the calendar's date to 01/01/2021
evo('.js-my-calendar-class').calendar('setDate', {
year: 2021
})
With the nextMonth
method, you can cycle the calendar 1 month forward.
evo('.js-my-calendar-class').calendar('nextMonth');
With the prevMonth
method, you can cycle the calendar 1 month backwards.
evo('.js-my-calendar-class').calendar('prevMonth');
This component has bespoke events which trigger automatically on certain actions. You can hook into these using event listeners to run your own custom code.
Typically, most events are fired from the block level class (eg:- c-tabs
), however some may fire from element level classes (eg:- c-tabs__item
). In practice, this usually doesn't matter as these element level events will bubble upwards and trigger any listeners on the block element. When this happens, you can get a reference to the element via the target
property of the event object.
Name | Description |
---|---|
|
Fires when a new date is selected. |
|
Fires when the month changes. |
|
Fires when the month cycles forward. |
|
Fires when the month cycles backwards. |
Example code snippet showing how you can set up an event listener.
const element = document.querySelector('.c-my-component');
element.addEventListener('eventName', (e) => {
console.log('my event has fired');
// Access event details object, if it exists
console.log(e.details);
// Access the element the event was fired from
console.log(e.target);
});
You can theme the calendar component to make it fit your brand. For more information on theming EvoToolkit, please see Configuring EvoToolkit.
Below is a list of theme variables and their default values.
Theme Variables | Default |
---|---|
$component-calendar-button-color |
primary |
$component-calendar-border-color |
light |
$component-calendar-prevnextmonth-cell-color |
very-light |
$component-calendar-cell-selected |
primary |