import { html, LitElement } from '@lion/core';
import {
localize,
getWeekdayNames,
getMonthNames,
normalizeDateTime,
LocalizeMixin,
} from '@lion/localize';
import '@lion/core/src/differentKeyEventNamesShimIE.js';
import { createMultipleMonth } from './utils/createMultipleMonth.js';
import { dayTemplate } from './utils/dayTemplate.js';
import { dataTemplate } from './utils/dataTemplate.js';
import { getFirstDayNextMonth } from './utils/getFirstDayNextMonth.js';
import { getLastDayPreviousMonth } from './utils/getLastDayPreviousMonth.js';
import { isSameDate } from './utils/isSameDate.js';
import { calendarStyle } from './calendarStyle.js';
import { createDay } from './utils/createDay.js';
/**
* @customElement lion-calendar
*/
export class LionCalendar extends LocalizeMixin(LitElement) {
static get localizeNamespaces() {
return [
{
'lion-calendar': locale => {
switch (locale) {
case 'bg-BG':
return import('../translations/bg.js');
case 'cs-CZ':
return import('../translations/cs.js');
case 'de-AT':
case 'de-DE':
return import('../translations/de.js');
case 'en-AU':
case 'en-GB':
case 'en-PH':
case 'en-US':
return import('../translations/en.js');
case 'es-ES':
return import('../translations/es.js');
case 'fr-FR':
case 'fr-BE':
return import('../translations/fr.js');
case 'hu-HU':
return import('../translations/hu.js');
case 'it-IT':
return import('../translations/it.js');
case 'nl-BE':
case 'nl-NL':
return import('../translations/nl.js');
case 'pl-PL':
return import('../translations/pl.js');
case 'ro-RO':
return import('../translations/ro.js');
case 'ru-RU':
return import('../translations/ru.js');
case 'sk-SK':
return import('../translations/sk.js');
case 'uk-UA':
return import('../translations/uk.js');
case 'zh-CN':
return import('../translations/zh.js');
default:
return import(`../translations/${locale}.js`);
}
},
},
...super.localizeNamespaces,
];
}
static get properties() {
return {
/**
* Minimum date. All dates before will be disabled
*/
minDate: { type: Date },
/**
* Maximum date. All dates after will be disabled
*/
maxDate: { type: Date },
/**
* Disable certain dates
*/
disableDates: { type: Function },
/**
* The selected date, usually synchronized with datepicker-input
* Not to be confused with the focused date (therefore not necessarily in active month view)
*/
selectedDate: { type: Date },
/**
* The date that
* 1. determines the currently visible month
* 2. will be focused when the month grid gets focused by the keyboard
*/
centralDate: { type: Date },
/**
* Weekday that will be displayed in first column of month grid.
* 0: sunday, 1: monday, 2: tuesday, 3: wednesday , 4: thursday, 5: friday, 6: saturday
* Default is 0
*/
firstDayOfWeek: { type: Number },
/**
* Weekday header notation, based on Intl DatetimeFormat:
* - 'long' (e.g., Thursday)
* - 'short' (e.g., Thu)
* - 'narrow' (e.g., T).
* Default is 'short'
*/
weekdayHeaderNotation: { type: String },
/**
* Different locale for this component scope
*/
locale: { type: String },
/**
* The currently focused date (if any)
*/
__focusedDate: { type: Date },
/**
* Data to render current month grid
*/
__data: { type: Object },
};
}
constructor() {
super();
// Defaults
this.__data = {};
this.minDate = null;
this.maxDate = null;
this.dayPreprocessor = day => day;
this.disableDates = () => false;
this.firstDayOfWeek = 0;
this.weekdayHeaderNotation = 'short';
this.__today = normalizeDateTime(new Date());
this.centralDate = this.__today;
this.__focusedDate = null;
this.__connectedCallbackDone = false;
}
static get styles() {
return [calendarStyle];
}
render() {
return html`