@nuralyui/datepicker 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constants.d.ts +2 -0
- package/constants.d.ts.map +1 -0
- package/constants.js +2 -0
- package/constants.js.map +1 -0
- package/core/day.helper.d.ts +5 -0
- package/core/day.helper.d.ts.map +1 -0
- package/core/day.helper.js +53 -0
- package/core/day.helper.js.map +1 -0
- package/core/formatter.d.ts +2 -0
- package/core/formatter.d.ts.map +1 -0
- package/core/formatter.js +9 -0
- package/core/formatter.js.map +1 -0
- package/core/locale.helper.d.ts +144 -0
- package/core/locale.helper.d.ts.map +1 -0
- package/core/locale.helper.js +151 -0
- package/core/locale.helper.js.map +1 -0
- package/core/month.helper.d.ts +3 -0
- package/core/month.helper.d.ts.map +1 -0
- package/core/month.helper.js +24 -0
- package/core/month.helper.js.map +1 -0
- package/core/string.helper.d.ts +2 -0
- package/core/string.helper.d.ts.map +1 -0
- package/core/string.helper.js +4 -0
- package/core/string.helper.js.map +1 -0
- package/date-picker.component.d.ts +83 -0
- package/date-picker.component.d.ts.map +1 -0
- package/date-picker.component.js +478 -0
- package/date-picker.component.js.map +1 -0
- package/date-picker.style.d.ts +2 -0
- package/date-picker.style.d.ts.map +1 -0
- package/date-picker.style.js +223 -0
- package/date-picker.style.js.map +1 -0
- package/datepicker.types.d.ts +39 -0
- package/datepicker.types.d.ts.map +1 -0
- package/datepicker.types.js +8 -0
- package/datepicker.types.js.map +1 -0
- package/demo/date-picker-demo.d.ts +18 -0
- package/demo/date-picker-demo.d.ts.map +1 -0
- package/demo/date-picker-demo.js +95 -0
- package/demo/date-picker-demo.js.map +1 -0
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -0
- package/index.js +2 -0
- package/index.js.map +1 -0
- package/package.json +15 -0
- package/react.d.ts +3 -0
- package/react.d.ts.map +1 -0
- package/react.js +10 -0
- package/react.js.map +1 -0
- package/templates/days.template.d.ts +4 -0
- package/templates/days.template.d.ts.map +1 -0
- package/templates/days.template.js +28 -0
- package/templates/days.template.js.map +1 -0
- package/templates/headers.template.d.ts +2 -0
- package/templates/headers.template.d.ts.map +1 -0
- package/templates/headers.template.js +5 -0
- package/templates/headers.template.js.map +1 -0
- package/templates/months.template.d.ts +6 -0
- package/templates/months.template.d.ts.map +1 -0
- package/templates/months.template.js +10 -0
- package/templates/months.template.js.map +1 -0
- package/templates/years.template.d.ts +6 -0
- package/templates/years.template.d.ts.map +1 -0
- package/templates/years.template.js +11 -0
- package/templates/years.template.js.map +1 -0
- package/test/datepicker_test.d.ts +2 -0
- package/test/datepicker_test.d.ts.map +1 -0
- package/test/datepicker_test.js +132 -0
- package/test/datepicker_test.js.map +1 -0
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
/* eslint-disable no-case-declarations */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2023 Google Laabidi Aymen
|
|
6
|
+
* SPDX-License-Identifier: MIT
|
|
7
|
+
*/
|
|
8
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
9
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
11
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
12
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
import { LitElement, html, nothing } from 'lit';
|
|
24
|
+
import { customElement, property, query, state } from 'lit/decorators.js';
|
|
25
|
+
import dayjs from 'dayjs';
|
|
26
|
+
import '../input/input.component.js';
|
|
27
|
+
import '../icon/icon.component.js';
|
|
28
|
+
import '../button/hy-button.component.js';
|
|
29
|
+
import { getMonthDetails } from './core/month.helper.js';
|
|
30
|
+
import { styles } from './date-picker.style.js';
|
|
31
|
+
import { Mode } from './datepicker.types.js';
|
|
32
|
+
import { renderMonthsTemplate } from './templates/months.template.js';
|
|
33
|
+
import { renderYearsTemplate } from './templates/years.template.js';
|
|
34
|
+
import { renderDays } from './templates/days.template.js';
|
|
35
|
+
import { oneToTwoDigit } from './core/formatter.js';
|
|
36
|
+
import { capitalizeFirstLetter } from './core/string.helper.js';
|
|
37
|
+
import './core/locale.helper.js';
|
|
38
|
+
import { EMPTY_STRING } from './constants.js';
|
|
39
|
+
let HyDatePickerElement = class HyDatePickerElement extends LitElement {
|
|
40
|
+
constructor() {
|
|
41
|
+
super(...arguments);
|
|
42
|
+
this.today = dayjs();
|
|
43
|
+
this.locale = 'en';
|
|
44
|
+
this.mode = Mode.Day;
|
|
45
|
+
this.range = false;
|
|
46
|
+
this.prevMode = this.mode;
|
|
47
|
+
this.openedCalendar = false;
|
|
48
|
+
this.monthsShort = dayjs().localeData().monthsShort();
|
|
49
|
+
this.months = dayjs().localeData().months();
|
|
50
|
+
this.days = dayjs().localeData().weekdays();
|
|
51
|
+
this.weekdaysShort = dayjs().localeData().weekdaysShort();
|
|
52
|
+
this.currentYear = this.today.year();
|
|
53
|
+
this.currentDay = this.today.date();
|
|
54
|
+
this.currentMonth = this.today.month() + 1;
|
|
55
|
+
this.inputFieldValue = '';
|
|
56
|
+
this.fieldFormat = 'DD/MM/YYYY';
|
|
57
|
+
this.dateValue = '';
|
|
58
|
+
this.navigationDates = {
|
|
59
|
+
start: {
|
|
60
|
+
year: this.currentYear,
|
|
61
|
+
month: this.currentMonth,
|
|
62
|
+
day: this.currentDay,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
this.size = "medium" /* INPUT_SIZE.Medium */;
|
|
66
|
+
this.state = "default" /* INPUT_STATE.Default */;
|
|
67
|
+
this.disabled = false;
|
|
68
|
+
this.INPUT_TYPE = 'calendar';
|
|
69
|
+
this.positionCalendar = () => __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
if (this.openedCalendar) {
|
|
71
|
+
yield this.updateComplete;
|
|
72
|
+
const dateInput = this.shadowRoot.querySelector('#date-input');
|
|
73
|
+
const calendarHeight = this.calendarContainer.getBoundingClientRect().height;
|
|
74
|
+
const dateInputRect = dateInput.getBoundingClientRect();
|
|
75
|
+
const availableBottomSpace = window.visualViewport.height - dateInputRect.bottom;
|
|
76
|
+
const availableTopSpace = dateInputRect.top;
|
|
77
|
+
this.calendarContainer.style.removeProperty('top');
|
|
78
|
+
this.calendarContainer.style.removeProperty('position');
|
|
79
|
+
if (calendarHeight > availableBottomSpace && availableTopSpace > calendarHeight) {
|
|
80
|
+
const inputElement = dateInput.shadowRoot.querySelector('#input-container');
|
|
81
|
+
const inputBorderTop = +getComputedStyle(inputElement).borderTopWidth.split('px')[0];
|
|
82
|
+
this.calendarContainer.style.top = `${availableTopSpace - calendarHeight - inputBorderTop}px`;
|
|
83
|
+
this.calendarContainer.style.position = 'fixed';
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
this.selectMonth = (selectedMonth) => {
|
|
88
|
+
const _month = selectedMonth + 1 > 11 && this.range ? 11 : selectedMonth + 1;
|
|
89
|
+
this.navigationDates.start.month = _month;
|
|
90
|
+
this.navigationDates = Object.assign({}, this.navigationDates);
|
|
91
|
+
//TODO: handle mainMode
|
|
92
|
+
if (this.mode == Mode.Month) {
|
|
93
|
+
this.currentDay = 1;
|
|
94
|
+
this.openedCalendar = false;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
this.prevMode = Mode.Day;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
this.selectYear = (selectedYear) => {
|
|
101
|
+
this.navigationDates = Object.assign(Object.assign({}, this.navigationDates), { start: Object.assign(Object.assign({}, this.navigationDates.start), { year: selectedYear }) });
|
|
102
|
+
//TODO: handle mainMode
|
|
103
|
+
if (this.mode == Mode.Year) {
|
|
104
|
+
this.currentDay = 1;
|
|
105
|
+
this.currentMonth = 1;
|
|
106
|
+
this.openedCalendar = false;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
this.prevMode = Mode.Month;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
this.selectDay = (selectedDay) => {
|
|
113
|
+
if (!this.range) {
|
|
114
|
+
this.currentDay = Number(oneToTwoDigit(selectedDay.date));
|
|
115
|
+
this.currentMonth = selectedDay.month + 1;
|
|
116
|
+
this.currentYear = selectedDay.year;
|
|
117
|
+
const _month = this.currentMonth > 11 && this.range ? 11 : this.currentMonth;
|
|
118
|
+
this.navigationDates = Object.assign(Object.assign({}, this.navigationDates), { start: {
|
|
119
|
+
month: _month,
|
|
120
|
+
day: this.currentDay,
|
|
121
|
+
year: selectedDay.year,
|
|
122
|
+
} });
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
this.selectDateRange(selectedDay);
|
|
126
|
+
}
|
|
127
|
+
//TODO: handle mainMode
|
|
128
|
+
this.prevMode = Mode.Day;
|
|
129
|
+
if (!this.range)
|
|
130
|
+
this.openedCalendar = false;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
connectedCallback() {
|
|
134
|
+
super.connectedCallback();
|
|
135
|
+
document.addEventListener('click', this._onClickOutside.bind(this));
|
|
136
|
+
document.addEventListener('scroll', this.positionCalendar);
|
|
137
|
+
}
|
|
138
|
+
firstUpdated() {
|
|
139
|
+
if (this.range) {
|
|
140
|
+
this.endYear = this.currentYear;
|
|
141
|
+
this.endMonth = this.currentMonth;
|
|
142
|
+
this.endDay = this.currentDay;
|
|
143
|
+
}
|
|
144
|
+
this.fillInputField();
|
|
145
|
+
}
|
|
146
|
+
willUpdate(changedProperties) {
|
|
147
|
+
if (changedProperties.has('fieldFormat')) {
|
|
148
|
+
this.fillInputField();
|
|
149
|
+
}
|
|
150
|
+
if (changedProperties.has('openedCalendar') && this.openedCalendar) {
|
|
151
|
+
this.daysPresentation = getMonthDetails(this.currentYear, this.currentMonth - 1, this.days);
|
|
152
|
+
this.positionCalendar();
|
|
153
|
+
}
|
|
154
|
+
if (changedProperties.has('dateValue') && this.dateValue) {
|
|
155
|
+
const dateObj = dayjs(this.dateValue, this.fieldFormat, true);
|
|
156
|
+
if (dateObj.isValid()) {
|
|
157
|
+
const { years, months, date } = dateObj.toObject();
|
|
158
|
+
this.currentYear = years;
|
|
159
|
+
this.currentMonth = months + 1;
|
|
160
|
+
this.currentDay = date;
|
|
161
|
+
this.navigationDates = Object.assign(Object.assign({}, this.navigationDates), { start: { year: years, month: months + 1, day: date } });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if ((changedProperties.has('currentDay') && changedProperties.get('currentDay')) ||
|
|
165
|
+
(changedProperties.has('currentMonth') && changedProperties.get('currentMonth')) ||
|
|
166
|
+
(changedProperties.has('currentYear') && changedProperties.get('currentYear'))) {
|
|
167
|
+
this.fillInputField();
|
|
168
|
+
this.dispatchDateChange();
|
|
169
|
+
}
|
|
170
|
+
if (changedProperties.has('locale')) {
|
|
171
|
+
this.updateLocale(this.locale);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
_onClickOutside(e) {
|
|
175
|
+
if (!e.composedPath().includes(this)) {
|
|
176
|
+
this.openedCalendar = false;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
toggleCaldendar() {
|
|
180
|
+
this.openedCalendar = !this.openedCalendar;
|
|
181
|
+
}
|
|
182
|
+
fillInputField() {
|
|
183
|
+
this.inputFieldValue = this.range
|
|
184
|
+
? dayjs(`${this.currentYear}-${this.currentMonth}-${this.currentDay}`).format(this.fieldFormat) +
|
|
185
|
+
'-' +
|
|
186
|
+
dayjs(`${this.endYear}-${this.endMonth}-${this.endDay}`).format(this.fieldFormat)
|
|
187
|
+
: dayjs(`${this.currentYear}-${this.currentMonth}-${this.currentDay}`).format(this.fieldFormat);
|
|
188
|
+
}
|
|
189
|
+
dispatchDateChange() {
|
|
190
|
+
this.dispatchEvent(new CustomEvent('date-change', { bubbles: true, composed: true, detail: { value: this.inputFieldValue } }));
|
|
191
|
+
}
|
|
192
|
+
updateLocale(locale) {
|
|
193
|
+
dayjs.locale(locale);
|
|
194
|
+
this.monthsShort = dayjs().localeData().monthsShort();
|
|
195
|
+
this.months = dayjs().localeData().months();
|
|
196
|
+
this.weekdaysShort = dayjs().localeData().weekdaysShort();
|
|
197
|
+
this.days = dayjs().localeData().weekdays();
|
|
198
|
+
}
|
|
199
|
+
nextYear() {
|
|
200
|
+
let startYear = this.navigationDates.start.year;
|
|
201
|
+
this.navigationDates = Object.assign(Object.assign({}, this.navigationDates), { start: Object.assign(Object.assign({}, this.navigationDates.start), { year: ++startYear }) });
|
|
202
|
+
}
|
|
203
|
+
prevYear() {
|
|
204
|
+
let startYear = this.navigationDates.start.year;
|
|
205
|
+
this.navigationDates = Object.assign(Object.assign({}, this.navigationDates), { start: Object.assign(Object.assign({}, this.navigationDates.start), { year: --startYear }) });
|
|
206
|
+
}
|
|
207
|
+
nextMonth() {
|
|
208
|
+
const { start } = this.navigationDates;
|
|
209
|
+
let startMonth = start.month;
|
|
210
|
+
let startYear = start.year;
|
|
211
|
+
if ((startMonth == 11 && this.range) || startMonth == 12) {
|
|
212
|
+
startMonth = 1;
|
|
213
|
+
startYear++;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
startMonth++;
|
|
217
|
+
}
|
|
218
|
+
this.navigationDates = Object.assign(Object.assign({}, this.navigationDates), { start: {
|
|
219
|
+
day: this.navigationDates.start.day,
|
|
220
|
+
month: startMonth,
|
|
221
|
+
year: startYear,
|
|
222
|
+
} });
|
|
223
|
+
}
|
|
224
|
+
prevMonth() {
|
|
225
|
+
const { start } = this.navigationDates;
|
|
226
|
+
let startMonth = start.month;
|
|
227
|
+
let startYear = start.year;
|
|
228
|
+
if (startMonth >= 2) {
|
|
229
|
+
startMonth = --startMonth;
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
if (this.range)
|
|
233
|
+
startMonth = 11;
|
|
234
|
+
else
|
|
235
|
+
startMonth = 12;
|
|
236
|
+
startYear = --startYear;
|
|
237
|
+
}
|
|
238
|
+
this.navigationDates = Object.assign(Object.assign({}, this.navigationDates), { start: {
|
|
239
|
+
day: this.navigationDates.start.day,
|
|
240
|
+
year: startYear,
|
|
241
|
+
month: startMonth,
|
|
242
|
+
} });
|
|
243
|
+
}
|
|
244
|
+
selectDateRange(selectedDay) {
|
|
245
|
+
const selectedDateDay = selectedDay.date;
|
|
246
|
+
const selectedDateMonth = selectedDay.month;
|
|
247
|
+
const selectedDateYear = selectedDay.year;
|
|
248
|
+
const selectedDate = new Date(selectedDateYear, selectedDateMonth, selectedDateDay);
|
|
249
|
+
const endDateDay = this.endDay;
|
|
250
|
+
const endDateMonth = this.endMonth - 1;
|
|
251
|
+
const endDateYear = this.endYear;
|
|
252
|
+
const endDate = new Date(endDateYear, endDateMonth, endDateDay);
|
|
253
|
+
const startDateDay = this.currentDay;
|
|
254
|
+
const startDateMonth = this.currentMonth - 1;
|
|
255
|
+
const startDateYear = this.currentYear;
|
|
256
|
+
const startDate = new Date(startDateYear, startDateMonth, startDateDay);
|
|
257
|
+
if (!startDate ||
|
|
258
|
+
(endDate &&
|
|
259
|
+
startDate &&
|
|
260
|
+
(selectedDate.getTime() < startDate.getTime() || selectedDate.getTime() < endDate.getTime())) ||
|
|
261
|
+
(startDate && !endDate && selectedDate.getTime() < startDate.getTime())) {
|
|
262
|
+
this.currentDay = Number(oneToTwoDigit(selectedDay.date));
|
|
263
|
+
this.currentMonth = selectedDay.month + 1;
|
|
264
|
+
this.currentYear = selectedDay.year;
|
|
265
|
+
const _month = this.currentMonth > 11 && this.range ? 11 : this.currentMonth;
|
|
266
|
+
this.navigationDates = Object.assign(Object.assign({}, this.navigationDates), { start: {
|
|
267
|
+
month: _month,
|
|
268
|
+
day: this.currentDay,
|
|
269
|
+
year: selectedDay.year,
|
|
270
|
+
} });
|
|
271
|
+
}
|
|
272
|
+
else if ((startDate && !endDate && selectedDate.getTime() > startDate.getTime()) ||
|
|
273
|
+
(startDate && selectedDate.getTime() > startDate.getTime()) ||
|
|
274
|
+
(endDate && startDate && selectedDate.getTime() > endDate.getTime())) {
|
|
275
|
+
const _month = selectedDay.month + 1 > 12 ? 11 : selectedDay.month + 1;
|
|
276
|
+
this.endDay = Number(oneToTwoDigit(selectedDay.date));
|
|
277
|
+
this.endMonth = _month;
|
|
278
|
+
this.endYear = selectedDay.year;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
toggleMonthView() {
|
|
282
|
+
if (this.prevMode != Mode.Month) {
|
|
283
|
+
this.prevMode = Mode.Month;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
toggleYearView() {
|
|
287
|
+
if (this.prevMode != Mode.Year) {
|
|
288
|
+
this.prevMode = Mode.Year;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
inputChanged(inputChangedEvent) {
|
|
292
|
+
this.dateValue = inputChangedEvent.detail.value;
|
|
293
|
+
}
|
|
294
|
+
onFocus() {
|
|
295
|
+
this.openedCalendar = true;
|
|
296
|
+
}
|
|
297
|
+
renderContainer(isRange = false) {
|
|
298
|
+
switch (this.prevMode) {
|
|
299
|
+
case Mode.Day:
|
|
300
|
+
return renderDays(this.weekdaysShort, this.navigationDates, this.selectDay, {
|
|
301
|
+
curentYear: this.currentYear,
|
|
302
|
+
currentMonth: this.currentMonth,
|
|
303
|
+
currentDay: this.currentDay,
|
|
304
|
+
endYear: this.endYear,
|
|
305
|
+
endMonth: this.endMonth,
|
|
306
|
+
endDay: this.endDay,
|
|
307
|
+
}, isRange, this.days);
|
|
308
|
+
case Mode.Month:
|
|
309
|
+
return renderMonthsTemplate(this.monthsShort, this.currentMonth, this.selectMonth);
|
|
310
|
+
case Mode.Year:
|
|
311
|
+
return renderYearsTemplate(this.navigationDates.start.year, this.selectYear);
|
|
312
|
+
default:
|
|
313
|
+
return nothing;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
renderCalendarHeader() {
|
|
317
|
+
return html `
|
|
318
|
+
<div class="year-month-header">
|
|
319
|
+
${this.mode !== Mode.Year
|
|
320
|
+
? html `<hy-button @click=${this.toggleMonthView} class="toggle-month-view">
|
|
321
|
+
${capitalizeFirstLetter(this.months[this.navigationDates.start.month - 1])}
|
|
322
|
+
${this.range && this.prevMode === Mode.Day
|
|
323
|
+
? ' - ' + capitalizeFirstLetter(this.months[this.navigationDates.start.month])
|
|
324
|
+
: nothing}
|
|
325
|
+
</hy-button> `
|
|
326
|
+
: nothing}
|
|
327
|
+
|
|
328
|
+
<div class="current-year-container">
|
|
329
|
+
<hy-button class="toggle-year-view" @click=${this.toggleYearView}>${this.navigationDates.start.year}</hy-button>
|
|
330
|
+
<div class="year-icons-toggler">
|
|
331
|
+
<hy-button class="next-year" .icon=${['caret-up']} @click=${() => this.nextYear()}></hy-button>
|
|
332
|
+
<hy-button class="previous-year" .icon=${['caret-down']} @click=${() => this.prevYear()}></hy-button>
|
|
333
|
+
</div>
|
|
334
|
+
</div>
|
|
335
|
+
</div>
|
|
336
|
+
</div>
|
|
337
|
+
`;
|
|
338
|
+
}
|
|
339
|
+
renderCalendar() {
|
|
340
|
+
return html ` <div
|
|
341
|
+
class="calendar-container ${this.range && this.prevMode === Mode.Day ? 'calendar-container-range' : EMPTY_STRING}"
|
|
342
|
+
>
|
|
343
|
+
<div class="calendar-header">
|
|
344
|
+
<hy-button
|
|
345
|
+
type="text"
|
|
346
|
+
class="header-prev-button prev-month"
|
|
347
|
+
.icon="${['angle-left']}"
|
|
348
|
+
@click=${() => this.prevMonth()}
|
|
349
|
+
></hy-button>
|
|
350
|
+
${this.renderCalendarHeader()}
|
|
351
|
+
|
|
352
|
+
<hy-button
|
|
353
|
+
type="text"
|
|
354
|
+
class="header-next-button next-month"
|
|
355
|
+
.icon="${['angle-right']}"
|
|
356
|
+
@click=${() => this.nextMonth()}
|
|
357
|
+
></hy-button>
|
|
358
|
+
</div>
|
|
359
|
+
<span class="day-containers">
|
|
360
|
+
${this.renderContainer()}
|
|
361
|
+
${this.range && this.prevMode === Mode.Day ? this.renderContainer(this.range) : nothing}
|
|
362
|
+
</span>
|
|
363
|
+
</div>`;
|
|
364
|
+
}
|
|
365
|
+
disconnectedCallback() {
|
|
366
|
+
super.disconnectedCallback();
|
|
367
|
+
document.removeEventListener('click', this._onClickOutside.bind(this));
|
|
368
|
+
document.removeEventListener('scroll', this.positionCalendar);
|
|
369
|
+
}
|
|
370
|
+
render() {
|
|
371
|
+
return html `
|
|
372
|
+
<hy-input
|
|
373
|
+
id="date-input"
|
|
374
|
+
.type=${this.INPUT_TYPE}
|
|
375
|
+
.value=${this.inputFieldValue}
|
|
376
|
+
.size=${this.size}
|
|
377
|
+
.state=${this.state}
|
|
378
|
+
.disabled=${this.disabled}
|
|
379
|
+
@valueChange=${this.inputChanged}
|
|
380
|
+
@focus=${this.onFocus}
|
|
381
|
+
>
|
|
382
|
+
${this.label ? html ` <span slot="label">${this.label}</span> ` : nothing}
|
|
383
|
+
${this.helper ? html ` <span slot="helper-text">${this.helper}</span> ` : nothing}
|
|
384
|
+
</hy-input>
|
|
385
|
+
${this.openedCalendar ? this.renderCalendar() : nothing}
|
|
386
|
+
`;
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
HyDatePickerElement.styles = styles;
|
|
390
|
+
__decorate([
|
|
391
|
+
property({ type: String })
|
|
392
|
+
], HyDatePickerElement.prototype, "name", void 0);
|
|
393
|
+
__decorate([
|
|
394
|
+
property({ type: String })
|
|
395
|
+
], HyDatePickerElement.prototype, "locale", void 0);
|
|
396
|
+
__decorate([
|
|
397
|
+
property({ reflect: true })
|
|
398
|
+
], HyDatePickerElement.prototype, "mode", void 0);
|
|
399
|
+
__decorate([
|
|
400
|
+
property({ type: Boolean })
|
|
401
|
+
], HyDatePickerElement.prototype, "range", void 0);
|
|
402
|
+
__decorate([
|
|
403
|
+
state()
|
|
404
|
+
], HyDatePickerElement.prototype, "prevMode", void 0);
|
|
405
|
+
__decorate([
|
|
406
|
+
property({ reflect: true, type: Boolean })
|
|
407
|
+
], HyDatePickerElement.prototype, "openedCalendar", void 0);
|
|
408
|
+
__decorate([
|
|
409
|
+
state()
|
|
410
|
+
], HyDatePickerElement.prototype, "monthsShort", void 0);
|
|
411
|
+
__decorate([
|
|
412
|
+
state()
|
|
413
|
+
], HyDatePickerElement.prototype, "months", void 0);
|
|
414
|
+
__decorate([
|
|
415
|
+
state()
|
|
416
|
+
], HyDatePickerElement.prototype, "days", void 0);
|
|
417
|
+
__decorate([
|
|
418
|
+
state()
|
|
419
|
+
], HyDatePickerElement.prototype, "weekdaysShort", void 0);
|
|
420
|
+
__decorate([
|
|
421
|
+
state()
|
|
422
|
+
], HyDatePickerElement.prototype, "currentYear", void 0);
|
|
423
|
+
__decorate([
|
|
424
|
+
state()
|
|
425
|
+
], HyDatePickerElement.prototype, "currentDay", void 0);
|
|
426
|
+
__decorate([
|
|
427
|
+
state()
|
|
428
|
+
], HyDatePickerElement.prototype, "currentMonth", void 0);
|
|
429
|
+
__decorate([
|
|
430
|
+
state()
|
|
431
|
+
], HyDatePickerElement.prototype, "endYear", void 0);
|
|
432
|
+
__decorate([
|
|
433
|
+
state()
|
|
434
|
+
], HyDatePickerElement.prototype, "endDay", void 0);
|
|
435
|
+
__decorate([
|
|
436
|
+
state()
|
|
437
|
+
], HyDatePickerElement.prototype, "endMonth", void 0);
|
|
438
|
+
__decorate([
|
|
439
|
+
state()
|
|
440
|
+
], HyDatePickerElement.prototype, "inputFieldValue", void 0);
|
|
441
|
+
__decorate([
|
|
442
|
+
property({ type: String })
|
|
443
|
+
], HyDatePickerElement.prototype, "fieldFormat", void 0);
|
|
444
|
+
__decorate([
|
|
445
|
+
property({ type: String })
|
|
446
|
+
], HyDatePickerElement.prototype, "dateValue", void 0);
|
|
447
|
+
__decorate([
|
|
448
|
+
state()
|
|
449
|
+
], HyDatePickerElement.prototype, "navigationDates", void 0);
|
|
450
|
+
__decorate([
|
|
451
|
+
query('#date-input')
|
|
452
|
+
], HyDatePickerElement.prototype, "dateInput", void 0);
|
|
453
|
+
__decorate([
|
|
454
|
+
query('.calendar-container')
|
|
455
|
+
], HyDatePickerElement.prototype, "calendarContainer", void 0);
|
|
456
|
+
__decorate([
|
|
457
|
+
state()
|
|
458
|
+
], HyDatePickerElement.prototype, "daysPresentation", void 0);
|
|
459
|
+
__decorate([
|
|
460
|
+
property()
|
|
461
|
+
], HyDatePickerElement.prototype, "size", void 0);
|
|
462
|
+
__decorate([
|
|
463
|
+
property()
|
|
464
|
+
], HyDatePickerElement.prototype, "state", void 0);
|
|
465
|
+
__decorate([
|
|
466
|
+
property()
|
|
467
|
+
], HyDatePickerElement.prototype, "label", void 0);
|
|
468
|
+
__decorate([
|
|
469
|
+
property()
|
|
470
|
+
], HyDatePickerElement.prototype, "helper", void 0);
|
|
471
|
+
__decorate([
|
|
472
|
+
property({ reflect: true, type: Boolean })
|
|
473
|
+
], HyDatePickerElement.prototype, "disabled", void 0);
|
|
474
|
+
HyDatePickerElement = __decorate([
|
|
475
|
+
customElement('hy-datepicker')
|
|
476
|
+
], HyDatePickerElement);
|
|
477
|
+
export { HyDatePickerElement };
|
|
478
|
+
//# sourceMappingURL=date-picker.component.js.map
|
|
@@ -0,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CAAC,eAAe,CAAC;GAClB,mBAAmB,CA0d/B;SA1dY,mBAAmB","sourcesContent":["/* eslint-disable no-case-declarations */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/**\n * @license\n * Copyright 2023 Google Laabidi Aymen\n * SPDX-License-Identifier: MIT\n */\n\nimport {LitElement, html, nothing, PropertyValues, TemplateResult} from 'lit';\nimport {customElement, property, query, state} from 'lit/decorators.js';\nimport dayjs from 'dayjs';\nimport '../input/input.component.js';\nimport '../icon/icon.component.js';\nimport '../button/hy-button.component.js';\nimport {getMonthDetails} from './core/month.helper.js';\nimport {styles} from './date-picker.style.js';\nimport {IDayPresentation, INavigationDate, Mode} from './datepicker.types.js';\nimport {renderMonthsTemplate} from './templates/months.template.js';\nimport {renderYearsTemplate} from './templates/years.template.js';\nimport {renderDays} from './templates/days.template.js';\nimport {oneToTwoDigit} from './core/formatter.js';\nimport {capitalizeFirstLetter} from './core/string.helper.js';\nimport './core/locale.helper.js';\nimport {INPUT_SIZE, INPUT_STATE} from '../input/input.constant.js';\nimport {EMPTY_STRING} from './constants.js';\n\n@customElement('hy-datepicker')\nexport class HyDatePickerElement extends LitElement {\n today = dayjs();\n\n @property({type: String})\n name!: string;\n @property({type: String})\n locale = 'en';\n\n @property({reflect: true})\n mode = Mode.Day;\n\n @property({type: Boolean})\n range = false;\n\n @state()\n prevMode = this.mode;\n\n @property({reflect: true, type: Boolean})\n openedCalendar = false;\n\n @state()\n monthsShort = dayjs().localeData().monthsShort()\n \n @state()\n months = dayjs().localeData().months();\n\n @state()\n days = dayjs().localeData().weekdays();\n\n @state()\n weekdaysShort = dayjs().localeData().weekdaysShort();\n\n @state()\n currentYear = this.today.year();\n\n @state()\n currentDay = this.today.date();\n\n @state()\n currentMonth = this.today.month() + 1;\n\n @state()\n endYear!: number;\n\n @state()\n endDay!: number;\n\n @state()\n endMonth!: number;\n\n @state()\n inputFieldValue = '';\n\n @property({type: String})\n fieldFormat = 'DD/MM/YYYY';\n\n @property({type: String})\n dateValue = '';\n\n @state()\n navigationDates: INavigationDate = {\n start: {\n year: this.currentYear,\n month: this.currentMonth,\n day: this.currentDay,\n },\n };\n\n @query('#date-input')\n dateInput!: HTMLElement;\n\n @query('.calendar-container')\n calendarContainer!: HTMLElement;\n\n @state()\n daysPresentation!: IDayPresentation[];\n\n @property()\n size = INPUT_SIZE.Medium;\n\n @property()\n state = INPUT_STATE.Default;\n\n @property()\n label!: string;\n\n @property()\n helper!: string;\n\n @property({reflect: true, type: Boolean})\n disabled = false;\n\n INPUT_TYPE = 'calendar';\n\n static override styles = styles;\n\n override connectedCallback() {\n super.connectedCallback();\n document.addEventListener('click', this._onClickOutside.bind(this));\n document.addEventListener('scroll', this.positionCalendar);\n }\n override firstUpdated() {\n if (this.range) {\n this.endYear = this.currentYear;\n this.endMonth = this.currentMonth;\n this.endDay = this.currentDay;\n }\n this.fillInputField()\n }\n override willUpdate(changedProperties: PropertyValues) {\n if(changedProperties.has('fieldFormat')){\n this.fillInputField()\n }\n if (changedProperties.has('openedCalendar') && this.openedCalendar) {\n this.daysPresentation = getMonthDetails(this.currentYear, this.currentMonth - 1, this.days);\n this.positionCalendar();\n }\n if (changedProperties.has('dateValue') && this.dateValue) {\n const dateObj = dayjs(this.dateValue, this.fieldFormat, true);\n if (dateObj.isValid()) {\n const {years, months, date} = dateObj.toObject();\n this.currentYear = years;\n this.currentMonth = months + 1;\n this.currentDay = date;\n this.navigationDates = {...this.navigationDates, start: {year: years, month: months + 1, day: date}};\n }\n }\n if (\n (changedProperties.has('currentDay') && changedProperties.get('currentDay')) ||\n (changedProperties.has('currentMonth') && changedProperties.get('currentMonth')) ||\n (changedProperties.has('currentYear') && changedProperties.get('currentYear'))\n ) { \n this.fillInputField()\n this.dispatchDateChange();\n }\n if (changedProperties.has('locale')) {\n this.updateLocale(this.locale);\n }\n }\n\n _onClickOutside(e: MouseEvent) {\n if (!e.composedPath().includes(this)) {\n this.openedCalendar = false;\n }\n }\n\n toggleCaldendar() {\n this.openedCalendar = !this.openedCalendar;\n }\n fillInputField(){\n this.inputFieldValue = this.range\n ? dayjs(`${this.currentYear}-${this.currentMonth}-${this.currentDay}`).format(this.fieldFormat) +\n '-' +\n dayjs(`${this.endYear}-${this.endMonth}-${this.endDay}`).format(this.fieldFormat)\n : dayjs(`${this.currentYear}-${this.currentMonth}-${this.currentDay}`).format(this.fieldFormat);\n }\n\n dispatchDateChange() {\n this.dispatchEvent(\n new CustomEvent('date-change', {bubbles: true, composed: true, detail: {value: this.inputFieldValue}})\n );\n }\n\n positionCalendar = async () => {\n if (this.openedCalendar) {\n await this.updateComplete;\n const dateInput = this.shadowRoot!.querySelector('#date-input')!;\n const calendarHeight = this.calendarContainer.getBoundingClientRect().height;\n const dateInputRect = dateInput.getBoundingClientRect();\n const availableBottomSpace = window.visualViewport!.height - dateInputRect.bottom;\n const availableTopSpace = dateInputRect.top;\n this.calendarContainer.style.removeProperty('top');\n this.calendarContainer.style.removeProperty('position');\n if (calendarHeight > availableBottomSpace && availableTopSpace > calendarHeight) {\n const inputElement = dateInput.shadowRoot!.querySelector('#input-container')!;\n const inputBorderTop = +getComputedStyle(inputElement).borderTopWidth.split('px')[0];\n this.calendarContainer.style.top = `${availableTopSpace - calendarHeight - inputBorderTop}px`;\n this.calendarContainer.style.position = 'fixed';\n }\n }\n };\n\n updateLocale(locale: string): void {\n dayjs.locale(locale);\n this.monthsShort = dayjs().localeData().monthsShort();\n this.months = dayjs().localeData().months();\n this.weekdaysShort = dayjs().localeData().weekdaysShort();\n this.days = dayjs().localeData().weekdays();\n }\n\n nextYear() {\n let startYear = this.navigationDates.start.year;\n this.navigationDates = {\n ...this.navigationDates,\n start: {\n ...this.navigationDates.start,\n year: ++startYear,\n },\n };\n }\n\n prevYear() {\n let startYear = this.navigationDates.start.year;\n this.navigationDates = {\n ...this.navigationDates,\n start: {\n ...this.navigationDates.start,\n year: --startYear,\n },\n };\n }\n\n nextMonth() {\n const {start} = this.navigationDates;\n let startMonth = start.month;\n let startYear = start.year;\n if ((startMonth == 11 && this.range) || startMonth == 12) {\n startMonth = 1;\n startYear++;\n } else {\n startMonth++;\n }\n this.navigationDates = {\n ...this.navigationDates,\n start: {\n day: this.navigationDates.start.day,\n month: startMonth,\n year: startYear,\n },\n };\n }\n\n prevMonth() {\n const {start} = this.navigationDates;\n let startMonth = start.month;\n let startYear = start.year;\n if (startMonth >= 2) {\n startMonth = --startMonth;\n } else {\n if (this.range) startMonth = 11;\n else startMonth = 12;\n startYear = --startYear;\n }\n\n this.navigationDates = {\n ...this.navigationDates,\n start: {\n day: this.navigationDates.start.day,\n year: startYear,\n month: startMonth,\n },\n };\n }\n\n selectMonth = (selectedMonth: number): void => {\n const _month = selectedMonth + 1 > 11 && this.range ? 11 : selectedMonth + 1;\n this.navigationDates.start.month = _month;\n this.navigationDates = {...this.navigationDates};\n //TODO: handle mainMode\n if (this.mode == Mode.Month) {\n this.currentDay = 1;\n this.openedCalendar = false;\n } else {\n this.prevMode = Mode.Day;\n }\n };\n\n selectYear = (selectedYear: number): void => {\n this.navigationDates = {\n ...this.navigationDates,\n start: {...this.navigationDates.start, year: selectedYear},\n };\n\n //TODO: handle mainMode\n if (this.mode == Mode.Year) {\n this.currentDay = 1;\n this.currentMonth = 1;\n this.openedCalendar = false;\n } else {\n this.prevMode = Mode.Month;\n }\n };\n\n selectDay = (selectedDay: IDayPresentation): void => {\n if (!this.range) {\n this.currentDay = Number(oneToTwoDigit(selectedDay.date));\n this.currentMonth = selectedDay.month + 1;\n this.currentYear = selectedDay.year;\n const _month = this.currentMonth > 11 && this.range ? 11 : this.currentMonth;\n this.navigationDates = {\n ...this.navigationDates,\n start: {\n month: _month,\n day: this.currentDay,\n year: selectedDay.year,\n },\n };\n } else {\n this.selectDateRange(selectedDay);\n }\n\n //TODO: handle mainMode\n this.prevMode = Mode.Day;\n if (!this.range) this.openedCalendar = false;\n };\n selectDateRange(selectedDay: IDayPresentation) {\n const selectedDateDay = selectedDay.date;\n const selectedDateMonth = selectedDay.month;\n const selectedDateYear = selectedDay.year;\n const selectedDate = new Date(selectedDateYear, selectedDateMonth, selectedDateDay);\n\n const endDateDay = this.endDay;\n const endDateMonth = this.endMonth - 1;\n const endDateYear = this.endYear;\n const endDate = new Date(endDateYear, endDateMonth, endDateDay);\n\n const startDateDay = this.currentDay;\n const startDateMonth = this.currentMonth - 1;\n const startDateYear = this.currentYear;\n const startDate = new Date(startDateYear, startDateMonth, startDateDay);\n\n if (\n !startDate ||\n (endDate &&\n startDate &&\n (selectedDate.getTime() < startDate.getTime() || selectedDate.getTime() < endDate.getTime())) ||\n (startDate && !endDate && selectedDate.getTime() < startDate.getTime())\n ) {\n this.currentDay = Number(oneToTwoDigit(selectedDay.date));\n this.currentMonth = selectedDay.month + 1;\n this.currentYear = selectedDay.year;\n const _month = this.currentMonth > 11 && this.range ? 11 : this.currentMonth;\n this.navigationDates = {\n ...this.navigationDates,\n start: {\n month: _month,\n day: this.currentDay,\n year: selectedDay.year,\n },\n };\n } else if (\n (startDate && !endDate && selectedDate.getTime() > startDate.getTime()) ||\n (startDate && selectedDate.getTime() > startDate.getTime()) ||\n (endDate && startDate && selectedDate.getTime() > endDate.getTime())\n ) {\n const _month = selectedDay.month + 1 > 12 ? 11 : selectedDay.month + 1;\n this.endDay = Number(oneToTwoDigit(selectedDay.date));\n this.endMonth = _month;\n this.endYear = selectedDay.year;\n }\n }\n toggleMonthView(): void {\n if (this.prevMode != Mode.Month) {\n this.prevMode = Mode.Month;\n }\n }\n\n toggleYearView(): void {\n if (this.prevMode != Mode.Year) {\n this.prevMode = Mode.Year;\n }\n }\n inputChanged(inputChangedEvent: CustomEvent): void {\n this.dateValue = inputChangedEvent.detail.value;\n }\n onFocus() {\n this.openedCalendar = true;\n }\n\n renderContainer(isRange = false): TemplateResult | typeof nothing {\n switch (this.prevMode) {\n case Mode.Day:\n return renderDays(\n this.weekdaysShort,\n this.navigationDates,\n this.selectDay,\n {\n curentYear: this.currentYear,\n currentMonth: this.currentMonth,\n currentDay: this.currentDay,\n endYear: this.endYear,\n endMonth: this.endMonth,\n endDay: this.endDay,\n },\n isRange,\n this.days\n );\n case Mode.Month:\n return renderMonthsTemplate(this.monthsShort, this.currentMonth, this.selectMonth);\n case Mode.Year:\n return renderYearsTemplate(this.navigationDates.start.year, this.selectYear);\n default:\n return nothing;\n }\n }\n\n renderCalendarHeader() {\n return html`\n <div class=\"year-month-header\">\n ${\n this.mode !== Mode.Year\n ? html`<hy-button @click=${this.toggleMonthView} class=\"toggle-month-view\">\n ${capitalizeFirstLetter(this.months[this.navigationDates.start.month - 1])}\n ${this.range && this.prevMode === Mode.Day\n ? ' - ' + capitalizeFirstLetter(this.months[this.navigationDates.start.month])\n : nothing}\n </hy-button> `\n : nothing\n } \n \n <div class=\"current-year-container\">\n <hy-button class=\"toggle-year-view\" @click=${this.toggleYearView}>${\n this.navigationDates.start.year\n }</hy-button>\n <div class=\"year-icons-toggler\">\n <hy-button class=\"next-year\" .icon=${['caret-up']} @click=${() => this.nextYear()}></hy-button>\n <hy-button class=\"previous-year\" .icon=${['caret-down']} @click=${() => this.prevYear()}></hy-button>\n </div>\n </div>\n </div>\n </div>\n `;\n }\n\n renderCalendar() {\n return html` <div\n class=\"calendar-container ${this.range && this.prevMode === Mode.Day ? 'calendar-container-range' : EMPTY_STRING}\"\n >\n <div class=\"calendar-header\">\n <hy-button\n type=\"text\"\n class=\"header-prev-button prev-month\"\n .icon=\"${['angle-left']}\"\n @click=${() => this.prevMonth()}\n ></hy-button>\n ${this.renderCalendarHeader()}\n\n <hy-button\n type=\"text\"\n class=\"header-next-button next-month\"\n .icon=\"${['angle-right']}\"\n @click=${() => this.nextMonth()}\n ></hy-button>\n </div>\n <span class=\"day-containers\">\n ${this.renderContainer()}\n ${this.range && this.prevMode === Mode.Day ? this.renderContainer(this.range) : nothing}\n </span>\n </div>`;\n }\n override disconnectedCallback() {\n super.disconnectedCallback();\n document.removeEventListener('click', this._onClickOutside.bind(this));\n document.removeEventListener('scroll', this.positionCalendar);\n }\n\n override render(): TemplateResult {\n return html`\n <hy-input\n id=\"date-input\"\n .type=${this.INPUT_TYPE}\n .value=${this.inputFieldValue}\n .size=${this.size}\n .state=${this.state}\n .disabled=${this.disabled}\n @valueChange=${this.inputChanged}\n @focus=${this.onFocus}\n >\n ${this.label ? html` <span slot=\"label\">${this.label}</span> ` : nothing}\n ${this.helper ? html` <span slot=\"helper-text\">${this.helper}</span> ` : nothing}\n </hy-input>\n ${this.openedCalendar ? this.renderCalendar() : nothing}\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'hy-datepicker': HyDatePickerElement;\n }\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n 'hy-datepicker':\n | React.DetailedHTMLProps<React.HTMLAttributes<HyDatePickerElement>, HyDatePickerElement>\n | Partial<HyDatePickerElement>;\n }\n }\n}"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-picker.style.d.ts","sourceRoot":"","sources":["../../../src/components/datepicker/date-picker.style.ts"],"names":[],"mappings":"AA8NA,eAAO,MAAM,MAAM,2BAAmB,CAAC"}
|