Add range change event
This commit is contained in:
parent
00a36e0b35
commit
7ddca43a01
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tp/tp-date-picker",
|
"name": "@tp/tp-date-picker",
|
||||||
"version": "2.2.0",
|
"version": "2.3.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "tp-date-picker.js",
|
"main": "tp-date-picker.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -303,6 +303,7 @@ class TpDatePicker extends FormElement(LitElement) {
|
|||||||
|
|
||||||
this.month = prevMonth;
|
this.month = prevMonth;
|
||||||
this.year = prevYear;
|
this.year = prevYear;
|
||||||
|
this.dispatchRangeChangeEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
nextMonth() {
|
nextMonth() {
|
||||||
@ -316,14 +317,17 @@ class TpDatePicker extends FormElement(LitElement) {
|
|||||||
|
|
||||||
this.month = nextMonth;
|
this.month = nextMonth;
|
||||||
this.year = nextYear;
|
this.year = nextYear;
|
||||||
|
this.dispatchRangeChangeEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
previousYear() {
|
previousYear() {
|
||||||
this.year -= 1;
|
this.year -= 1;
|
||||||
|
this.dispatchRangeChangeEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
nextYear() {
|
nextYear() {
|
||||||
this.year += 1;
|
this.year += 1;
|
||||||
|
this.dispatchRangeChangeEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
getMonthDates(month = null, year = null) {
|
getMonthDates(month = null, year = null) {
|
||||||
@ -386,6 +390,7 @@ class TpDatePicker extends FormElement(LitElement) {
|
|||||||
if (el.value) {
|
if (el.value) {
|
||||||
this.year = el.value;
|
this.year = el.value;
|
||||||
this.showYearSelector = false;
|
this.showYearSelector = false;
|
||||||
|
this.dispatchRangeChangeEvent();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -395,6 +400,24 @@ class TpDatePicker extends FormElement(LitElement) {
|
|||||||
if (!Array.isArray(this.events)) return 0;
|
if (!Array.isArray(this.events)) return 0;
|
||||||
return this.events.filter(event => this.equalDate(event, date)).length;
|
return this.events.filter(event => this.equalDate(event, date)).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dispatchRangeChangeEvent() {
|
||||||
|
const currentMonthDates = this.getMonthDates(this.month, this.year);
|
||||||
|
const rangeStart = currentMonthDates[0];
|
||||||
|
const rangeEnd = currentMonthDates[currentMonthDates.length - 1];
|
||||||
|
|
||||||
|
this.dispatchEvent(new CustomEvent('range-changed', {
|
||||||
|
detail: {
|
||||||
|
month: this.month,
|
||||||
|
year: this.year,
|
||||||
|
rangeStart,
|
||||||
|
rangeEnd,
|
||||||
|
visibleDates: currentMonthDates
|
||||||
|
},
|
||||||
|
bubbles: true,
|
||||||
|
composed: true
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.customElements.define('tp-date-picker', TpDatePicker);
|
window.customElements.define('tp-date-picker', TpDatePicker);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user